aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-06-13 11:22:14 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit818b3193ffabec57501e3bdfa997206e3c0671ef (patch)
treef5a4d3cc23ac367dde617b849561177fc20d767a /application/front
parentc22fa57a5505fe95fd01860e3d3dfbb089f869cd (diff)
downloadShaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.gz
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.zst
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.zip
Explicitly define base and asset path in templates
With the new routes, all pages are not all at the same folder level anymore (e.g. /shaare and /shaare/123), so we can't just use './' everywhere. The most consistent way to handle this is to prefix all path with the proper variable, and handle the actual path in controllers.
Diffstat (limited to 'application/front')
-rw-r--r--application/front/ShaarliMiddleware.php2
-rw-r--r--application/front/controller/visitor/ShaarliVisitorController.php15
2 files changed, 16 insertions, 1 deletions
diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php
index f8992e0b..47aa61bb 100644
--- a/application/front/ShaarliMiddleware.php
+++ b/application/front/ShaarliMiddleware.php
@@ -39,6 +39,8 @@ class ShaarliMiddleware
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 try {
42 $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
43
42 $response = $next($request, $response); 44 $response = $next($request, $response);
43 } catch (ShaarliFrontException $e) { 45 } catch (ShaarliFrontException $e) {
44 $this->container->pageBuilder->assign('message', $e->getMessage()); 46 $this->container->pageBuilder->assign('message', $e->getMessage());
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php
index 98423d90..b90b1e8f 100644
--- a/application/front/controller/visitor/ShaarliVisitorController.php
+++ b/application/front/controller/visitor/ShaarliVisitorController.php
@@ -60,6 +60,19 @@ abstract class ShaarliVisitorController
60 $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE)); 60 $this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE));
61 $this->assignView('plugin_errors', $this->container->pluginManager->getErrors()); 61 $this->assignView('plugin_errors', $this->container->pluginManager->getErrors());
62 62
63 /*
64 * Define base path (if Shaarli is installed in a domain's subfolder, e.g. `/shaarli`)
65 * and the asset path (subfolder/tpl/default for default theme).
66 * These MUST be used to create an internal link or to include an asset in templates.
67 */
68 $this->assignView('base_path', $this->container->basePath);
69 $this->assignView(
70 'asset_path',
71 $this->container->basePath . '/' .
72 rtrim($this->container->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
73 $this->container->conf->get('resource.theme', 'default')
74 );
75
63 $this->executeDefaultHooks($template); 76 $this->executeDefaultHooks($template);
64 77
65 return $this->container->pageBuilder->render($template); 78 return $this->container->pageBuilder->render($template);
@@ -105,7 +118,7 @@ abstract class ShaarliVisitorController
105 array $clearParams = [], 118 array $clearParams = [],
106 string $anchor = null 119 string $anchor = null
107 ): Response { 120 ): Response {
108 $defaultPath = rtrim($request->getUri()->getBasePath(), '/') . '/'; 121 $defaultPath = $this->container->basePath . '/';
109 $referer = $this->container->environment['HTTP_REFERER'] ?? null; 122 $referer = $this->container->environment['HTTP_REFERER'] ?? null;
110 123
111 if (null !== $referer) { 124 if (null !== $referer) {