// -------- Tag cloud
if ($targetPage == Router::$PAGE_TAGCLOUD) {
- header('Location: ./tag-cloud');
+ header('Location: ./tags/cloud');
exit;
}
// -------- Tag list
if ($targetPage == Router::$PAGE_TAGLIST) {
- header('Location: ./tag-list');
+ header('Location: ./tags/list');
exit;
}
if ($targetPage == Router::$PAGE_FEED_ATOM || $targetPage == Router::$PAGE_FEED_RSS) {
$feedType = $targetPage == Router::$PAGE_FEED_RSS ? FeedBuilder::$FEED_RSS : FeedBuilder::$FEED_ATOM;
- header('Location: ./feed-'. $feedType .'?'. http_build_query($_GET));
+ header('Location: ./feed/'. $feedType .'?'. http_build_query($_GET));
exit;
}
// -------- 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: ./tools');
+ header('Location: ./admin/tools');
exit;
}
// -------- User wants to change his/her password.
if ($targetPage == Router::$PAGE_CHANGEPASSWORD) {
- header('Location: ./password');
+ header('Location: ./admin/password');
exit;
}
// -------- User wants to change configuration
if ($targetPage == Router::$PAGE_CONFIGURE) {
- header('Location: ./configure');
+ header('Location: ./admin/configure');
exit;
}
// -------- User wants to rename a tag or delete it
if ($targetPage == Router::$PAGE_CHANGETAG) {
- header('Location: ./manage-tags');
+ header('Location: ./admin/tags');
exit;
}
// -------- User wants to add a link without using the bookmarklet: Show form.
if ($targetPage == Router::$PAGE_ADDLINK) {
- header('Location: ./shaare');
+ header('Location: ./admin/shaare');
exit;
}
// -------- User clicked the "Delete" button when editing a link: Delete link from database.
if ($targetPage == Router::$PAGE_DELETELINK) {
- if (! $sessionManager->checkToken($_GET['token'])) {
- die(t('Wrong token.'));
- }
-
- $ids = trim($_GET['lf_linkdate']);
- if (strpos($ids, ' ') !== false) {
- // multiple, space-separated ids provided
- $ids = array_values(array_filter(
- preg_split('/\s+/', escape($ids)),
- function ($item) {
- return $item !== '';
- }
- ));
- } else {
- // only a single id provided
- $shortUrl = $bookmarkService->get($ids)->getShortUrl();
- $ids = [$ids];
- }
- // assert at least one id is given
- if (!count($ids)) {
- die('no id provided');
- }
- $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
- $formatter = $factory->getFormatter('raw');
- foreach ($ids as $id) {
- $id = (int) escape($id);
- $bookmark = $bookmarkService->get($id);
- $data = $formatter->format($bookmark);
- $pluginManager->executeHooks('delete_link', $data);
- $bookmarkService->remove($bookmark, false);
- }
- $bookmarkService->save();
-
- // If we are called from the bookmarklet, we must close the popup:
- if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
- echo '<script>self.close();</script>';
- exit;
- }
-
- $location = '?';
- if (isset($_SERVER['HTTP_REFERER'])) {
- // Don't redirect to where we were previously if it was a permalink or an edit_link, because it would 404.
- $location = generateLocation(
- $_SERVER['HTTP_REFERER'],
- $_SERVER['HTTP_HOST'],
- ['delete_link', 'edit_link', ! empty($shortUrl) ? $shortUrl : null]
- );
- }
+ $ids = $_GET['lf_linkdate'] ?? '';
+ $token = $_GET['token'] ?? '';
- header('Location: ' . $location); // After deleting the link, redirect to appropriate location
+ header('Location: ./admin/shaare/delete?id=' . $ids . '&token=' . $token);
exit;
}
// -------- 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;
}
// -------- User clicked the "EDIT" button on a link: Display link edit form.
if (isset($_GET['edit_link'])) {
$id = (int) escape($_GET['edit_link']);
- header('Location: ./shaare-' . $id);
+ header('Location: ./admin/shaare/' . $id);
exit;
}
// -------- User want to post a new link: Display link edit form.
if (isset($_GET['post'])) {
- header('Location: ./shaare?' . http_build_query($_GET));
+ header('Location: ./admin/shaare?' . http_build_query($_GET));
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;
exit;
}
-$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager, WEB_PATH);
+$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
$container = $containerBuilder->build();
$app = new App($container);
$app->group('', function () {
/* -- PUBLIC --*/
- $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index')->setName('login');
- $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index')->setName('picwall');
- $this->get('/tag-cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud')->setName('tagcloud');
- $this->get('/tag-list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list')->setName('taglist');
- $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index')->setName('daily');
- $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss')->setName('dailyrss');
- $this->get('/feed-atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom')->setName('feedatom');
- $this->get('/feed-rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss')->setName('feedrss');
- $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index')->setName('opensearch');
-
- $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\Visitor\TagController:addTag')->setName('add-tag');
- $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag')->setName('remove-tag');
+ $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index');
+ $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index');
+ $this->get('/tags/cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud');
+ $this->get('/tags/list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list');
+ $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index');
+ $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss');
+ $this->get('/feed/atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom');
+ $this->get('/feed/rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss');
+ $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index');
+
+ $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\Visitor\TagController:addTag');
+ $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag');
/* -- LOGGED IN -- */
- $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index')->setName('logout');
- $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index')->setName('tools');
- $this->get('/password', '\Shaarli\Front\Controller\Admin\PasswordController:index')->setName('password');
- $this->post('/password', '\Shaarli\Front\Controller\Admin\PasswordController:change')->setName('changePassword');
- $this->get('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:index')->setName('configure');
- $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save')->setName('saveConfigure');
- $this->get('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index')->setName('manageTag');
- $this->post('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save')->setName('saveManageTag');
- $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:addShaare')->setName('addShaare');
- $this
- ->get('/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayCreateForm')
- ->setName('newShaare');
- $this
- ->get('/shaare-{id}', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayEditForm')
- ->setName('editShaare');
- $this
- ->post('/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:save')
- ->setName('saveShaare');
- $this
- ->get('/delete-shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:deleteBookmark')
- ->setName('deleteShaare');
-
- $this
- ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')
- ->setName('filter-links-per-page');
- $this
- ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility')
- ->setName('visibility');
- $this
- ->get('/untagged-only', '\Shaarli\Front\Controller\Admin\SessionFilterController:untaggedOnly')
- ->setName('untagged-only');
+ $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index');
+ $this->get('/admin/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index');
+ $this->get('/admin/password', '\Shaarli\Front\Controller\Admin\PasswordController:index');
+ $this->post('/admin/password', '\Shaarli\Front\Controller\Admin\PasswordController:change');
+ $this->get('/admin/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:index');
+ $this->post('/admin/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save');
+ $this->get('/admin/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index');
+ $this->post('/admin/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save');
+ $this->get('/admin/add-shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:addShaare');
+ $this->get('/admin/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayCreateForm');
+ $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');
+ $this->get('/untagged-only', '\Shaarli\Front\Controller\Admin\SessionFilterController:untaggedOnly');
})->add('\Shaarli\Front\ShaarliMiddleware');
$response = $app->run(true);