From: ArthurHoaro Date: Sat, 13 Jun 2020 11:08:01 +0000 (+0200) Subject: Use multi-level routes for existing controllers instead of 1 level everywhere X-Git-Tag: v0.12.0-beta~4^2~29 X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=commitdiff_plain;h=9c75f877935fa6adec951a4d8d32b328aaab314f Use multi-level routes for existing controllers instead of 1 level everywhere Also prefix most admin routes with /admin/ --- 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 @@ class ContainerBuilder $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 @@ use Slim\Container; /** * 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 BookmarkServiceInterface $bookmarkService * @property ConfigManager $conf - * @property SessionManager $sessionManager - * @property LoginManager $loginManager - * @property string $webPath + * @property mixed[] $environment $_SERVER automatically injected by Slim + * @property FeedBuilder $feedBuilder + * @property FormatterFactory $formatterFactory * @property History $history - * @property BookmarkServiceInterface $bookmarkService + * @property HttpAccess $httpAccess + * @property LoginManager $loginManager * @property PageBuilder $pageBuilder - * @property PluginManager $pluginManager - * @property FormatterFactory $formatterFactory * @property PageCacheManager $pageCacheManager - * @property FeedBuilder $feedBuilder + * @property PluginManager $pluginManager + * @property SessionManager $sessionManager * @property Thumbnailer $thumbnailer - * @property HttpAccess $httpAccess */ 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 @@ class ShaarliMiddleware */ 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 @@ class ShaarliMiddleware $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 @@ use Throwable; 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 @@ class ConfigureController extends ShaarliAdminController } /** - * 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 @@ class ConfigureController extends ShaarliAdminController $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 @@ class LogoutController extends ShaarliAdminController $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 @@ use Slim\Http\Response; 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 @@ class ManageTagController extends ShaarliAdminController } /** - * 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 @@ class ManageTagController extends ShaarliAdminController 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 @@ class ManageTagController extends ShaarliAdminController $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 @@ class PasswordController extends ShaarliAdminController } /** - * 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 @@ class PasswordController extends ShaarliAdminController } /** - * 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 @@ use Slim\Http\Response; 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 @@ class PostBookmarkController extends ShaarliAdminController } /** - * 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 @@ class PostBookmarkController extends ShaarliAdminController } /** - * 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 @@ class PostBookmarkController extends ShaarliAdminController } 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 @@ class PostBookmarkController extends ShaarliAdminController } /** - * POST /shaare + * POST /admin/shaare */ public function save(Request $request, Response $response): Response { @@ -170,11 +170,14 @@ class PostBookmarkController extends ShaarliAdminController ); } + /** + * 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 @@ class PostBookmarkController extends ShaarliAdminController } // 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 @@ class LoginController extends ShaarliVisitorController 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 @@ abstract class ShaarliVisitorController } } + /** + * 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 @@ use Slim\Http\Response; * Class TagController * * Slim controller handle tags. + * + * TODO: check redirections with new helper */ class TagController extends ShaarliVisitorController { @@ -27,10 +29,10 @@ class TagController extends ShaarliVisitorController // 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 @@ class TagController extends ShaarliVisitorController // 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 = 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; - } + $ids = $_GET['lf_linkdate'] ?? ''; + $token = $_GET['token'] ?? ''; - $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 renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM // -------- 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 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do= 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 @@ $app->group('/api/v1', function () { $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\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'); + $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 @@ namespace Shaarli\Container; 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 @@ class ContainerBuilderTest extends TestCase $this->containerBuilder = new ContainerBuilder( $this->conf, $this->sessionManager, - $this->loginManager, - 'UT web path' + $this->loginManager ); } @@ -51,11 +54,17 @@ class ContainerBuilderTest extends TestCase 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 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase { 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 @@ class ConfigureControllerTest extends TestCase $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 @@ class ConfigureControllerTest extends TestCase $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 @@ class ConfigureControllerTest extends TestCase $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 @@ class LogoutControllerTest extends TestCase 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 @@ class ManageTagControllerTest extends TestCase $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 @@ class ManageTagControllerTest extends TestCase $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 @@ class ManageTagControllerTest extends TestCase $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 @@ class ManageTagControllerTest extends TestCase $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 @@ class ManageTagControllerTest extends TestCase $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 @@ class PostBookmarkControllerTest extends TestCase '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 @@ class PostBookmarkControllerTest extends TestCase $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 @@ class PostBookmarkControllerTest extends TestCase $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 @@ class LoginControllerTest extends TestCase 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 @@ class LoginControllerTest extends TestCase 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 @@ class TagControllerTest extends TestCase 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 @@ class TagControllerTest extends TestCase 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 @@ class TagControllerTest extends TestCase 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 @@ class TagControllerTest extends TestCase 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 @@