+// ------------------------------------------------------------------------------------------
+// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
+// Gives the last 7 days (which have links).
+// This RSS feed cannot be filtered.
+function showDailyRSS()
+{
+ global $LINKSDB;
+
+ /* Some Shaarlies may have very few links, so we need to look
+ back in time (rsort()) until we have enough days ($nb_of_days).
+ */
+ $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; }
+ rsort($linkdates);
+ $nb_of_days=7; // We take 7 days.
+ $today=Date('Ymd');
+ $days=array();
+ foreach($linkdates as $linkdate)
+ {
+ $day=substr($linkdate,0,8); // Extract day (without time)
+ 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 ?
+ }
+
+ // Build the RSS feed.
+ header('Content-Type: application/rss+xml; charset=utf-8');
+ $pageaddr=htmlspecialchars(indexUrl());
+ echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
+ echo '<channel><title>Daily - '.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>';
+ echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n";
+
+ foreach($days as $day=>$linkdates) // For each day.
+ {
+ $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date
+ $rfc822date = linkdate2rfc822($day.'_000000');
+ $absurl=htmlspecialchars(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
+ echo '<item><title>'.htmlspecialchars($GLOBALS['title'].' - '.$daydate).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
+ echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>";
+
+ // Build the HTML body of this RSS entry.
+ $html='';
+ $href='';
+ $links=array();
+ // We pre-format some fields for proper output.
+ foreach($linkdates as $linkdate)
+ {
+ $l = $LINKSDB[$linkdate];
+ $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($l['description']))));
+ $l['thumbnail'] = thumbnail($l['url']);
+ $l['localdate']=linkdate2locale($l['linkdate']);
+ if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute
+ $links[$linkdate]=$l;
+ }
+ // Then build the HTML for this day:
+ $tpl = new RainTPL;
+ $tpl->assign('links',$links);
+ $html = $tpl->draw('dailyrss',$return_string=true);
+ echo "\n";
+ echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n";
+
+ }
+ echo '</channel></rss>';
+ exit;
+}
+
+