aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <tamisier.aurelien@gmail.com>2015-07-11 19:09:52 +0200
committerVirtualTam <tamisier.aurelien@gmail.com>2015-07-11 19:09:52 +0200
commitbba021defce15184c986d5e3db138bdbdd4df5d5 (patch)
treeb494366fee211dcb492ce8cb9b96ec6383c2f7c1
parent1b73f35ebf690cdbc60e6e3423d9347634a841bd (diff)
parentf3b8f9f0f80a05739756fb05cbec403011c46607 (diff)
downloadShaarli-bba021defce15184c986d5e3db138bdbdd4df5d5.tar.gz
Shaarli-bba021defce15184c986d5e3db138bdbdd4df5d5.tar.zst
Shaarli-bba021defce15184c986d5e3db138bdbdd4df5d5.zip
Merge pull request #268 from ArthurHoaro/dailrss-template
Include the whole <item> in Daily RSS template
-rw-r--r--index.php100
-rw-r--r--tpl/dailyrss.html24
2 files changed, 75 insertions, 49 deletions
diff --git a/index.php b/index.php
index 8058a745..d8fb3007 100644
--- a/index.php
+++ b/index.php
@@ -859,15 +859,18 @@ function showATOM()
859// Daily RSS feed: 1 RSS entry per day giving all the links on that day. 859// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
860// Gives the last 7 days (which have links). 860// Gives the last 7 days (which have links).
861// This RSS feed cannot be filtered. 861// This RSS feed cannot be filtered.
862function showDailyRSS() 862function showDailyRSS() {
863{
864 // Cache system 863 // Cache system
865 $query = $_SERVER["QUERY_STRING"]; 864 $query = $_SERVER["QUERY_STRING"];
866 $cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn()); 865 $cache = new pageCache(pageUrl(), startsWith($query, 'do=dailyrss') && !isLoggedIn());
867 $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } 866 $cached = $cache->cachedVersion();
868 // If cached was not found (or not usable), then read the database and build the response: 867 if (!empty($cached)) {
868 echo $cached;
869 exit;
870 }
869 871
870// Read links from database (and filter private links if used it not logged in). 872 // If cached was not found (or not usable), then read the database and build the response:
873 // Read links from database (and filter private links if used it not logged in).
871 $LINKSDB = new LinkDB( 874 $LINKSDB = new LinkDB(
872 $GLOBALS['config']['DATASTORE'], 875 $GLOBALS['config']['DATASTORE'],
873 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], 876 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
@@ -877,60 +880,75 @@ function showDailyRSS()
877 /* Some Shaarlies may have very few links, so we need to look 880 /* Some Shaarlies may have very few links, so we need to look
878 back in time (rsort()) until we have enough days ($nb_of_days). 881 back in time (rsort()) until we have enough days ($nb_of_days).
879 */ 882 */
880 $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; } 883 $linkdates = array();
884 foreach ($LINKSDB as $linkdate => $value) {
885 $linkdates[] = $linkdate;
886 }
881 rsort($linkdates); 887 rsort($linkdates);
882 $nb_of_days=7; // We take 7 days. 888 $nb_of_days = 7; // We take 7 days.
883 $today=Date('Ymd'); 889 $today = Date('Ymd');
884 $days=array(); 890 $days = array();
885 foreach($linkdates as $linkdate) 891
886 { 892 foreach ($linkdates as $linkdate) {
887 $day=substr($linkdate,0,8); // Extract day (without time) 893 $day = substr($linkdate, 0, 8); // Extract day (without time)
888 if (strcmp($day,$today)<0) 894 if (strcmp($day,$today) < 0) {
889 { 895 if (empty($days[$day])) {
890 if (empty($days[$day])) $days[$day]=array(); 896 $days[$day] = array();
891 $days[$day][]=$linkdate; 897 }
898 $days[$day][] = $linkdate;
899 }
900
901 if (count($days) > $nb_of_days) {
902 break; // Have we collected enough days?
892 } 903 }
893 if (count($days)>$nb_of_days) break; // Have we collected enough days?
894 } 904 }
895 905
896 // Build the RSS feed. 906 // Build the RSS feed.
897 header('Content-Type: application/rss+xml; charset=utf-8'); 907 header('Content-Type: application/rss+xml; charset=utf-8');
898 $pageaddr=escape(indexUrl()); 908 $pageaddr = escape(indexUrl());
899 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">'; 909 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
900 echo '<channel><title>Daily - '.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>'; 910 echo '<channel>';
901 echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n"; 911 echo '<title>Daily - '. $GLOBALS['title'] . '</title>';
902 912 echo '<link>'. $pageaddr .'</link>';
903 foreach($days as $day=>$linkdates) // For each day. 913 echo '<description>Daily shared links</description>';
904 { 914 echo '<language>en-en</language>';
905 $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date 915 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
916
917 // For each day.
918 foreach ($days as $day => $linkdates) {
919 $daydate = linkdate2timestamp($day.'_000000'); // Full text date
906 $rfc822date = linkdate2rfc822($day.'_000000'); 920 $rfc822date = linkdate2rfc822($day.'_000000');
907 $absurl=escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 921 $absurl = escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
908 echo '<item><title>'.$GLOBALS['title'].' - '.$daydate.'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
909 echo '<pubDate>'.escape($rfc822date)."</pubDate>";
910 922
911 // Build the HTML body of this RSS entry. 923 // Build the HTML body of this RSS entry.
912 $html=''; 924 $html = '';
913 $href=''; 925 $href = '';
914 $links=array(); 926 $links = array();
927
915 // We pre-format some fields for proper output. 928 // We pre-format some fields for proper output.
916 foreach($linkdates as $linkdate) 929 foreach ($linkdates as $linkdate) {
917 {
918 $l = $LINKSDB[$linkdate]; 930 $l = $LINKSDB[$linkdate];
919 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable($l['description']))); 931 $l['formatedDescription'] = nl2br(keepMultipleSpaces(text2clickable($l['description'])));
920 $l['thumbnail'] = thumbnail($l['url']); 932 $l['thumbnail'] = thumbnail($l['url']);
921 $l['timestamp'] = linkdate2timestamp($l['linkdate']); 933 $l['timestamp'] = linkdate2timestamp($l['linkdate']);
922 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute 934 if (startsWith($l['url'], '?')) {
923 $links[$linkdate]=$l; 935 $l['url'] = indexUrl() . $l['url']; // make permalink URL absolute
936 }
937 $links[$linkdate] = $l;
924 } 938 }
939
925 // Then build the HTML for this day: 940 // Then build the HTML for this day:
926 $tpl = new RainTPL; 941 $tpl = new RainTPL;
927 $tpl->assign('links',$links); 942 $tpl->assign('title', $GLOBALS['title']);
928 $html = $tpl->draw('dailyrss',$return_string=true); 943 $tpl->assign('daydate', $daydate);
929 echo "\n"; 944 $tpl->assign('absurl', $absurl);
930 echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n"; 945 $tpl->assign('links', $links);
946 $tpl->assign('rfc822date', escape($rfc822date));
947 $html = $tpl->draw('dailyrss', $return_string=true);
931 948
949 echo $html . PHP_EOL;
932 } 950 }
933 echo '</channel></rss><!-- Cached version of '.escape(pageUrl()).' -->'; 951 echo '</channel></rss><!-- Cached version of '. escape(pageUrl()) .' -->';
934 952
935 $cache->cache(ob_get_contents()); 953 $cache->cache(ob_get_contents());
936 ob_end_flush(); 954 ob_end_flush();
diff --git a/tpl/dailyrss.html b/tpl/dailyrss.html
index 1b7ab8e9..d959d6be 100644
--- a/tpl/dailyrss.html
+++ b/tpl/dailyrss.html
@@ -1,8 +1,16 @@
1{loop="links"} 1<item>
2 <h3><a href="{$value.url}">{$value.title}</a></h3> 2 <title>{$title} - {function="strftime('%A %e %B %Y', $daydate)"}</title>
3 <small>{if="!$GLOBALS['config']['HIDE_TIMESTAMPS']"}{function="strftime('%c', $value.timestamp)"} - {/if}{if="$value.tags"}{$value.tags}{/if}<br> 3 <guid>{$absurl}</guid>
4 {$value.url}</small><br> 4 <link>{$absurl}</link>
5 {if="$value.thumbnail"}{$value.thumbnail}{/if}<br> 5 <pubDate>{$rfc822date}</pubDate>
6 {if="$value.description"}{$value.formatedDescription}{/if} 6 <description><![CDATA[
7 <br><br><hr> 7 {loop="links"}
8{/loop} \ No newline at end of file 8 <h3><a href="{$value.url}">{$value.title}</a></h3>
9 <small>{if="!$GLOBALS['config']['HIDE_TIMESTAMPS']"}{function="strftime('%c', $value.timestamp)"} - {/if}{if="$value.tags"}{$value.tags}{/if}<br>
10 {$value.url}</small><br>
11 {if="$value.thumbnail"}{$value.thumbnail}{/if}<br>
12 {if="$value.description"}{$value.formatedDescription}{/if}
13 <br><br><hr>
14 {/loop}
15 ]]></description>
16</item> \ No newline at end of file