diff options
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r-- | application/LinkDB.php | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 22c1f0ab..c1661d52 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -133,16 +133,16 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
133 | { | 133 | { |
134 | // TODO: use exceptions instead of "die" | 134 | // TODO: use exceptions instead of "die" |
135 | if (!$this->loggedIn) { | 135 | if (!$this->loggedIn) { |
136 | die('You are not authorized to add a link.'); | 136 | die(t('You are not authorized to add a link.')); |
137 | } | 137 | } |
138 | if (!isset($value['id']) || empty($value['url'])) { | 138 | if (!isset($value['id']) || empty($value['url'])) { |
139 | die('Internal Error: A link should always have an id and URL.'); | 139 | die(t('Internal Error: A link should always have an id and URL.')); |
140 | } | 140 | } |
141 | if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) { | 141 | if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) { |
142 | die('You must specify an integer as a key.'); | 142 | die(t('You must specify an integer as a key.')); |
143 | } | 143 | } |
144 | if ($offset !== null && $offset !== $value['id']) { | 144 | if ($offset !== null && $offset !== $value['id']) { |
145 | die('Array offset and link ID must be equal.'); | 145 | die(t('Array offset and link ID must be equal.')); |
146 | } | 146 | } |
147 | 147 | ||
148 | // If the link exists, we reuse the real offset, otherwise new entry | 148 | // If the link exists, we reuse the real offset, otherwise new entry |
@@ -248,13 +248,13 @@ class LinkDB implements Iterator, Countable, ArrayAccess | |||
248 | $this->links = array(); | 248 | $this->links = array(); |
249 | $link = array( | 249 | $link = array( |
250 | 'id' => 1, | 250 | 'id' => 1, |
251 | 'title'=>' Shaarli: the personal, minimalist, super-fast, no-database delicious clone', | 251 | 'title'=> t('The personal, minimalist, super-fast, database free, bookmarking service'), |
252 | 'url'=>'https://shaarli.readthedocs.io', | 252 | 'url'=>'https://shaarli.readthedocs.io', |
253 | 'description'=>'Welcome to Shaarli! This is your first public bookmark. To edit or delete me, you must first login. | 253 | 'description'=>t('Welcome to Shaarli! This is your first public bookmark. To edit or delete me, you must first login. |
254 | 254 | ||
255 | To learn how to use Shaarli, consult the link "Help/documentation" at the bottom of this page. | 255 | To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page. |
256 | 256 | ||
257 | You use the community supported version of the original Shaarli project, by Sebastien Sauvage.', | 257 | You use the community supported version of the original Shaarli project, by Sebastien Sauvage.'), |
258 | 'private'=>0, | 258 | 'private'=>0, |
259 | 'created'=> new DateTime(), | 259 | 'created'=> new DateTime(), |
260 | 'tags'=>'opensource software' | 260 | 'tags'=>'opensource software' |
@@ -264,9 +264,9 @@ You use the community supported version of the original Shaarli project, by Seba | |||
264 | 264 | ||
265 | $link = array( | 265 | $link = array( |
266 | 'id' => 0, | 266 | 'id' => 0, |
267 | 'title'=>'My secret stuff... - Pastebin.com', | 267 | 'title'=> t('My secret stuff... - Pastebin.com'), |
268 | 'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', | 268 | 'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=', |
269 | 'description'=>'Shhhh! I\'m a private link only YOU can see. You can delete me too.', | 269 | 'description'=> t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'), |
270 | 'private'=>1, | 270 | 'private'=>1, |
271 | 'created'=> new DateTime('1 minute ago'), | 271 | 'created'=> new DateTime('1 minute ago'), |
272 | 'tags'=>'secretstuff', | 272 | 'tags'=>'secretstuff', |
@@ -289,13 +289,15 @@ You use the community supported version of the original Shaarli project, by Seba | |||
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | 291 | ||
292 | $this->urls = []; | ||
293 | $this->ids = []; | ||
292 | $this->links = FileUtils::readFlatDB($this->datastore, []); | 294 | $this->links = FileUtils::readFlatDB($this->datastore, []); |
293 | 295 | ||
294 | $toremove = array(); | 296 | $toremove = array(); |
295 | foreach ($this->links as $key => &$link) { | 297 | foreach ($this->links as $key => &$link) { |
296 | if (! $this->loggedIn && $link['private'] != 0) { | 298 | if (! $this->loggedIn && $link['private'] != 0) { |
297 | // Transition for not upgraded databases. | 299 | // Transition for not upgraded databases. |
298 | $toremove[] = $key; | 300 | unset($this->links[$key]); |
299 | continue; | 301 | continue; |
300 | } | 302 | } |
301 | 303 | ||
@@ -329,14 +331,10 @@ You use the community supported version of the original Shaarli project, by Seba | |||
329 | } | 331 | } |
330 | $link['shorturl'] = smallHash($link['linkdate']); | 332 | $link['shorturl'] = smallHash($link['linkdate']); |
331 | } | 333 | } |
332 | } | ||
333 | 334 | ||
334 | // If user is not logged in, filter private links. | 335 | $this->urls[$link['url']] = $key; |
335 | foreach ($toremove as $offset) { | 336 | $this->ids[$link['id']] = $key; |
336 | unset($this->links[$offset]); | ||
337 | } | 337 | } |
338 | |||
339 | $this->reorder(); | ||
340 | } | 338 | } |
341 | 339 | ||
342 | /** | 340 | /** |
@@ -346,6 +344,7 @@ You use the community supported version of the original Shaarli project, by Seba | |||
346 | */ | 344 | */ |
347 | private function write() | 345 | private function write() |
348 | { | 346 | { |
347 | $this->reorder(); | ||
349 | FileUtils::writeFlatDB($this->datastore, $this->links); | 348 | FileUtils::writeFlatDB($this->datastore, $this->links); |
350 | } | 349 | } |
351 | 350 | ||
@@ -528,8 +527,8 @@ You use the community supported version of the original Shaarli project, by Seba | |||
528 | return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; | 527 | return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; |
529 | }); | 528 | }); |
530 | 529 | ||
531 | $this->urls = array(); | 530 | $this->urls = []; |
532 | $this->ids = array(); | 531 | $this->ids = []; |
533 | foreach ($this->links as $key => $link) { | 532 | foreach ($this->links as $key => $link) { |
534 | $this->urls[$link['url']] = $key; | 533 | $this->urls[$link['url']] = $key; |
535 | $this->ids[$link['id']] = $key; | 534 | $this->ids[$link['id']] = $key; |