aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/FeedBuilder.php6
-rw-r--r--application/LinkFilter.php37
-rw-r--r--application/NetscapeBookmarkUtils.php25
-rw-r--r--application/Updater.php6
4 files changed, 31 insertions, 43 deletions
diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php
index 4036a7cc..bfdf2fd3 100644
--- a/application/FeedBuilder.php
+++ b/application/FeedBuilder.php
@@ -143,7 +143,7 @@ class FeedBuilder
143 */ 143 */
144 protected function buildItem($link, $pageaddr) 144 protected function buildItem($link, $pageaddr)
145 { 145 {
146 $link['guid'] = $pageaddr .'?'. smallHash($link['linkdate']); 146 $link['guid'] = $pageaddr .'?'. smallHash($link['created']->format('Ymd_His'));
147 // 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.
148 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 148 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
149 $link['url'] = $pageaddr . $link['url']; 149 $link['url'] = $pageaddr . $link['url'];
@@ -156,12 +156,12 @@ class FeedBuilder
156 $link['description'] = format_description($link['description'], '', $pageaddr); 156 $link['description'] = format_description($link['description'], '', $pageaddr);
157 $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink; 157 $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink;
158 158
159 $pubDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 159 $pubDate = $link['created'];
160 $link['pub_iso_date'] = $this->getIsoDate($pubDate); 160 $link['pub_iso_date'] = $this->getIsoDate($pubDate);
161 161
162 // atom:entry elements MUST contain exactly one atom:updated element. 162 // atom:entry elements MUST contain exactly one atom:updated element.
163 if (!empty($link['updated'])) { 163 if (!empty($link['updated'])) {
164 $upDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']); 164 $upDate = $link['updated'];
165 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); 165 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
166 } else { 166 } else {
167 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);; 167 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);;
diff --git a/application/LinkFilter.php b/application/LinkFilter.php
index d4fe28df..7bab46ba 100644
--- a/application/LinkFilter.php
+++ b/application/LinkFilter.php
@@ -33,12 +33,12 @@ class LinkFilter
33 public static $HASHTAG_CHARS = '\p{Pc}\p{N}\p{L}\p{Mn}'; 33 public static $HASHTAG_CHARS = '\p{Pc}\p{N}\p{L}\p{Mn}';
34 34
35 /** 35 /**
36 * @var array all available links. 36 * @var LinkDB all available links.
37 */ 37 */
38 private $links; 38 private $links;
39 39
40 /** 40 /**
41 * @param array $links initialization. 41 * @param LinkDB $links initialization.
42 */ 42 */
43 public function __construct($links) 43 public function __construct($links)
44 { 44 {
@@ -94,18 +94,16 @@ class LinkFilter
94 private function noFilter($privateonly = false) 94 private function noFilter($privateonly = false)
95 { 95 {
96 if (! $privateonly) { 96 if (! $privateonly) {
97 krsort($this->links);
98 return $this->links; 97 return $this->links;
99 } 98 }
100 99
101 $out = array(); 100 $out = array();
102 foreach ($this->links as $value) { 101 foreach ($this->links as $key => $value) {
103 if ($value['private']) { 102 if ($value['private']) {
104 $out[$value['linkdate']] = $value; 103 $out[$key] = $value;
105 } 104 }
106 } 105 }
107 106
108 krsort($out);
109 return $out; 107 return $out;
110 } 108 }
111 109
@@ -121,10 +119,10 @@ class LinkFilter
121 private function filterSmallHash($smallHash) 119 private function filterSmallHash($smallHash)
122 { 120 {
123 $filtered = array(); 121 $filtered = array();
124 foreach ($this->links as $l) { 122 foreach ($this->links as $key => $l) {
125 if ($smallHash == smallHash($l['linkdate'])) { 123 if ($smallHash == smallHash($l['created']->format('Ymd_His'))) {
126 // Yes, this is ugly and slow 124 // Yes, this is ugly and slow
127 $filtered[$l['linkdate']] = $l; 125 $filtered[$key] = $l;
128 return $filtered; 126 return $filtered;
129 } 127 }
130 } 128 }
@@ -188,7 +186,7 @@ class LinkFilter
188 $keys = array('title', 'description', 'url', 'tags'); 186 $keys = array('title', 'description', 'url', 'tags');
189 187
190 // Iterate over every stored link. 188 // Iterate over every stored link.
191 foreach ($this->links as $link) { 189 foreach ($this->links as $id => $link) {
192 190
193 // ignore non private links when 'privatonly' is on. 191 // ignore non private links when 'privatonly' is on.
194 if (! $link['private'] && $privateonly === true) { 192 if (! $link['private'] && $privateonly === true) {
@@ -222,11 +220,10 @@ class LinkFilter
222 } 220 }
223 221
224 if ($found) { 222 if ($found) {
225 $filtered[$link['linkdate']] = $link; 223 $filtered[$id] = $link;
226 } 224 }
227 } 225 }
228 226
229 krsort($filtered);
230 return $filtered; 227 return $filtered;
231 } 228 }
232 229
@@ -256,7 +253,7 @@ class LinkFilter
256 return $filtered; 253 return $filtered;
257 } 254 }
258 255
259 foreach ($this->links as $link) { 256 foreach ($this->links as $key => $link) {
260 // ignore non private links when 'privatonly' is on. 257 // ignore non private links when 'privatonly' is on.
261 if (! $link['private'] && $privateonly === true) { 258 if (! $link['private'] && $privateonly === true) {
262 continue; 259 continue;
@@ -278,10 +275,9 @@ class LinkFilter
278 } 275 }
279 276
280 if ($found) { 277 if ($found) {
281 $filtered[$link['linkdate']] = $link; 278 $filtered[$key] = $link;
282 } 279 }
283 } 280 }
284 krsort($filtered);
285 return $filtered; 281 return $filtered;
286 } 282 }
287 283
@@ -304,13 +300,14 @@ class LinkFilter
304 } 300 }
305 301
306 $filtered = array(); 302 $filtered = array();
307 foreach ($this->links as $l) { 303 foreach ($this->links as $key => $l) {
308 if (startsWith($l['linkdate'], $day)) { 304 if ($l['created']->format('Ymd') == $day) {
309 $filtered[$l['linkdate']] = $l; 305 $filtered[$key] = $l;
310 } 306 }
311 } 307 }
312 ksort($filtered); 308
313 return $filtered; 309 // sort by date ASC
310 return array_reverse($filtered, true);
314 } 311 }
315 312
316 /** 313 /**
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index dd21f05b..8a939adb 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -38,7 +38,7 @@ class NetscapeBookmarkUtils
38 if ($link['private'] == 0 && $selection == 'private') { 38 if ($link['private'] == 0 && $selection == 'private') {
39 continue; 39 continue;
40 } 40 }
41 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 41 $date = $link['created'];
42 $link['timestamp'] = $date->getTimestamp(); 42 $link['timestamp'] = $date->getTimestamp();
43 $link['taglist'] = str_replace(' ', ',', $link['tags']); 43 $link['taglist'] = str_replace(' ', ',', $link['tags']);
44 44
@@ -147,7 +147,6 @@ class NetscapeBookmarkUtils
147 'url' => $bkm['uri'], 147 'url' => $bkm['uri'],
148 'description' => $bkm['note'], 148 'description' => $bkm['note'],
149 'private' => $private, 149 'private' => $private,
150 'linkdate'=> '',
151 'tags' => $bkm['tags'] 150 'tags' => $bkm['tags']
152 ); 151 );
153 152
@@ -161,25 +160,21 @@ class NetscapeBookmarkUtils
161 } 160 }
162 161
163 // Overwrite an existing link, keep its date 162 // Overwrite an existing link, keep its date
164 $newLink['linkdate'] = $existingLink['linkdate']; 163 $newLink['id'] = $existingLink['id'];
165 $linkDb[$existingLink['linkdate']] = $newLink; 164 $newLink['created'] = $existingLink['created'];
165 $newLink['updated'] = new DateTime();
166 $linkDb[$existingLink['id']] = $newLink;
166 $importCount++; 167 $importCount++;
167 $overwriteCount++; 168 $overwriteCount++;
168 continue; 169 continue;
169 } 170 }
170 171
171 // Add a new link 172 // Add a new link - @ used for UNIX timestamps
172 $newLinkDate = new DateTime('@'.strval($bkm['time'])); 173 $newLinkDate = new DateTime('@'.strval($bkm['time']));
173 while (!empty($linkDb[$newLinkDate->format(LinkDB::LINK_DATE_FORMAT)])) { 174 $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
174 // Ensure the date/time is not already used 175 $newLink['created'] = $newLinkDate;
175 // - this hack is necessary as the date/time acts as a primary key 176 $newLink['id'] = $linkDb->getNextId();
176 // - apply 1 second increments until an unused index is found 177 $linkDb[$newLink['id']] = $newLink;
177 // See https://github.com/shaarli/Shaarli/issues/351
178 $newLinkDate->add(new DateInterval('PT1S'));
179 }
180 $linkDbDate = $newLinkDate->format(LinkDB::LINK_DATE_FORMAT);
181 $newLink['linkdate'] = $linkDbDate;
182 $linkDb[$linkDbDate] = $newLink;
183 $importCount++; 178 $importCount++;
184 } 179 }
185 180
diff --git a/application/Updater.php b/application/Updater.php
index 94b63990..16c8c376 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -218,7 +218,7 @@ class Updater
218 218
219 /** 219 /**
220 * Update the database to use the new ID system, which replaces linkdate primary keys. 220 * Update the database to use the new ID system, which replaces linkdate primary keys.
221 * Also, creation and update dates are now DateTime objects. 221 * Also, creation and update dates are now DateTime objects (done by LinkDB).
222 * 222 *
223 * Since this update is very sensitve (changing the whole database), the datastore will be 223 * Since this update is very sensitve (changing the whole database), the datastore will be
224 * automatically backed up into the file datastore.<datetime>.php. 224 * automatically backed up into the file datastore.<datetime>.php.
@@ -243,10 +243,6 @@ class Updater
243 $links = array_reverse($links); 243 $links = array_reverse($links);
244 $cpt = 0; 244 $cpt = 0;
245 foreach ($links as $l) { 245 foreach ($links as $l) {
246 $l['created'] = DateTime::createFromFormat('Ymd_His', $l['linkdate']);
247 if (! empty($l['updated'])) {
248 $l['updated'] = DateTime::createFromFormat('Ymd_His', $l['updated']);
249 }
250 unset($l['linkdate']); 246 unset($l['linkdate']);
251 $l['id'] = $cpt; 247 $l['id'] = $cpt;
252 $this->linkDB[$cpt++] = $l; 248 $this->linkDB[$cpt++] = $l;