2020-06-27 12:08:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shaarli\Front\Controller\Admin;
|
|
|
|
|
|
|
|
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
|
2020-07-06 08:04:35 +02:00
|
|
|
use Shaarli\Render\TemplatePage;
|
2020-06-27 12:08:26 +02:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ToolsController
|
|
|
|
*
|
|
|
|
* Slim controller used to handle thumbnails update.
|
|
|
|
*/
|
|
|
|
class ThumbnailsController extends ShaarliAdminController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* GET /admin/thumbnails - Display thumbnails update page
|
|
|
|
*/
|
|
|
|
public function index(Request $request, Response $response): Response
|
|
|
|
{
|
|
|
|
$ids = [];
|
2021-01-20 14:45:59 +01:00
|
|
|
foreach ($this->container->bookmarkService->search()->getBookmarks() as $bookmark) {
|
2020-06-27 12:08:26 +02:00
|
|
|
// A note or not HTTP(S)
|
|
|
|
if ($bookmark->isNote() || !startsWith(strtolower($bookmark->getUrl()), 'http')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids[] = $bookmark->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assignView('ids', $ids);
|
|
|
|
$this->assignView(
|
|
|
|
'pagetitle',
|
2020-09-22 20:25:47 +02:00
|
|
|
t('Thumbnails update') . ' - ' . $this->container->conf->get('general.title', 'Shaarli')
|
2020-06-27 12:08:26 +02:00
|
|
|
);
|
|
|
|
|
2020-07-06 08:04:35 +02:00
|
|
|
return $response->write($this->render(TemplatePage::THUMBNAILS));
|
2020-06-27 12:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PATCH /admin/shaare/{id}/thumbnail-update - Route for AJAX calls
|
|
|
|
*/
|
|
|
|
public function ajaxUpdate(Request $request, Response $response, array $args): Response
|
|
|
|
{
|
|
|
|
$id = $args['id'] ?? null;
|
|
|
|
|
|
|
|
if (false === ctype_digit($id)) {
|
|
|
|
return $response->withStatus(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-10-02 17:50:59 +02:00
|
|
|
$bookmark = $this->container->bookmarkService->get((int) $id);
|
2020-06-27 12:08:26 +02:00
|
|
|
} catch (BookmarkNotFoundException $e) {
|
|
|
|
return $response->withStatus(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl()));
|
|
|
|
$this->container->bookmarkService->set($bookmark);
|
|
|
|
|
|
|
|
return $response->withJson($this->container->formatterFactory->getFormatter('raw')->format($bookmark));
|
|
|
|
}
|
|
|
|
}
|