MyShaarli/plugins/readitlater/ReadItLaterController.php
ArthurHoaro bf8bec322b New Core Plugin: ReadItLater
Create a new core plugin allowing to mark bookmarks to read them later.
When enabled:

  * checkbox is displayed in editlink view for new bookmarks
  * a plugin setting is available to check it or not it by default
  * in bookmark list:
    * new global filter to display only bookmark flagged as read it
      later
    * for each bookmarks, new action icon to toggle read it later status
    * for each « readitlater » bookmark, red label « To Read » added,
      and red line on the right of the bookmark added (default template)

Fixes #143

Signed-off-by: ArthurHoaro <arthur@hoa.ro>
2022-08-12 19:58:07 +02:00

46 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Shaarli\Plugin\ReadItLater;
use Shaarli\Front\Controller\Admin\ShaarliAdminController;
use Slim\Http\Request;
use Slim\Http\Response;
class ReadItLaterController extends ShaarliAdminController
{
/**
* GET /plugin/readitlater/bookmarks
*/
public function toggleFilterBookmarkList(Request $request, Response $response): Response
{
$this->container->sessionManager->setSessionParameter(
'readitlater-only',
!$this->container->sessionManager->getSessionParameter('readitlater-only', false)
);
return $this->redirectFromReferer($request, $response, ['readitlater']);
}
/**
* GET /plugin/readitlater/toggle/:id
*/
public function toggleBookmark(Request $request, Response $response, array $args): Response
{
if (!array_key_exists('id', $args) || !$this->container->bookmarkService->exists((int) $args['id'])) {
$this->saveErrorMessage('Invalid ID provided.');
return $this->redirectFromReferer($request, $response, ['readitlater']);
}
$bookmark = $this->container->bookmarkService->get((int) $args['id']);
$bookmark->setAdditionalContentEntry(
'readitlater',
!$bookmark->getAdditionalContentEntry('readitlater', false)
);
$this->container->bookmarkService->save();
return $this->redirectFromReferer($request, $response, ['readitlater']);
}
}