aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php67
1 files changed, 25 insertions, 42 deletions
diff --git a/index.php b/index.php
index 231b63f6..a9264cbb 100644
--- a/index.php
+++ b/index.php
@@ -531,33 +531,6 @@ function getMaxFileSize()
531 return $maxsize; 531 return $maxsize;
532} 532}
533 533
534/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a timestamp (Unix epoch)
535 (used to build the ADD_DATE attribute in Netscape-bookmarks file)
536 PS: I could have used strptime(), but it does not exist on Windows. I'm too kind. */
537function linkdate2timestamp($linkdate)
538{
539 if(strcmp($linkdate, '_000000') !== 0 || !$linkdate){
540 $Y=$M=$D=$h=$m=$s=0;
541 $r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
542 return mktime($h,$m,$s,$M,$D,$Y);
543 }
544 return time();
545}
546
547/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a RFC822 date.
548 (used to build the pubDate attribute in RSS feed.) */
549function linkdate2rfc822($linkdate)
550{
551 return date('r',linkdate2timestamp($linkdate)); // 'r' is for RFC822 date format.
552}
553
554/* Converts a linkdate time (YYYYMMDD_HHMMSS) of an article to a ISO 8601 date.
555 (used to build the updated tags in ATOM feed.) */
556function linkdate2iso8601($linkdate)
557{
558 return date('c',linkdate2timestamp($linkdate)); // 'c' is for ISO 8601 date format.
559}
560
561// ------------------------------------------------------------------------------------------ 534// ------------------------------------------------------------------------------------------
562// Token management for XSRF protection 535// Token management for XSRF protection
563// Token should be used in any form which acts on data (create,update,delete,import...). 536// Token should be used in any form which acts on data (create,update,delete,import...).
@@ -749,14 +722,16 @@ function showRSS()
749 { 722 {
750 $link = $linksToDisplay[$keys[$i]]; 723 $link = $linksToDisplay[$keys[$i]];
751 $guid = $pageaddr.'?'.smallHash($link['linkdate']); 724 $guid = $pageaddr.'?'.smallHash($link['linkdate']);
752 $rfc822date = linkdate2rfc822($link['linkdate']); 725 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
753 $absurl = $link['url']; 726 $absurl = $link['url'];
754 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute 727 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
755 if ($usepermalinks===true) 728 if ($usepermalinks===true)
756 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="true">'.$guid.'</guid><link>'.$guid.'</link>'; 729 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="true">'.$guid.'</guid><link>'.$guid.'</link>';
757 else 730 else
758 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="false">'.$guid.'</guid><link>'.$absurl.'</link>'; 731 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="false">'.$guid.'</guid><link>'.$absurl.'</link>';
759 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo '<pubDate>'.escape($rfc822date)."</pubDate>\n"; 732 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
733 echo '<pubDate>'.escape($date->format(DateTime::RSS))."</pubDate>\n";
734 }
760 if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) 735 if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification)
761 { 736 {
762 foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.$pageaddr.'">'.$tag.'</category>'."\n"; } 737 foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.$pageaddr.'">'.$tag.'</category>'."\n"; }
@@ -837,8 +812,9 @@ function showATOM()
837 { 812 {
838 $link = $linksToDisplay[$keys[$i]]; 813 $link = $linksToDisplay[$keys[$i]];
839 $guid = $pageaddr.'?'.smallHash($link['linkdate']); 814 $guid = $pageaddr.'?'.smallHash($link['linkdate']);
840 $iso8601date = linkdate2iso8601($link['linkdate']); 815 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
841 $latestDate = max($latestDate,$iso8601date); 816 $iso8601date = $date->format(DateTime::ISO8601);
817 $latestDate = max($latestDate, $iso8601date);
842 $absurl = $link['url']; 818 $absurl = $link['url'];
843 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute 819 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute
844 $entries.='<entry><title>'.$link['title'].'</title>'; 820 $entries.='<entry><title>'.$link['title'].'</title>';
@@ -846,7 +822,10 @@ function showATOM()
846 $entries.='<link href="'.$guid.'" /><id>'.$guid.'</id>'; 822 $entries.='<link href="'.$guid.'" /><id>'.$guid.'</id>';
847 else 823 else
848 $entries.='<link href="'.$absurl.'" /><id>'.$guid.'</id>'; 824 $entries.='<link href="'.$absurl.'" /><id>'.$guid.'</id>';
849 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.='<updated>'.escape($iso8601date).'</updated>'; 825
826 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
827 $entries.='<updated>'.escape($iso8601date).'</updated>';
828 }
850 829
851 // Add permalink in description 830 // Add permalink in description
852 $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)'; 831 $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)';
@@ -952,8 +931,7 @@ function showDailyRSS() {
952 931
953 // For each day. 932 // For each day.
954 foreach ($days as $day => $linkdates) { 933 foreach ($days as $day => $linkdates) {
955 $daydate = linkdate2timestamp($day.'_000000'); // Full text date 934 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
956 $rfc822date = linkdate2rfc822($day.'_000000');
957 $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 935 $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
958 936
959 // Build the HTML body of this RSS entry. 937 // Build the HTML body of this RSS entry.
@@ -966,7 +944,8 @@ function showDailyRSS() {
966 $l = $LINKSDB[$linkdate]; 944 $l = $LINKSDB[$linkdate];
967 $l['formatedDescription'] = format_description($l['description'], $GLOBALS['redirector']); 945 $l['formatedDescription'] = format_description($l['description'], $GLOBALS['redirector']);
968 $l['thumbnail'] = thumbnail($l['url']); 946 $l['thumbnail'] = thumbnail($l['url']);
969 $l['timestamp'] = linkdate2timestamp($l['linkdate']); 947 $l_date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $l['linkdate']);
948 $l['timestamp'] = $l_date->getTimestamp();
970 if (startsWith($l['url'], '?')) { 949 if (startsWith($l['url'], '?')) {
971 $l['url'] = index_url($_SERVER) . $l['url']; // make permalink URL absolute 950 $l['url'] = index_url($_SERVER) . $l['url']; // make permalink URL absolute
972 } 951 }
@@ -976,10 +955,10 @@ function showDailyRSS() {
976 // Then build the HTML for this day: 955 // Then build the HTML for this day:
977 $tpl = new RainTPL; 956 $tpl = new RainTPL;
978 $tpl->assign('title', $GLOBALS['title']); 957 $tpl->assign('title', $GLOBALS['title']);
979 $tpl->assign('daydate', $daydate); 958 $tpl->assign('daydate', $dayDate->getTimestamp());
980 $tpl->assign('absurl', $absurl); 959 $tpl->assign('absurl', $absurl);
981 $tpl->assign('links', $links); 960 $tpl->assign('links', $links);
982 $tpl->assign('rfc822date', escape($rfc822date)); 961 $tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS)));
983 $html = $tpl->draw('dailyrss', $return_string=true); 962 $html = $tpl->draw('dailyrss', $return_string=true);
984 963
985 echo $html . PHP_EOL; 964 echo $html . PHP_EOL;
@@ -1035,7 +1014,8 @@ function showDaily($pageBuilder)
1035 $linksToDisplay[$key]['taglist']=$taglist; 1014 $linksToDisplay[$key]['taglist']=$taglist;
1036 $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $GLOBALS['redirector']); 1015 $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $GLOBALS['redirector']);
1037 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']); 1016 $linksToDisplay[$key]['thumbnail'] = thumbnail($link['url']);
1038 $linksToDisplay[$key]['timestamp'] = linkdate2timestamp($link['linkdate']); 1017 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
1018 $linksToDisplay[$key]['timestamp'] = $date->getTimestamp();
1039 } 1019 }
1040 1020
1041 /* We need to spread the articles on 3 columns. 1021 /* We need to spread the articles on 3 columns.
@@ -1060,11 +1040,12 @@ function showDaily($pageBuilder)
1060 $fill[$index]+=$length; 1040 $fill[$index]+=$length;
1061 } 1041 }
1062 1042
1043 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
1063 $data = array( 1044 $data = array(
1064 'linksToDisplay' => $linksToDisplay, 1045 'linksToDisplay' => $linksToDisplay,
1065 'linkcount' => count($LINKSDB), 1046 'linkcount' => count($LINKSDB),
1066 'cols' => $columns, 1047 'cols' => $columns,
1067 'day' => linkdate2timestamp($day.'_000000'), 1048 'day' => $dayDate->getTimestamp(),
1068 'previousday' => $previousday, 1049 'previousday' => $previousday,
1069 'nextday' => $nextday, 1050 'nextday' => $nextday,
1070 ); 1051 );
@@ -1569,7 +1550,7 @@ function renderPage()
1569 $link = array( 1550 $link = array(
1570 'title' => trim($_POST['lf_title']), 1551 'title' => trim($_POST['lf_title']),
1571 'url' => $url, 1552 'url' => $url,
1572 'description' => trim($_POST['lf_description']), 1553 'description' => $_POST['lf_description'],
1573 'private' => (isset($_POST['lf_private']) ? 1 : 0), 1554 'private' => (isset($_POST['lf_private']) ? 1 : 0),
1574 'linkdate' => $linkdate, 1555 'linkdate' => $linkdate,
1575 'tags' => str_replace(',', ' ', $tags) 1556 'tags' => str_replace(',', ' ', $tags)
@@ -1780,7 +1761,8 @@ HTML;
1780 ($exportWhat=='private' && $link['private']!=0) || 1761 ($exportWhat=='private' && $link['private']!=0) ||
1781 ($exportWhat=='public' && $link['private']==0)) 1762 ($exportWhat=='public' && $link['private']==0))
1782 { 1763 {
1783 echo '<DT><A HREF="'.$link['url'].'" ADD_DATE="'.linkdate2timestamp($link['linkdate']).'" PRIVATE="'.$link['private'].'"'; 1764 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
1765 echo '<DT><A HREF="'.$link['url'].'" ADD_DATE="'.$date->getTimestamp().'" PRIVATE="'.$link['private'].'"';
1784 if ($link['tags']!='') echo ' TAGS="'.str_replace(' ',',',$link['tags']).'"'; 1766 if ($link['tags']!='') echo ' TAGS="'.str_replace(' ',',',$link['tags']).'"';
1785 echo '>'.$link['title']."</A>\n"; 1767 echo '>'.$link['title']."</A>\n";
1786 if ($link['description']!='') echo '<DD>'.$link['description']."\n"; 1768 if ($link['description']!='') echo '<DD>'.$link['description']."\n";
@@ -2023,7 +2005,8 @@ function buildLinkList($PAGE,$LINKSDB)
2023 $link['description'] = format_description($link['description'], $GLOBALS['redirector']); 2005 $link['description'] = format_description($link['description'], $GLOBALS['redirector']);
2024 $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight'; 2006 $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight';
2025 $link['class'] = $link['private'] == 0 ? $classLi : 'private'; 2007 $link['class'] = $link['private'] == 0 ? $classLi : 'private';
2026 $link['timestamp'] = linkdate2timestamp($link['linkdate']); 2008 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
2009 $link['timestamp'] = $date->getTimestamp();
2027 $taglist = explode(' ', $link['tags']); 2010 $taglist = explode(' ', $link['tags']);
2028 uasort($taglist, 'strcasecmp'); 2011 uasort($taglist, 'strcasecmp');
2029 $link['taglist'] = $taglist; 2012 $link['taglist'] = $taglist;