// -------- All other functions are reserved for the registered user:
+ // TODO: Remove legacy admin route redirections. We'll only keep public URL.
+
// -------- Display the Tools menu if requested (import/export/bookmarklet...)
if ($targetPage == Router::$PAGE_TOOLS) {
header('Location: ./admin/tools');
// -------- User clicked either "Set public" or "Set private" bulk operation
if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
- if (! $sessionManager->checkToken($_GET['token'])) {
- die(t('Wrong token.'));
- }
-
- $ids = trim($_GET['ids']);
- if (strpos($ids, ' ') !== false) {
- // multiple, space-separated ids provided
- $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
- } else {
- // only a single id provided
- $ids = [$ids];
- }
-
- // assert at least one id is given
- if (!count($ids)) {
- die('no id provided');
- }
- // assert that the visibility is valid
- if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
- die('invalid visibility');
- } else {
- $private = $_GET['newVisibility'] === 'private';
- }
- $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
- $formatter = $factory->getFormatter('raw');
- foreach ($ids as $id) {
- $id = (int) escape($id);
- $bookmark = $bookmarkService->get($id);
- $bookmark->setPrivate($private);
-
- // To preserve backward compatibility with 3rd parties, plugins still use arrays
- $data = $formatter->format($bookmark);
- $pluginManager->executeHooks('save_link', $data);
- $bookmark->fromArray($data);
-
- $bookmarkService->set($bookmark);
- }
- $bookmarkService->save();
-
- $location = '?';
- if (isset($_SERVER['HTTP_REFERER'])) {
- $location = generateLocation(
- $_SERVER['HTTP_REFERER'],
- $_SERVER['HTTP_HOST']
- );
- }
- header('Location: ' . $location); // After deleting the link, redirect to appropriate location
+ header('Location: ./admin/shaare/visibility?id=' . $_GET['token']);
exit;
}
}
if ($targetPage == Router::$PAGE_PINLINK) {
- if (! isset($_GET['id']) || !$bookmarkService->exists($_GET['id'])) {
- // FIXME! Use a proper error system.
- $msg = t('Invalid link ID provided');
- echo '<script>alert("'. $msg .'");document.location=\''. index_url($_SERVER) .'\';</script>';
- exit;
- }
- if (! $sessionManager->checkToken($_GET['token'])) {
- die('Wrong token.');
- }
-
- $link = $bookmarkService->get($_GET['id']);
- $link->setSticky(! $link->isSticky());
- $bookmarkService->set($link);
- header('Location: '.index_url($_SERVER));
+ // This route is no longer supported in legacy mode
+ header('Location: ./');
exit;
}
if ($targetPage == Router::$PAGE_EXPORT) {
- // Export bookmarks as a Netscape Bookmarks file
-
- if (empty($_GET['selection'])) {
- $PAGE->assign('pagetitle', t('Export') .' - '. $conf->get('general.title', 'Shaarli'));
- $PAGE->renderPage('export');
- exit;
- }
-
- // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
- $selection = $_GET['selection'];
- if (isset($_GET['prepend_note_url'])) {
- $prependNoteUrl = $_GET['prepend_note_url'];
- } else {
- $prependNoteUrl = false;
- }
-
- try {
- $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
- $formatter = $factory->getFormatter('raw');
- $PAGE->assign(
- 'links',
- NetscapeBookmarkUtils::filterAndFormat(
- $bookmarkService,
- $formatter,
- $selection,
- $prependNoteUrl,
- index_url($_SERVER)
- )
- );
- } catch (Exception $exc) {
- header('Content-Type: text/plain; charset=utf-8');
- echo $exc->getMessage();
- exit;
- }
- $now = new DateTime();
- header('Content-Type: text/html; charset=utf-8');
- header(
- 'Content-disposition: attachment; filename=bookmarks_'
- .$selection.'_'.$now->format(Bookmark::LINK_DATE_FORMAT).'.html'
- );
- $PAGE->assign('date', $now->format(DateTime::RFC822));
- $PAGE->assign('eol', PHP_EOL);
- $PAGE->assign('selection', $selection);
- $PAGE->renderPage('export.bookmarks');
+ header('Location: ./admin/export');
exit;
}
if (! $sessionManager->checkToken($_POST['token'])) {
die('Wrong token.');
}
- $status = NetscapeBookmarkUtils::import(
- $_POST,
- $_FILES,
- $bookmarkService,
- $conf,
- $history
- );
+ $netscapeBookmarkUtils = new NetscapeBookmarkUtils($bookmarkService, $conf, $history);
+ $status = $netscapeBookmarkUtils->import($_POST, $_FILES);
echo '<script>alert("'.$status.'");document.location=\'./?do='
.Router::$PAGE_IMPORT .'\';</script>';
exit;
$this->get('/admin/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayEditForm');
$this->post('/admin/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:save');
$this->get('/admin/shaare/delete', '\Shaarli\Front\Controller\Admin\ManageShaareController:deleteBookmark');
+ $this->get('/admin/shaare/visibility', '\Shaarli\Front\Controller\Admin\ManageShaareController:changeVisibility');
+ $this->get('/admin/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ManageShaareController:pinBookmark');
+ $this->get('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:index');
+ $this->post('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:export');
$this->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage');
$this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');