diff options
author | BoboTiG <bobotig@gmail.com> | 2013-07-26 08:57:19 +0200 |
---|---|---|
committer | BoboTiG <bobotig@gmail.com> | 2013-07-26 08:57:19 +0200 |
commit | fbd9e52716d2309437dd39760b45d6fa0026cf71 (patch) | |
tree | 7916ee3b682390a4a77e92f0e7d97b6ff31c334e | |
parent | 99954e12900401c5c725e65bce28cc1711653e45 (diff) | |
download | Shaarli-fbd9e52716d2309437dd39760b45d6fa0026cf71.tar.gz Shaarli-fbd9e52716d2309437dd39760b45d6fa0026cf71.tar.zst Shaarli-fbd9e52716d2309437dd39760b45d6fa0026cf71.zip |
RSS/Atom: add a parameter to print only the N last links
-rw-r--r-- | index.php | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -876,7 +876,7 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
876 | } | 876 | } |
877 | 877 | ||
878 | // ------------------------------------------------------------------------------------------ | 878 | // ------------------------------------------------------------------------------------------ |
879 | // Ouput the last 50 links in RSS 2.0 format. | 879 | // Ouput the last N links in RSS 2.0 format. |
880 | function showRSS() | 880 | function showRSS() |
881 | { | 881 | { |
882 | header('Content-Type: application/rss+xml; charset=utf-8'); | 882 | header('Content-Type: application/rss+xml; charset=utf-8'); |
@@ -898,6 +898,7 @@ function showRSS() | |||
898 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); | 898 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); |
899 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 899 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
900 | else $linksToDisplay = $LINKSDB; | 900 | else $linksToDisplay = $LINKSDB; |
901 | $nblinksToDisplay = !empty($_GET['nb']) ? max($_GET['nb'] + 0, 1) : 50; | ||
901 | 902 | ||
902 | $pageaddr=htmlspecialchars(indexUrl()); | 903 | $pageaddr=htmlspecialchars(indexUrl()); |
903 | echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; | 904 | echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; |
@@ -912,7 +913,7 @@ function showRSS() | |||
912 | } | 913 | } |
913 | $i=0; | 914 | $i=0; |
914 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). | 915 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). |
915 | while ($i<50 && $i<count($keys)) | 916 | while ($i<$nblinksToDisplay && $i<count($keys)) |
916 | { | 917 | { |
917 | $link = $linksToDisplay[$keys[$i]]; | 918 | $link = $linksToDisplay[$keys[$i]]; |
918 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | 919 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); |
@@ -945,7 +946,7 @@ function showRSS() | |||
945 | } | 946 | } |
946 | 947 | ||
947 | // ------------------------------------------------------------------------------------------ | 948 | // ------------------------------------------------------------------------------------------ |
948 | // Ouput the last 50 links in ATOM format. | 949 | // Ouput the last N links in ATOM format. |
949 | function showATOM() | 950 | function showATOM() |
950 | { | 951 | { |
951 | header('Content-Type: application/atom+xml; charset=utf-8'); | 952 | header('Content-Type: application/atom+xml; charset=utf-8'); |
@@ -968,13 +969,14 @@ function showATOM() | |||
968 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); | 969 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); |
969 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 970 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
970 | else $linksToDisplay = $LINKSDB; | 971 | else $linksToDisplay = $LINKSDB; |
972 | $nblinksToDisplay = !empty($_GET['nb']) ? max($_GET['nb'] + 0, 1) : 50; | ||
971 | 973 | ||
972 | $pageaddr=htmlspecialchars(indexUrl()); | 974 | $pageaddr=htmlspecialchars(indexUrl()); |
973 | $latestDate = ''; | 975 | $latestDate = ''; |
974 | $entries=''; | 976 | $entries=''; |
975 | $i=0; | 977 | $i=0; |
976 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). | 978 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). |
977 | while ($i<50 && $i<count($keys)) | 979 | while ($i<$nblinksToDisplay && $i<count($keys)) |
978 | { | 980 | { |
979 | $link = $linksToDisplay[$keys[$i]]; | 981 | $link = $linksToDisplay[$keys[$i]]; |
980 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | 982 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); |
@@ -2419,4 +2421,4 @@ if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=d | |||
2419 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) | 2421 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) |
2420 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; | 2422 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; |
2421 | renderPage(); | 2423 | renderPage(); |
2422 | ?> \ No newline at end of file | 2424 | ?> |