X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/da1cea06ca5db56a9635bf8bb01da2516d601620..refs/pull/2734/head:/app/Uploads/ImageRepo.php diff --git a/app/Uploads/ImageRepo.php b/app/Uploads/ImageRepo.php index b7a21809f..e6f766824 100644 --- a/app/Uploads/ImageRepo.php +++ b/app/Uploads/ImageRepo.php @@ -1,7 +1,7 @@ image->newQuery()->where('type', '=', strtolower($type)); if ($uploadedTo !== null) { @@ -83,7 +82,7 @@ class ImageRepo } // Filter by page access - $imageQuery = $this->restrictionService->filterRelatedEntity('page', $imageQuery, 'images', 'uploaded_to'); + $imageQuery = $this->restrictionService->filterRelatedEntity(Page::class, $imageQuery, 'images', 'uploaded_to'); if ($whereClause !== null) { $imageQuery = $imageQuery->where($whereClause); @@ -102,8 +101,7 @@ class ImageRepo int $pageSize = 24, int $uploadedTo = null, string $search = null - ): array - { + ): array { $contextPage = $this->page->findOrFail($uploadedTo); $parentFilter = null; @@ -112,7 +110,7 @@ class ImageRepo if ($filterType === 'page') { $query->where('uploaded_to', '=', $contextPage->id); } elseif ($filterType === 'book') { - $validPageIds = $contextPage->book->pages()->get(['id'])->pluck('id')->toArray(); + $validPageIds = $contextPage->book->pages()->visible()->get(['id'])->pluck('id')->toArray(); $query->whereIn('uploaded_to', $validPageIds); } }; @@ -185,7 +183,7 @@ class ImageRepo * Load thumbnails onto an image object. * @throws Exception */ - protected function loadThumbs(Image $image) + public function loadThumbs(Image $image) { $image->thumbs = [ 'gallery' => $this->getThumbnail($image, 150, 150, false), @@ -219,4 +217,20 @@ class ImageRepo return null; } } + + /** + * Get the user visible pages using the given image. + */ + public function getPagesUsingImage(Image $image): array + { + $pages = Page::visible() + ->where('html', 'like', '%' . $image->url . '%') + ->get(['id', 'name', 'slug', 'book_id']); + + foreach ($pages as $page) { + $page->url = $page->getUrl(); + } + + return $pages->all(); + } }