X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FFeedBuilder.php;h=4036a7cccdf3e77fc1a026adc5ddff93c9845fde;hb=fbc28ff1c892460e90e87a1be6dd3e28a4cd58b8;hp=ddefe6ce93a83ed8f6869d1eee57941264731e72;hpb=1a84bf1e2bc45787d9cfa81fa427a11a3aba623a;p=github%2Fshaarli%2FShaarli.git
diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php
index ddefe6ce..4036a7cc 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;
@@ -152,19 +153,26 @@ 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;
- $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 +257,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.
*