From 9646b7da22c4c6f3419bfe51431720dd622374d8 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 3 Aug 2016 09:44:04 +0200 Subject: Save the update date in LinkDB and pass it to linklist templates It can be used as a timestamp by templates under the key 'updated_timestamp'. --- application/LinkDB.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/LinkDB.php b/application/LinkDB.php index d80434bf..de9e73b0 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@ -12,8 +12,9 @@ * * Available keys: * - description: description of the entry - * - linkdate: date of the creation of this entry, in the form YYYYMMDD_HHMMSS + * - linkdate: creation date of this entry, format: YYYYMMDD_HHMMSS * (e.g.'20110914_192317') + * - updated: last modification date of this entry, format: YYYYMMDD_HHMMSS * - private: Is this link private? 0=no, other value=yes * - tags: tags attached to this entry (separated by spaces) * - title Title of the link -- cgit v1.2.3 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') 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