'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);
}
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.
*
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 {
}
}
- $queryString = count($params) > 0 ? '?'. http_build_query($params) : '';
+ $queryString = count($params) > 0 ? '?' . http_build_query($params) : '';
$anchor = $anchor ? '#' . $anchor : '';
return $response->withRedirect($path . $queryString . $anchor);