aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/FeedBuilder.php38
-rw-r--r--application/HttpUtils.php26
-rw-r--r--application/LinkDB.php3
3 files changed, 60 insertions, 7 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.
diff --git a/application/HttpUtils.php b/application/HttpUtils.php
index 27a39d3d..e705cfd6 100644
--- a/application/HttpUtils.php
+++ b/application/HttpUtils.php
@@ -355,3 +355,29 @@ function page_url($server)
355 } 355 }
356 return index_url($server); 356 return index_url($server);
357} 357}
358
359/**
360 * Retrieve the initial IP forwarded by the reverse proxy.
361 *
362 * Inspired from: https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/RemoteAddress.php
363 *
364 * @param array $server $_SERVER array which contains HTTP headers.
365 * @param array $trustedIps List of trusted IP from the configuration.
366 *
367 * @return string|bool The forwarded IP, or false if none could be extracted.
368 */
369function getIpAddressFromProxy($server, $trustedIps)
370{
371 $forwardedIpHeader = 'HTTP_X_FORWARDED_FOR';
372 if (empty($server[$forwardedIpHeader])) {
373 return false;
374 }
375
376 $ips = preg_split('/\s*,\s*/', $server[$forwardedIpHeader]);
377 $ips = array_diff($ips, $trustedIps);
378 if (empty($ips)) {
379 return false;
380 }
381
382 return array_pop($ips);
383}
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 @@
12 * 12 *
13 * Available keys: 13 * Available keys:
14 * - description: description of the entry 14 * - description: description of the entry
15 * - linkdate: date of the creation of this entry, in the form YYYYMMDD_HHMMSS 15 * - linkdate: creation date of this entry, format: YYYYMMDD_HHMMSS
16 * (e.g.'20110914_192317') 16 * (e.g.'20110914_192317')
17 * - updated: last modification date of this entry, format: YYYYMMDD_HHMMSS
17 * - private: Is this link private? 0=no, other value=yes 18 * - private: Is this link private? 0=no, other value=yes
18 * - tags: tags attached to this entry (separated by spaces) 19 * - tags: tags attached to this entry (separated by spaces)
19 * - title Title of the link 20 * - title Title of the link