aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-09-24 02:10:18 -0700
committerSébastien SAUVAGE <sebsauvage@sebsauvage.net>2013-09-24 02:10:18 -0700
commit85c02058768eb779e33524c5530d842e0513f9ce (patch)
tree83f7b4fe39ea1ccaba59073067b2531782ef7d75
parent0b88c6022d494c9c4de779ef10df3ecd1328a55c (diff)
parentfbd9e52716d2309437dd39760b45d6fa0026cf71 (diff)
downloadShaarli-85c02058768eb779e33524c5530d842e0513f9ce.tar.gz
Shaarli-85c02058768eb779e33524c5530d842e0513f9ce.tar.zst
Shaarli-85c02058768eb779e33524c5530d842e0513f9ce.zip
Merge pull request #112 from BoboTiG/master
RSS/Atom: add a parameter to print only the N last links
-rw-r--r--index.php10
1 files changed, 6 insertions, 4 deletions
diff --git a/index.php b/index.php
index 8567efb5..9446c660 100644
--- a/index.php
+++ b/index.php
@@ -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.
880function showRSS() 880function 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.
949function showATOM() 950function 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']);