diff options
-rw-r--r-- | application/FeedBuilder.php | 38 | ||||
-rw-r--r-- | application/LinkDB.php | 3 | ||||
-rw-r--r-- | index.php | 12 | ||||
-rw-r--r-- | tests/FeedBuilderTest.php | 14 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 6 | ||||
-rw-r--r-- | tpl/feed.atom.html | 3 | ||||
-rw-r--r-- | tpl/feed.rss.html | 3 | ||||
-rw-r--r-- | tpl/linklist.html | 11 |
8 files changed, 74 insertions, 16 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>— '. $permalink; | 155 | $link['description'] = format_description($link['description']) . PHP_EOL .'<br>— '. $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/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 |
@@ -1245,6 +1245,9 @@ function renderPage($conf, $pluginManager) | |||
1245 | // -------- User clicked the "Save" button when editing a link: Save link to database. | 1245 | // -------- User clicked the "Save" button when editing a link: Save link to database. |
1246 | if (isset($_POST['save_edit'])) | 1246 | if (isset($_POST['save_edit'])) |
1247 | { | 1247 | { |
1248 | $linkdate = $_POST['lf_linkdate']; | ||
1249 | $updated = isset($LINKSDB[$linkdate]) ? strval(date('Ymd_His')) : false; | ||
1250 | |||
1248 | // Go away! | 1251 | // Go away! |
1249 | if (! tokenOk($_POST['token'])) { | 1252 | if (! tokenOk($_POST['token'])) { |
1250 | die('Wrong token.'); | 1253 | die('Wrong token.'); |
@@ -1255,7 +1258,7 @@ function renderPage($conf, $pluginManager) | |||
1255 | $tags = preg_replace('/(^| )\-/', '$1', $tags); | 1258 | $tags = preg_replace('/(^| )\-/', '$1', $tags); |
1256 | // Remove duplicates. | 1259 | // Remove duplicates. |
1257 | $tags = implode(' ', array_unique(explode(' ', $tags))); | 1260 | $tags = implode(' ', array_unique(explode(' ', $tags))); |
1258 | $linkdate = $_POST['lf_linkdate']; | 1261 | |
1259 | $url = trim($_POST['lf_url']); | 1262 | $url = trim($_POST['lf_url']); |
1260 | if (! startsWith($url, 'http:') && ! startsWith($url, 'https:') | 1263 | if (! startsWith($url, 'http:') && ! startsWith($url, 'https:') |
1261 | && ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:') | 1264 | && ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:') |
@@ -1270,6 +1273,7 @@ function renderPage($conf, $pluginManager) | |||
1270 | 'description' => $_POST['lf_description'], | 1273 | 'description' => $_POST['lf_description'], |
1271 | 'private' => (isset($_POST['lf_private']) ? 1 : 0), | 1274 | 'private' => (isset($_POST['lf_private']) ? 1 : 0), |
1272 | 'linkdate' => $linkdate, | 1275 | 'linkdate' => $linkdate, |
1276 | 'updated' => $updated, | ||
1273 | 'tags' => str_replace(',', ' ', $tags) | 1277 | 'tags' => str_replace(',', ' ', $tags) |
1274 | ); | 1278 | ); |
1275 | // If title is empty, use the URL as title. | 1279 | // If title is empty, use the URL as title. |
@@ -1633,6 +1637,12 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | |||
1633 | $link['class'] = $link['private'] == 0 ? $classLi : 'private'; | 1637 | $link['class'] = $link['private'] == 0 ? $classLi : 'private'; |
1634 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | 1638 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); |
1635 | $link['timestamp'] = $date->getTimestamp(); | 1639 | $link['timestamp'] = $date->getTimestamp(); |
1640 | if (! empty($link['updated'])) { | ||
1641 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']); | ||
1642 | $link['updated_timestamp'] = $date->getTimestamp(); | ||
1643 | } else { | ||
1644 | $link['updated_timestamp'] = ''; | ||
1645 | } | ||
1636 | $taglist = explode(' ', $link['tags']); | 1646 | $taglist = explode(' ', $link['tags']); |
1637 | uasort($taglist, 'strcasecmp'); | 1647 | uasort($taglist, 'strcasecmp'); |
1638 | $link['taglist'] = $taglist; | 1648 | $link['taglist'] = $taglist; |
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php index 460fb0c5..c9ff397d 100644 --- a/tests/FeedBuilderTest.php +++ b/tests/FeedBuilderTest.php | |||
@@ -76,7 +76,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
76 | // Test headers (RSS) | 76 | // Test headers (RSS) |
77 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); | 77 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); |
78 | $this->assertEmpty($data['pubsubhub_url']); | 78 | $this->assertEmpty($data['pubsubhub_url']); |
79 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $data['last_update']); | 79 | $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); |
80 | $this->assertEquals(true, $data['show_dates']); | 80 | $this->assertEquals(true, $data['show_dates']); |
81 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); | 81 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); |
82 | $this->assertEquals('http://host.tld/', $data['index_url']); | 82 | $this->assertEquals('http://host.tld/', $data['index_url']); |
@@ -88,7 +88,10 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
88 | $this->assertEquals('20150310_114651', $link['linkdate']); | 88 | $this->assertEquals('20150310_114651', $link['linkdate']); |
89 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | 89 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); |
90 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | 90 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); |
91 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['iso_date']); | 91 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); |
92 | $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); | ||
93 | $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); | ||
94 | $this->assertEquals($pub, $up); | ||
92 | $this->assertContains('Stallman has a beard', $link['description']); | 95 | $this->assertContains('Stallman has a beard', $link['description']); |
93 | $this->assertContains('Permalink', $link['description']); | 96 | $this->assertContains('Permalink', $link['description']); |
94 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | 97 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); |
@@ -101,6 +104,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
101 | // Test multitags. | 104 | // Test multitags. |
102 | $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); | 105 | $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); |
103 | $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); | 106 | $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); |
107 | |||
108 | // Test update date | ||
109 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); | ||
104 | } | 110 | } |
105 | 111 | ||
106 | /** | 112 | /** |
@@ -112,8 +118,10 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
112 | $feedBuilder->setLocale(self::$LOCALE); | 118 | $feedBuilder->setLocale(self::$LOCALE); |
113 | $data = $feedBuilder->buildData(); | 119 | $data = $feedBuilder->buildData(); |
114 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 120 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
121 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); | ||
115 | $link = array_shift($data['links']); | 122 | $link = array_shift($data['links']); |
116 | $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:+\d{2}/', $link['iso_date']); | 123 | $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); |
124 | $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); | ||
117 | } | 125 | } |
118 | 126 | ||
119 | /** | 127 | /** |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index fcc7a4f9..937961c8 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -30,7 +30,8 @@ class ReferenceLinkDB | |||
30 | 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', | 30 | 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', |
31 | 0, | 31 | 0, |
32 | '20150310_114633', | 32 | '20150310_114633', |
33 | 'free gnu software stallman -exclude stuff hashtag' | 33 | 'free gnu software stallman -exclude stuff hashtag', |
34 | '20160803_093033' | ||
34 | ); | 35 | ); |
35 | 36 | ||
36 | $this->addLink( | 37 | $this->addLink( |
@@ -82,7 +83,7 @@ class ReferenceLinkDB | |||
82 | /** | 83 | /** |
83 | * Adds a new link | 84 | * Adds a new link |
84 | */ | 85 | */ |
85 | protected function addLink($title, $url, $description, $private, $date, $tags) | 86 | protected function addLink($title, $url, $description, $private, $date, $tags, $updated = '') |
86 | { | 87 | { |
87 | $link = array( | 88 | $link = array( |
88 | 'title' => $title, | 89 | 'title' => $title, |
@@ -91,6 +92,7 @@ class ReferenceLinkDB | |||
91 | 'private' => $private, | 92 | 'private' => $private, |
92 | 'linkdate' => $date, | 93 | 'linkdate' => $date, |
93 | 'tags' => $tags, | 94 | 'tags' => $tags, |
95 | 'updated' => $updated, | ||
94 | ); | 96 | ); |
95 | $this->_links[$date] = $link; | 97 | $this->_links[$date] = $link; |
96 | 98 | ||
diff --git a/tpl/feed.atom.html b/tpl/feed.atom.html index 2ebb162a..1932f507 100644 --- a/tpl/feed.atom.html +++ b/tpl/feed.atom.html | |||
@@ -27,7 +27,8 @@ | |||
27 | {/if} | 27 | {/if} |
28 | <id>{$value.guid}</id> | 28 | <id>{$value.guid}</id> |
29 | {if="$show_dates"} | 29 | {if="$show_dates"} |
30 | <updated>{$value.iso_date}</updated> | 30 | <published>{$value.pub_iso_date}</published> |
31 | <updated>{$value.up_iso_date}</updated> | ||
31 | {/if} | 32 | {/if} |
32 | <content type="html" xml:lang="{$language}"> | 33 | <content type="html" xml:lang="{$language}"> |
33 | <![CDATA[{$value.description}]]> | 34 | <![CDATA[{$value.description}]]> |
diff --git a/tpl/feed.rss.html b/tpl/feed.rss.html index 26de7f19..4bfe4196 100644 --- a/tpl/feed.rss.html +++ b/tpl/feed.rss.html | |||
@@ -22,7 +22,8 @@ | |||
22 | <link>{$value.url}</link> | 22 | <link>{$value.url}</link> |
23 | {/if} | 23 | {/if} |
24 | {if="$show_dates"} | 24 | {if="$show_dates"} |
25 | <pubDate>{$value.iso_date}</pubDate> | 25 | <pubDate>{$value.pub_iso_date}</pubDate> |
26 | <atom:modified>{$value.up_iso_date}</atom:modified> | ||
26 | {/if} | 27 | {/if} |
27 | <description><![CDATA[{$value.description}]]></description> | 28 | <description><![CDATA[{$value.description}]]></description> |
28 | {loop="$value.taglist"} | 29 | {loop="$value.taglist"} |
diff --git a/tpl/linklist.html b/tpl/linklist.html index 2316f145..9979f12a 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html | |||
@@ -89,7 +89,16 @@ | |||
89 | <br> | 89 | <br> |
90 | {if="$value.description"}<div class="linkdescription">{$value.description}</div>{/if} | 90 | {if="$value.description"}<div class="linkdescription">{$value.description}</div>{/if} |
91 | {if="!$hide_timestamps || isLoggedIn()"} | 91 | {if="!$hide_timestamps || isLoggedIn()"} |
92 | <span class="linkdate" title="Permalink"><a href="?{$value.linkdate|smallHash}">{function="strftime('%c', $value.timestamp)"} - permalink</a> - </span> | 92 | {$updated=$value.updated_timestamp ? 'Edited: '. strftime('%c', $value.updated_timestamp) : 'Permalink'} |
93 | <span class="linkdate" title="Permalink"> | ||
94 | <a href="?{$value.linkdate|smallHash}"> | ||
95 | <span title="{$updated}"> | ||
96 | {function="strftime('%c', $value.timestamp)"} | ||
97 | {if="$value.updated_timestamp"}*{/if} | ||
98 | </span> | ||
99 | - permalink | ||
100 | </a> - | ||
101 | </span> | ||
93 | {else} | 102 | {else} |
94 | <span class="linkdate" title="Short link here"><a href="?{$value.shorturl}">permalink</a> - </span> | 103 | <span class="linkdate" title="Short link here"><a href="?{$value.shorturl}">permalink</a> - </span> |
95 | {/if} | 104 | {/if} |