X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/919660678bec2b94eaa84ac60d0313f5ef07dfb7..refs/pull/1688/head:/app/Entities/Book.php diff --git a/app/Entities/Book.php b/app/Entities/Book.php index b8a29322d..ce4c4b90e 100644 --- a/app/Entities/Book.php +++ b/app/Entities/Book.php @@ -1,8 +1,14 @@ slug) . '/' . trim($path, '/')); + return url('/http/source.bookstackapp.com/books/' . urlencode($this->slug) . '/' . trim($path, '/')); } - return baseUrl('/books/' . urlencode($this->slug)); + return url('/http/source.bookstackapp.com/books/' . urlencode($this->slug)); } /** @@ -39,13 +45,13 @@ class Book extends Entity */ public function getBookCover($width = 440, $height = 250) { - $default = baseUrl('/book_default_cover.png'); + $default = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; if (!$this->image_id) { return $default; } try { - $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default; + $cover = $this->cover ? url($this->cover->getThumb($width, $height, false)) : $default; } catch (\Exception $err) { $cover = $default; } @@ -70,6 +76,15 @@ class Book extends Entity return $this->hasMany(Page::class); } + /** + * Get the direct child pages of this book. + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function directPages() + { + return $this->pages()->where('chapter_id', '=', '0'); + } + /** * Get all chapters within this book. * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -93,10 +108,10 @@ class Book extends Entity * @param int $length * @return string */ - public function getExcerpt($length = 100) + public function getExcerpt(int $length = 100) { $description = $this->description; - return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description; + return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description; } /**