From 2abd39052da6f5b050bb29232548f17c2ea7e2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20SAUVAGE?= Date: Wed, 27 Feb 2013 16:39:16 +0100 Subject: [PATCH] Link in description & option to invert link/permalink. Patch for issue https://github.com/sebsauvage/Shaarli/issues/19 Now: * The (perma)link is added at the bottom of description. * If "permalinks" is added in URL parameters, link/permalinks will be swapped. eg. * Normal link in title + permalink in description: http://mysite.com/shaarli/?do=rss * Permalink in title + normal link in description : http://mysite.com/shaarli/?do=rss&permalinks It works for the ATOM feed too. (Happy ? :-D ) --- index.php | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 448c23a..b7ed370 100644 --- a/index.php +++ b/index.php @@ -858,6 +858,10 @@ function showRSS() { header('Content-Type: application/rss+xml; charset=utf-8'); + // $usepermalink : If true, use permalink instead of final link. + // User just has to add 'permalink' in URL parameters. eg. http://mysite.com/shaarli/?do=rss&permalinks + $usepermalinks = isset($_GET['permalinks']); + // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new pageCache(pageUrl(),startsWith($query,'do=rss') && !isLoggedIn()); @@ -892,13 +896,22 @@ function showRSS() $rfc822date = linkdate2rfc822($link['linkdate']); $absurl = htmlspecialchars($link['url']); if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute - echo ''.htmlspecialchars($link['title']).''.$guid.''.$absurl.''; + if ($usepermalinks===true) + echo ''.htmlspecialchars($link['title']).''.$guid.''.$guid.''; + else + echo ''.htmlspecialchars($link['title']).''.$guid.''.$absurl.''; if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo ''.htmlspecialchars($rfc822date)."\n"; if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) { foreach(explode(' ',$link['tags']) as $tag) { echo ''.htmlspecialchars($tag).''."\n"; } } - echo ''."\n\n"; + + // Add permalink in description + $descriptionlink = '(Permalink)'; + // If user wants permalinks first, put the final link in description + if ($usepermalinks===true) $descriptionlink = '(Link)'; + if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; + echo ''."\n
\n"; $i++; } echo ''; @@ -914,6 +927,10 @@ function showATOM() { header('Content-Type: application/atom+xml; charset=utf-8'); + // $usepermalink : If true, use permalink instead of final link. + // User just has to add 'permalink' in URL parameters. eg. http://mysite.com/shaarli/?do=atom&permalinks + $usepermalinks = isset($_GET['permalinks']); + // Cache system $query = $_SERVER["QUERY_STRING"]; $cache = new pageCache(pageUrl(),startsWith($query,'do=atom') && !isLoggedIn()); @@ -942,9 +959,20 @@ function showATOM() $latestDate = max($latestDate,$iso8601date); $absurl = htmlspecialchars($link['url']); if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute - $entries.=''.htmlspecialchars($link['title']).''.$guid.''; + $entries.=''.htmlspecialchars($link['title']).''; + if ($usepermalinks===true) + $entries.=''.$guid.''; + else + $entries.=''.$guid.''; if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.=''.htmlspecialchars($iso8601date).''; - $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))))."\n"; + + // Add permalink in description + $descriptionlink = htmlspecialchars('(Permalink)'); + // If user wants permalinks first, put the final link in description + if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(Link)'); + if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; + + $entries.=''.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."\n"; if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) { foreach(explode(' ',$link['tags']) as $tag)