]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/front/controller/visitor/ShaarliVisitorController.php
New basePath: fix officiel plugin paths and vintage template
[github/shaarli/Shaarli.git] / application / front / controller / visitor / ShaarliVisitorController.php
index 98423d9000cfdca2958fcd685173974701074a49..47057d97664920a08e25af6590491a3f2cbaa7a3 100644 (file)
@@ -62,7 +62,7 @@ abstract class ShaarliVisitorController
 
         $this->executeDefaultHooks($template);
 
-        return $this->container->pageBuilder->render($template);
+        return $this->container->pageBuilder->render($template, $this->container->basePath);
     }
 
     /**
@@ -84,13 +84,42 @@ abstract class ShaarliVisitorController
                 $pluginData,
                 [
                     'target' => $template,
-                    'loggedin' => $this->container->loginManager->isLoggedIn()
+                    'loggedin' => $this->container->loginManager->isLoggedIn(),
+                    'basePath' => $this->container->basePath,
                 ]
             );
             $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
+        );
+    }
+
+    /**
+     * 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.
@@ -105,7 +134,7 @@ abstract class ShaarliVisitorController
         array $clearParams = [],
         string $anchor = null
     ): Response {
-        $defaultPath = rtrim($request->getUri()->getBasePath(), '/') . '/';
+        $defaultPath = $this->container->basePath . '/';
         $referer = $this->container->environment['HTTP_REFERER'] ?? null;
 
         if (null !== $referer) {