From: Seb Sauvage Date: Tue, 27 Sep 2011 15:25:52 +0000 (+0200) Subject: Version 0.0.21 beta: X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=0adcceeea91382dedecc7dbc3531b2a754142f2a;p=github%2Fshaarli%2FShaarli.git Version 0.0.21 beta: - New: Thumbnails for some services (currently supports: YouTube.com, dailymotion.com, vimeo.com (slow!) and imgur.com). Thumbnails are enabled by default, but you can turn them off (set define('ENABLE_THUMBNAILS',true); to false.) - Changed: Removed the focus on the searchbox (this is cumbersome when you want to browse pages and scroll with the keyboard). --- diff --git a/index.php b/index.php index e1da9bc0..57a64004 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ HTML; - $onload = 'onload="document.searchform.searchterm.focus();"'; - $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>$onload); + $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>''); templatePage($data); exit; // Never remove this one ! All operations below are reserved for logged in user. } @@ -1101,8 +1101,7 @@ HTML;
HTML; - $onload = 'onload="document.searchform.searchterm.focus();"'; - $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>$onload); + $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>''); templatePage($data); exit; } @@ -1262,10 +1261,11 @@ function templateLinkList() if (isLoggedIn()) $actions='
'; $tags=''; if ($link['tags']!='') foreach(explode(' ',$link['tags']) as $tag) { $tags.=''.htmlspecialchars($tag).' '; } - $linklist.='
  • '.htmlspecialchars($title).''.$actions.'
    '; + $linklist.='
  • '.thumbnail($link['url']); + $linklist.='
  • \n"; + $linklist.=''.htmlspecialchars($link['url']).'
    '.$tags."\n"; $i++; } @@ -1286,6 +1286,53 @@ HTML; return $linklist; } +// Returns the HTML code to display a thumbnail for a link. +// Understands various services (youtube.com...) +function thumbnail($url) +{ + if (!ENABLE_THUMBNAILS) return ''; + $domain = parse_url($url,PHP_URL_HOST); + if ($domain=='youtube.com' || $domain=='www.youtube.com') + { + parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract video ID and get thumbnail + if (!empty($params['v'])) return '
    '; + } + if ($domain=='imgur.com') + { + $path = parse_url($url,PHP_URL_PATH); + if (substr_count($path,'/')==1) return '
    '; + } + if ($domain=='i.imgur.com') + { + $pi = pathinfo(parse_url($url,PHP_URL_PATH)); + if (!empty($pi['filename'])) return '
    '; + } + if ($domain=='dailymotion.com' || $domain=='www.dailymotion.com') + { + if (strpos($url,'dailymotion.com/video/')) + { + $thumburl=str_replace('dailymotion.com/video/','dailymotion.com/thumbnail/video/',$url); + return '
    '; + } + } + if ($domain=='vimeo.com') + { + // This is more complex: we have to perform a HTTP request, then parse the result. + // This slows down page generation :-( + // Maybe we should deport this to javascript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098 + $vid = substr(parse_url($url,PHP_URL_PATH),1); + // We allow 2 seconds for Vimeo servers to respond. + list($httpstatus,$headers,$data) = getHTTP('http://vimeo.com/api/v2/video/'.htmlspecialchars($vid).'.php',2); + if (strpos($httpstatus,'200 OK')) + { + $t = unserialize($data); + if (!empty($t[0]['thumbnail_medium'])) return '
    '; + } + } + return ''; // No thumbnail. + +} + // ----------------------------------------------------------------------------------------------- // Template for the whole page. /* Input: $data (associative array). diff --git a/shaarli.css b/shaarli.css index 5a977439..3136755b 100644 --- a/shaarli.css +++ b/shaarli.css @@ -44,7 +44,7 @@ margin: auto; .paging a:active { color:#fff; } #headerform { padding:5 5 5 5; } #editlinkform { padding:5 5 5 15px; width:80%; } -#linklist li { padding:4 10 8 20; border-bottom: 1px solid #bbb;} +#linklist li { padding:4 10 8 20; border-top: 1px solid #bbb; clear:both; } #linklist li.private { background-color: #ccc; border-left:8px solid #888; } .linktitle { font-size:14pt; font-weight:bold; } .linktitle a { text-decoration: none; color:#0000EE; } @@ -63,6 +63,13 @@ border-bottom:1px solid #aaa; border-right:1px solid #aaa; } #cloudtag a { color:black; text-decoration:none; } #installform td { font-size: 10pt; padding:10 5 10 5; } #configform td { color:#ccc; font-size: 10pt; padding:10 5 10 5; } +.thumbnail { float:right; margin-left: 10px; } + +/* If you want thumbnails on the right: +.thumbnail { float:left; margin-right: 10px; } +.linkcontainer { position: static; margin-left:130px; } +*/ + /* Minimal customisation for jQuery widgets */ .ui-autocomplete { background-color:#fff; padding-left:5px;}