diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-11-08 14:07:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-08 14:07:33 +0100 |
commit | d9d71b10c3bc70a0881d630b37dc4e918c9e812f (patch) | |
tree | d8f772a9106fbd5072ebee1b9fa536babe90f7b1 /application/front/controller/admin | |
parent | c51d65238be43d61b7e6a6f9940948afea0c13fa (diff) | |
parent | 8a1ce1da15fdbae99b24700b06f2008c7a657603 (diff) | |
download | Shaarli-d9d71b10c3bc70a0881d630b37dc4e918c9e812f.tar.gz Shaarli-d9d71b10c3bc70a0881d630b37dc4e918c9e812f.tar.zst Shaarli-d9d71b10c3bc70a0881d630b37dc4e918c9e812f.zip |
Merge pull request #1621 from ArthurHoaro/feature/tag-separators
Diffstat (limited to 'application/front/controller/admin')
3 files changed, 45 insertions, 4 deletions
diff --git a/application/front/controller/admin/ManageTagController.php b/application/front/controller/admin/ManageTagController.php index 2065c3e2..22fb461c 100644 --- a/application/front/controller/admin/ManageTagController.php +++ b/application/front/controller/admin/ManageTagController.php | |||
@@ -24,6 +24,12 @@ class ManageTagController extends ShaarliAdminController | |||
24 | $fromTag = $request->getParam('fromtag') ?? ''; | 24 | $fromTag = $request->getParam('fromtag') ?? ''; |
25 | 25 | ||
26 | $this->assignView('fromtag', escape($fromTag)); | 26 | $this->assignView('fromtag', escape($fromTag)); |
27 | $separator = escape($this->container->conf->get('general.tags_separator', ' ')); | ||
28 | if ($separator === ' ') { | ||
29 | $separator = ' '; | ||
30 | $this->assignView('tags_separator_desc', t('whitespace')); | ||
31 | } | ||
32 | $this->assignView('tags_separator', $separator); | ||
27 | $this->assignView( | 33 | $this->assignView( |
28 | 'pagetitle', | 34 | 'pagetitle', |
29 | t('Manage tags') .' - '. $this->container->conf->get('general.title', 'Shaarli') | 35 | t('Manage tags') .' - '. $this->container->conf->get('general.title', 'Shaarli') |
@@ -85,4 +91,31 @@ class ManageTagController extends ShaarliAdminController | |||
85 | 91 | ||
86 | return $this->redirect($response, $redirect); | 92 | return $this->redirect($response, $redirect); |
87 | } | 93 | } |
94 | |||
95 | /** | ||
96 | * POST /admin/tags/change-separator - Change tag separator | ||
97 | */ | ||
98 | public function changeSeparator(Request $request, Response $response): Response | ||
99 | { | ||
100 | $this->checkToken($request); | ||
101 | |||
102 | $reservedCharacters = ['-', '.', '*']; | ||
103 | $newSeparator = $request->getParam('separator'); | ||
104 | if ($newSeparator === null || mb_strlen($newSeparator) !== 1) { | ||
105 | $this->saveErrorMessage(t('Tags separator must be a single character.')); | ||
106 | } elseif (in_array($newSeparator, $reservedCharacters, true)) { | ||
107 | $reservedCharacters = implode(' ', array_map(function (string $character) { | ||
108 | return '<code>' . $character . '</code>'; | ||
109 | }, $reservedCharacters)); | ||
110 | $this->saveErrorMessage( | ||
111 | t('These characters are reserved and can\'t be used as tags separator: ') . $reservedCharacters | ||
112 | ); | ||
113 | } else { | ||
114 | $this->container->conf->set('general.tags_separator', $newSeparator, true, true); | ||
115 | |||
116 | $this->saveSuccessMessage('Your tags separator setting has been updated!'); | ||
117 | } | ||
118 | |||
119 | return $this->redirect($response, '/admin/tags'); | ||
120 | } | ||
88 | } | 121 | } |
diff --git a/application/front/controller/admin/ShaareManageController.php b/application/front/controller/admin/ShaareManageController.php index 2ed298f5..0b143172 100644 --- a/application/front/controller/admin/ShaareManageController.php +++ b/application/front/controller/admin/ShaareManageController.php | |||
@@ -125,7 +125,7 @@ class ShaareManageController extends ShaarliAdminController | |||
125 | // To preserve backward compatibility with 3rd parties, plugins still use arrays | 125 | // To preserve backward compatibility with 3rd parties, plugins still use arrays |
126 | $data = $formatter->format($bookmark); | 126 | $data = $formatter->format($bookmark); |
127 | $this->executePageHooks('save_link', $data); | 127 | $this->executePageHooks('save_link', $data); |
128 | $bookmark->fromArray($data); | 128 | $bookmark->fromArray($data, $this->container->conf->get('general.tags_separator', ' ')); |
129 | 129 | ||
130 | $this->container->bookmarkService->set($bookmark, false); | 130 | $this->container->bookmarkService->set($bookmark, false); |
131 | ++$count; | 131 | ++$count; |
@@ -167,7 +167,7 @@ class ShaareManageController extends ShaarliAdminController | |||
167 | // To preserve backward compatibility with 3rd parties, plugins still use arrays | 167 | // To preserve backward compatibility with 3rd parties, plugins still use arrays |
168 | $data = $formatter->format($bookmark); | 168 | $data = $formatter->format($bookmark); |
169 | $this->executePageHooks('save_link', $data); | 169 | $this->executePageHooks('save_link', $data); |
170 | $bookmark->fromArray($data); | 170 | $bookmark->fromArray($data, $this->container->conf->get('general.tags_separator', ' ')); |
171 | 171 | ||
172 | $this->container->bookmarkService->set($bookmark); | 172 | $this->container->bookmarkService->set($bookmark); |
173 | 173 | ||
diff --git a/application/front/controller/admin/ShaarePublishController.php b/application/front/controller/admin/ShaarePublishController.php index 18afc2d1..625a5680 100644 --- a/application/front/controller/admin/ShaarePublishController.php +++ b/application/front/controller/admin/ShaarePublishController.php | |||
@@ -113,7 +113,10 @@ class ShaarePublishController extends ShaarliAdminController | |||
113 | $bookmark->setDescription($request->getParam('lf_description')); | 113 | $bookmark->setDescription($request->getParam('lf_description')); |
114 | $bookmark->setUrl($request->getParam('lf_url'), $this->container->conf->get('security.allowed_protocols', [])); | 114 | $bookmark->setUrl($request->getParam('lf_url'), $this->container->conf->get('security.allowed_protocols', [])); |
115 | $bookmark->setPrivate(filter_var($request->getParam('lf_private'), FILTER_VALIDATE_BOOLEAN)); | 115 | $bookmark->setPrivate(filter_var($request->getParam('lf_private'), FILTER_VALIDATE_BOOLEAN)); |
116 | $bookmark->setTagsString($request->getParam('lf_tags')); | 116 | $bookmark->setTagsString( |
117 | $request->getParam('lf_tags'), | ||
118 | $this->container->conf->get('general.tags_separator', ' ') | ||
119 | ); | ||
117 | 120 | ||
118 | if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE | 121 | if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE |
119 | && true !== $this->container->conf->get('general.enable_async_metadata', true) | 122 | && true !== $this->container->conf->get('general.enable_async_metadata', true) |
@@ -128,7 +131,7 @@ class ShaarePublishController extends ShaarliAdminController | |||
128 | $data = $formatter->format($bookmark); | 131 | $data = $formatter->format($bookmark); |
129 | $this->executePageHooks('save_link', $data); | 132 | $this->executePageHooks('save_link', $data); |
130 | 133 | ||
131 | $bookmark->fromArray($data); | 134 | $bookmark->fromArray($data, $this->container->conf->get('general.tags_separator', ' ')); |
132 | $this->container->bookmarkService->set($bookmark); | 135 | $this->container->bookmarkService->set($bookmark); |
133 | 136 | ||
134 | // If we are called from the bookmarklet, we must close the popup: | 137 | // If we are called from the bookmarklet, we must close the popup: |
@@ -221,6 +224,11 @@ class ShaarePublishController extends ShaarliAdminController | |||
221 | 224 | ||
222 | protected function buildFormData(array $link, bool $isNew, Request $request): array | 225 | protected function buildFormData(array $link, bool $isNew, Request $request): array |
223 | { | 226 | { |
227 | $link['tags'] = strlen($link['tags']) > 0 | ||
228 | ? $link['tags'] . $this->container->conf->get('general.tags_separator', ' ') | ||
229 | : $link['tags'] | ||
230 | ; | ||
231 | |||
224 | return escape([ | 232 | return escape([ |
225 | 'link' => $link, | 233 | 'link' => $link, |
226 | 'link_is_new' => $isNew, | 234 | 'link_is_new' => $isNew, |