aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php120
1 files changed, 67 insertions, 53 deletions
diff --git a/index.php b/index.php
index 14811c56..261c8a37 100644
--- a/index.php
+++ b/index.php
@@ -683,7 +683,7 @@ class pageBuilder
683 683
684// ------------------------------------------------------------------------------------------ 684// ------------------------------------------------------------------------------------------
685// Output the last N links in RSS 2.0 format. 685// Output the last N links in RSS 2.0 format.
686function showRSS() 686function showRSS($pageBuilder, $linkDB)
687{ 687{
688 header('Content-Type: application/rss+xml; charset=utf-8'); 688 header('Content-Type: application/rss+xml; charset=utf-8');
689 689
@@ -693,11 +693,11 @@ function showRSS()
693 $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; 693 $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS'];
694 694
695 // Cache system 695 // Cache system
696 $query = $_SERVER["QUERY_STRING"]; 696 $query = $_SERVER['QUERY_STRING'];
697 $cache = new CachedPage( 697 $cache = new CachedPage(
698 $GLOBALS['config']['PAGECACHE'], 698 $GLOBALS['config']['PAGECACHE'],
699 page_url($_SERVER), 699 page_url($_SERVER),
700 startsWith($query,'do=rss') && !isLoggedIn() 700 startsWith($query, 'do=rss') && !isLoggedIn()
701 ); 701 );
702 $cached = $cache->cachedVersion(); 702 $cached = $cache->cachedVersion();
703 if (! empty($cached)) { 703 if (! empty($cached)) {
@@ -705,32 +705,23 @@ function showRSS()
705 exit; 705 exit;
706 } 706 }
707 707
708 // If cached was not found (or not usable), then read the database and build the response:
709 $LINKSDB = new LinkDB(
710 $GLOBALS['config']['DATASTORE'],
711 isLoggedIn(),
712 $GLOBALS['config']['HIDE_PUBLIC_LINKS'],
713 $GLOBALS['redirector']
714 );
715 // Read links from database (and filter private links if user it not logged in).
716
717 // Optionally filter the results: 708 // Optionally filter the results:
718 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; 709 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
719 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; 710 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
720 if (! empty($searchtags) && ! empty($searchterm)) { 711 if (! empty($searchtags) && ! empty($searchterm)) {
721 $linksToDisplay = $LINKSDB->filter( 712 $linksToDisplay = $linkDB->filter(
722 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, 713 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
723 array($searchtags, $searchterm) 714 array($searchtags, $searchterm)
724 ); 715 );
725 } 716 }
726 elseif ($searchtags) { 717 elseif ($searchtags) {
727 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); 718 $linksToDisplay = $linkDB->filter(LinkFilter::$FILTER_TAG, $searchtags);
728 } 719 }
729 elseif ($searchterm) { 720 elseif ($searchterm) {
730 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); 721 $linksToDisplay = $linkDB->filter(LinkFilter::$FILTER_TEXT, $searchterm);
731 } 722 }
732 else { 723 else {
733 $linksToDisplay = $LINKSDB; 724 $linksToDisplay = $linkDB;
734 } 725 }
735 726
736 $nblinksToDisplay = 50; // Number of links to display. 727 $nblinksToDisplay = 50; // Number of links to display.
@@ -739,50 +730,63 @@ function showRSS()
739 $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); 730 $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1);
740 } 731 }
741 732
733 $keys = array();
734 foreach ($linksToDisplay as $key=>$value) {
735 $keys[] = $key; // No, I can't use array_keys().
736 }
737
742 $pageaddr = escape(index_url($_SERVER)); 738 $pageaddr = escape(index_url($_SERVER));
743 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; 739 $latestDate = '';
744 echo '<channel><title>'.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>'; 740 $i = 0;
745 echo '<description>Shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n\n"; 741 $linkDisp = array();
746 if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) 742 while ($i < $nblinksToDisplay && $i < count($keys))
747 {
748 echo '<!-- PubSubHubbub Discovery -->';
749 echo '<link rel="hub" href="'.escape($GLOBALS['config']['PUBSUBHUB_URL']).'" xmlns="http://www.w3.org/2005/Atom" />';
750 echo '<link rel="self" href="'.$pageaddr.'?do=rss" xmlns="http://www.w3.org/2005/Atom" />';
751 echo '<!-- End Of PubSubHubbub Discovery -->';
752 }
753 $i=0;
754 $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys().
755 while ($i<$nblinksToDisplay && $i<count($keys))
756 { 743 {
757 $link = $linksToDisplay[$keys[$i]]; 744 $link = $linksToDisplay[$keys[$i]];
758 $guid = $pageaddr.'?'.smallHash($link['linkdate']); 745 $link['guid'] = $pageaddr. '?' .smallHash($link['linkdate']);
759 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 746 // Check for both signs of a note: starting with ? and 7 chars long.
760 $absurl = $link['url']; 747 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
761 if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute 748 $link['url'] = $pageaddr . $link['url'];
762 if ($usepermalinks===true)
763 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="true">'.$guid.'</guid><link>'.$guid.'</link>';
764 else
765 echo '<item><title>'.$link['title'].'</title><guid isPermaLink="false">'.$guid.'</guid><link>'.$absurl.'</link>';
766 if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
767 echo '<pubDate>'.escape($date->format(DateTime::RSS))."</pubDate>\n";
768 }
769 if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification)
770 {
771 foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.$pageaddr.'">'.$tag.'</category>'."\n"; }
772 } 749 }
750 if ($usepermalinks) {
751 $permalink = '<a href="'. $link['url'] .'" title="Direct link">Direct link</a>';
752 } else {
753 $permalink = '<a href="'. $link['guid'] .'" title="Permalink">Permalink</a>';
754 }
755 $link['description'] = format_description($link['description']) . PHP_EOL .'<br>&#8212; '. $permalink;
756
757 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
758 $link['iso_date'] = $date->format(DateTime::RSS);
759 $latestDate = max($latestDate, $link['iso_date']);
760 $taglist = array_filter(explode(' ', $link['tags']), 'strlen');
761 uasort($taglist, 'strcasecmp');
762 $link['taglist'] = $taglist;
773 763
774 // Add permalink in description 764 $linkDisp[$keys[$i]] = $link;
775 $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)';
776 // If user wants permalinks first, put the final link in description
777 if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)';
778 if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink;
779 echo '<description><![CDATA['.
780 format_description($link['description'], $GLOBALS['redirector']) .
781 $descriptionlink . ']]></description>' . "\n</item>\n";
782 $i++; 765 $i++;
783 } 766 }
784 echo '</channel></rss><!-- Cached version of '.escape(page_url($_SERVER)).' -->';
785 767
768 $data = array();
769 if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) {
770 $data['pubsubhub_url'] = escape($GLOBALS['config']['PUBSUBHUB_URL']);
771 }
772
773 // Use the locale do define the language, if available.
774 $locale = strtolower(setlocale(LC_COLLATE, 0));
775 if (! empty($locale) && preg_match('/^\w{2}[_\-]\w{2}/', $locale)) {
776 $data['language'] = str_replace('_', '-', substr($locale, 0, 5));
777 } else {
778 $data['language'] = 'en-en';
779 }
780 $data['last_update'] = escape($latestDate);
781 $data['show_dates'] = !$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn();
782 // Remove starting slash from REQUEST_URI.
783 $data['self_link'] = escape($pageaddr . substr($_SERVER['REQUEST_URI'], 1));
784 $data['index_url'] = escape($pageaddr);
785 $data['usepermalinks'] = $usepermalinks;
786 $data['links'] = $linkDisp;
787
788 $pageBuilder->assignAll($data);
789 $pageBuilder->renderPage('feed.rss', false);
786 $cache->cache(ob_get_contents()); 790 $cache->cache(ob_get_contents());
787 ob_end_flush(); 791 ob_end_flush();
788 exit; 792 exit;
@@ -889,6 +893,12 @@ function showATOM($pageBuilder, $linkDB)
889 $data['usepermalinks'] = $usepermalinks; 893 $data['usepermalinks'] = $usepermalinks;
890 $data['links'] = $linkDisp; 894 $data['links'] = $linkDisp;
891 895
896 $pluginManager = PluginManager::getInstance();
897 $pluginManager->executeHooks('render_feed', $data, array(
898 'loggedin' => isLoggedIn(),
899 'target' => Router::$PAGE_ATOM,
900 ));
901
892 $pageBuilder->assignAll($data); 902 $pageBuilder->assignAll($data);
893 $pageBuilder->renderPage('feed.atom', false); 903 $pageBuilder->renderPage('feed.atom', false);
894 $cache->cache(ob_get_contents()); 904 $cache->cache(ob_get_contents());
@@ -1277,6 +1287,11 @@ function renderPage()
1277 showATOM($PAGE, $LINKSDB); 1287 showATOM($PAGE, $LINKSDB);
1278 } 1288 }
1279 1289
1290 // RSS feed.
1291 if ($targetPage == Router::$PAGE_RSS) {
1292 showRSS($PAGE, $LINKSDB);
1293 }
1294
1280 // Display openseach plugin (XML) 1295 // Display openseach plugin (XML)
1281 if ($targetPage == Router::$PAGE_OPENSEARCH) { 1296 if ($targetPage == Router::$PAGE_OPENSEARCH) {
1282 header('Content-Type: application/xml; charset=utf-8'); 1297 header('Content-Type: application/xml; charset=utf-8');
@@ -2601,7 +2616,6 @@ function resizeImage($filepath)
2601} 2616}
2602 2617
2603if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. 2618if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
2604if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
2605if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } 2619if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; }
2606if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; 2620if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
2607renderPage(); 2621renderPage();