diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-10 10:46:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 10:46:04 +0100 |
commit | 302662797cb5e8ac6579a99297ceae301f7927a6 (patch) | |
tree | 67f493a1cc6d3691742946f1d7e512bffe41e02f /application/bookmark/BookmarkFileService.php | |
parent | c94c32d1a3e86a479cb2582eadc668a5bb476fc6 (diff) | |
parent | 2f4df753041088d788d1923692a7d530167a6840 (diff) | |
download | Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.gz Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.tar.zst Shaarli-302662797cb5e8ac6579a99297ceae301f7927a6.zip |
Merge pull request #1635 from ArthurHoaro/feature/phpcs
Diffstat (limited to 'application/bookmark/BookmarkFileService.php')
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index 85efeea6..6666a251 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -69,7 +69,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
69 | } else { | 69 | } else { |
70 | try { | 70 | try { |
71 | $this->bookmarks = $this->bookmarksIO->read(); | 71 | $this->bookmarks = $this->bookmarksIO->read(); |
72 | } catch (EmptyDataStoreException|DatastoreNotInitializedException $e) { | 72 | } catch (EmptyDataStoreException | DatastoreNotInitializedException $e) { |
73 | $this->bookmarks = new BookmarkArray(); | 73 | $this->bookmarks = new BookmarkArray(); |
74 | 74 | ||
75 | if ($this->isLoggedIn) { | 75 | if ($this->isLoggedIn) { |
@@ -85,7 +85,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
85 | if (! $this->bookmarks instanceof BookmarkArray) { | 85 | if (! $this->bookmarks instanceof BookmarkArray) { |
86 | $this->migrate(); | 86 | $this->migrate(); |
87 | exit( | 87 | exit( |
88 | 'Your data store has been migrated, please reload the page.'. PHP_EOL . | 88 | 'Your data store has been migrated, please reload the page.' . PHP_EOL . |
89 | 'If this message keeps showing up, please delete data/updates.txt file.' | 89 | 'If this message keeps showing up, please delete data/updates.txt file.' |
90 | ); | 90 | ); |
91 | } | 91 | } |
@@ -102,7 +102,8 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
102 | $bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash); | 102 | $bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash); |
103 | // PHP 7.3 introduced array_key_first() to avoid this hack | 103 | // PHP 7.3 introduced array_key_first() to avoid this hack |
104 | $first = reset($bookmark); | 104 | $first = reset($bookmark); |
105 | if (!$this->isLoggedIn | 105 | if ( |
106 | !$this->isLoggedIn | ||
106 | && $first->isPrivate() | 107 | && $first->isPrivate() |
107 | && (empty($privateKey) || $privateKey !== $first->getAdditionalContentEntry('private_key')) | 108 | && (empty($privateKey) || $privateKey !== $first->getAdditionalContentEntry('private_key')) |
108 | ) { | 109 | ) { |
@@ -165,7 +166,8 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
165 | } | 166 | } |
166 | 167 | ||
167 | $bookmark = $this->bookmarks[$id]; | 168 | $bookmark = $this->bookmarks[$id]; |
168 | if (($bookmark->isPrivate() && $visibility != 'all' && $visibility != 'private') | 169 | if ( |
170 | ($bookmark->isPrivate() && $visibility != 'all' && $visibility != 'private') | ||
169 | || (! $bookmark->isPrivate() && $visibility != 'all' && $visibility != 'public') | 171 | || (! $bookmark->isPrivate() && $visibility != 'all' && $visibility != 'public') |
170 | ) { | 172 | ) { |
171 | throw new Exception('Unauthorized'); | 173 | throw new Exception('Unauthorized'); |
@@ -265,7 +267,8 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
265 | } | 267 | } |
266 | 268 | ||
267 | $bookmark = $this->bookmarks[$id]; | 269 | $bookmark = $this->bookmarks[$id]; |
268 | if (($bookmark->isPrivate() && $visibility != 'all' && $visibility != 'private') | 270 | if ( |
271 | ($bookmark->isPrivate() && $visibility != 'all' && $visibility != 'private') | ||
269 | || (! $bookmark->isPrivate() && $visibility != 'all' && $visibility != 'public') | 272 | || (! $bookmark->isPrivate() && $visibility != 'all' && $visibility != 'public') |
270 | ) { | 273 | ) { |
271 | return false; | 274 | return false; |
@@ -307,7 +310,8 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
307 | $caseMapping = []; | 310 | $caseMapping = []; |
308 | foreach ($bookmarks as $bookmark) { | 311 | foreach ($bookmarks as $bookmark) { |
309 | foreach ($bookmark->getTags() as $tag) { | 312 | foreach ($bookmark->getTags() as $tag) { |
310 | if (empty($tag) | 313 | if ( |
314 | empty($tag) | ||
311 | || (! $this->isLoggedIn && startsWith($tag, '.')) | 315 | || (! $this->isLoggedIn && startsWith($tag, '.')) |
312 | || $tag === BookmarkMarkdownFormatter::NO_MD_TAG | 316 | || $tag === BookmarkMarkdownFormatter::NO_MD_TAG |
313 | || in_array($tag, $filteringTags, true) | 317 | || in_array($tag, $filteringTags, true) |
@@ -356,7 +360,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
356 | foreach ($this->search([], null, false, false, true) as $bookmark) { | 360 | foreach ($this->search([], null, false, false, true) as $bookmark) { |
357 | if ($to < $bookmark->getCreated()) { | 361 | if ($to < $bookmark->getCreated()) { |
358 | $next = $bookmark->getCreated(); | 362 | $next = $bookmark->getCreated(); |
359 | } else if ($from < $bookmark->getCreated() && $to > $bookmark->getCreated()) { | 363 | } elseif ($from < $bookmark->getCreated() && $to > $bookmark->getCreated()) { |
360 | $out[] = $bookmark; | 364 | $out[] = $bookmark; |
361 | } else { | 365 | } else { |
362 | if ($previous !== null) { | 366 | if ($previous !== null) { |
@@ -405,14 +409,14 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
405 | false | 409 | false |
406 | ); | 410 | ); |
407 | $updater = new LegacyUpdater( | 411 | $updater = new LegacyUpdater( |
408 | UpdaterUtils::read_updates_file($this->conf->get('resource.updates')), | 412 | UpdaterUtils::readUpdatesFile($this->conf->get('resource.updates')), |
409 | $bookmarkDb, | 413 | $bookmarkDb, |
410 | $this->conf, | 414 | $this->conf, |
411 | true | 415 | true |
412 | ); | 416 | ); |
413 | $newUpdates = $updater->update(); | 417 | $newUpdates = $updater->update(); |
414 | if (! empty($newUpdates)) { | 418 | if (! empty($newUpdates)) { |
415 | UpdaterUtils::write_updates_file( | 419 | UpdaterUtils::writeUpdatesFile( |
416 | $this->conf->get('resource.updates'), | 420 | $this->conf->get('resource.updates'), |
417 | $updater->getDoneUpdates() | 421 | $updater->getDoneUpdates() |
418 | ); | 422 | ); |