diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/front/controller/admin/ManageShaareController.php | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php index 620bbc40..ff330a99 100644 --- a/application/front/controller/admin/ManageShaareController.php +++ b/application/front/controller/admin/ManageShaareController.php | |||
@@ -174,7 +174,7 @@ class ManageShaareController extends ShaarliAdminController | |||
174 | } | 174 | } |
175 | 175 | ||
176 | /** | 176 | /** |
177 | * GET /admin/shaare/delete | 177 | * GET /admin/shaare/delete - Delete one or multiple bookmarks (depending on `id` query parameter). |
178 | */ | 178 | */ |
179 | public function deleteBookmark(Request $request, Response $response): Response | 179 | public function deleteBookmark(Request $request, Response $response): Response |
180 | { | 180 | { |
@@ -229,6 +229,74 @@ class ManageShaareController extends ShaarliAdminController | |||
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * GET /admin/shaare/visibility | ||
233 | * | ||
234 | * Change visibility (public/private) of one or multiple bookmarks (depending on `id` query parameter). | ||
235 | */ | ||
236 | public function changeVisibility(Request $request, Response $response): Response | ||
237 | { | ||
238 | $this->checkToken($request); | ||
239 | |||
240 | $ids = trim(escape($request->getParam('id') ?? '')); | ||
241 | if (empty($ids) || strpos($ids, ' ') !== false) { | ||
242 | // multiple, space-separated ids provided | ||
243 | $ids = array_values(array_filter(preg_split('/\s+/', $ids), 'ctype_digit')); | ||
244 | } else { | ||
245 | // only a single id provided | ||
246 | $ids = [$ids]; | ||
247 | } | ||
248 | |||
249 | // assert at least one id is given | ||
250 | if (0 === count($ids)) { | ||
251 | $this->saveErrorMessage(t('Invalid bookmark ID provided.')); | ||
252 | |||
253 | return $this->redirectFromReferer($request, $response, [], ['change_visibility']); | ||
254 | } | ||
255 | |||
256 | // assert that the visibility is valid | ||
257 | $visibility = $request->getParam('newVisibility'); | ||
258 | if (null === $visibility || false === in_array($visibility, ['public', 'private'], true)) { | ||
259 | $this->saveErrorMessage(t('Invalid visibility provided.')); | ||
260 | |||
261 | return $this->redirectFromReferer($request, $response, [], ['change_visibility']); | ||
262 | } else { | ||
263 | $isPrivate = $visibility === 'private'; | ||
264 | } | ||
265 | |||
266 | $formatter = $this->container->formatterFactory->getFormatter('raw'); | ||
267 | $count = 0; | ||
268 | |||
269 | foreach ($ids as $id) { | ||
270 | try { | ||
271 | $bookmark = $this->container->bookmarkService->get((int) $id); | ||
272 | } catch (BookmarkNotFoundException $e) { | ||
273 | $this->saveErrorMessage(sprintf( | ||
274 | t('Bookmark with identifier %s could not be found.'), | ||
275 | $id | ||
276 | )); | ||
277 | |||
278 | continue; | ||
279 | } | ||
280 | |||
281 | $bookmark->setPrivate($isPrivate); | ||
282 | |||
283 | // To preserve backward compatibility with 3rd parties, plugins still use arrays | ||
284 | $data = $formatter->format($bookmark); | ||
285 | $this->container->pluginManager->executeHooks('save_link', $data); | ||
286 | $bookmark->fromArray($data); | ||
287 | |||
288 | $this->container->bookmarkService->set($bookmark, false); | ||
289 | ++$count; | ||
290 | } | ||
291 | |||
292 | if ($count > 0) { | ||
293 | $this->container->bookmarkService->save(); | ||
294 | } | ||
295 | |||
296 | return $this->redirectFromReferer($request, $response, ['/visibility'], ['change_visibility']); | ||
297 | } | ||
298 | |||
299 | /** | ||
232 | * Helper function used to display the shaare form whether it's a new or existing bookmark. | 300 | * Helper function used to display the shaare form whether it's a new or existing bookmark. |
233 | * | 301 | * |
234 | * @param array $link data used in template, either from parameters or from the data store | 302 | * @param array $link data used in template, either from parameters or from the data store |