From c6d876bb2afe7e9ec1a64c74e766360e2fa441e0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 3 Aug 2016 09:45:28 +0200 Subject: Set updated date for items in feeds RSS doesn't support updated date for items, so we use the ATOM extension. Updated dates also bump the global update --- application/FeedBuilder.php | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'application/FeedBuilder.php') diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index ddefe6ce..58c6bb17 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -154,17 +154,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'); @@ -249,6 +255,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. * -- cgit v1.2.3 From 44a718090d716e53c0e78bf3a0225fd2fb30071e Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sun, 16 Oct 2016 20:52:35 +0200 Subject: Fix: return the proper value for the "self" feed attribute Fixes https://github.com/shaarli/Shaarli/issues/629 Closes https://github.com/shaarli/Shaarli/pull/630 Note: you might need to empty the "pagecache" directory for the fix to be taken into account Signed-off-by: VirtualTam --- application/FeedBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'application/FeedBuilder.php') diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index 58c6bb17..c6657fbb 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -124,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; -- cgit v1.2.3 From fbc28ff1c892460e90e87a1be6dd3e28a4cd58b8 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 19 Oct 2016 11:05:20 +0200 Subject: Fix hashtags links in Feeds Make the hashtag link absolute in feeds to work properly in RSS syndication tools. --- application/FeedBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'application/FeedBuilder.php') diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index c6657fbb..4036a7cc 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -153,7 +153,8 @@ class FeedBuilder } else { $permalink = 'Permalink'; } - $link['description'] = format_description($link['description']) . PHP_EOL .'
— '. $permalink; + $link['description'] = format_description($link['description'], '', $pageaddr); + $link['description'] .= PHP_EOL .'
— '. $permalink; $pubDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); $link['pub_iso_date'] = $this->getIsoDate($pubDate); -- cgit v1.2.3 From 01878a75b93b9966f7366ea2937c118bbc3e459e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 16:16:44 +0100 Subject: Apply the new ID system accros the whole codebase --- application/FeedBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'application/FeedBuilder.php') diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index 4036a7cc..bfdf2fd3 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -143,7 +143,7 @@ class FeedBuilder */ protected function buildItem($link, $pageaddr) { - $link['guid'] = $pageaddr .'?'. smallHash($link['linkdate']); + $link['guid'] = $pageaddr .'?'. smallHash($link['created']->format('Ymd_His')); // 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']; @@ -156,12 +156,12 @@ class FeedBuilder $link['description'] = format_description($link['description'], '', $pageaddr); $link['description'] .= PHP_EOL .'
— '. $permalink; - $pubDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $pubDate = $link['created']; $link['pub_iso_date'] = $this->getIsoDate($pubDate); // atom:entry elements MUST contain exactly one atom:updated element. if (!empty($link['updated'])) { - $upDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']); + $upDate = $link['updated']; $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); } else { $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);; -- cgit v1.2.3 From d592daea8343bb4dfecff5d97e93699581ccc58c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 18:24:15 +0100 Subject: Add a persistent 'shorturl' key to all links All existing link will keep their permalinks. New links will have smallhash generated with date+id. The purpose of this is to avoid collision between links due to their creation date. --- application/FeedBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/FeedBuilder.php') diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php index bfdf2fd3..fedd90e6 100644 --- a/application/FeedBuilder.php +++ b/application/FeedBuilder.php @@ -143,7 +143,7 @@ class FeedBuilder */ protected function buildItem($link, $pageaddr) { - $link['guid'] = $pageaddr .'?'. smallHash($link['created']->format('Ymd_His')); + $link['guid'] = $pageaddr .'?'. $link['shorturl']; // 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']; -- cgit v1.2.3