X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fbookmark%2FBookmark.php;h=1beb8be2e127a2b0b905e71e256b0279f8018598;hb=0d930454a2892715e691f9c7713e26a3bb4ee96c;hp=b08e5d67262b68516a345dc3b403e3d01173e38e;hpb=336a28fa4a09b968ce4705900bf57693e672f0bf;p=github%2Fshaarli%2FShaarli.git diff --git a/application/bookmark/Bookmark.php b/application/bookmark/Bookmark.php index b08e5d67..1beb8be2 100644 --- a/application/bookmark/Bookmark.php +++ b/application/bookmark/Bookmark.php @@ -3,6 +3,7 @@ namespace Shaarli\Bookmark; use DateTime; +use DateTimeInterface; use Shaarli\Bookmark\Exception\InvalidBookmarkException; /** @@ -36,16 +37,16 @@ class Bookmark /** @var array List of bookmark's tags */ protected $tags; - /** @var string Thumbnail's URL - false if no thumbnail could be found */ + /** @var string|bool|null Thumbnail's URL - initialized at null, false if no thumbnail could be found */ protected $thumbnail; /** @var bool Set to true if the bookmark is set as sticky */ protected $sticky; - /** @var DateTime Creation datetime */ + /** @var DateTimeInterface Creation datetime */ protected $created; - /** @var DateTime Update datetime */ + /** @var DateTimeInterface datetime */ protected $updated; /** @var bool True if the bookmark can only be seen while logged in */ @@ -65,8 +66,8 @@ class Bookmark $this->url = $data['url']; $this->title = $data['title']; $this->description = $data['description']; - $this->thumbnail = ! empty($data['thumbnail']) ? $data['thumbnail'] : null; - $this->sticky = ! empty($data['sticky']) ? $data['sticky'] : false; + $this->thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : null; + $this->sticky = isset($data['sticky']) ? $data['sticky'] : false; $this->created = $data['created']; if (is_array($data['tags'])) { $this->tags = $data['tags']; @@ -100,12 +101,12 @@ class Bookmark || ! is_int($this->id) || empty($this->shortUrl) || empty($this->created) - || ! $this->created instanceof DateTime + || ! $this->created instanceof DateTimeInterface ) { throw new InvalidBookmarkException($this); } if (empty($this->url)) { - $this->url = '?'. $this->shortUrl; + $this->url = '/shaare/'. $this->shortUrl; } if (empty($this->title)) { $this->title = $this->url; @@ -188,7 +189,7 @@ class Bookmark /** * Get the Created. * - * @return DateTime + * @return DateTimeInterface */ public function getCreated() { @@ -198,7 +199,7 @@ class Bookmark /** * Get the Updated. * - * @return DateTime + * @return DateTimeInterface */ public function getUpdated() { @@ -270,7 +271,7 @@ class Bookmark * Set the Created. * Note: you shouldn't set this manually except for special cases (like bookmark import) * - * @param DateTime $created + * @param DateTimeInterface $created * * @return Bookmark */ @@ -284,7 +285,7 @@ class Bookmark /** * Set the Updated. * - * @param DateTime $updated + * @param DateTimeInterface $updated * * @return Bookmark */ @@ -346,7 +347,7 @@ class Bookmark /** * Get the Thumbnail. * - * @return string|bool + * @return string|bool|null Thumbnail's URL - initialized at null, false if no thumbnail could be found */ public function getThumbnail() { @@ -356,7 +357,7 @@ class Bookmark /** * Set the Thumbnail. * - * @param string|bool $thumbnail + * @param string|bool $thumbnail Thumbnail's URL - false if no thumbnail could be found * * @return Bookmark */ @@ -405,7 +406,7 @@ class Bookmark public function isNote() { // We check empty value to get a valid result if the link has not been saved yet - return empty($this->url) || $this->url[0] === '?'; + return empty($this->url) || startsWith($this->url, '/shaare/') || $this->url[0] === '?'; } /**