aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/FeedBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/FeedBuilder.php')
-rw-r--r--application/FeedBuilder.php46
1 files changed, 37 insertions, 9 deletions
diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php
index ddefe6ce..fedd90e6 100644
--- a/application/FeedBuilder.php
+++ b/application/FeedBuilder.php
@@ -124,7 +124,8 @@ class FeedBuilder
124 $data['last_update'] = $this->getLatestDateFormatted(); 124 $data['last_update'] = $this->getLatestDateFormatted();
125 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; 125 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
126 // Remove leading slash from REQUEST_URI. 126 // Remove leading slash from REQUEST_URI.
127 $data['self_link'] = $pageaddr . escape(ltrim($this->serverInfo['REQUEST_URI'], '/')); 127 $data['self_link'] = escape(server_url($this->serverInfo))
128 . escape($this->serverInfo['REQUEST_URI']);
128 $data['index_url'] = $pageaddr; 129 $data['index_url'] = $pageaddr;
129 $data['usepermalinks'] = $this->usePermalinks === true; 130 $data['usepermalinks'] = $this->usePermalinks === true;
130 $data['links'] = $linkDisplayed; 131 $data['links'] = $linkDisplayed;
@@ -142,7 +143,7 @@ class FeedBuilder
142 */ 143 */
143 protected function buildItem($link, $pageaddr) 144 protected function buildItem($link, $pageaddr)
144 { 145 {
145 $link['guid'] = $pageaddr .'?'. smallHash($link['linkdate']); 146 $link['guid'] = $pageaddr .'?'. $link['shorturl'];
146 // Check for both signs of a note: starting with ? and 7 chars long. 147 // Check for both signs of a note: starting with ? and 7 chars long.
147 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 148 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
148 $link['url'] = $pageaddr . $link['url']; 149 $link['url'] = $pageaddr . $link['url'];
@@ -152,19 +153,26 @@ class FeedBuilder
152 } else { 153 } else {
153 $permalink = '<a href="'. $link['guid'] .'" title="Permalink">Permalink</a>'; 154 $permalink = '<a href="'. $link['guid'] .'" title="Permalink">Permalink</a>';
154 } 155 }
155 $link['description'] = format_description($link['description']) . PHP_EOL .'<br>&#8212; '. $permalink; 156 $link['description'] = format_description($link['description'], '', $pageaddr);
157 $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink;
156 158
157 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 159 $pubDate = $link['created'];
160 $link['pub_iso_date'] = $this->getIsoDate($pubDate);
158 161
159 if ($this->feedType == self::$FEED_RSS) { 162 // atom:entry elements MUST contain exactly one atom:updated element.
160 $link['iso_date'] = $date->format(DateTime::RSS); 163 if (!empty($link['updated'])) {
164 $upDate = $link['updated'];
165 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
161 } else { 166 } else {
162 $link['iso_date'] = $date->format(DateTime::ATOM); 167 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);;
163 } 168 }
164 169
165 // Save the more recent item. 170 // Save the more recent item.
166 if (empty($this->latestDate) || $this->latestDate < $date) { 171 if (empty($this->latestDate) || $this->latestDate < $pubDate) {
167 $this->latestDate = $date; 172 $this->latestDate = $pubDate;
173 }
174 if (!empty($upDate) && $this->latestDate < $upDate) {
175 $this->latestDate = $upDate;
168 } 176 }
169 177
170 $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); 178 $taglist = array_filter(explode(' ', $link['tags']), 'strlen');
@@ -250,6 +258,26 @@ class FeedBuilder
250 } 258 }
251 259
252 /** 260 /**
261 * Get ISO date from DateTime according to feed type.
262 *
263 * @param DateTime $date Date to format.
264 * @param string|bool $format Force format.
265 *
266 * @return string Formatted date.
267 */
268 protected function getIsoDate(DateTime $date, $format = false)
269 {
270 if ($format !== false) {
271 return $date->format($format);
272 }
273 if ($this->feedType == self::$FEED_RSS) {
274 return $date->format(DateTime::RSS);
275
276 }
277 return $date->format(DateTime::ATOM);
278 }
279
280 /**
253 * Returns the number of link to display according to 'nb' user input parameter. 281 * Returns the number of link to display according to 'nb' user input parameter.
254 * 282 *
255 * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS. 283 * If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS.