]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/controller/admin/ManageShaareController.php
Move PHP and config init to dedicated file
[github/shaarli/Shaarli.git] / application / front / controller / admin / ManageShaareController.php
index ff330a990ebcc021ccf8d419b4abec47c0af9636..3aa484239e71b62539157e20ba7b9f70b15e543c 100644 (file)
@@ -7,6 +7,7 @@ namespace Shaarli\Front\Controller\Admin;
 use Shaarli\Bookmark\Bookmark;
 use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
 use Shaarli\Formatter\BookmarkMarkdownFormatter;
+use Shaarli\Render\TemplatePage;
 use Shaarli\Thumbnailer;
 use Slim\Http\Request;
 use Slim\Http\Response;
@@ -28,7 +29,7 @@ class ManageShaareController extends ShaarliAdminController
             t('Shaare a new link') .' - '. $this->container->conf->get('general.title', 'Shaarli')
         );
 
-        return $response->write($this->render('addlink'));
+        return $response->write($this->render(TemplatePage::ADDLINK));
     }
 
     /**
@@ -296,6 +297,42 @@ class ManageShaareController extends ShaarliAdminController
         return $this->redirectFromReferer($request, $response, ['/visibility'], ['change_visibility']);
     }
 
+    /**
+     * GET /admin/shaare/{id}/pin - Pin or unpin a bookmark.
+     */
+    public function pinBookmark(Request $request, Response $response, array $args): Response
+    {
+        $this->checkToken($request);
+
+        $id = $args['id'] ?? '';
+        try {
+            if (false === ctype_digit($id)) {
+                throw new BookmarkNotFoundException();
+            }
+            $bookmark = $this->container->bookmarkService->get((int) $id);  // Read database
+        } catch (BookmarkNotFoundException $e) {
+            $this->saveErrorMessage(sprintf(
+                t('Bookmark with identifier %s could not be found.'),
+                $id
+            ));
+
+            return $this->redirectFromReferer($request, $response, ['/pin'], ['pin']);
+        }
+
+        $formatter = $this->container->formatterFactory->getFormatter('raw');
+
+        $bookmark->setSticky(!$bookmark->isSticky());
+
+        // To preserve backward compatibility with 3rd parties, plugins still use arrays
+        $data = $formatter->format($bookmark);
+        $this->container->pluginManager->executeHooks('save_link', $data);
+        $bookmark->fromArray($data);
+
+        $this->container->bookmarkService->set($bookmark);
+
+        return $this->redirectFromReferer($request, $response, ['/pin'], ['pin']);
+    }
+
     /**
      * Helper function used to display the shaare form whether it's a new or existing bookmark.
      *
@@ -329,7 +366,7 @@ class ManageShaareController extends ShaarliAdminController
             $editLabel . t('Shaare') .' - '. $this->container->conf->get('general.title', 'Shaarli')
         );
 
-        return $response->write($this->render('editlink'));
+        return $response->write($this->render(TemplatePage::EDIT_LINK));
     }
 
     /**