aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-07-10 15:41:59 +0200
committerArthurHoaro <arthur@hoa.ro>2015-07-11 10:25:25 +0200
commitf3b8f9f0f80a05739756fb05cbec403011c46607 (patch)
tree05d38f4d4feba7c3168adcc22aaab0dbe0bc5c9b /index.php
parente92f1ba59edb9fd60b185dc633e64a62dffe3b04 (diff)
downloadShaarli-f3b8f9f0f80a05739756fb05cbec403011c46607.tar.gz
Shaarli-f3b8f9f0f80a05739756fb05cbec403011c46607.tar.zst
Shaarli-f3b8f9f0f80a05739756fb05cbec403011c46607.zip
Include the whole <item> in dailyRSS
Allow custom date format and title in templates. Also a bit of code style review. Fixes #182
Diffstat (limited to 'index.php')
-rw-r--r--index.php100
1 files changed, 59 insertions, 41 deletions
diff --git a/index.php b/index.php
index 236fd4e2..2b1426e9 100644
--- a/index.php
+++ b/index.php
@@ -853,15 +853,18 @@ function showATOM()
853// Daily RSS feed: 1 RSS entry per day giving all the links on that day. 853// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
854// Gives the last 7 days (which have links). 854// Gives the last 7 days (which have links).
855// This RSS feed cannot be filtered. 855// This RSS feed cannot be filtered.
856function showDailyRSS() 856function showDailyRSS() {
857{
858 // Cache system 857 // Cache system
859 $query = $_SERVER["QUERY_STRING"]; 858 $query = $_SERVER["QUERY_STRING"];
860 $cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn()); 859 $cache = new pageCache(pageUrl(), startsWith($query, 'do=dailyrss') && !isLoggedIn());
861 $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } 860 $cached = $cache->cachedVersion();
862 // If cached was not found (or not usable), then read the database and build the response: 861 if (!empty($cached)) {
862 echo $cached;
863 exit;
864 }
863 865
864// Read links from database (and filter private links if used it not logged in). 866 // If cached was not found (or not usable), then read the database and build the response:
867 // Read links from database (and filter private links if used it not logged in).
865 $LINKSDB = new LinkDB( 868 $LINKSDB = new LinkDB(
866 $GLOBALS['config']['DATASTORE'], 869 $GLOBALS['config']['DATASTORE'],
867 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], 870 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
@@ -871,60 +874,75 @@ function showDailyRSS()
871 /* Some Shaarlies may have very few links, so we need to look 874 /* Some Shaarlies may have very few links, so we need to look
872 back in time (rsort()) until we have enough days ($nb_of_days). 875 back in time (rsort()) until we have enough days ($nb_of_days).
873 */ 876 */
874 $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; } 877 $linkdates = array();
878 foreach ($LINKSDB as $linkdate => $value) {
879 $linkdates[] = $linkdate;
880 }
875 rsort($linkdates); 881 rsort($linkdates);
876 $nb_of_days=7; // We take 7 days. 882 $nb_of_days = 7; // We take 7 days.
877 $today=Date('Ymd'); 883 $today = Date('Ymd');
878 $days=array(); 884 $days = array();
879 foreach($linkdates as $linkdate) 885
880 { 886 foreach ($linkdates as $linkdate) {
881 $day=substr($linkdate,0,8); // Extract day (without time) 887 $day = substr($linkdate, 0, 8); // Extract day (without time)
882 if (strcmp($day,$today)<0) 888 if (strcmp($day,$today) < 0) {
883 { 889 if (empty($days[$day])) {
884 if (empty($days[$day])) $days[$day]=array(); 890 $days[$day] = array();
885 $days[$day][]=$linkdate; 891 }
892 $days[$day][] = $linkdate;
893 }
894
895 if (count($days) > $nb_of_days) {
896 break; // Have we collected enough days?
886 } 897 }
887 if (count($days)>$nb_of_days) break; // Have we collected enough days?
888 } 898 }
889 899
890 // Build the RSS feed. 900 // Build the RSS feed.
891 header('Content-Type: application/rss+xml; charset=utf-8'); 901 header('Content-Type: application/rss+xml; charset=utf-8');
892 $pageaddr=escape(indexUrl()); 902 $pageaddr = escape(indexUrl());
893 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">'; 903 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
894 echo '<channel><title>Daily - '.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>'; 904 echo '<channel>';
895 echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n"; 905 echo '<title>Daily - '. $GLOBALS['title'] . '</title>';
896 906 echo '<link>'. $pageaddr .'</link>';
897 foreach($days as $day=>$linkdates) // For each day. 907 echo '<description>Daily shared links</description>';
898 { 908 echo '<language>en-en</language>';
899 $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date 909 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
910
911 // For each day.
912 foreach ($days as $day => $linkdates) {
913 $daydate = linkdate2timestamp($day.'_000000'); // Full text date
900 $rfc822date = linkdate2rfc822($day.'_000000'); 914 $rfc822date = linkdate2rfc822($day.'_000000');
901 $absurl=escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 915 $absurl = escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
902 echo '<item><title>'.$GLOBALS['title'].' - '.$daydate.'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
903 echo '<pubDate>'.escape($rfc822date)."</pubDate>";
904 916
905 // Build the HTML body of this RSS entry. 917 // Build the HTML body of this RSS entry.
906 $html=''; 918 $html = '';
907 $href=''; 919 $href = '';
908 $links=array(); 920 $links = array();
921
909 // We pre-format some fields for proper output. 922 // We pre-format some fields for proper output.
910 foreach($linkdates as $linkdate) 923 foreach ($linkdates as $linkdate) {
911 {
912 $l = $LINKSDB[$linkdate]; 924 $l = $LINKSDB[$linkdate];
913 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable($l['description']))); 925 $l['formatedDescription'] = nl2br(keepMultipleSpaces(text2clickable($l['description'])));
914 $l['thumbnail'] = thumbnail($l['url']); 926 $l['thumbnail'] = thumbnail($l['url']);
915 $l['timestamp'] = linkdate2timestamp($l['linkdate']); 927 $l['timestamp'] = linkdate2timestamp($l['linkdate']);
916 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute 928 if (startsWith($l['url'], '?')) {
917 $links[$linkdate]=$l; 929 $l['url'] = indexUrl() . $l['url']; // make permalink URL absolute
930 }
931 $links[$linkdate] = $l;
918 } 932 }
933
919 // Then build the HTML for this day: 934 // Then build the HTML for this day:
920 $tpl = new RainTPL; 935 $tpl = new RainTPL;
921 $tpl->assign('links',$links); 936 $tpl->assign('title', $GLOBALS['title']);
922 $html = $tpl->draw('dailyrss',$return_string=true); 937 $tpl->assign('daydate', $daydate);
923 echo "\n"; 938 $tpl->assign('absurl', $absurl);
924 echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n"; 939 $tpl->assign('links', $links);
940 $tpl->assign('rfc822date', escape($rfc822date));
941 $html = $tpl->draw('dailyrss', $return_string=true);
925 942
943 echo $html . PHP_EOL;
926 } 944 }
927 echo '</channel></rss><!-- Cached version of '.escape(pageUrl()).' -->'; 945 echo '</channel></rss><!-- Cached version of '. escape(pageUrl()) .' -->';
928 946
929 $cache->cache(ob_get_contents()); 947 $cache->cache(ob_get_contents());
930 ob_end_flush(); 948 ob_end_flush();