aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/FeedBuilder.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-10-12 14:51:37 +0200
committerGitHub <noreply@github.com>2016-10-12 14:51:37 +0200
commit03542572665bae57705a2f57b0737ed43f4f1415 (patch)
treeed4f096826babda6ad25eba4951a6a76cbad2a34 /application/FeedBuilder.php
parentadcdac1dec45090e2fa1cd4a340e91a40c7a205f (diff)
parentc6d876bb2afe7e9ec1a64c74e766360e2fa441e0 (diff)
downloadShaarli-03542572665bae57705a2f57b0737ed43f4f1415.tar.gz
Shaarli-03542572665bae57705a2f57b0737ed43f4f1415.tar.zst
Shaarli-03542572665bae57705a2f57b0737ed43f4f1415.zip
Merge pull request #622 from ArthurHoaro/update-date
Save link update dates and render it in templates and feeds
Diffstat (limited to 'application/FeedBuilder.php')
-rw-r--r--application/FeedBuilder.php38
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>&#8212; '. $permalink; 155 $link['description'] = format_description($link['description']) . PHP_EOL .'<br>&#8212; '. $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.