aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/admin
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-30 15:51:14 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit8eac2e54882d8adae8cbb45386dca1b465242632 (patch)
treee833e0ada87ac350ec2de8b7519a62e30e6731c6 /application/front/controller/admin
parent66063ed1a18d739b1a60bfb163d8656417a4c529 (diff)
downloadShaarli-8eac2e54882d8adae8cbb45386dca1b465242632.tar.gz
Shaarli-8eac2e54882d8adae8cbb45386dca1b465242632.tar.zst
Shaarli-8eac2e54882d8adae8cbb45386dca1b465242632.zip
Process manage tags page through Slim controller
Diffstat (limited to 'application/front/controller/admin')
-rw-r--r--application/front/controller/admin/ConfigureController.php2
-rw-r--r--application/front/controller/admin/ManageTagController.php87
2 files changed, 88 insertions, 1 deletions
diff --git a/application/front/controller/admin/ConfigureController.php b/application/front/controller/admin/ConfigureController.php
index b1d32270..5a482d8e 100644
--- a/application/front/controller/admin/ConfigureController.php
+++ b/application/front/controller/admin/ConfigureController.php
@@ -12,7 +12,7 @@ use Slim\Http\Response;
12use Throwable; 12use Throwable;
13 13
14/** 14/**
15 * Class PasswordController 15 * Class ConfigureController
16 * 16 *
17 * Slim controller used to handle Shaarli configuration page (display + save new config). 17 * Slim controller used to handle Shaarli configuration page (display + save new config).
18 */ 18 */
diff --git a/application/front/controller/admin/ManageTagController.php b/application/front/controller/admin/ManageTagController.php
new file mode 100644
index 00000000..e015e613
--- /dev/null
+++ b/application/front/controller/admin/ManageTagController.php
@@ -0,0 +1,87 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use Shaarli\Bookmark\BookmarkFilter;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class ManageTagController
13 *
14 * Slim controller used to handle Shaarli manage tags page (rename and delete tags).
15 */
16class ManageTagController extends ShaarliAdminController
17{
18 /**
19 * GET /manage-tags - Displays the manage tags page
20 */
21 public function index(Request $request, Response $response): Response
22 {
23 $fromTag = $request->getParam('fromtag') ?? '';
24
25 $this->assignView('fromtag', escape($fromTag));
26 $this->assignView(
27 'pagetitle',
28 t('Manage tags') .' - '. $this->container->conf->get('general.title', 'Shaarli')
29 );
30
31 return $response->write($this->render('changetag'));
32 }
33
34 /**
35 * POST /manage-tags - Update or delete provided tag
36 */
37 public function save(Request $request, Response $response): Response
38 {
39 $this->checkToken($request);
40
41 $isDelete = null !== $request->getParam('deletetag') && null === $request->getParam('renametag');
42
43 $fromTag = escape(trim($request->getParam('fromtag') ?? ''));
44 $toTag = escape(trim($request->getParam('totag') ?? ''));
45
46 if (0 === strlen($fromTag) || false === $isDelete && 0 === strlen($toTag)) {
47 $this->saveWarningMessage(t('Invalid tags provided.'));
48
49 return $response->withRedirect('./manage-tags');
50 }
51
52 // TODO: move this to bookmark service
53 $count = 0;
54 $bookmarks = $this->container->bookmarkService->search(['searchtags' => $fromTag], BookmarkFilter::$ALL, true);
55 foreach ($bookmarks as $bookmark) {
56 if (false === $isDelete) {
57 $bookmark->renameTag($fromTag, $toTag);
58 } else {
59 $bookmark->deleteTag($fromTag);
60 }
61
62 $this->container->bookmarkService->set($bookmark, false);
63 $this->container->history->updateLink($bookmark);
64 $count++;
65 }
66
67 $this->container->bookmarkService->save();
68
69 if (true === $isDelete) {
70 $alert = sprintf(
71 t('The tag was removed from %d bookmark.', 'The tag was removed from %d bookmarks.', $count),
72 $count
73 );
74 } else {
75 $alert = sprintf(
76 t('The tag was renamed in %d bookmark.', 'The tag was renamed in %d bookmarks.', $count),
77 $count
78 );
79 }
80
81 $this->saveSuccessMessage($alert);
82
83 $redirect = true === $isDelete ? './manage-tags' : './?searchtags='. urlencode($toTag);
84
85 return $response->withRedirect($redirect);
86 }
87}