diff options
Diffstat (limited to 'application')
11 files changed, 56 insertions, 41 deletions
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 | |||
38 | /** @var LoginManager */ | 38 | /** @var LoginManager */ |
39 | protected $login; | 39 | protected $login; |
40 | 40 | ||
41 | /** @var string */ | 41 | /** @var string|null */ |
42 | protected $webPath; | 42 | protected $basePath = null; |
43 | 43 | ||
44 | public function __construct( | 44 | public function __construct( |
45 | ConfigManager $conf, | 45 | ConfigManager $conf, |
46 | SessionManager $session, | 46 | SessionManager $session, |
47 | LoginManager $login, | 47 | LoginManager $login |
48 | string $webPath | ||
49 | ) { | 48 | ) { |
50 | $this->conf = $conf; | 49 | $this->conf = $conf; |
51 | $this->session = $session; | 50 | $this->session = $session; |
52 | $this->login = $login; | 51 | $this->login = $login; |
53 | $this->webPath = $webPath; | ||
54 | } | 52 | } |
55 | 53 | ||
56 | public function build(): ShaarliContainer | 54 | public function build(): ShaarliContainer |
@@ -60,7 +58,7 @@ class ContainerBuilder | |||
60 | $container['conf'] = $this->conf; | 58 | $container['conf'] = $this->conf; |
61 | $container['sessionManager'] = $this->session; | 59 | $container['sessionManager'] = $this->session; |
62 | $container['loginManager'] = $this->login; | 60 | $container['loginManager'] = $this->login; |
63 | $container['webPath'] = $this->webPath; | 61 | $container['basePath'] = $this->basePath; |
64 | 62 | ||
65 | $container['plugins'] = function (ShaarliContainer $container): PluginManager { | 63 | $container['plugins'] = function (ShaarliContainer $container): PluginManager { |
66 | return new PluginManager($container->conf); | 64 | 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; | |||
21 | /** | 21 | /** |
22 | * Extension of Slim container to document the injected objects. | 22 | * Extension of Slim container to document the injected objects. |
23 | * | 23 | * |
24 | * @property mixed[] $environment $_SERVER automatically injected by Slim | ||
25 | * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) | 24 | * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) |
25 | * @property BookmarkServiceInterface $bookmarkService | ||
26 | * @property ConfigManager $conf | 26 | * @property ConfigManager $conf |
27 | * @property SessionManager $sessionManager | 27 | * @property mixed[] $environment $_SERVER automatically injected by Slim |
28 | * @property LoginManager $loginManager | 28 | * @property FeedBuilder $feedBuilder |
29 | * @property string $webPath | 29 | * @property FormatterFactory $formatterFactory |
30 | * @property History $history | 30 | * @property History $history |
31 | * @property BookmarkServiceInterface $bookmarkService | 31 | * @property HttpAccess $httpAccess |
32 | * @property LoginManager $loginManager | ||
32 | * @property PageBuilder $pageBuilder | 33 | * @property PageBuilder $pageBuilder |
33 | * @property PluginManager $pluginManager | ||
34 | * @property FormatterFactory $formatterFactory | ||
35 | * @property PageCacheManager $pageCacheManager | 34 | * @property PageCacheManager $pageCacheManager |
36 | * @property FeedBuilder $feedBuilder | 35 | * @property PluginManager $pluginManager |
36 | * @property SessionManager $sessionManager | ||
37 | * @property Thumbnailer $thumbnailer | 37 | * @property Thumbnailer $thumbnailer |
38 | * @property HttpAccess $httpAccess | ||
39 | */ | 38 | */ |
40 | class ShaarliContainer extends Container | 39 | class ShaarliContainer extends Container |
41 | { | 40 | { |
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 | |||
38 | */ | 38 | */ |
39 | public function __invoke(Request $request, Response $response, callable $next) | 39 | public function __invoke(Request $request, Response $response, callable $next) |
40 | { | 40 | { |
41 | try { | 41 | $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/'); |
42 | $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/'); | ||
43 | 42 | ||
43 | try { | ||
44 | $response = $next($request, $response); | 44 | $response = $next($request, $response); |
45 | } catch (ShaarliFrontException $e) { | 45 | } catch (ShaarliFrontException $e) { |
46 | $this->container->pageBuilder->assign('message', $e->getMessage()); | 46 | $this->container->pageBuilder->assign('message', $e->getMessage()); |
@@ -54,7 +54,7 @@ class ShaarliMiddleware | |||
54 | $response = $response->withStatus($e->getCode()); | 54 | $response = $response->withStatus($e->getCode()); |
55 | $response = $response->write($this->container->pageBuilder->render('error')); | 55 | $response = $response->write($this->container->pageBuilder->render('error')); |
56 | } catch (UnauthorizedException $e) { | 56 | } catch (UnauthorizedException $e) { |
57 | return $response->withRedirect($request->getUri()->getBasePath() . '/login'); | 57 | return $response->withRedirect($this->container->basePath . '/login'); |
58 | } | 58 | } |
59 | 59 | ||
60 | return $response; | 60 | 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; | |||
19 | class ConfigureController extends ShaarliAdminController | 19 | class ConfigureController extends ShaarliAdminController |
20 | { | 20 | { |
21 | /** | 21 | /** |
22 | * GET /configure - Displays the configuration page | 22 | * GET /admin/configure - Displays the configuration page |
23 | */ | 23 | */ |
24 | public function index(Request $request, Response $response): Response | 24 | public function index(Request $request, Response $response): Response |
25 | { | 25 | { |
@@ -56,7 +56,7 @@ class ConfigureController extends ShaarliAdminController | |||
56 | } | 56 | } |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * POST /configure - Update Shaarli's configuration | 59 | * POST /admin/configure - Update Shaarli's configuration |
60 | */ | 60 | */ |
61 | public function save(Request $request, Response $response): Response | 61 | public function save(Request $request, Response $response): Response |
62 | { | 62 | { |
@@ -115,6 +115,6 @@ class ConfigureController extends ShaarliAdminController | |||
115 | 115 | ||
116 | $this->saveSuccessMessage(t('Configuration was saved.')); | 116 | $this->saveSuccessMessage(t('Configuration was saved.')); |
117 | 117 | ||
118 | return $response->withRedirect('./configure'); | 118 | return $this->redirect($response, '/admin/configure'); |
119 | } | 119 | } |
120 | } | 120 | } |
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 | |||
22 | $this->container->sessionManager->logout(); | 22 | $this->container->sessionManager->logout(); |
23 | 23 | ||
24 | // TODO: switch to a simple Cookie manager allowing to check the session, and create mocks. | 24 | // TODO: switch to a simple Cookie manager allowing to check the session, and create mocks. |
25 | setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->webPath); | 25 | setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->basePath . '/'); |
26 | 26 | ||
27 | return $response->withRedirect('./'); | 27 | return $this->redirect($response, '/'); |
28 | } | 28 | } |
29 | } | 29 | } |
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; | |||
16 | class ManageTagController extends ShaarliAdminController | 16 | class ManageTagController extends ShaarliAdminController |
17 | { | 17 | { |
18 | /** | 18 | /** |
19 | * GET /manage-tags - Displays the manage tags page | 19 | * GET /admin/tags - Displays the manage tags page |
20 | */ | 20 | */ |
21 | public function index(Request $request, Response $response): Response | 21 | public function index(Request $request, Response $response): Response |
22 | { | 22 | { |
@@ -32,7 +32,7 @@ class ManageTagController extends ShaarliAdminController | |||
32 | } | 32 | } |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * POST /manage-tags - Update or delete provided tag | 35 | * POST /admin/tags - Update or delete provided tag |
36 | */ | 36 | */ |
37 | public function save(Request $request, Response $response): Response | 37 | public function save(Request $request, Response $response): Response |
38 | { | 38 | { |
@@ -46,7 +46,7 @@ class ManageTagController extends ShaarliAdminController | |||
46 | if (0 === strlen($fromTag) || false === $isDelete && 0 === strlen($toTag)) { | 46 | if (0 === strlen($fromTag) || false === $isDelete && 0 === strlen($toTag)) { |
47 | $this->saveWarningMessage(t('Invalid tags provided.')); | 47 | $this->saveWarningMessage(t('Invalid tags provided.')); |
48 | 48 | ||
49 | return $response->withRedirect('./manage-tags'); | 49 | return $this->redirect($response, '/admin/tags'); |
50 | } | 50 | } |
51 | 51 | ||
52 | // TODO: move this to bookmark service | 52 | // TODO: move this to bookmark service |
@@ -80,8 +80,8 @@ class ManageTagController extends ShaarliAdminController | |||
80 | 80 | ||
81 | $this->saveSuccessMessage($alert); | 81 | $this->saveSuccessMessage($alert); |
82 | 82 | ||
83 | $redirect = true === $isDelete ? './manage-tags' : './?searchtags='. urlencode($toTag); | 83 | $redirect = true === $isDelete ? '/admin/tags' : '/?searchtags='. urlencode($toTag); |
84 | 84 | ||
85 | return $response->withRedirect($redirect); | 85 | return $this->redirect($response, $redirect); |
86 | } | 86 | } |
87 | } | 87 | } |
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 | |||
29 | } | 29 | } |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * GET /password - Displays the change password template | 32 | * GET /admin/password - Displays the change password template |
33 | */ | 33 | */ |
34 | public function index(Request $request, Response $response): Response | 34 | public function index(Request $request, Response $response): Response |
35 | { | 35 | { |
@@ -37,7 +37,7 @@ class PasswordController extends ShaarliAdminController | |||
37 | } | 37 | } |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * POST /password - Change admin password - existing and new passwords need to be provided. | 40 | * POST /admin/password - Change admin password - existing and new passwords need to be provided. |
41 | */ | 41 | */ |
42 | public function change(Request $request, Response $response): Response | 42 | public function change(Request $request, Response $response): Response |
43 | { | 43 | { |
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; | |||
19 | class PostBookmarkController extends ShaarliAdminController | 19 | class PostBookmarkController extends ShaarliAdminController |
20 | { | 20 | { |
21 | /** | 21 | /** |
22 | * GET /add-shaare - Displays the form used to create a new bookmark from an URL | 22 | * GET /admin/add-shaare - Displays the form used to create a new bookmark from an URL |
23 | */ | 23 | */ |
24 | public function addShaare(Request $request, Response $response): Response | 24 | public function addShaare(Request $request, Response $response): Response |
25 | { | 25 | { |
@@ -32,7 +32,7 @@ class PostBookmarkController extends ShaarliAdminController | |||
32 | } | 32 | } |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * GET /shaare - Displays the bookmark form for creation. | 35 | * GET /admin/shaare - Displays the bookmark form for creation. |
36 | * Note that if the URL is found in existing bookmarks, then it will be in edit mode. | 36 | * Note that if the URL is found in existing bookmarks, then it will be in edit mode. |
37 | */ | 37 | */ |
38 | public function displayCreateForm(Request $request, Response $response): Response | 38 | public function displayCreateForm(Request $request, Response $response): Response |
@@ -93,7 +93,7 @@ class PostBookmarkController extends ShaarliAdminController | |||
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * GET /shaare-{id} - Displays the bookmark form in edition mode. | 96 | * GET /admin/shaare/{id} - Displays the bookmark form in edition mode. |
97 | */ | 97 | */ |
98 | public function displayEditForm(Request $request, Response $response, array $args): Response | 98 | public function displayEditForm(Request $request, Response $response, array $args): Response |
99 | { | 99 | { |
@@ -106,7 +106,7 @@ class PostBookmarkController extends ShaarliAdminController | |||
106 | } catch (BookmarkNotFoundException $e) { | 106 | } catch (BookmarkNotFoundException $e) { |
107 | $this->saveErrorMessage(t('Bookmark not found')); | 107 | $this->saveErrorMessage(t('Bookmark not found')); |
108 | 108 | ||
109 | return $response->withRedirect('./'); | 109 | return $this->redirect($response, '/'); |
110 | } | 110 | } |
111 | 111 | ||
112 | $formatter = $this->container->formatterFactory->getFormatter('raw'); | 112 | $formatter = $this->container->formatterFactory->getFormatter('raw'); |
@@ -116,7 +116,7 @@ class PostBookmarkController extends ShaarliAdminController | |||
116 | } | 116 | } |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * POST /shaare | 119 | * POST /admin/shaare |
120 | */ | 120 | */ |
121 | public function save(Request $request, Response $response): Response | 121 | public function save(Request $request, Response $response): Response |
122 | { | 122 | { |
@@ -170,11 +170,14 @@ class PostBookmarkController extends ShaarliAdminController | |||
170 | ); | 170 | ); |
171 | } | 171 | } |
172 | 172 | ||
173 | /** | ||
174 | * GET /admin/shaare/delete | ||
175 | */ | ||
173 | public function deleteBookmark(Request $request, Response $response): Response | 176 | public function deleteBookmark(Request $request, Response $response): Response |
174 | { | 177 | { |
175 | $this->checkToken($request); | 178 | $this->checkToken($request); |
176 | 179 | ||
177 | $ids = escape(trim($request->getParam('lf_linkdate'))); | 180 | $ids = escape(trim($request->getParam('id'))); |
178 | if (strpos($ids, ' ') !== false) { | 181 | if (strpos($ids, ' ') !== false) { |
179 | // multiple, space-separated ids provided | 182 | // multiple, space-separated ids provided |
180 | $ids = array_values(array_filter(preg_split('/\s+/', $ids), 'strlen')); | 183 | $ids = array_values(array_filter(preg_split('/\s+/', $ids), 'strlen')); |
@@ -207,7 +210,7 @@ class PostBookmarkController extends ShaarliAdminController | |||
207 | } | 210 | } |
208 | 211 | ||
209 | // Don't redirect to where we were previously because the datastore has changed. | 212 | // Don't redirect to where we were previously because the datastore has changed. |
210 | return $response->withRedirect('./'); | 213 | return $this->redirect($response, '/'); |
211 | } | 214 | } |
212 | 215 | ||
213 | protected function displayForm(array $link, bool $isNew, Request $request, Response $response): Response | 216 | 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 | |||
23 | if ($this->container->loginManager->isLoggedIn() | 23 | if ($this->container->loginManager->isLoggedIn() |
24 | || $this->container->conf->get('security.open_shaarli', false) | 24 | || $this->container->conf->get('security.open_shaarli', false) |
25 | ) { | 25 | ) { |
26 | return $response->withRedirect('./'); | 26 | return $this->redirect($response, '/'); |
27 | } | 27 | } |
28 | 28 | ||
29 | $userCanLogin = $this->container->loginManager->canLogin($request->getServerParams()); | 29 | $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 | |||
@@ -105,6 +105,19 @@ abstract class ShaarliVisitorController | |||
105 | } | 105 | } |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Simple helper which prepend the base path to redirect path. | ||
109 | * | ||
110 | * @param Response $response | ||
111 | * @param string $path Absolute path, e.g.: `/`, or `/admin/shaare/123` regardless of install directory | ||
112 | * | ||
113 | * @return Response updated | ||
114 | */ | ||
115 | protected function redirect(Response $response, string $path): Response | ||
116 | { | ||
117 | return $response->withRedirect($this->container->basePath . $path); | ||
118 | } | ||
119 | |||
120 | /** | ||
108 | * Generates a redirection to the previous page, based on the HTTP_REFERER. | 121 | * Generates a redirection to the previous page, based on the HTTP_REFERER. |
109 | * It fails back to the home page. | 122 | * It fails back to the home page. |
110 | * | 123 | * |
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; | |||
11 | * Class TagController | 11 | * Class TagController |
12 | * | 12 | * |
13 | * Slim controller handle tags. | 13 | * Slim controller handle tags. |
14 | * | ||
15 | * TODO: check redirections with new helper | ||
14 | */ | 16 | */ |
15 | class TagController extends ShaarliVisitorController | 17 | class TagController extends ShaarliVisitorController |
16 | { | 18 | { |
@@ -27,10 +29,10 @@ class TagController extends ShaarliVisitorController | |||
27 | // In case browser does not send HTTP_REFERER, we search a single tag | 29 | // In case browser does not send HTTP_REFERER, we search a single tag |
28 | if (null === $referer) { | 30 | if (null === $referer) { |
29 | if (null !== $newTag) { | 31 | if (null !== $newTag) { |
30 | return $response->withRedirect('./?searchtags='. urlencode($newTag)); | 32 | return $this->redirect($response, '/?searchtags='. urlencode($newTag)); |
31 | } | 33 | } |
32 | 34 | ||
33 | return $response->withRedirect('./'); | 35 | return $this->redirect($response, '/'); |
34 | } | 36 | } |
35 | 37 | ||
36 | $currentUrl = parse_url($referer); | 38 | $currentUrl = parse_url($referer); |
@@ -81,7 +83,7 @@ class TagController extends ShaarliVisitorController | |||
81 | 83 | ||
82 | // If the referrer is not provided, we can update the search, so we failback on the bookmark list | 84 | // If the referrer is not provided, we can update the search, so we failback on the bookmark list |
83 | if (empty($referer)) { | 85 | if (empty($referer)) { |
84 | return $response->withRedirect('./'); | 86 | return $this->redirect($response, '/'); |
85 | } | 87 | } |
86 | 88 | ||
87 | $tagToRemove = $args['tag'] ?? null; | 89 | $tagToRemove = $args['tag'] ?? null; |