aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-02-27 16:39:16 +0100
committerSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-02-27 16:39:16 +0100
commit2abd39052da6f5b050bb29232548f17c2ea7e2ee (patch)
tree3315bfcea78a5607a4d96b8927a2b891102ca4a2
parent30b0672d0437578d8eaec8b9cc74c2f1700cf484 (diff)
downloadShaarli-2abd39052da6f5b050bb29232548f17c2ea7e2ee.tar.gz
Shaarli-2abd39052da6f5b050bb29232548f17c2ea7e2ee.tar.zst
Shaarli-2abd39052da6f5b050bb29232548f17c2ea7e2ee.zip
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 )
-rw-r--r--index.php36
1 files changed, 32 insertions, 4 deletions
diff --git a/index.php b/index.php
index 448c23a6..b7ed370d 100644
--- a/index.php
+++ b/index.php
@@ -858,6 +858,10 @@ function showRSS()
858{ 858{
859 header('Content-Type: application/rss+xml; charset=utf-8'); 859 header('Content-Type: application/rss+xml; charset=utf-8');
860 860
861 // $usepermalink : If true, use permalink instead of final link.
862 // User just has to add 'permalink' in URL parameters. eg. http://mysite.com/shaarli/?do=rss&permalinks
863 $usepermalinks = isset($_GET['permalinks']);
864
861 // Cache system 865 // Cache system
862 $query = $_SERVER["QUERY_STRING"]; 866 $query = $_SERVER["QUERY_STRING"];
863 $cache = new pageCache(pageUrl(),startsWith($query,'do=rss') && !isLoggedIn()); 867 $cache = new pageCache(pageUrl(),startsWith($query,'do=rss') && !isLoggedIn());
@@ -892,13 +896,22 @@ function showRSS()
892 $rfc822date = linkdate2rfc822($link['linkdate']); 896 $rfc822date = linkdate2rfc822($link['linkdate']);
893 $absurl = htmlspecialchars($link['url']); 897 $absurl = htmlspecialchars($link['url']);
894 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute 898 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
895 echo '<item><title>'.htmlspecialchars($link['title']).'</title><guid>'.$guid.'</guid><link>'.$absurl.'</link>'; 899 if ($usepermalinks===true)
900 echo '<item><title>'.htmlspecialchars($link['title']).'</title><guid>'.$guid.'</guid><link>'.$guid.'</link>';
901 else
902 echo '<item><title>'.htmlspecialchars($link['title']).'</title><guid>'.$guid.'</guid><link>'.$absurl.'</link>';
896 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>\n"; 903 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>\n";
897 if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) 904 if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification)
898 { 905 {
899 foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.htmlspecialchars($pageaddr).'">'.htmlspecialchars($tag).'</category>'."\n"; } 906 foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.htmlspecialchars($pageaddr).'">'.htmlspecialchars($tag).'</category>'."\n"; }
900 } 907 }
901 echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).']]></description>'."\n</item>\n"; 908
909 // Add permalink in description
910 $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)';
911 // If user wants permalinks first, put the final link in description
912 if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)';
913 if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;
914 echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).$descriptionlink.']]></description>'."\n</item>\n";
902 $i++; 915 $i++;
903 } 916 }
904 echo '</channel></rss>'; 917 echo '</channel></rss>';
@@ -914,6 +927,10 @@ function showATOM()
914{ 927{
915 header('Content-Type: application/atom+xml; charset=utf-8'); 928 header('Content-Type: application/atom+xml; charset=utf-8');
916 929
930 // $usepermalink : If true, use permalink instead of final link.
931 // User just has to add 'permalink' in URL parameters. eg. http://mysite.com/shaarli/?do=atom&permalinks
932 $usepermalinks = isset($_GET['permalinks']);
933
917 // Cache system 934 // Cache system
918 $query = $_SERVER["QUERY_STRING"]; 935 $query = $_SERVER["QUERY_STRING"];
919 $cache = new pageCache(pageUrl(),startsWith($query,'do=atom') && !isLoggedIn()); 936 $cache = new pageCache(pageUrl(),startsWith($query,'do=atom') && !isLoggedIn());
@@ -942,9 +959,20 @@ function showATOM()
942 $latestDate = max($latestDate,$iso8601date); 959 $latestDate = max($latestDate,$iso8601date);
943 $absurl = htmlspecialchars($link['url']); 960 $absurl = htmlspecialchars($link['url']);
944 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute 961 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
945 $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title><link href="'.$absurl.'" /><id>'.$guid.'</id>'; 962 $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title>';
963 if ($usepermalinks===true)
964 $entries.='<link href="'.$guid.'" /><id>'.$guid.'</id>';
965 else
966 $entries.='<link href="'.$absurl.'" /><id>'.$guid.'</id>';
946 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>'; 967 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>';
947 $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))))."</content>\n"; 968
969 // Add permalink in description
970 $descriptionlink = htmlspecialchars('(<a href="'.$guid.'">Permalink</a>)');
971 // If user wants permalinks first, put the final link in description
972 if ($usepermalinks===true) $descriptionlink = htmlspecialchars('(<a href="'.$absurl.'">Link</a>)');
973 if (strlen($link['description'])>0) $descriptionlink = '&lt;br&gt;'.$descriptionlink;
974
975 $entries.='<content type="html">'.htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))).$descriptionlink."</content>\n";
948 if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) 976 if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification)
949 { 977 {
950 foreach(explode(' ',$link['tags']) as $tag) 978 foreach(explode(' ',$link['tags']) as $tag)