From d664544a2ef6eb580c22041cc9b02574dd369108 Mon Sep 17 00:00:00 2001 From: Kevin P Date: Sun, 4 Oct 2015 13:27:39 +0200 Subject: [PATCH] allow setting custom thumbnails --- index.php | 12 +++++++----- tpl/editlink.html | 3 ++- tpl/linklist.html | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index c102e4222..6e9cfa70c 100644 --- a/index.php +++ b/index.php @@ -1104,7 +1104,7 @@ function showDailyRSS() { $l = $LINKSDB[$linkdate]; $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description'])))); - $l['thumbnail'] = thumbnail($l['url']); + $l['thumbnail'] = thumbnail($l['url'], isset($l['thumb']) ? $l['thumb'] : False); $l['localdate']=linkdate2locale($l['linkdate']); if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute $links[$linkdate]=$l; @@ -1152,7 +1152,7 @@ function showDaily() uasort($taglist, 'strcasecmp'); $linksToDisplay[$key]['taglist']=$taglist; $linksToDisplay[$key]['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); - $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']); + $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url'], isset($link['thumb']) ? $link['thumb'] : False); } /* We need to spread the articles on 3 columns. @@ -1232,7 +1232,7 @@ function renderPage() foreach($links as $link) { $permalink='?'.htmlspecialchars(smallhash($link['linkdate']),ENT_QUOTES); - $thumb=lazyThumbnail($link['url'],$permalink); + $thumb=lazyThumbnail($link['url'], isset($link['thumb']) ? $link['thumb'] : False); if ($thumb!='') // Only output links which have a thumbnail. { $link['thumbnail']=$thumb; // Thumbnail HTML code. @@ -1482,10 +1482,11 @@ function renderPage() $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. $linkdate=$_POST['lf_linkdate']; $url = trim($_POST['lf_url']); + $thumb = trim($_POST['lf_thumb']); if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?')) $url = 'http://'.$url; $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), - 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); + 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags),'thumb'=>$thumb); if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. $LINKSDB[$linkdate] = $link; $LINKSDB->savedb(); // save to disk @@ -1885,7 +1886,8 @@ function buildLinkList($PAGE,$LINKSDB) function computeThumbnail($url,$href=false) { if (!$GLOBALS['config']['ENABLE_THUMBNAILS']) return array(); - if ($href==false) $href=$url; + if ($href!=false and !empty($href)) $url=$href; + // For most hosts, the URL of the thumbnail can be easily deduced from the URL of the link. // (eg. http://www.youtube.com/watch?v=spVypYk4kto ---> http://img.youtube.com/vi/spVypYk4kto/default.jpg ) diff --git a/tpl/editlink.html b/tpl/editlink.html index 4a2c30cc4..0e62e84a1 100644 --- a/tpl/editlink.html +++ b/tpl/editlink.html @@ -16,6 +16,7 @@ Title

Description

Tags

+ Thumbnail

{if condition="($link_is_new && $GLOBALS['privateLinkByDefault']==true) || $link.private == true"}  
@@ -41,4 +42,4 @@ {/if} - \ No newline at end of file + diff --git a/tpl/linklist.html b/tpl/linklist.html index ddc38cb0a..a1893f50e 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html @@ -31,7 +31,7 @@ {loop="links"} -
{$value.url|thumbnail}
+
{function="thumbnail($value['url'], isset($value['thumb']) ? $value['thumb'] : False)"}