diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-08-03 09:45:28 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-08-03 09:54:57 +0200 |
commit | c6d876bb2afe7e9ec1a64c74e766360e2fa441e0 (patch) | |
tree | f1e704d6c937ac6aec8814141cbb2f1e40e5ba88 /application | |
parent | 9646b7da22c4c6f3419bfe51431720dd622374d8 (diff) | |
download | Shaarli-c6d876bb2afe7e9ec1a64c74e766360e2fa441e0.tar.gz Shaarli-c6d876bb2afe7e9ec1a64c74e766360e2fa441e0.tar.zst Shaarli-c6d876bb2afe7e9ec1a64c74e766360e2fa441e0.zip |
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
Diffstat (limited to 'application')
-rw-r--r-- | application/FeedBuilder.php | 38 |
1 files changed, 32 insertions, 6 deletions
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 | |||
154 | } | 154 | } |
155 | $link['description'] = format_description($link['description']) . PHP_EOL .'<br>— '. $permalink; | 155 | $link['description'] = format_description($link['description']) . PHP_EOL .'<br>— '. $permalink; |
156 | 156 | ||
157 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | 157 | $pubDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); |
158 | $link['pub_iso_date'] = $this->getIsoDate($pubDate); | ||
158 | 159 | ||
159 | if ($this->feedType == self::$FEED_RSS) { | 160 | // atom:entry elements MUST contain exactly one atom:updated element. |
160 | $link['iso_date'] = $date->format(DateTime::RSS); | 161 | if (!empty($link['updated'])) { |
162 | $upDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']); | ||
163 | $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); | ||
161 | } else { | 164 | } else { |
162 | $link['iso_date'] = $date->format(DateTime::ATOM); | 165 | $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);; |
163 | } | 166 | } |
164 | 167 | ||
165 | // Save the more recent item. | 168 | // Save the more recent item. |
166 | if (empty($this->latestDate) || $this->latestDate < $date) { | 169 | if (empty($this->latestDate) || $this->latestDate < $pubDate) { |
167 | $this->latestDate = $date; | 170 | $this->latestDate = $pubDate; |
171 | } | ||
172 | if (!empty($upDate) && $this->latestDate < $upDate) { | ||
173 | $this->latestDate = $upDate; | ||
168 | } | 174 | } |
169 | 175 | ||
170 | $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); | 176 | $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); |
@@ -250,6 +256,26 @@ class FeedBuilder | |||
250 | } | 256 | } |
251 | 257 | ||
252 | /** | 258 | /** |
259 | * Get ISO date from DateTime according to feed type. | ||
260 | * | ||
261 | * @param DateTime $date Date to format. | ||
262 | * @param string|bool $format Force format. | ||
263 | * | ||
264 | * @return string Formatted date. | ||
265 | */ | ||
266 | protected function getIsoDate(DateTime $date, $format = false) | ||
267 | { | ||
268 | if ($format !== false) { | ||
269 | return $date->format($format); | ||
270 | } | ||
271 | if ($this->feedType == self::$FEED_RSS) { | ||
272 | return $date->format(DateTime::RSS); | ||
273 | |||
274 | } | ||
275 | return $date->format(DateTime::ATOM); | ||
276 | } | ||
277 | |||
278 | /** | ||
253 | * Returns the number of link to display according to 'nb' user input parameter. | 279 | * Returns the number of link to display according to 'nb' user input parameter. |
254 | * | 280 | * |
255 | * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. | 281 | * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. |