X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Ffront%2Fcontroller%2Fvisitor%2FShaarliVisitorController.php;h=54f9fe03fc5bd4c506b04c7cfaae02b8afea0ee5;hb=3adbdc2a83e6b77a4ca62094c5d857524e39d211;hp=f17c8ed37936550304cfdfbe59735e98e677c4e4;hpb=06f05c923ae59e5daa1aaa8d1ad4c50bd9064bb2;p=github%2Fshaarli%2FShaarli.git diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index f17c8ed3..54f9fe03 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -78,16 +78,14 @@ abstract class ShaarliVisitorController 'footer', ]; + $parameters = $this->buildPluginParameters($template); + foreach ($common_hooks as $name) { $pluginData = []; $this->container->pluginManager->executeHooks( 'render_' . $name, $pluginData, - [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ] + $parameters ); $this->assignView('plugins_' . $name, $pluginData); } @@ -95,19 +93,24 @@ abstract class ShaarliVisitorController protected function executePageHooks(string $hook, array &$data, string $template = null): void { - $params = [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ]; - $this->container->pluginManager->executeHooks( $hook, $data, - $params + $this->buildPluginParameters($template) ); } + protected function buildPluginParameters(?string $template): array + { + return [ + 'target' => $template, + 'loggedin' => $this->container->loginManager->isLoggedIn(), + 'basePath' => $this->container->basePath, + 'rootPath' => preg_replace('#/index\.php$#', '', $this->container->basePath), + 'bookmarkService' => $this->container->bookmarkService + ]; + } + /** * Simple helper which prepend the base path to redirect path. * @@ -140,6 +143,13 @@ abstract class ShaarliVisitorController if (null !== $referer) { $currentUrl = parse_url($referer); + // If the referer is not related to Shaarli instance, redirect to default + if (isset($currentUrl['host']) + && strpos(index_url($this->container->environment), $currentUrl['host']) === false + ) { + return $response->withRedirect($defaultPath); + } + parse_str($currentUrl['query'] ?? '', $params); $path = $currentUrl['path'] ?? $defaultPath; } else {