diff options
Diffstat (limited to 'application/FeedBuilder.php')
-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. |