diff options
-rw-r--r-- | index.php | 100 | ||||
-rw-r--r-- | tpl/dailyrss.html | 24 |
2 files changed, 75 insertions, 49 deletions
@@ -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. |
856 | function showDailyRSS() | 856 | function 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(); |
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 | ||