3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Admin
;
7 use Shaarli\Bookmark\Exception\BookmarkNotFoundException
;
9 use Slim\Http\Response
;
12 * Class ToolsController
14 * Slim controller used to handle thumbnails update.
16 class ThumbnailsController
extends ShaarliAdminController
19 * GET /admin/thumbnails - Display thumbnails update page
21 public function index(Request
$request, Response
$response): Response
24 foreach ($this->container
->bookmarkService
->search() as $bookmark) {
25 // A note or not HTTP(S)
26 if ($bookmark->isNote() || !startsWith(strtolower($bookmark->getUrl()), 'http')) {
30 $ids[] = $bookmark->getId();
33 $this->assignView('ids', $ids);
36 t('Thumbnails update') .' - '. $this->container
->conf
->get('general.title', 'Shaarli')
39 return $response->write($this->render('thumbnails'));
43 * PATCH /admin/shaare/{id}/thumbnail-update - Route for AJAX calls
45 public function ajaxUpdate(Request
$request, Response
$response, array $args): Response
47 $id = $args['id'] ?? null;
49 if (false === ctype_digit($id)) {
50 return $response->withStatus(400);
54 $bookmark = $this->container
->bookmarkService
->get($id);
55 } catch (BookmarkNotFoundException
$e) {
56 return $response->withStatus(404);
59 $bookmark->setThumbnail($this->container
->thumbnailer
->get($bookmark->getUrl()));
60 $this->container
->bookmarkService
->set($bookmark);
62 return $response->withJson($this->container
->formatterFactory
->getFormatter('raw')->format($bookmark));
66 * @param mixed[] $data Variables passed to the template engine
68 * @return mixed[] Template data after active plugins render_picwall hook execution.
70 protected function executeHooks(array $data): array
72 $this->container
->pluginManager
->executeHooks(