diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php index 85126246..72a85710 100644 --- a/application/container/ContainerBuilder.php +++ b/application/container/ContainerBuilder.php @@ -38,19 +38,17 @@ class ContainerBuilder /** @var LoginManager */ protected $login; - /** @var string */ - protected $webPath; + /** @var string|null */ + protected $basePath = null; public function __construct( ConfigManager $conf, SessionManager $session, - LoginManager $login, - string $webPath + LoginManager $login ) { $this->conf = $conf; $this->session = $session; $this->login = $login; - $this->webPath = $webPath; } public function build(): ShaarliContainer @@ -60,7 +58,7 @@ public function build(): ShaarliContainer $container['conf'] = $this->conf; $container['sessionManager'] = $this->session; $container['loginManager'] = $this->login; - $container['webPath'] = $this->webPath; + $container['basePath'] = $this->basePath; $container['plugins'] = function (ShaarliContainer $container): PluginManager { return new PluginManager($container->conf); diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php index a95393cd..4b97aae2 100644 --- a/application/container/ShaarliContainer.php +++ b/application/container/ShaarliContainer.php @@ -21,21 +21,20 @@ /** * Extension of Slim container to document the injected objects. * - * @property mixed[] $environment $_SERVER automatically injected by Slim * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) - * @property ConfigManager $conf - * @property SessionManager $sessionManager - * @property LoginManager $loginManager - * @property string $webPath - * @property History $history * @property BookmarkServiceInterface $bookmarkService - * @property PageBuilder $pageBuilder - * @property PluginManager $pluginManager - * @property FormatterFactory $formatterFactory - * @property PageCacheManager $pageCacheManager + * @property ConfigManager $conf + * @property mixed[] $environment $_SERVER automatically injected by Slim * @property FeedBuilder $feedBuilder - * @property Thumbnailer $thumbnailer + * @property FormatterFactory $formatterFactory + * @property History $history * @property HttpAccess $httpAccess + * @property LoginManager $loginManager + * @property PageBuilder $pageBuilder + * @property PageCacheManager $pageCacheManager + * @property PluginManager $pluginManager + * @property SessionManager $sessionManager + * @property Thumbnailer $thumbnailer */ class ShaarliContainer extends Container { diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php index 47aa61bb..7ad610c7 100644 --- a/application/front/ShaarliMiddleware.php +++ b/application/front/ShaarliMiddleware.php @@ -38,9 +38,9 @@ public function __construct(ShaarliContainer $container) */ public function __invoke(Request $request, Response $response, callable $next) { - try { - $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/'); + $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/'); + try { $response = $next($request, $response); } catch (ShaarliFrontException $e) { $this->container->pageBuilder->assign('message', $e->getMessage()); @@ -54,7 +54,7 @@ public function __invoke(Request $request, Response $response, callable $next) $response = $response->withStatus($e->getCode()); $response = $response->write($this->container->pageBuilder->render('error')); } catch (UnauthorizedException $e) { - return $response->withRedirect($request->getUri()->getBasePath() . '/login'); + return $response->withRedirect($this->container->basePath . '/login'); } return $response; diff --git a/application/front/controller/admin/ConfigureController.php b/application/front/controller/admin/ConfigureController.php index 5a482d8e..44971c43 100644 --- a/application/front/controller/admin/ConfigureController.php +++ b/application/front/controller/admin/ConfigureController.php @@ -19,7 +19,7 @@ class ConfigureController extends ShaarliAdminController { /** - * GET /configure - Displays the configuration page + * GET /admin/configure - Displays the configuration page */ public function index(Request $request, Response $response): Response { @@ -56,7 +56,7 @@ public function index(Request $request, Response $response): Response } /** - * POST /configure - Update Shaarli's configuration + * POST /admin/configure - Update Shaarli's configuration */ public function save(Request $request, Response $response): Response { @@ -115,6 +115,6 @@ public function save(Request $request, Response $response): Response $this->saveSuccessMessage(t('Configuration was saved.')); - return $response->withRedirect('./configure'); + return $this->redirect($response, '/admin/configure'); } } diff --git a/application/front/controller/admin/LogoutController.php b/application/front/controller/admin/LogoutController.php index 41e81984..c5984814 100644 --- a/application/front/controller/admin/LogoutController.php +++ b/application/front/controller/admin/LogoutController.php @@ -22,8 +22,8 @@ public function index(Request $request, Response $response): Response $this->container->sessionManager->logout(); // TODO: switch to a simple Cookie manager allowing to check the session, and create mocks. - setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->webPath); + setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->basePath . '/'); - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } } diff --git a/application/front/controller/admin/ManageTagController.php b/application/front/controller/admin/ManageTagController.php index e015e613..7dab288a 100644 --- a/application/front/controller/admin/ManageTagController.php +++ b/application/front/controller/admin/ManageTagController.php @@ -16,7 +16,7 @@ class ManageTagController extends ShaarliAdminController { /** - * GET /manage-tags - Displays the manage tags page + * GET /admin/tags - Displays the manage tags page */ public function index(Request $request, Response $response): Response { @@ -32,7 +32,7 @@ public function index(Request $request, Response $response): Response } /** - * POST /manage-tags - Update or delete provided tag + * POST /admin/tags - Update or delete provided tag */ public function save(Request $request, Response $response): Response { @@ -46,7 +46,7 @@ public function save(Request $request, Response $response): Response if (0 === strlen($fromTag) || false === $isDelete && 0 === strlen($toTag)) { $this->saveWarningMessage(t('Invalid tags provided.')); - return $response->withRedirect('./manage-tags'); + return $this->redirect($response, '/admin/tags'); } // TODO: move this to bookmark service @@ -80,8 +80,8 @@ public function save(Request $request, Response $response): Response $this->saveSuccessMessage($alert); - $redirect = true === $isDelete ? './manage-tags' : './?searchtags='. urlencode($toTag); + $redirect = true === $isDelete ? '/admin/tags' : '/?searchtags='. urlencode($toTag); - return $response->withRedirect($redirect); + return $this->redirect($response, $redirect); } } diff --git a/application/front/controller/admin/PasswordController.php b/application/front/controller/admin/PasswordController.php index 6e8f0bcb..bcce01a6 100644 --- a/application/front/controller/admin/PasswordController.php +++ b/application/front/controller/admin/PasswordController.php @@ -29,7 +29,7 @@ public function __construct(ShaarliContainer $container) } /** - * GET /password - Displays the change password template + * GET /admin/password - Displays the change password template */ public function index(Request $request, Response $response): Response { @@ -37,7 +37,7 @@ public function index(Request $request, Response $response): Response } /** - * POST /password - Change admin password - existing and new passwords need to be provided. + * POST /admin/password - Change admin password - existing and new passwords need to be provided. */ public function change(Request $request, Response $response): Response { diff --git a/application/front/controller/admin/PostBookmarkController.php b/application/front/controller/admin/PostBookmarkController.php index dbe570e2..f3ee5dea 100644 --- a/application/front/controller/admin/PostBookmarkController.php +++ b/application/front/controller/admin/PostBookmarkController.php @@ -19,7 +19,7 @@ class PostBookmarkController extends ShaarliAdminController { /** - * GET /add-shaare - Displays the form used to create a new bookmark from an URL + * GET /admin/add-shaare - Displays the form used to create a new bookmark from an URL */ public function addShaare(Request $request, Response $response): Response { @@ -32,7 +32,7 @@ public function addShaare(Request $request, Response $response): Response } /** - * GET /shaare - Displays the bookmark form for creation. + * GET /admin/shaare - Displays the bookmark form for creation. * Note that if the URL is found in existing bookmarks, then it will be in edit mode. */ public function displayCreateForm(Request $request, Response $response): Response @@ -93,7 +93,7 @@ public function displayCreateForm(Request $request, Response $response): Respons } /** - * GET /shaare-{id} - Displays the bookmark form in edition mode. + * GET /admin/shaare/{id} - Displays the bookmark form in edition mode. */ public function displayEditForm(Request $request, Response $response, array $args): Response { @@ -106,7 +106,7 @@ public function displayEditForm(Request $request, Response $response, array $arg } catch (BookmarkNotFoundException $e) { $this->saveErrorMessage(t('Bookmark not found')); - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } $formatter = $this->container->formatterFactory->getFormatter('raw'); @@ -116,7 +116,7 @@ public function displayEditForm(Request $request, Response $response, array $arg } /** - * POST /shaare + * POST /admin/shaare */ public function save(Request $request, Response $response): Response { @@ -170,11 +170,14 @@ public function save(Request $request, Response $response): Response ); } + /** + * GET /admin/shaare/delete + */ public function deleteBookmark(Request $request, Response $response): Response { $this->checkToken($request); - $ids = escape(trim($request->getParam('lf_linkdate'))); + $ids = escape(trim($request->getParam('id'))); if (strpos($ids, ' ') !== false) { // multiple, space-separated ids provided $ids = array_values(array_filter(preg_split('/\s+/', $ids), 'strlen')); @@ -207,7 +210,7 @@ public function deleteBookmark(Request $request, Response $response): Response } // Don't redirect to where we were previously because the datastore has changed. - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } protected function displayForm(array $link, bool $isNew, Request $request, Response $response): Response diff --git a/application/front/controller/visitor/LoginController.php b/application/front/controller/visitor/LoginController.php index 4de2f55d..0db1f463 100644 --- a/application/front/controller/visitor/LoginController.php +++ b/application/front/controller/visitor/LoginController.php @@ -23,7 +23,7 @@ public function index(Request $request, Response $response): Response if ($this->container->loginManager->isLoggedIn() || $this->container->conf->get('security.open_shaarli', false) ) { - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } $userCanLogin = $this->container->loginManager->canLogin($request->getServerParams()); diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index b90b1e8f..b494a8e6 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -104,6 +104,19 @@ protected function executeDefaultHooks(string $template): void } } + /** + * Simple helper which prepend the base path to redirect path. + * + * @param Response $response + * @param string $path Absolute path, e.g.: `/`, or `/admin/shaare/123` regardless of install directory + * + * @return Response updated + */ + protected function redirect(Response $response, string $path): Response + { + return $response->withRedirect($this->container->basePath . $path); + } + /** * Generates a redirection to the previous page, based on the HTTP_REFERER. * It fails back to the home page. diff --git a/application/front/controller/visitor/TagController.php b/application/front/controller/visitor/TagController.php index a0bc1d1b..c176f43f 100644 --- a/application/front/controller/visitor/TagController.php +++ b/application/front/controller/visitor/TagController.php @@ -11,6 +11,8 @@ * Class TagController * * Slim controller handle tags. + * + * TODO: check redirections with new helper */ class TagController extends ShaarliVisitorController { @@ -27,10 +29,10 @@ public function addTag(Request $request, Response $response, array $args): Respo // In case browser does not send HTTP_REFERER, we search a single tag if (null === $referer) { if (null !== $newTag) { - return $response->withRedirect('./?searchtags='. urlencode($newTag)); + return $this->redirect($response, '/?searchtags='. urlencode($newTag)); } - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } $currentUrl = parse_url($referer); @@ -81,7 +83,7 @@ public function removeTag(Request $request, Response $response, array $args): Re // If the referrer is not provided, we can update the search, so we failback on the bookmark list if (empty($referer)) { - return $response->withRedirect('./'); + return $this->redirect($response, '/'); } $tagToRemove = $args['tag'] ?? null; diff --git a/assets/default/js/base.js b/assets/default/js/base.js index b428a420..9f67d980 100644 --- a/assets/default/js/base.js +++ b/assets/default/js/base.js @@ -463,7 +463,7 @@ function init(description) { }); if (window.confirm(message)) { - window.location = `${basePath}/?delete_link&lf_linkdate=${ids.join('+')}&token=${token.value}`; + window.location = `${basePath}/admin/shaare/delete?id=${ids.join('+')}&token=${token.value}`; } }); } @@ -549,7 +549,7 @@ function init(description) { const refreshedToken = document.getElementById('token').value; const fromtag = block.getAttribute('data-tag'); const xhr = new XMLHttpRequest(); - xhr.open('POST', `${basePath}/manage-tags`); + xhr.open('POST', `${basePath}/admin/tags`); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = () => { if (xhr.status !== 200) { @@ -566,7 +566,7 @@ function init(description) { .setAttribute('href', `${basePath}/?searchtags=${encodeURIComponent(totag)}`); block .querySelector('a.rename-tag') - .setAttribute('href', `${basePath}/manage-tags?fromtag=${encodeURIComponent(totag)}`); + .setAttribute('href', `${basePath}/admin/tags?fromtag=${encodeURIComponent(totag)}`); // Refresh awesomplete values existingTags = existingTags.map(tag => (tag === fromtag ? totag : tag)); @@ -600,7 +600,7 @@ function init(description) { if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) { const xhr = new XMLHttpRequest(); - xhr.open('POST', `${basePath}/manage-tags`); + xhr.open('POST', `${basePath}/admin/tags`); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = () => { block.remove(); diff --git a/doc/md/RSS-feeds.md b/doc/md/RSS-feeds.md index cdfb8c78..ecbff09a 100644 --- a/doc/md/RSS-feeds.md +++ b/doc/md/RSS-feeds.md @@ -1,14 +1,14 @@ ### Feeds options -Feeds are available in ATOM with `/feed-atom` and RSS with `/feed-rss`. +Feeds are available in ATOM with `/feed/atom` and RSS with `/feed/rss`. Options: - You can use `permalinks` in the feed URL to get permalink to Shaares instead of direct link to shaared URL. - - E.G. `https://my.shaarli.domain/feed-atom?permalinks`. + - E.G. `https://my.shaarli.domain/feed/atom?permalinks`. - You can use `nb` parameter in the feed URL to specify the number of Shaares you want in a feed (default if not specified: `50`). The keyword `all` is available if you want everything. - - `https://my.shaarli.domain/feed-atom?permalinks&nb=42` - - `https://my.shaarli.domain/feed-atom?permalinks&nb=all` + - `https://my.shaarli.domain/feed/atom?permalinks&nb=42` + - `https://my.shaarli.domain/feed/atom?permalinks&nb=all` ### RSS Feeds or Picture Wall for a specific search/tag diff --git a/doc/md/Translations.md b/doc/md/Translations.md index 5c775d30..75eeed7d 100644 --- a/doc/md/Translations.md +++ b/doc/md/Translations.md @@ -32,11 +32,11 @@ Here is a list : ``` http:/// http:///?nonope -http:///add-shaare -http:///?do=changepasswd +http:///admin/add-shaare +http:///admin/password http:///?do=changetag -http:///configure -http:///tools +http:///admin/configure +http:///admin/tools http:///daily http:///?post http:///?do=export @@ -44,8 +44,8 @@ http:///?do=import http:///login http:///picture-wall http:///?do=pluginadmin -http:///tag-cloud -http:///tag-list +http:///tags/cloud +http:///tags/list ``` #### Improve existing translation diff --git a/index.php b/index.php index fb528eeb..aa358da0 100644 --- a/index.php +++ b/index.php @@ -412,13 +412,13 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM // -------- 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; } @@ -433,7 +433,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM 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; } @@ -501,31 +501,31 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM // -------- 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; } @@ -538,56 +538,10 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM // -------- 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 = $_GET['lf_linkdate'] ?? ''; + $token = $_GET['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 ''; - 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] - ); - } - - header('Location: ' . $location); // After deleting the link, redirect to appropriate location + header('Location: ./admin/shaare/delete?id=' . $ids . '&token=' . $token); exit; } @@ -646,13 +600,13 @@ function ($item) { // -------- 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; } @@ -1160,7 +1114,7 @@ function install($conf, $sessionManager, $loginManager) exit; } -$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager, WEB_PATH); +$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager); $container = $containerBuilder->build(); $app = new App($container); @@ -1183,51 +1137,37 @@ function install($conf, $sessionManager, $loginManager) $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('/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')->setName('add-tag'); - $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag')->setName('remove-tag'); + $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('/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\PostBookmarkController:addShaare'); + $this->get('/admin/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayCreateForm'); + $this->get('/admin/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayEditForm'); + $this->post('/admin/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:save'); + $this->get('/admin/shaare/delete', '\Shaarli\Front\Controller\Admin\PostBookmarkController:deleteBookmark'); - $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('/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); diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 41634dda..170f3494 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -60,8 +60,8 @@ function hook_pubsubhubbub_render_feed($data, $conf) function hook_pubsubhubbub_save_link($data, $conf) { $feeds = array( - index_url($_SERVER) .'feed-atom', - index_url($_SERVER) .'feed-rss', + index_url($_SERVER) .'feed/atom', + index_url($_SERVER) .'feed/rss', ); $httpPost = function_exists('curl_version') ? false : 'nocurl_http_post'; diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index 65647249..db533f37 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -7,12 +7,16 @@ use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; +use Shaarli\Http\HttpAccess; +use Shaarli\Plugin\PluginManager; use Shaarli\Render\PageBuilder; use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\Thumbnailer; class ContainerBuilderTest extends TestCase { @@ -39,8 +43,7 @@ public function setUp(): void $this->containerBuilder = new ContainerBuilder( $this->conf, $this->sessionManager, - $this->loginManager, - 'UT web path' + $this->loginManager ); } @@ -51,11 +54,17 @@ public function testBuildContainer(): void static::assertInstanceOf(ConfigManager::class, $container->conf); static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(LoginManager::class, $container->loginManager); - static::assertSame('UT web path', $container->webPath); static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); + static::assertInstanceOf(PluginManager::class, $container->pluginManager); static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); + static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); + static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); + static::assertInstanceOf(HttpAccess::class, $container->httpAccess); + + // Set by the middleware + static::assertNull($container->basePath); } } diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 57f3b09b..2e716432 100644 --- a/tests/feed/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -11,7 +11,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/pagecache'; - protected static $url = 'http://shaar.li/feed-atom'; + protected static $url = 'http://shaar.li/feed/atom'; protected static $filename; /** @@ -42,8 +42,8 @@ public function testConstruct() { new CachedPage(self::$testCacheDir, '', true); new CachedPage(self::$testCacheDir, '', false); - new CachedPage(self::$testCacheDir, 'http://shaar.li/feed-rss', true); - new CachedPage(self::$testCacheDir, 'http://shaar.li/feed-atom', false); + new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/rss', true); + new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/atom', false); $this->addToAssertionCount(1); } diff --git a/tests/front/controller/admin/ConfigureControllerTest.php b/tests/front/controller/admin/ConfigureControllerTest.php index 40304a18..f2f84bac 100644 --- a/tests/front/controller/admin/ConfigureControllerTest.php +++ b/tests/front/controller/admin/ConfigureControllerTest.php @@ -142,7 +142,7 @@ public function testSaveNewConfig(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./configure'], $result->getHeader('Location')); + static::assertSame(['/subfolder/admin/configure'], $result->getHeader('Location')); static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); @@ -193,7 +193,7 @@ public function testSaveNewConfigThumbnailsActivation(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./configure'], $result->getHeader('Location')); + static::assertSame(['/subfolder/admin/configure'], $result->getHeader('Location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); @@ -242,7 +242,7 @@ public function testSaveNewConfigThumbnailsAlreadyActive(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./configure'], $result->getHeader('Location')); + static::assertSame(['/subfolder/admin/configure'], $result->getHeader('Location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php index 78a0fe73..ca177085 100644 --- a/tests/front/controller/admin/LogoutControllerTest.php +++ b/tests/front/controller/admin/LogoutControllerTest.php @@ -49,7 +49,7 @@ public function testValidControllerInvoke(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertContains('./', $result->getHeader('Location')); + static::assertSame(['/subfolder/'], $result->getHeader('location')); static::assertSame('false', $_COOKIE[LoginManager::$STAY_SIGNED_IN_COOKIE]); } } diff --git a/tests/front/controller/admin/ManageTagControllerTest.php b/tests/front/controller/admin/ManageTagControllerTest.php index eed99231..09ba0b4b 100644 --- a/tests/front/controller/admin/ManageTagControllerTest.php +++ b/tests/front/controller/admin/ManageTagControllerTest.php @@ -93,7 +93,7 @@ public function testSaveRenameTagValid(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./?searchtags=new-tag'], $result->getHeader('location')); + static::assertSame(['/subfolder/?searchtags=new-tag'], $result->getHeader('location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); @@ -146,7 +146,7 @@ public function testSaveDeleteTagValid(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./manage-tags'], $result->getHeader('location')); + static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayNotHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); @@ -197,7 +197,7 @@ public function testSaveRenameTagMissingFrom(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./manage-tags'], $result->getHeader('location')); + static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); @@ -229,7 +229,7 @@ public function testSaveDeleteTagMissingFrom(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./manage-tags'], $result->getHeader('location')); + static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); @@ -262,7 +262,7 @@ public function testSaveRenameTagMissingTo(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./manage-tags'], $result->getHeader('location')); + static::assertSame(['/subfolder/admin/tags'], $result->getHeader('location')); static::assertArrayNotHasKey(SessionManager::KEY_ERROR_MESSAGES, $session); static::assertArrayHasKey(SessionManager::KEY_WARNING_MESSAGES, $session); diff --git a/tests/front/controller/admin/PostBookmarkControllerTest.php b/tests/front/controller/admin/PostBookmarkControllerTest.php index 69673bd2..8dcd1b50 100644 --- a/tests/front/controller/admin/PostBookmarkControllerTest.php +++ b/tests/front/controller/admin/PostBookmarkControllerTest.php @@ -395,7 +395,7 @@ public function testSaveBookmark(): void 'lf_description' => 'Provided description.', 'lf_tags' => 'abc def', 'lf_private' => '1', - 'returnurl' => 'http://shaarli.tld/subfolder/add-shaare' + 'returnurl' => 'http://shaarli.tld/subfolder/admin/add-shaare' ]; $request = $this->createMock(Request::class); @@ -459,7 +459,7 @@ public function testSaveBookmark(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertRegExp('@/subfolder/#\w{6}@', $result->getHeader('location')[0]); + static::assertRegExp('@/subfolder/#[\w\-]{6}@', $result->getHeader('location')[0]); } @@ -545,7 +545,7 @@ public function testSaveExistingBookmark(): void $result = $this->controller->save($request, $response); static::assertSame(302, $result->getStatusCode()); - static::assertRegExp('@/subfolder/\?page=2#\w{6}@', $result->getHeader('location')[0]); + static::assertRegExp('@/subfolder/\?page=2#[\w\-]{6}@', $result->getHeader('location')[0]); } /** diff --git a/tests/front/controller/visitor/LoginControllerTest.php b/tests/front/controller/visitor/LoginControllerTest.php index faa8ac71..e57f44b9 100644 --- a/tests/front/controller/visitor/LoginControllerTest.php +++ b/tests/front/controller/visitor/LoginControllerTest.php @@ -95,7 +95,7 @@ public function testLoginControllerWhileLoggedIn(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./'], $result->getHeader('Location')); + static::assertSame(['/subfolder/'], $result->getHeader('Location')); } public function testLoginControllerOpenShaarli(): void @@ -116,7 +116,7 @@ public function testLoginControllerOpenShaarli(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./'], $result->getHeader('Location')); + static::assertSame(['/subfolder/'], $result->getHeader('Location')); } public function testLoginControllerWhileBanned(): void diff --git a/tests/front/controller/visitor/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php index 1242a2e9..43076086 100644 --- a/tests/front/controller/visitor/TagControllerTest.php +++ b/tests/front/controller/visitor/TagControllerTest.php @@ -64,7 +64,7 @@ public function testAddTagWithoutRefererAndExistingSearch(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./?searchtags=abc'], $result->getHeader('location')); + static::assertSame(['/subfolder/?searchtags=abc'], $result->getHeader('location')); } public function testAddTagRemoveLegacyQueryParam(): void @@ -138,7 +138,7 @@ public function testAddTagWithoutNewTagWithoutReferer(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./'], $result->getHeader('location')); + static::assertSame(['/subfolder/'], $result->getHeader('location')); } public function testRemoveTagWithoutMatchingTag(): void @@ -184,7 +184,7 @@ public function testRemoveTagWithoutReferer(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./'], $result->getHeader('location')); + static::assertSame(['/subfolder/'], $result->getHeader('location')); } public function testRemoveTagWithoutTag(): void @@ -210,6 +210,6 @@ public function testRemoveTagWithoutTagWithoutReferer(): void static::assertInstanceOf(Response::class, $result); static::assertSame(302, $result->getStatusCode()); - static::assertSame(['./'], $result->getHeader('location')); + static::assertSame(['/subfolder/'], $result->getHeader('location')); } } diff --git a/tpl/default/addlink.html b/tpl/default/addlink.html index c37827f4..67d3ebd1 100644 --- a/tpl/default/addlink.html +++ b/tpl/default/addlink.html @@ -9,7 +9,7 @@