<?php namespace BookStack\Uploads;
use BookStack\Auth\Permissions\PermissionService;
-use BookStack\Entities\Page;
+use BookStack\Entities\Models\Page;
use BookStack\Exceptions\ImageUploadException;
use Exception;
use Illuminate\Database\Eloquent\Builder;
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);
}
};
*/
public function saveDrawing(string $base64Uri, int $uploadedTo): Image
{
- $name = 'Drawing-' . user()->getShortName(40) . '-' . strval(time()) . '.png';
+ $name = 'Drawing-' . strval(user()->id) . '-' . strval(time()) . '.png';
return $this->imageService->saveNewFromBase64Uri($base64Uri, $name, 'drawio', $uploadedTo);
}
* 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),
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();
+ }
}