diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 394 |
1 files changed, 94 insertions, 300 deletions
@@ -154,6 +154,7 @@ if (is_file($GLOBALS['config']['CONFIG_FILE'])) { | |||
154 | require_once 'application/ApplicationUtils.php'; | 154 | require_once 'application/ApplicationUtils.php'; |
155 | require_once 'application/Cache.php'; | 155 | require_once 'application/Cache.php'; |
156 | require_once 'application/CachedPage.php'; | 156 | require_once 'application/CachedPage.php'; |
157 | require_once 'application/FeedBuilder.php'; | ||
157 | require_once 'application/FileUtils.php'; | 158 | require_once 'application/FileUtils.php'; |
158 | require_once 'application/HttpUtils.php'; | 159 | require_once 'application/HttpUtils.php'; |
159 | require_once 'application/LinkDB.php'; | 160 | require_once 'application/LinkDB.php'; |
@@ -483,7 +484,7 @@ if (isset($_POST['login'])) | |||
483 | if (isset($_POST['returnurl'])) { | 484 | if (isset($_POST['returnurl'])) { |
484 | // Prevent loops over login screen. | 485 | // Prevent loops over login screen. |
485 | if (strpos($_POST['returnurl'], 'do=login') === false) { | 486 | if (strpos($_POST['returnurl'], 'do=login') === false) { |
486 | header('Location: '. escape($_POST['returnurl'])); | 487 | header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); |
487 | exit; | 488 | exit; |
488 | } | 489 | } |
489 | } | 490 | } |
@@ -637,6 +638,29 @@ class pageBuilder | |||
637 | $this->tpl->assign($what,$where); | 638 | $this->tpl->assign($what,$where); |
638 | } | 639 | } |
639 | 640 | ||
641 | /** | ||
642 | * Assign an array of data to the template builder. | ||
643 | * | ||
644 | * @param array $data Data to assign. | ||
645 | * | ||
646 | * @return false if invalid data. | ||
647 | */ | ||
648 | public function assignAll($data) | ||
649 | { | ||
650 | // Lazy initialization | ||
651 | if ($this->tpl === false) { | ||
652 | $this->initialize(); | ||
653 | } | ||
654 | |||
655 | if (empty($data) || !is_array($data)){ | ||
656 | return false; | ||
657 | } | ||
658 | |||
659 | foreach ($data as $key => $value) { | ||
660 | $this->assign($key, $value); | ||
661 | } | ||
662 | } | ||
663 | |||
640 | // Render a specific page (using a template). | 664 | // Render a specific page (using a template). |
641 | // e.g. pb.renderPage('picwall') | 665 | // e.g. pb.renderPage('picwall') |
642 | public function renderPage($page) | 666 | public function renderPage($page) |
@@ -659,232 +683,6 @@ class pageBuilder | |||
659 | } | 683 | } |
660 | 684 | ||
661 | // ------------------------------------------------------------------------------------------ | 685 | // ------------------------------------------------------------------------------------------ |
662 | // Output the last N links in RSS 2.0 format. | ||
663 | function showRSS() | ||
664 | { | ||
665 | header('Content-Type: application/rss+xml; charset=utf-8'); | ||
666 | |||
667 | // $usepermalink : If true, use permalink instead of final link. | ||
668 | // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=rss&permalinks | ||
669 | // Also enabled through a config option | ||
670 | $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; | ||
671 | |||
672 | // Cache system | ||
673 | $query = $_SERVER["QUERY_STRING"]; | ||
674 | $cache = new CachedPage( | ||
675 | $GLOBALS['config']['PAGECACHE'], | ||
676 | page_url($_SERVER), | ||
677 | startsWith($query,'do=rss') && !isLoggedIn() | ||
678 | ); | ||
679 | $cached = $cache->cachedVersion(); | ||
680 | if (! empty($cached)) { | ||
681 | echo $cached; | ||
682 | exit; | ||
683 | } | ||
684 | |||
685 | // If cached was not found (or not usable), then read the database and build the response: | ||
686 | $LINKSDB = new LinkDB( | ||
687 | $GLOBALS['config']['DATASTORE'], | ||
688 | isLoggedIn(), | ||
689 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | ||
690 | $GLOBALS['redirector'] | ||
691 | ); | ||
692 | // Read links from database (and filter private links if user it not logged in). | ||
693 | |||
694 | // Optionally filter the results: | ||
695 | $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; | ||
696 | $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; | ||
697 | if (! empty($searchtags) && ! empty($searchterm)) { | ||
698 | $linksToDisplay = $LINKSDB->filter( | ||
699 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | ||
700 | array($searchtags, $searchterm) | ||
701 | ); | ||
702 | } | ||
703 | elseif ($searchtags) { | ||
704 | $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); | ||
705 | } | ||
706 | elseif ($searchterm) { | ||
707 | $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); | ||
708 | } | ||
709 | else { | ||
710 | $linksToDisplay = $LINKSDB; | ||
711 | } | ||
712 | |||
713 | $nblinksToDisplay = 50; // Number of links to display. | ||
714 | // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. | ||
715 | if (!empty($_GET['nb'])) { | ||
716 | $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); | ||
717 | } | ||
718 | |||
719 | $pageaddr = escape(index_url($_SERVER)); | ||
720 | echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; | ||
721 | echo '<channel><title>'.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>'; | ||
722 | echo '<description>Shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n\n"; | ||
723 | if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) | ||
724 | { | ||
725 | echo '<!-- PubSubHubbub Discovery -->'; | ||
726 | echo '<link rel="hub" href="'.escape($GLOBALS['config']['PUBSUBHUB_URL']).'" xmlns="http://www.w3.org/2005/Atom" />'; | ||
727 | echo '<link rel="self" href="'.$pageaddr.'?do=rss" xmlns="http://www.w3.org/2005/Atom" />'; | ||
728 | echo '<!-- End Of PubSubHubbub Discovery -->'; | ||
729 | } | ||
730 | $i=0; | ||
731 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). | ||
732 | while ($i<$nblinksToDisplay && $i<count($keys)) | ||
733 | { | ||
734 | $link = $linksToDisplay[$keys[$i]]; | ||
735 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | ||
736 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
737 | $absurl = $link['url']; | ||
738 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute | ||
739 | if ($usepermalinks===true) | ||
740 | echo '<item><title>'.$link['title'].'</title><guid isPermaLink="true">'.$guid.'</guid><link>'.$guid.'</link>'; | ||
741 | else | ||
742 | echo '<item><title>'.$link['title'].'</title><guid isPermaLink="false">'.$guid.'</guid><link>'.$absurl.'</link>'; | ||
743 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { | ||
744 | echo '<pubDate>'.escape($date->format(DateTime::RSS))."</pubDate>\n"; | ||
745 | } | ||
746 | if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) | ||
747 | { | ||
748 | foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.$pageaddr.'">'.$tag.'</category>'."\n"; } | ||
749 | } | ||
750 | |||
751 | // Add permalink in description | ||
752 | $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)'; | ||
753 | // If user wants permalinks first, put the final link in description | ||
754 | if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)'; | ||
755 | if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; | ||
756 | echo '<description><![CDATA['. | ||
757 | format_description($link['description'], $GLOBALS['redirector']) . | ||
758 | $descriptionlink . ']]></description>' . "\n</item>\n"; | ||
759 | $i++; | ||
760 | } | ||
761 | echo '</channel></rss><!-- Cached version of '.escape(page_url($_SERVER)).' -->'; | ||
762 | |||
763 | $cache->cache(ob_get_contents()); | ||
764 | ob_end_flush(); | ||
765 | exit; | ||
766 | } | ||
767 | |||
768 | // ------------------------------------------------------------------------------------------ | ||
769 | // Output the last N links in ATOM format. | ||
770 | function showATOM() | ||
771 | { | ||
772 | header('Content-Type: application/atom+xml; charset=utf-8'); | ||
773 | |||
774 | // $usepermalink : If true, use permalink instead of final link. | ||
775 | // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=atom&permalinks | ||
776 | $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; | ||
777 | |||
778 | // Cache system | ||
779 | $query = $_SERVER["QUERY_STRING"]; | ||
780 | $cache = new CachedPage( | ||
781 | $GLOBALS['config']['PAGECACHE'], | ||
782 | page_url($_SERVER), | ||
783 | startsWith($query,'do=atom') && !isLoggedIn() | ||
784 | ); | ||
785 | $cached = $cache->cachedVersion(); | ||
786 | if (!empty($cached)) { | ||
787 | echo $cached; | ||
788 | exit; | ||
789 | } | ||
790 | |||
791 | // If cached was not found (or not usable), then read the database and build the response: | ||
792 | // Read links from database (and filter private links if used it not logged in). | ||
793 | $LINKSDB = new LinkDB( | ||
794 | $GLOBALS['config']['DATASTORE'], | ||
795 | isLoggedIn(), | ||
796 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | ||
797 | $GLOBALS['redirector'] | ||
798 | ); | ||
799 | |||
800 | // Optionally filter the results: | ||
801 | $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; | ||
802 | $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; | ||
803 | if (! empty($searchtags) && ! empty($searchterm)) { | ||
804 | $linksToDisplay = $LINKSDB->filter( | ||
805 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | ||
806 | array($searchtags, $searchterm) | ||
807 | ); | ||
808 | } | ||
809 | elseif ($searchtags) { | ||
810 | $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); | ||
811 | } | ||
812 | elseif ($searchterm) { | ||
813 | $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); | ||
814 | } | ||
815 | else { | ||
816 | $linksToDisplay = $LINKSDB; | ||
817 | } | ||
818 | |||
819 | $nblinksToDisplay = 50; // Number of links to display. | ||
820 | // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. | ||
821 | if (!empty($_GET['nb'])) { | ||
822 | $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); | ||
823 | } | ||
824 | |||
825 | $pageaddr=escape(index_url($_SERVER)); | ||
826 | $latestDate = ''; | ||
827 | $entries=''; | ||
828 | $i=0; | ||
829 | $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). | ||
830 | while ($i<$nblinksToDisplay && $i<count($keys)) | ||
831 | { | ||
832 | $link = $linksToDisplay[$keys[$i]]; | ||
833 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | ||
834 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
835 | $iso8601date = $date->format(DateTime::ISO8601); | ||
836 | $latestDate = max($latestDate, $iso8601date); | ||
837 | $absurl = $link['url']; | ||
838 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute | ||
839 | $entries.='<entry><title>'.$link['title'].'</title>'; | ||
840 | if ($usepermalinks===true) | ||
841 | $entries.='<link href="'.$guid.'" /><id>'.$guid.'</id>'; | ||
842 | else | ||
843 | $entries.='<link href="'.$absurl.'" /><id>'.$guid.'</id>'; | ||
844 | |||
845 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { | ||
846 | $entries.='<updated>'.escape($iso8601date).'</updated>'; | ||
847 | } | ||
848 | |||
849 | // Add permalink in description | ||
850 | $descriptionlink = '(<a href="'.$guid.'">Permalink</a>)'; | ||
851 | // If user wants permalinks first, put the final link in description | ||
852 | if ($usepermalinks===true) $descriptionlink = '(<a href="'.$absurl.'">Link</a>)'; | ||
853 | if (strlen($link['description'])>0) $descriptionlink = '<br>'.$descriptionlink; | ||
854 | |||
855 | $entries .= '<content type="html"><![CDATA['. | ||
856 | format_description($link['description'], $GLOBALS['redirector']) . | ||
857 | $descriptionlink . "]]></content>\n"; | ||
858 | if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) | ||
859 | { | ||
860 | foreach(explode(' ',$link['tags']) as $tag) | ||
861 | { $entries.='<category scheme="'.$pageaddr.'" term="'.$tag.'" />'."\n"; } | ||
862 | } | ||
863 | $entries.="</entry>\n"; | ||
864 | $i++; | ||
865 | } | ||
866 | $feed='<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">'; | ||
867 | $feed.='<title>'.$GLOBALS['title'].'</title>'; | ||
868 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $feed.='<updated>'.escape($latestDate).'</updated>'; | ||
869 | $feed.='<link rel="self" href="'.escape(server_url($_SERVER).$_SERVER["REQUEST_URI"]).'" />'; | ||
870 | if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) | ||
871 | { | ||
872 | $feed.='<!-- PubSubHubbub Discovery -->'; | ||
873 | $feed.='<link rel="hub" href="'.escape($GLOBALS['config']['PUBSUBHUB_URL']).'" />'; | ||
874 | $feed.='<!-- End Of PubSubHubbub Discovery -->'; | ||
875 | } | ||
876 | $feed.='<author><name>'.$pageaddr.'</name><uri>'.$pageaddr.'</uri></author>'; | ||
877 | $feed.='<id>'.$pageaddr.'</id>'."\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do. | ||
878 | $feed.=$entries; | ||
879 | $feed.='</feed><!-- Cached version of '.escape(page_url($_SERVER)).' -->'; | ||
880 | echo $feed; | ||
881 | |||
882 | $cache->cache(ob_get_contents()); | ||
883 | ob_end_flush(); | ||
884 | exit; | ||
885 | } | ||
886 | |||
887 | // ------------------------------------------------------------------------------------------ | ||
888 | // Daily RSS feed: 1 RSS entry per day giving all the links on that day. | 686 | // Daily RSS feed: 1 RSS entry per day giving all the links on that day. |
889 | // Gives the last 7 days (which have links). | 687 | // Gives the last 7 days (which have links). |
890 | // This RSS feed cannot be filtered. | 688 | // This RSS feed cannot be filtered. |
@@ -1018,7 +816,7 @@ function showDaily($pageBuilder) | |||
1018 | } | 816 | } |
1019 | 817 | ||
1020 | try { | 818 | try { |
1021 | $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_DAY, $day); | 819 | $linksToDisplay = $LINKSDB->filterDay($day); |
1022 | } catch (Exception $exc) { | 820 | } catch (Exception $exc) { |
1023 | error_log($exc); | 821 | error_log($exc); |
1024 | $linksToDisplay = array(); | 822 | $linksToDisplay = array(); |
@@ -1164,24 +962,7 @@ function renderPage() | |||
1164 | if ($targetPage == Router::$PAGE_PICWALL) | 962 | if ($targetPage == Router::$PAGE_PICWALL) |
1165 | { | 963 | { |
1166 | // Optionally filter the results: | 964 | // Optionally filter the results: |
1167 | $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; | 965 | $links = $LINKSDB->filterSearch($_GET); |
1168 | $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; | ||
1169 | if (! empty($searchtags) && ! empty($searchterm)) { | ||
1170 | $links = $LINKSDB->filter( | ||
1171 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | ||
1172 | array($searchtags, $searchterm) | ||
1173 | ); | ||
1174 | } | ||
1175 | elseif ($searchtags) { | ||
1176 | $links = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); | ||
1177 | } | ||
1178 | elseif ($searchterm) { | ||
1179 | $links = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); | ||
1180 | } | ||
1181 | else { | ||
1182 | $links = $LINKSDB; | ||
1183 | } | ||
1184 | |||
1185 | $linksToDisplay = array(); | 966 | $linksToDisplay = array(); |
1186 | 967 | ||
1187 | // Get only links which have a thumbnail. | 968 | // Get only links which have a thumbnail. |
@@ -1260,6 +1041,49 @@ function renderPage() | |||
1260 | showDaily($PAGE); | 1041 | showDaily($PAGE); |
1261 | } | 1042 | } |
1262 | 1043 | ||
1044 | // ATOM and RSS feed. | ||
1045 | if ($targetPage == Router::$PAGE_FEED_ATOM || $targetPage == Router::$PAGE_FEED_RSS) { | ||
1046 | $feedType = $targetPage == Router::$PAGE_FEED_RSS ? FeedBuilder::$FEED_RSS : FeedBuilder::$FEED_ATOM; | ||
1047 | header('Content-Type: application/'. $feedType .'+xml; charset=utf-8'); | ||
1048 | |||
1049 | // Cache system | ||
1050 | $query = $_SERVER['QUERY_STRING']; | ||
1051 | $cache = new CachedPage( | ||
1052 | $GLOBALS['config']['PAGECACHE'], | ||
1053 | page_url($_SERVER), | ||
1054 | startsWith($query,'do='. $targetPage) && !isLoggedIn() | ||
1055 | ); | ||
1056 | $cached = $cache->cachedVersion(); | ||
1057 | if (false && !empty($cached)) { | ||
1058 | echo $cached; | ||
1059 | exit; | ||
1060 | } | ||
1061 | |||
1062 | // Generate data. | ||
1063 | $feedGenerator = new FeedBuilder($LINKSDB, $feedType, $_SERVER, $_GET, isLoggedIn()); | ||
1064 | $feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0))); | ||
1065 | $feedGenerator->setHideDates($GLOBALS['config']['HIDE_TIMESTAMPS'] && !isLoggedIn()); | ||
1066 | $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']); | ||
1067 | if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { | ||
1068 | $feedGenerator->setPubsubhubUrl($GLOBALS['config']['PUBSUBHUB_URL']); | ||
1069 | } | ||
1070 | $data = $feedGenerator->buildData(); | ||
1071 | |||
1072 | // Process plugin hook. | ||
1073 | $pluginManager = PluginManager::getInstance(); | ||
1074 | $pluginManager->executeHooks('render_feed', $data, array( | ||
1075 | 'loggedin' => isLoggedIn(), | ||
1076 | 'target' => $targetPage, | ||
1077 | )); | ||
1078 | |||
1079 | // Render the template. | ||
1080 | $PAGE->assignAll($data); | ||
1081 | $PAGE->renderPage('feed.'. $feedType); | ||
1082 | $cache->cache(ob_get_contents()); | ||
1083 | ob_end_flush(); | ||
1084 | exit; | ||
1085 | } | ||
1086 | |||
1263 | // Display openseach plugin (XML) | 1087 | // Display openseach plugin (XML) |
1264 | if ($targetPage == Router::$PAGE_OPENSEARCH) { | 1088 | if ($targetPage == Router::$PAGE_OPENSEARCH) { |
1265 | header('Content-Type: application/xml; charset=utf-8'); | 1089 | header('Content-Type: application/xml; charset=utf-8'); |
@@ -1511,9 +1335,9 @@ function renderPage() | |||
1511 | 1335 | ||
1512 | // Delete a tag: | 1336 | // Delete a tag: |
1513 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { | 1337 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { |
1514 | $needle=trim($_POST['fromtag']); | 1338 | $needle = trim($_POST['fromtag']); |
1515 | // True for case-sensitive tag search. | 1339 | // True for case-sensitive tag search. |
1516 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); | 1340 | $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); |
1517 | foreach($linksToAlter as $key=>$value) | 1341 | foreach($linksToAlter as $key=>$value) |
1518 | { | 1342 | { |
1519 | $tags = explode(' ',trim($value['tags'])); | 1343 | $tags = explode(' ',trim($value['tags'])); |
@@ -1528,9 +1352,9 @@ function renderPage() | |||
1528 | 1352 | ||
1529 | // Rename a tag: | 1353 | // Rename a tag: |
1530 | if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { | 1354 | if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { |
1531 | $needle=trim($_POST['fromtag']); | 1355 | $needle = trim($_POST['fromtag']); |
1532 | // True for case-sensitive tag search. | 1356 | // True for case-sensitive tag search. |
1533 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); | 1357 | $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); |
1534 | foreach($linksToAlter as $key=>$value) | 1358 | foreach($linksToAlter as $key=>$value) |
1535 | { | 1359 | { |
1536 | $tags = explode(' ',trim($value['tags'])); | 1360 | $tags = explode(' ',trim($value['tags'])); |
@@ -1966,60 +1790,32 @@ function importFile() | |||
1966 | } | 1790 | } |
1967 | } | 1791 | } |
1968 | 1792 | ||
1969 | // ----------------------------------------------------------------------------------------------- | 1793 | /** |
1970 | // Template for the list of links (<div id="linklist">) | 1794 | * Template for the list of links (<div id="linklist">) |
1971 | // This function fills all the necessary fields in the $PAGE for the template 'linklist.html' | 1795 | * This function fills all the necessary fields in the $PAGE for the template 'linklist.html' |
1796 | * | ||
1797 | * @param pageBuilder $PAGE pageBuilder instance. | ||
1798 | * @param LinkDB $LINKSDB LinkDB instance. | ||
1799 | */ | ||
1972 | function buildLinkList($PAGE,$LINKSDB) | 1800 | function buildLinkList($PAGE,$LINKSDB) |
1973 | { | 1801 | { |
1974 | // Filter link database according to parameters. | 1802 | // Used in templates |
1975 | $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; | 1803 | $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; |
1976 | $searchterm = !empty($_GET['searchterm']) ? escape(trim($_GET['searchterm'])) : ''; | 1804 | $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; |
1977 | $privateonly = !empty($_SESSION['privateonly']) ? true : false; | ||
1978 | |||
1979 | // Search tags + fullsearch. | ||
1980 | if (! empty($searchtags) && ! empty($searchterm)) { | ||
1981 | $linksToDisplay = $LINKSDB->filter( | ||
1982 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | ||
1983 | array($searchtags, $searchterm), | ||
1984 | false, | ||
1985 | $privateonly | ||
1986 | ); | ||
1987 | } | ||
1988 | // Search by tags. | ||
1989 | elseif (! empty($searchtags)) { | ||
1990 | $linksToDisplay = $LINKSDB->filter( | ||
1991 | LinkFilter::$FILTER_TAG, | ||
1992 | $searchtags, | ||
1993 | false, | ||
1994 | $privateonly | ||
1995 | ); | ||
1996 | } | ||
1997 | // Fulltext search. | ||
1998 | elseif (! empty($searchterm)) { | ||
1999 | $linksToDisplay = $LINKSDB->filter( | ||
2000 | LinkFilter::$FILTER_TEXT, | ||
2001 | $searchterm, | ||
2002 | false, | ||
2003 | $privateonly | ||
2004 | ); | ||
2005 | } | ||
2006 | // Detect smallHashes in URL. | ||
2007 | elseif (! empty($_SERVER['QUERY_STRING']) | ||
2008 | && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING']) | ||
2009 | ) { | ||
2010 | $linksToDisplay = $LINKSDB->filter( | ||
2011 | LinkFilter::$FILTER_HASH, | ||
2012 | substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6) | ||
2013 | ); | ||
2014 | 1805 | ||
2015 | if (count($linksToDisplay) == 0) { | 1806 | // Smallhash filter |
2016 | $PAGE->render404('The link you are trying to reach does not exist or has been deleted.'); | 1807 | if (! empty($_SERVER['QUERY_STRING']) |
1808 | && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) { | ||
1809 | try { | ||
1810 | $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']); | ||
1811 | } catch (LinkNotFoundException $e) { | ||
1812 | $PAGE->render404($e->getMessage()); | ||
2017 | exit; | 1813 | exit; |
2018 | } | 1814 | } |
2019 | } | 1815 | } else { |
2020 | // Otherwise, display without filtering. | 1816 | // Filter links according search parameters. |
2021 | else { | 1817 | $privateonly = !empty($_SESSION['privateonly']); |
2022 | $linksToDisplay = $LINKSDB->filter('', '', false, $privateonly); | 1818 | $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly); |
2023 | } | 1819 | } |
2024 | 1820 | ||
2025 | // ---- Handle paging. | 1821 | // ---- Handle paging. |
@@ -2584,8 +2380,6 @@ function resizeImage($filepath) | |||
2584 | } | 2380 | } |
2585 | 2381 | ||
2586 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. | 2382 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. |
2587 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } | ||
2588 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } | ||
2589 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } | 2383 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } |
2590 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; | 2384 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; |
2591 | renderPage(); | 2385 | renderPage(); |