X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FFeedBuilder.php;h=c6657fbb483215074a4bd5ce5cb57adf6a4276ff;hb=44a718090d716e53c0e78bf3a0225fd2fb30071e;hp=50e0983152484a3e9fc53d06dd15f62debe60b7e;hpb=82e3680203896f024958ae969e2c4fccee9682f4;p=github%2Fshaarli%2FShaarli.git diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index 50e09831..c6657fbb 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -103,23 +103,7 @@ class FeedBuilder public function buildData() { // Optionally filter the results: - $searchtags = !empty($this->userInput['searchtags']) ? escape($this->userInput['searchtags']) : ''; - $searchterm = !empty($this->userInput['searchterm']) ? escape($this->userInput['searchterm']) : ''; - if (! empty($searchtags) && ! empty($searchterm)) { - $linksToDisplay = $this->linkDB->filter( - LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, - array($searchtags, $searchterm) - ); - } - elseif ($searchtags) { - $linksToDisplay = $this->linkDB->filter(LinkFilter::$FILTER_TAG, $searchtags); - } - elseif ($searchterm) { - $linksToDisplay = $this->linkDB->filter(LinkFilter::$FILTER_TEXT, $searchterm); - } - else { - $linksToDisplay = $this->linkDB; - } + $linksToDisplay = $this->linkDB->filterSearch($this->userInput); $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay)); @@ -140,7 +124,8 @@ class FeedBuilder $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['self_link'] = escape(server_url($this->serverInfo)) + . escape($this->serverInfo['REQUEST_URI']); $data['index_url'] = $pageaddr; $data['usepermalinks'] = $this->usePermalinks === true; $data['links'] = $linkDisplayed; @@ -170,17 +155,23 @@ class FeedBuilder } $link['description'] = format_description($link['description']) . PHP_EOL .'
— '. $permalink; - $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $pubDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $link['pub_iso_date'] = $this->getIsoDate($pubDate); - if ($this->feedType == self::$FEED_RSS) { - $link['iso_date'] = $date->format(DateTime::RSS); + // atom:entry elements MUST contain exactly one atom:updated element. + if (!empty($link['updated'])) { + $upDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']); + $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); } else { - $link['iso_date'] = $date->format(DateTime::ATOM); + $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);; } // Save the more recent item. - if (empty($this->latestDate) || $this->latestDate < $date) { - $this->latestDate = $date; + if (empty($this->latestDate) || $this->latestDate < $pubDate) { + $this->latestDate = $pubDate; + } + if (!empty($upDate) && $this->latestDate < $upDate) { + $this->latestDate = $upDate; } $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); @@ -265,6 +256,26 @@ class FeedBuilder return $this->latestDate->format($type); } + /** + * Get ISO date from DateTime according to feed type. + * + * @param DateTime $date Date to format. + * @param string|bool $format Force format. + * + * @return string Formatted date. + */ + protected function getIsoDate(DateTime $date, $format = false) + { + if ($format !== false) { + return $date->format($format); + } + if ($this->feedType == self::$FEED_RSS) { + return $date->format(DateTime::RSS); + + } + return $date->format(DateTime::ATOM); + } + /** * Returns the number of link to display according to 'nb' user input parameter. *