]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/bookmark/BookmarkFileService.php
Feature: Share private bookmarks using a URL containing a private key
[github/shaarli/Shaarli.git] / application / bookmark / BookmarkFileService.php
index 804b25207a95bf1c698682bf49f009a58b35ea46..14b3d620cebfa3de717089e3cf518d15c390aca1 100644 (file)
@@ -97,12 +97,15 @@ class BookmarkFileService implements BookmarkServiceInterface
     /**
      * @inheritDoc
      */
-    public function findByHash(string $hash): Bookmark
+    public function findByHash(string $hash, string $privateKey = null): Bookmark
     {
         $bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash);
         // PHP 7.3 introduced array_key_first() to avoid this hack
         $first = reset($bookmark);
-        if (! $this->isLoggedIn && $first->isPrivate()) {
+        if (!$this->isLoggedIn
+            && $first->isPrivate()
+            && (empty($privateKey) || $privateKey !== $first->getAdditionalContentEntry('private_key'))
+        ) {
             throw new Exception('Not authorized');
         }
 
@@ -349,7 +352,7 @@ class BookmarkFileService implements BookmarkServiceInterface
         $bookmarkDays = array_keys($bookmarkDays);
         sort($bookmarkDays);
 
-        return $bookmarkDays;
+        return array_map('strval', $bookmarkDays);
     }
 
     /**