From: Arthur Date: Sat, 26 Mar 2016 15:46:04 +0000 (+0100) Subject: Merge pull request #520 from ArthurHoaro/plugins/nomarkdown X-Git-Tag: v0.7.0~22 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=1a84bf1e2bc45787d9cfa81fa427a11a3aba623a;hp=340252ae5de67f46ad43793858532da0cce8b4e2;p=github%2Fshaarli%2FShaarli.git Merge pull request #520 from ArthurHoaro/plugins/nomarkdown Markdown: Add the 'meta-tag' `.nomarkdown` which prevent a shaare fro… --- diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php new file mode 100644 index 00000000..ddefe6ce --- /dev/null +++ b/application/FeedBuilder.php @@ -0,0 +1,279 @@ +linkDB = $linkDB; + $this->feedType = $feedType; + $this->serverInfo = $serverInfo; + $this->userInput = $userInput; + $this->isLoggedIn = $isLoggedIn; + } + + /** + * Build data for feed templates. + * + * @return array Formatted data for feeds templates. + */ + public function buildData() + { + // Optionally filter the results: + $linksToDisplay = $this->linkDB->filterSearch($this->userInput); + + $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay)); + + // Can't use array_keys() because $link is a LinkDB instance and not a real array. + $keys = array(); + foreach ($linksToDisplay as $key => $value) { + $keys[] = $key; + } + + $pageaddr = escape(index_url($this->serverInfo)); + $linkDisplayed = array(); + for ($i = 0; $i < $nblinksToDisplay && $i < count($keys); $i++) { + $linkDisplayed[$keys[$i]] = $this->buildItem($linksToDisplay[$keys[$i]], $pageaddr); + } + + $data['language'] = $this->getTypeLanguage(); + $data['pubsubhub_url'] = $this->pubsubhubUrl; + $data['last_update'] = $this->getLatestDateFormatted(); + $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; + // Remove leading slash from REQUEST_URI. + $data['self_link'] = $pageaddr . escape(ltrim($this->serverInfo['REQUEST_URI'], '/')); + $data['index_url'] = $pageaddr; + $data['usepermalinks'] = $this->usePermalinks === true; + $data['links'] = $linkDisplayed; + + return $data; + } + + /** + * Build a feed item (one per shaare). + * + * @param array $link Single link array extracted from LinkDB. + * @param string $pageaddr Index URL. + * + * @return array Link array with feed attributes. + */ + protected function buildItem($link, $pageaddr) + { + $link['guid'] = $pageaddr .'?'. smallHash($link['linkdate']); + // Check for both signs of a note: starting with ? and 7 chars long. + if ($link['url'][0] === '?' && strlen($link['url']) === 7) { + $link['url'] = $pageaddr . $link['url']; + } + if ($this->usePermalinks === true) { + $permalink = 'Direct link'; + } else { + $permalink = 'Permalink'; + } + $link['description'] = format_description($link['description']) . PHP_EOL .'
— '. $permalink; + + $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + + if ($this->feedType == self::$FEED_RSS) { + $link['iso_date'] = $date->format(DateTime::RSS); + } else { + $link['iso_date'] = $date->format(DateTime::ATOM); + } + + // Save the more recent item. + if (empty($this->latestDate) || $this->latestDate < $date) { + $this->latestDate = $date; + } + + $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); + uasort($taglist, 'strcasecmp'); + $link['taglist'] = $taglist; + + return $link; + } + + /** + * Assign PubSub hub URL. + * + * @param string $pubsubhubUrl PubSub hub url. + */ + public function setPubsubhubUrl($pubsubhubUrl) + { + $this->pubsubhubUrl = $pubsubhubUrl; + } + + /** + * Set this to true to use permalinks instead of direct links. + * + * @param boolean $usePermalinks true to force permalinks. + */ + public function setUsePermalinks($usePermalinks) + { + $this->usePermalinks = $usePermalinks; + } + + /** + * Set this to true to hide timestamps in feeds. + * + * @param boolean $hideDates true to enable. + */ + public function setHideDates($hideDates) + { + $this->hideDates = $hideDates; + } + + /** + * Set the locale. Used to show feed language. + * + * @param string $locale The locale (eg. 'fr_FR.UTF8'). + */ + public function setLocale($locale) + { + $this->locale = strtolower($locale); + } + + /** + * Get the language according to the feed type, based on the locale: + * + * - RSS format: en-us (default: 'en-en'). + * - ATOM format: fr (default: 'en'). + * + * @return string The language. + */ + public function getTypeLanguage() + { + // Use the locale do define the language, if available. + if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { + $length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; + return str_replace('_', '-', substr($this->locale, 0, $length)); + } + return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en'; + } + + /** + * Format the latest item date found according to the feed type. + * + * Return an empty string if invalid DateTime is passed. + * + * @return string Formatted date. + */ + protected function getLatestDateFormatted() + { + if (empty($this->latestDate) || !$this->latestDate instanceof DateTime) { + return ''; + } + + $type = ($this->feedType == self::$FEED_RSS) ? DateTime::RSS : DateTime::ATOM; + return $this->latestDate->format($type); + } + + /** + * Returns the number of link to display according to 'nb' user input parameter. + * + * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. + * If 'nb' is set to 'all', display all filtered links (max parameter). + * + * @param int $max maximum number of links to display. + * + * @return int number of links to display. + */ + public function getNbLinks($max) + { + if (empty($this->userInput['nb'])) { + return self::$DEFAULT_NB_LINKS; + } + + if ($this->userInput['nb'] == 'all') { + return $max; + } + + $intNb = intval($this->userInput['nb']); + if (! is_int($intNb) || $intNb == 0) { + return self::$DEFAULT_NB_LINKS; + } + + return $intNb; + } +} diff --git a/application/LinkDB.php b/application/LinkDB.php index 1b505620..a62341fc 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@ -341,17 +341,71 @@ You use the community supported version of the original Shaarli project, by Seba } /** - * Filter links. + * Returns the shaare corresponding to a smallHash. * - * @param string $type Type of filter. - * @param mixed $request Search request, string or array. + * @param string $request QUERY_STRING server parameter. + * + * @return array $filtered array containing permalink data. + * + * @throws LinkNotFoundException if the smallhash is malformed or doesn't match any link. + */ + public function filterHash($request) + { + $request = substr($request, 0, 6); + $linkFilter = new LinkFilter($this->_links); + return $linkFilter->filter(LinkFilter::$FILTER_HASH, $request); + } + + /** + * Returns the list of articles for a given day. + * + * @param string $request day to filter. Format: YYYYMMDD. + * + * @return array list of shaare found. + */ + public function filterDay($request) { + $linkFilter = new LinkFilter($this->_links); + return $linkFilter->filter(LinkFilter::$FILTER_DAY, $request); + } + + /** + * Filter links according to search parameters. + * + * @param array $filterRequest Search request content. Supported keys: + * - searchtags: list of tags + * - searchterm: term search * @param bool $casesensitive Optional: Perform case sensitive filter * @param bool $privateonly Optional: Returns private links only if true. * - * @return array filtered links + * @return array filtered links, all links if no suitable filter was provided. */ - public function filter($type = '', $request = '', $casesensitive = false, $privateonly = false) + public function filterSearch($filterRequest = array(), $casesensitive = false, $privateonly = false) { + // Filter link database according to parameters. + $searchtags = !empty($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; + $searchterm = !empty($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; + + // Search tags + fullsearch. + if (empty($type) && ! empty($searchtags) && ! empty($searchterm)) { + $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; + $request = array($searchtags, $searchterm); + } + // Search by tags. + elseif (! empty($searchtags)) { + $type = LinkFilter::$FILTER_TAG; + $request = $searchtags; + } + // Fulltext search. + elseif (! empty($searchterm)) { + $type = LinkFilter::$FILTER_TEXT; + $request = $searchterm; + } + // Otherwise, display without filtering. + else { + $type = ''; + $request = ''; + } + $linkFilter = new LinkFilter($this->_links); return $linkFilter->filter($type, $request, $casesensitive, $privateonly); } diff --git a/application/LinkFilter.php b/application/LinkFilter.php index 3fd803cb..5e0d8015 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -44,7 +44,7 @@ class LinkFilter * Filter links according to parameters. * * @param string $type Type of filter (eg. tags, permalink, etc.). - * @param string $request Filter content. + * @param mixed $request Filter content. * @param bool $casesensitive Optional: Perform case sensitive filter if true. * @param bool $privateonly Optional: Only returns private links if true. * @@ -110,6 +110,8 @@ class LinkFilter * @param string $smallHash permalink hash. * * @return array $filtered array containing permalink data. + * + * @throws LinkNotFoundException if the smallhash doesn't match any link. */ private function filterSmallHash($smallHash) { @@ -121,6 +123,11 @@ class LinkFilter return $filtered; } } + + if (empty($filtered)) { + throw new LinkNotFoundException(); + } + return $filtered; } @@ -318,3 +325,8 @@ class LinkFilter return array_filter(explode(' ', trim($tagsOut)), 'strlen'); } } + +class LinkNotFoundException extends Exception +{ + protected $message = 'The link you are trying to reach does not exist or has been deleted.'; +} diff --git a/application/LinkUtils.php b/application/LinkUtils.php index 26dd6b67..d8dc8b5e 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php @@ -9,7 +9,7 @@ */ function html_extract_title($html) { - if (preg_match('!(.*)!is', $html, $matches)) { + if (preg_match('!(.*?)!is', $html, $matches)) { return trim(str_replace("\n", ' ', $matches[1])); } return false; diff --git a/application/Router.php b/application/Router.php index 6185f08e..a1e594a0 100644 --- a/application/Router.php +++ b/application/Router.php @@ -15,6 +15,10 @@ class Router public static $PAGE_DAILY = 'daily'; + public static $PAGE_FEED_ATOM = 'atom'; + + public static $PAGE_FEED_RSS = 'rss'; + public static $PAGE_TOOLS = 'tools'; public static $PAGE_CHANGEPASSWORD = 'changepasswd'; @@ -49,7 +53,7 @@ class Router * @param array $get $_SERVER['GET']. * @param bool $loggedIn true if authenticated user. * - * @return self::page found. + * @return string page found. */ public static function findPage($query, $get, $loggedIn) { @@ -79,6 +83,14 @@ class Router return self::$PAGE_DAILY; } + if (startsWith($query, 'do='. self::$PAGE_FEED_ATOM)) { + return self::$PAGE_FEED_ATOM; + } + + if (startsWith($query, 'do='. self::$PAGE_FEED_RSS)) { + return self::$PAGE_FEED_RSS; + } + // At this point, only loggedin pages. if (!$loggedIn) { return self::$PAGE_LINKLIST; diff --git a/application/Updater.php b/application/Updater.php index 773a1ffa..58c13c07 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -137,7 +137,7 @@ class Updater */ public function updateMethodRenameDashTags() { - $linklist = $this->linkDB->filter(); + $linklist = $this->linkDB->filterSearch(); foreach ($linklist as $link) { $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); diff --git a/application/Utils.php b/application/Utils.php index 3d819716..5b8ca508 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -63,14 +63,22 @@ function endsWith($haystack, $needle, $case=true) /** * Htmlspecialchars wrapper + * Support multidimensional array of strings. * - * @param string $str the string to escape. + * @param mixed $input Data to escape: a single string or an array of strings. * * @return string escaped. */ -function escape($str) +function escape($input) { - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); + if (is_array($input)) { + $out = array(); + foreach($input as $key => $value) { + $out[$key] = escape($value); + } + return $out; + } + return htmlspecialchars($input, ENT_COMPAT, 'UTF-8', false); } /** @@ -226,7 +234,7 @@ function space2nbsp($text) * * @return string formatted description. */ -function format_description($description, $redirector) { +function format_description($description, $redirector = false) { return nl2br(space2nbsp(text2clickable($description, $redirector))); } diff --git a/index.php b/index.php index 850b350e..74091f37 100644 --- a/index.php +++ b/index.php @@ -154,6 +154,7 @@ if (is_file($GLOBALS['config']['CONFIG_FILE'])) { require_once 'application/ApplicationUtils.php'; require_once 'application/Cache.php'; require_once 'application/CachedPage.php'; +require_once 'application/FeedBuilder.php'; require_once 'application/FileUtils.php'; require_once 'application/HttpUtils.php'; require_once 'application/LinkDB.php'; @@ -483,7 +484,7 @@ if (isset($_POST['login'])) if (isset($_POST['returnurl'])) { // Prevent loops over login screen. if (strpos($_POST['returnurl'], 'do=login') === false) { - header('Location: '. escape($_POST['returnurl'])); + header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); exit; } } @@ -637,6 +638,29 @@ class pageBuilder $this->tpl->assign($what,$where); } + /** + * Assign an array of data to the template builder. + * + * @param array $data Data to assign. + * + * @return false if invalid data. + */ + public function assignAll($data) + { + // Lazy initialization + if ($this->tpl === false) { + $this->initialize(); + } + + if (empty($data) || !is_array($data)){ + return false; + } + + foreach ($data as $key => $value) { + $this->assign($key, $value); + } + } + // Render a specific page (using a template). // e.g. pb.renderPage('picwall') public function renderPage($page) @@ -658,232 +682,6 @@ class pageBuilder } } -// ------------------------------------------------------------------------------------------ -// Output the last N links in RSS 2.0 format. -function showRSS() -{ - header('Content-Type: application/rss+xml; charset=utf-8'); - - // $usepermalink : If true, use permalink instead of final link. - // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=rss&permalinks - // Also enabled through a config option - $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; - - // Cache system - $query = $_SERVER["QUERY_STRING"]; - $cache = new CachedPage( - $GLOBALS['config']['PAGECACHE'], - page_url($_SERVER), - startsWith($query,'do=rss') && !isLoggedIn() - ); - $cached = $cache->cachedVersion(); - if (! empty($cached)) { - echo $cached; - exit; - } - - // If cached was not found (or not usable), then read the database and build the response: - $LINKSDB = new LinkDB( - $GLOBALS['config']['DATASTORE'], - isLoggedIn(), - $GLOBALS['config']['HIDE_PUBLIC_LINKS'], - $GLOBALS['redirector'] - ); - // Read links from database (and filter private links if user it not logged in). - - // Optionally filter the results: - $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; - $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; - if (! empty($searchtags) && ! empty($searchterm)) { - $linksToDisplay = $LINKSDB->filter( - LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, - array($searchtags, $searchterm) - ); - } - elseif ($searchtags) { - $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); - } - elseif ($searchterm) { - $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); - } - else { - $linksToDisplay = $LINKSDB; - } - - $nblinksToDisplay = 50; // Number of links to display. - // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - if (!empty($_GET['nb'])) { - $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); - } - - $pageaddr = escape(index_url($_SERVER)); - echo ''; - echo ''.$GLOBALS['title'].''.$pageaddr.''; - echo 'Shared linksen-en'.$pageaddr.''."\n\n"; - if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) - { - echo ''; - echo ''; - echo ''; - echo ''; - } - $i=0; - $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). - while ($i<$nblinksToDisplay && $i'.$link['title'].''.$guid.''.$guid.''; - else - echo ''.$link['title'].''.$guid.''.$absurl.''; - if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { - echo ''.escape($date->format(DateTime::RSS))."\n"; - } - if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) - { - foreach(explode(' ',$link['tags']) as $tag) { echo ''.$tag.''."\n"; } - } - - // Add permalink in description - $descriptionlink = '(Permalink)'; - // If user wants permalinks first, put the final link in description - if ($usepermalinks===true) $descriptionlink = '(Link)'; - if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; - echo '' . "\n
\n"; - $i++; - } - echo '
'; - - $cache->cache(ob_get_contents()); - ob_end_flush(); - exit; -} - -// ------------------------------------------------------------------------------------------ -// Output the last N links in ATOM format. -function showATOM() -{ - header('Content-Type: application/atom+xml; charset=utf-8'); - - // $usepermalink : If true, use permalink instead of final link. - // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=atom&permalinks - $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']; - - // Cache system - $query = $_SERVER["QUERY_STRING"]; - $cache = new CachedPage( - $GLOBALS['config']['PAGECACHE'], - page_url($_SERVER), - startsWith($query,'do=atom') && !isLoggedIn() - ); - $cached = $cache->cachedVersion(); - if (!empty($cached)) { - echo $cached; - exit; - } - - // If cached was not found (or not usable), then read the database and build the response: - // Read links from database (and filter private links if used it not logged in). - $LINKSDB = new LinkDB( - $GLOBALS['config']['DATASTORE'], - isLoggedIn(), - $GLOBALS['config']['HIDE_PUBLIC_LINKS'], - $GLOBALS['redirector'] - ); - - // Optionally filter the results: - $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; - $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; - if (! empty($searchtags) && ! empty($searchterm)) { - $linksToDisplay = $LINKSDB->filter( - LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, - array($searchtags, $searchterm) - ); - } - elseif ($searchtags) { - $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); - } - elseif ($searchterm) { - $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); - } - else { - $linksToDisplay = $LINKSDB; - } - - $nblinksToDisplay = 50; // Number of links to display. - // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - if (!empty($_GET['nb'])) { - $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max(intval($_GET['nb']), 1); - } - - $pageaddr=escape(index_url($_SERVER)); - $latestDate = ''; - $entries=''; - $i=0; - $keys=array(); foreach($linksToDisplay as $key=>$value) { $keys[]=$key; } // No, I can't use array_keys(). - while ($i<$nblinksToDisplay && $iformat(DateTime::ISO8601); - $latestDate = max($latestDate, $iso8601date); - $absurl = $link['url']; - if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute - $entries.=''.$link['title'].''; - if ($usepermalinks===true) - $entries.=''.$guid.''; - else - $entries.=''.$guid.''; - - if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) { - $entries.=''.escape($iso8601date).''; - } - - // Add permalink in description - $descriptionlink = '(Permalink)'; - // If user wants permalinks first, put the final link in description - if ($usepermalinks===true) $descriptionlink = '(Link)'; - if (strlen($link['description'])>0) $descriptionlink = '
'.$descriptionlink; - - $entries .= '\n"; - if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) - { - foreach(explode(' ',$link['tags']) as $tag) - { $entries.=''."\n"; } - } - $entries.="
\n"; - $i++; - } - $feed=''; - $feed.=''.$GLOBALS['title'].''; - if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $feed.=''.escape($latestDate).''; - $feed.=''; - if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) - { - $feed.=''; - $feed.=''; - $feed.=''; - } - $feed.=''.$pageaddr.''.$pageaddr.''; - $feed.=''.$pageaddr.''."\n\n"; // Yes, I know I should use a real IRI (RFC3987), but the site URL will do. - $feed.=$entries; - $feed.=''; - echo $feed; - - $cache->cache(ob_get_contents()); - ob_end_flush(); - exit; -} - // ------------------------------------------------------------------------------------------ // Daily RSS feed: 1 RSS entry per day giving all the links on that day. // Gives the last 7 days (which have links). @@ -1018,7 +816,7 @@ function showDaily($pageBuilder) } try { - $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_DAY, $day); + $linksToDisplay = $LINKSDB->filterDay($day); } catch (Exception $exc) { error_log($exc); $linksToDisplay = array(); @@ -1164,24 +962,7 @@ function renderPage() if ($targetPage == Router::$PAGE_PICWALL) { // Optionally filter the results: - $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; - $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; - if (! empty($searchtags) && ! empty($searchterm)) { - $links = $LINKSDB->filter( - LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, - array($searchtags, $searchterm) - ); - } - elseif ($searchtags) { - $links = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags); - } - elseif ($searchterm) { - $links = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); - } - else { - $links = $LINKSDB; - } - + $links = $LINKSDB->filterSearch($_GET); $linksToDisplay = array(); // Get only links which have a thumbnail. @@ -1260,6 +1041,49 @@ function renderPage() showDaily($PAGE); } + // ATOM and RSS feed. + if ($targetPage == Router::$PAGE_FEED_ATOM || $targetPage == Router::$PAGE_FEED_RSS) { + $feedType = $targetPage == Router::$PAGE_FEED_RSS ? FeedBuilder::$FEED_RSS : FeedBuilder::$FEED_ATOM; + header('Content-Type: application/'. $feedType .'+xml; charset=utf-8'); + + // Cache system + $query = $_SERVER['QUERY_STRING']; + $cache = new CachedPage( + $GLOBALS['config']['PAGECACHE'], + page_url($_SERVER), + startsWith($query,'do='. $targetPage) && !isLoggedIn() + ); + $cached = $cache->cachedVersion(); + if (false && !empty($cached)) { + echo $cached; + exit; + } + + // Generate data. + $feedGenerator = new FeedBuilder($LINKSDB, $feedType, $_SERVER, $_GET, isLoggedIn()); + $feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0))); + $feedGenerator->setHideDates($GLOBALS['config']['HIDE_TIMESTAMPS'] && !isLoggedIn()); + $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS']); + if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) { + $feedGenerator->setPubsubhubUrl($GLOBALS['config']['PUBSUBHUB_URL']); + } + $data = $feedGenerator->buildData(); + + // Process plugin hook. + $pluginManager = PluginManager::getInstance(); + $pluginManager->executeHooks('render_feed', $data, array( + 'loggedin' => isLoggedIn(), + 'target' => $targetPage, + )); + + // Render the template. + $PAGE->assignAll($data); + $PAGE->renderPage('feed.'. $feedType); + $cache->cache(ob_get_contents()); + ob_end_flush(); + exit; + } + // Display openseach plugin (XML) if ($targetPage == Router::$PAGE_OPENSEARCH) { header('Content-Type: application/xml; charset=utf-8'); @@ -1511,9 +1335,9 @@ function renderPage() // Delete a tag: if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { - $needle=trim($_POST['fromtag']); + $needle = trim($_POST['fromtag']); // True for case-sensitive tag search. - $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); + $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); foreach($linksToAlter as $key=>$value) { $tags = explode(' ',trim($value['tags'])); @@ -1528,9 +1352,9 @@ function renderPage() // Rename a tag: if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { - $needle=trim($_POST['fromtag']); + $needle = trim($_POST['fromtag']); // True for case-sensitive tag search. - $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); + $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true); foreach($linksToAlter as $key=>$value) { $tags = explode(' ',trim($value['tags'])); @@ -1966,60 +1790,32 @@ function importFile() } } -// ----------------------------------------------------------------------------------------------- -// Template for the list of links (