diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/container/ContainerBuilder.php | 4 | ||||
-rw-r--r-- | application/container/ShaarliContainer.php | 9 | ||||
-rw-r--r-- | application/front/controller/admin/PluginsController.php | 1 | ||||
-rw-r--r-- | application/front/controller/visitor/ErrorNotFoundController.php | 29 | ||||
-rw-r--r-- | application/plugin/PluginManager.php | 29 |
5 files changed, 54 insertions, 18 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php index 58067c99..55bb51b5 100644 --- a/application/container/ContainerBuilder.php +++ b/application/container/ContainerBuilder.php | |||
@@ -10,6 +10,7 @@ use Shaarli\Config\ConfigManager; | |||
10 | use Shaarli\Feed\FeedBuilder; | 10 | use Shaarli\Feed\FeedBuilder; |
11 | use Shaarli\Formatter\FormatterFactory; | 11 | use Shaarli\Formatter\FormatterFactory; |
12 | use Shaarli\Front\Controller\Visitor\ErrorController; | 12 | use Shaarli\Front\Controller\Visitor\ErrorController; |
13 | use Shaarli\Front\Controller\Visitor\ErrorNotFoundController; | ||
13 | use Shaarli\History; | 14 | use Shaarli\History; |
14 | use Shaarli\Http\HttpAccess; | 15 | use Shaarli\Http\HttpAccess; |
15 | use Shaarli\Netscape\NetscapeBookmarkUtils; | 16 | use Shaarli\Netscape\NetscapeBookmarkUtils; |
@@ -149,6 +150,9 @@ class ContainerBuilder | |||
149 | ); | 150 | ); |
150 | }; | 151 | }; |
151 | 152 | ||
153 | $container['notFoundHandler'] = function (ShaarliContainer $container): ErrorNotFoundController { | ||
154 | return new ErrorNotFoundController($container); | ||
155 | }; | ||
152 | $container['errorHandler'] = function (ShaarliContainer $container): ErrorController { | 156 | $container['errorHandler'] = function (ShaarliContainer $container): ErrorController { |
153 | return new ErrorController($container); | 157 | return new ErrorController($container); |
154 | }; | 158 | }; |
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php index 9a9a974a..66e669aa 100644 --- a/application/container/ShaarliContainer.php +++ b/application/container/ShaarliContainer.php | |||
@@ -24,21 +24,22 @@ use Slim\Container; | |||
24 | /** | 24 | /** |
25 | * Extension of Slim container to document the injected objects. | 25 | * Extension of Slim container to document the injected objects. |
26 | * | 26 | * |
27 | * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) | 27 | * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) |
28 | * @property BookmarkServiceInterface $bookmarkService | 28 | * @property BookmarkServiceInterface $bookmarkService |
29 | * @property CookieManager $cookieManager | 29 | * @property CookieManager $cookieManager |
30 | * @property ConfigManager $conf | 30 | * @property ConfigManager $conf |
31 | * @property mixed[] $environment $_SERVER automatically injected by Slim | 31 | * @property mixed[] $environment $_SERVER automatically injected by Slim |
32 | * @property callable $errorHandler Overrides default Slim exception display | 32 | * @property callable $errorHandler Overrides default Slim exception display |
33 | * @property FeedBuilder $feedBuilder | 33 | * @property FeedBuilder $feedBuilder |
34 | * @property FormatterFactory $formatterFactory | 34 | * @property FormatterFactory $formatterFactory |
35 | * @property History $history | 35 | * @property History $history |
36 | * @property HttpAccess $httpAccess | 36 | * @property HttpAccess $httpAccess |
37 | * @property LoginManager $loginManager | 37 | * @property LoginManager $loginManager |
38 | * @property NetscapeBookmarkUtils $netscapeBookmarkUtils | 38 | * @property NetscapeBookmarkUtils $netscapeBookmarkUtils |
39 | * @property callable $notFoundHandler Overrides default Slim exception display | ||
39 | * @property PageBuilder $pageBuilder | 40 | * @property PageBuilder $pageBuilder |
40 | * @property PageCacheManager $pageCacheManager | 41 | * @property PageCacheManager $pageCacheManager |
41 | * @property callable $phpErrorHandler Overrides default Slim PHP error display | 42 | * @property callable $phpErrorHandler Overrides default Slim PHP error display |
42 | * @property PluginManager $pluginManager | 43 | * @property PluginManager $pluginManager |
43 | * @property SessionManager $sessionManager | 44 | * @property SessionManager $sessionManager |
44 | * @property Thumbnailer $thumbnailer | 45 | * @property Thumbnailer $thumbnailer |
diff --git a/application/front/controller/admin/PluginsController.php b/application/front/controller/admin/PluginsController.php index 0e09116e..8e059681 100644 --- a/application/front/controller/admin/PluginsController.php +++ b/application/front/controller/admin/PluginsController.php | |||
@@ -62,6 +62,7 @@ class PluginsController extends ShaarliAdminController | |||
62 | 62 | ||
63 | if (isset($parameters['parameters_form'])) { | 63 | if (isset($parameters['parameters_form'])) { |
64 | unset($parameters['parameters_form']); | 64 | unset($parameters['parameters_form']); |
65 | unset($parameters['token']); | ||
65 | foreach ($parameters as $param => $value) { | 66 | foreach ($parameters as $param => $value) { |
66 | $this->container->conf->set('plugins.'. $param, escape($value)); | 67 | $this->container->conf->set('plugins.'. $param, escape($value)); |
67 | } | 68 | } |
diff --git a/application/front/controller/visitor/ErrorNotFoundController.php b/application/front/controller/visitor/ErrorNotFoundController.php new file mode 100644 index 00000000..758dd83b --- /dev/null +++ b/application/front/controller/visitor/ErrorNotFoundController.php | |||
@@ -0,0 +1,29 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
6 | |||
7 | use Slim\Http\Request; | ||
8 | use Slim\Http\Response; | ||
9 | |||
10 | /** | ||
11 | * Controller used to render the 404 error page. | ||
12 | */ | ||
13 | class ErrorNotFoundController extends ShaarliVisitorController | ||
14 | { | ||
15 | public function __invoke(Request $request, Response $response): Response | ||
16 | { | ||
17 | // Request from the API | ||
18 | if (false !== strpos($request->getRequestTarget(), '/api/v1')) { | ||
19 | return $response->withStatus(404); | ||
20 | } | ||
21 | |||
22 | // This is required because the middleware is ignored if the route is not found. | ||
23 | $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/'); | ||
24 | |||
25 | $this->assignView('error_message', t('Requested page could not be found.')); | ||
26 | |||
27 | return $response->withStatus(404)->write($this->render('404')); | ||
28 | } | ||
29 | } | ||
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index 7881e3be..1b2197c9 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php | |||
@@ -100,20 +100,17 @@ class PluginManager | |||
100 | */ | 100 | */ |
101 | public function executeHooks($hook, &$data, $params = array()) | 101 | public function executeHooks($hook, &$data, $params = array()) |
102 | { | 102 | { |
103 | if (!empty($params['target'])) { | 103 | $metadataParameters = [ |
104 | $data['_PAGE_'] = $params['target']; | 104 | 'target' => '_PAGE_', |
105 | } | 105 | 'loggedin' => '_LOGGEDIN_', |
106 | 106 | 'basePath' => '_BASE_PATH_', | |
107 | if (isset($params['loggedin'])) { | 107 | 'bookmarkService' => '_BOOKMARK_SERVICE_', |
108 | $data['_LOGGEDIN_'] = $params['loggedin']; | 108 | ]; |
109 | } | 109 | |
110 | 110 | foreach ($metadataParameters as $parameter => $metaKey) { | |
111 | if (isset($params['basePath'])) { | 111 | if (array_key_exists($parameter, $params)) { |
112 | $data['_BASE_PATH_'] = $params['basePath']; | 112 | $data[$metaKey] = $params[$parameter]; |
113 | } | 113 | } |
114 | |||
115 | if (isset($params['bookmarkService'])) { | ||
116 | $data['_BOOKMARK_SERVICE_'] = $params['bookmarkService']; | ||
117 | } | 114 | } |
118 | 115 | ||
119 | foreach ($this->loadedPlugins as $plugin) { | 116 | foreach ($this->loadedPlugins as $plugin) { |
@@ -128,6 +125,10 @@ class PluginManager | |||
128 | } | 125 | } |
129 | } | 126 | } |
130 | } | 127 | } |
128 | |||
129 | foreach ($metadataParameters as $metaKey) { | ||
130 | unset($data[$metaKey]); | ||
131 | } | ||
131 | } | 132 | } |
132 | 133 | ||
133 | /** | 134 | /** |