RSS/Atom: add a parameter to print only the N last links
This commit is contained in:
parent
99954e1290
commit
fbd9e52716
1 changed files with 7 additions and 5 deletions
12
index.php
12
index.php
|
@ -876,7 +876,7 @@ public function days()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
// Ouput the last 50 links in RSS 2.0 format.
|
// Ouput the last N links in RSS 2.0 format.
|
||||||
function showRSS()
|
function showRSS()
|
||||||
{
|
{
|
||||||
header('Content-Type: application/rss+xml; charset=utf-8');
|
header('Content-Type: application/rss+xml; charset=utf-8');
|
||||||
|
@ -898,6 +898,7 @@ function showRSS()
|
||||||
if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
|
if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
|
||||||
elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
|
elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
|
||||||
else $linksToDisplay = $LINKSDB;
|
else $linksToDisplay = $LINKSDB;
|
||||||
|
$nblinksToDisplay = !empty($_GET['nb']) ? max($_GET['nb'] + 0, 1) : 50;
|
||||||
|
|
||||||
$pageaddr=htmlspecialchars(indexUrl());
|
$pageaddr=htmlspecialchars(indexUrl());
|
||||||
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">';
|
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()
|
||||||
}
|
}
|
||||||
$i=0;
|
$i=0;
|
||||||
$keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
|
$keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
|
||||||
while ($i<50 && $i<count($keys))
|
while ($i<$nblinksToDisplay && $i<count($keys))
|
||||||
{
|
{
|
||||||
$link = $linksToDisplay[$keys[$i]];
|
$link = $linksToDisplay[$keys[$i]];
|
||||||
$guid = $pageaddr.'?'.smallHash($link['linkdate']);
|
$guid = $pageaddr.'?'.smallHash($link['linkdate']);
|
||||||
|
@ -945,7 +946,7 @@ function showRSS()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
// Ouput the last 50 links in ATOM format.
|
// Ouput the last N links in ATOM format.
|
||||||
function showATOM()
|
function showATOM()
|
||||||
{
|
{
|
||||||
header('Content-Type: application/atom+xml; charset=utf-8');
|
header('Content-Type: application/atom+xml; charset=utf-8');
|
||||||
|
@ -968,13 +969,14 @@ function showATOM()
|
||||||
if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
|
if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
|
||||||
elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
|
elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
|
||||||
else $linksToDisplay = $LINKSDB;
|
else $linksToDisplay = $LINKSDB;
|
||||||
|
$nblinksToDisplay = !empty($_GET['nb']) ? max($_GET['nb'] + 0, 1) : 50;
|
||||||
|
|
||||||
$pageaddr=htmlspecialchars(indexUrl());
|
$pageaddr=htmlspecialchars(indexUrl());
|
||||||
$latestDate = '';
|
$latestDate = '';
|
||||||
$entries='';
|
$entries='';
|
||||||
$i=0;
|
$i=0;
|
||||||
$keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
|
$keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
|
||||||
while ($i<50 && $i<count($keys))
|
while ($i<$nblinksToDisplay && $i<count($keys))
|
||||||
{
|
{
|
||||||
$link = $linksToDisplay[$keys[$i]];
|
$link = $linksToDisplay[$keys[$i]];
|
||||||
$guid = $pageaddr.'?'.smallHash($link['linkdate']);
|
$guid = $pageaddr.'?'.smallHash($link['linkdate']);
|
||||||
|
@ -2419,4 +2421,4 @@ function invalidateCaches()
|
||||||
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
|
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI)
|
||||||
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
|
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
|
||||||
renderPage();
|
renderPage();
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue