Include the whole <item> in dailyRSS
Allow custom date format and title in templates. Also a bit of code style review. Fixes #182
This commit is contained in:
parent
e92f1ba59e
commit
f3b8f9f0f8
2 changed files with 74 additions and 48 deletions
100
index.php
100
index.php
|
@ -853,15 +853,18 @@ function showATOM()
|
||||||
// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
|
// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
|
||||||
// Gives the last 7 days (which have links).
|
// Gives the last 7 days (which have links).
|
||||||
// This RSS feed cannot be filtered.
|
// This RSS feed cannot be filtered.
|
||||||
function showDailyRSS()
|
function showDailyRSS() {
|
||||||
{
|
|
||||||
// Cache system
|
// Cache system
|
||||||
$query = $_SERVER["QUERY_STRING"];
|
$query = $_SERVER["QUERY_STRING"];
|
||||||
$cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn());
|
$cache = new pageCache(pageUrl(), startsWith($query, 'do=dailyrss') && !isLoggedIn());
|
||||||
$cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; }
|
$cached = $cache->cachedVersion();
|
||||||
// If cached was not found (or not usable), then read the database and build the response:
|
if (!empty($cached)) {
|
||||||
|
echo $cached;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Read links from database (and filter private links if used it not logged in).
|
// If cached was not found (or not usable), then read the database and build the response:
|
||||||
|
// Read links from database (and filter private links if used it not logged in).
|
||||||
$LINKSDB = new LinkDB(
|
$LINKSDB = new LinkDB(
|
||||||
$GLOBALS['config']['DATASTORE'],
|
$GLOBALS['config']['DATASTORE'],
|
||||||
isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
|
isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
|
||||||
|
@ -871,60 +874,75 @@ function showDailyRSS()
|
||||||
/* Some Shaarlies may have very few links, so we need to look
|
/* Some Shaarlies may have very few links, so we need to look
|
||||||
back in time (rsort()) until we have enough days ($nb_of_days).
|
back in time (rsort()) until we have enough days ($nb_of_days).
|
||||||
*/
|
*/
|
||||||
$linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; }
|
$linkdates = array();
|
||||||
rsort($linkdates);
|
foreach ($LINKSDB as $linkdate => $value) {
|
||||||
$nb_of_days=7; // We take 7 days.
|
$linkdates[] = $linkdate;
|
||||||
$today=Date('Ymd');
|
}
|
||||||
$days=array();
|
rsort($linkdates);
|
||||||
foreach($linkdates as $linkdate)
|
$nb_of_days = 7; // We take 7 days.
|
||||||
{
|
$today = Date('Ymd');
|
||||||
$day=substr($linkdate,0,8); // Extract day (without time)
|
$days = array();
|
||||||
if (strcmp($day,$today)<0)
|
|
||||||
{
|
foreach ($linkdates as $linkdate) {
|
||||||
if (empty($days[$day])) $days[$day]=array();
|
$day = substr($linkdate, 0, 8); // Extract day (without time)
|
||||||
$days[$day][]=$linkdate;
|
if (strcmp($day,$today) < 0) {
|
||||||
|
if (empty($days[$day])) {
|
||||||
|
$days[$day] = array();
|
||||||
|
}
|
||||||
|
$days[$day][] = $linkdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($days) > $nb_of_days) {
|
||||||
|
break; // Have we collected enough days?
|
||||||
}
|
}
|
||||||
if (count($days)>$nb_of_days) break; // Have we collected enough days?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the RSS feed.
|
// Build the RSS feed.
|
||||||
header('Content-Type: application/rss+xml; charset=utf-8');
|
header('Content-Type: application/rss+xml; charset=utf-8');
|
||||||
$pageaddr=escape(indexUrl());
|
$pageaddr = escape(indexUrl());
|
||||||
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
|
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
|
||||||
echo '<channel><title>Daily - '.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>';
|
echo '<channel>';
|
||||||
echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n";
|
echo '<title>Daily - '. $GLOBALS['title'] . '</title>';
|
||||||
|
echo '<link>'. $pageaddr .'</link>';
|
||||||
|
echo '<description>Daily shared links</description>';
|
||||||
|
echo '<language>en-en</language>';
|
||||||
|
echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
|
||||||
|
|
||||||
foreach($days as $day=>$linkdates) // For each day.
|
// For each day.
|
||||||
{
|
foreach ($days as $day => $linkdates) {
|
||||||
$daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date
|
$daydate = linkdate2timestamp($day.'_000000'); // Full text date
|
||||||
$rfc822date = linkdate2rfc822($day.'_000000');
|
$rfc822date = linkdate2rfc822($day.'_000000');
|
||||||
$absurl=escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
|
$absurl = escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
|
||||||
echo '<item><title>'.$GLOBALS['title'].' - '.$daydate.'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
|
|
||||||
echo '<pubDate>'.escape($rfc822date)."</pubDate>";
|
|
||||||
|
|
||||||
// Build the HTML body of this RSS entry.
|
// Build the HTML body of this RSS entry.
|
||||||
$html='';
|
$html = '';
|
||||||
$href='';
|
$href = '';
|
||||||
$links=array();
|
$links = array();
|
||||||
|
|
||||||
// We pre-format some fields for proper output.
|
// We pre-format some fields for proper output.
|
||||||
foreach($linkdates as $linkdate)
|
foreach ($linkdates as $linkdate) {
|
||||||
{
|
|
||||||
$l = $LINKSDB[$linkdate];
|
$l = $LINKSDB[$linkdate];
|
||||||
$l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable($l['description'])));
|
$l['formatedDescription'] = nl2br(keepMultipleSpaces(text2clickable($l['description'])));
|
||||||
$l['thumbnail'] = thumbnail($l['url']);
|
$l['thumbnail'] = thumbnail($l['url']);
|
||||||
$l['timestamp'] = linkdate2timestamp($l['linkdate']);
|
$l['timestamp'] = linkdate2timestamp($l['linkdate']);
|
||||||
if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute
|
if (startsWith($l['url'], '?')) {
|
||||||
$links[$linkdate]=$l;
|
$l['url'] = indexUrl() . $l['url']; // make permalink URL absolute
|
||||||
}
|
}
|
||||||
|
$links[$linkdate] = $l;
|
||||||
|
}
|
||||||
|
|
||||||
// Then build the HTML for this day:
|
// Then build the HTML for this day:
|
||||||
$tpl = new RainTPL;
|
$tpl = new RainTPL;
|
||||||
$tpl->assign('links',$links);
|
$tpl->assign('title', $GLOBALS['title']);
|
||||||
$html = $tpl->draw('dailyrss',$return_string=true);
|
$tpl->assign('daydate', $daydate);
|
||||||
echo "\n";
|
$tpl->assign('absurl', $absurl);
|
||||||
echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n";
|
$tpl->assign('links', $links);
|
||||||
|
$tpl->assign('rfc822date', escape($rfc822date));
|
||||||
|
$html = $tpl->draw('dailyrss', $return_string=true);
|
||||||
|
|
||||||
|
echo $html . PHP_EOL;
|
||||||
}
|
}
|
||||||
echo '</channel></rss><!-- Cached version of '.escape(pageUrl()).' -->';
|
echo '</channel></rss><!-- Cached version of '. escape(pageUrl()) .' -->';
|
||||||
|
|
||||||
$cache->cache(ob_get_contents());
|
$cache->cache(ob_get_contents());
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
{loop="links"}
|
<item>
|
||||||
|
<title>{$title} - {function="strftime('%A %e %B %Y', $daydate)"}</title>
|
||||||
|
<guid>{$absurl}</guid>
|
||||||
|
<link>{$absurl}</link>
|
||||||
|
<pubDate>{$rfc822date}</pubDate>
|
||||||
|
<description><![CDATA[
|
||||||
|
{loop="links"}
|
||||||
<h3><a href="{$value.url}">{$value.title}</a></h3>
|
<h3><a href="{$value.url}">{$value.title}</a></h3>
|
||||||
<small>{if="!$GLOBALS['config']['HIDE_TIMESTAMPS']"}{function="strftime('%c', $value.timestamp)"} - {/if}{if="$value.tags"}{$value.tags}{/if}<br>
|
<small>{if="!$GLOBALS['config']['HIDE_TIMESTAMPS']"}{function="strftime('%c', $value.timestamp)"} - {/if}{if="$value.tags"}{$value.tags}{/if}<br>
|
||||||
{$value.url}</small><br>
|
{$value.url}</small><br>
|
||||||
{if="$value.thumbnail"}{$value.thumbnail}{/if}<br>
|
{if="$value.thumbnail"}{$value.thumbnail}{/if}<br>
|
||||||
{if="$value.description"}{$value.formatedDescription}{/if}
|
{if="$value.description"}{$value.formatedDescription}{/if}
|
||||||
<br><br><hr>
|
<br><br><hr>
|
||||||
{/loop}
|
{/loop}
|
||||||
|
]]></description>
|
||||||
|
</item>
|
Loading…
Reference in a new issue