diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-06-15 08:15:40 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 3447d888d7881eed437117a6de2450abb96f6a76 (patch) | |
tree | 6e04cb9ed27d587f9ded92fc2faf5dc58b6332e4 /application/front/controller | |
parent | 7b8a6f2858248601d43c1b8247deb91b74392d2e (diff) | |
download | Shaarli-3447d888d7881eed437117a6de2450abb96f6a76.tar.gz Shaarli-3447d888d7881eed437117a6de2450abb96f6a76.tar.zst Shaarli-3447d888d7881eed437117a6de2450abb96f6a76.zip |
Pin bookmarks through Slim controller
Diffstat (limited to 'application/front/controller')
-rw-r--r-- | application/front/controller/admin/ManageShaareController.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php index ff330a99..bdfc5ca7 100644 --- a/application/front/controller/admin/ManageShaareController.php +++ b/application/front/controller/admin/ManageShaareController.php | |||
@@ -297,6 +297,42 @@ class ManageShaareController extends ShaarliAdminController | |||
297 | } | 297 | } |
298 | 298 | ||
299 | /** | 299 | /** |
300 | * GET /admin/shaare/{id}/pin - Pin or unpin a bookmark. | ||
301 | */ | ||
302 | public function pinBookmark(Request $request, Response $response, array $args): Response | ||
303 | { | ||
304 | $this->checkToken($request); | ||
305 | |||
306 | $id = $args['id'] ?? ''; | ||
307 | try { | ||
308 | if (false === ctype_digit($id)) { | ||
309 | throw new BookmarkNotFoundException(); | ||
310 | } | ||
311 | $bookmark = $this->container->bookmarkService->get((int) $id); // Read database | ||
312 | } catch (BookmarkNotFoundException $e) { | ||
313 | $this->saveErrorMessage(sprintf( | ||
314 | t('Bookmark with identifier %s could not be found.'), | ||
315 | $id | ||
316 | )); | ||
317 | |||
318 | return $this->redirectFromReferer($request, $response, ['/pin'], ['pin']); | ||
319 | } | ||
320 | |||
321 | $formatter = $this->container->formatterFactory->getFormatter('raw'); | ||
322 | |||
323 | $bookmark->setSticky(!$bookmark->isSticky()); | ||
324 | |||
325 | // To preserve backward compatibility with 3rd parties, plugins still use arrays | ||
326 | $data = $formatter->format($bookmark); | ||
327 | $this->container->pluginManager->executeHooks('save_link', $data); | ||
328 | $bookmark->fromArray($data); | ||
329 | |||
330 | $this->container->bookmarkService->set($bookmark); | ||
331 | |||
332 | return $this->redirectFromReferer($request, $response, ['/pin'], ['pin']); | ||
333 | } | ||
334 | |||
335 | /** | ||
300 | * Helper function used to display the shaare form whether it's a new or existing bookmark. | 336 | * Helper function used to display the shaare form whether it's a new or existing bookmark. |
301 | * | 337 | * |
302 | * @param array $link data used in template, either from parameters or from the data store | 338 | * @param array $link data used in template, either from parameters or from the data store |