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;
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));
}
/**
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$formatter = $this->container->formatterFactory->getFormatter('raw');
$data = $formatter->format($bookmark);
- $data = $this->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark);
}
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('delete_link', $data);
+ $this->executePageHooks('delete_link', $data);
$this->container->bookmarkService->remove($bookmark, false);
++ $count;
}
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark, false);
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->executePageHooks('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.
*
'default_private_links' => $this->container->conf->get('privacy.default_private_links', false),
];
- $data = $this->executeHooks('render_editlink', $data);
+ $this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
foreach ($data as $key => $value) {
$this->assignView($key, $value);
$editLabel . t('Shaare') .' - '. $this->container->conf->get('general.title', 'Shaarli')
);
- return $response->write($this->render('editlink'));
- }
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(string $hook, array $data): array
- {
- $this->container->pluginManager->executeHooks(
- $hook,
- $data
- );
-
- return $data;
+ return $response->write($this->render(TemplatePage::EDIT_LINK));
}
}