aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-07-26 14:43:10 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-26 14:43:10 +0200
commit9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9 (patch)
tree9bfc3c9b185eb0c185d23146d44d42dd6685a4da /application
parentbc583903adfd768f115fae438e4d9ed1043682d9 (diff)
downloadShaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.tar.gz
Shaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.tar.zst
Shaarli-9fbc42294e7667c5ef19cafa0d1fcfbc1c0f36a9.zip
New basePath: fix officiel plugin paths and vintage template
Diffstat (limited to 'application')
-rw-r--r--application/config/ConfigPlugin.php17
-rw-r--r--application/front/ShaarliMiddleware.php4
-rw-r--r--application/front/controller/admin/ManageShaareController.php25
-rw-r--r--application/front/controller/admin/PluginsController.php17
-rw-r--r--application/front/controller/admin/ToolsController.php17
-rw-r--r--application/front/controller/visitor/BookmarkListController.php16
-rw-r--r--application/front/controller/visitor/DailyController.php22
-rw-r--r--application/front/controller/visitor/FeedController.php21
-rw-r--r--application/front/controller/visitor/PictureWallController.php23
-rw-r--r--application/front/controller/visitor/ShaarliVisitorController.php33
-rw-r--r--application/front/controller/visitor/TagCloudController.php24
-rw-r--r--application/plugin/PluginManager.php4
-rw-r--r--application/render/PageBuilder.php32
13 files changed, 70 insertions, 185 deletions
diff --git a/application/config/ConfigPlugin.php b/application/config/ConfigPlugin.php
index dbb24937..ea8dfbda 100644
--- a/application/config/ConfigPlugin.php
+++ b/application/config/ConfigPlugin.php
@@ -1,6 +1,7 @@
1<?php 1<?php
2 2
3use Shaarli\Config\Exception\PluginConfigOrderException; 3use Shaarli\Config\Exception\PluginConfigOrderException;
4use Shaarli\Plugin\PluginManager;
4 5
5/** 6/**
6 * Plugin configuration helper functions. 7 * Plugin configuration helper functions.
@@ -19,6 +20,20 @@ use Shaarli\Config\Exception\PluginConfigOrderException;
19 */ 20 */
20function save_plugin_config($formData) 21function save_plugin_config($formData)
21{ 22{
23 // We can only save existing plugins
24 $directories = str_replace(
25 PluginManager::$PLUGINS_PATH . '/',
26 '',
27 glob(PluginManager::$PLUGINS_PATH . '/*')
28 );
29 $formData = array_filter(
30 $formData,
31 function ($value, string $key) use ($directories) {
32 return startsWith($key, 'order') || in_array($key, $directories);
33 },
34 ARRAY_FILTER_USE_BOTH
35 );
36
22 // Make sure there are no duplicates in orders. 37 // Make sure there are no duplicates in orders.
23 if (!validate_plugin_order($formData)) { 38 if (!validate_plugin_order($formData)) {
24 throw new PluginConfigOrderException(); 39 throw new PluginConfigOrderException();
@@ -69,7 +84,7 @@ function validate_plugin_order($formData)
69 $orders = array(); 84 $orders = array();
70 foreach ($formData as $key => $value) { 85 foreach ($formData as $key => $value) {
71 // No duplicate order allowed. 86 // No duplicate order allowed.
72 if (in_array($value, $orders)) { 87 if (in_array($value, $orders, true)) {
73 return false; 88 return false;
74 } 89 }
75 90
diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php
index fd978e99..92c0e911 100644
--- a/application/front/ShaarliMiddleware.php
+++ b/application/front/ShaarliMiddleware.php
@@ -60,7 +60,7 @@ class ShaarliMiddleware
60 60
61 $response = $response->withStatus($e->getCode()); 61 $response = $response->withStatus($e->getCode());
62 62
63 return $response->write($this->container->pageBuilder->render('error')); 63 return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
64 } catch (UnauthorizedException $e) { 64 } catch (UnauthorizedException $e) {
65 $returnUrl = urlencode($this->container->environment['REQUEST_URI']); 65 $returnUrl = urlencode($this->container->environment['REQUEST_URI']);
66 66
@@ -80,7 +80,7 @@ class ShaarliMiddleware
80 80
81 $response = $response->withStatus(500); 81 $response = $response->withStatus(500);
82 82
83 return $response->write($this->container->pageBuilder->render('error')); 83 return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
84 } 84 }
85 } 85 }
86 86
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php
index 3aa48423..33e1188e 100644
--- a/application/front/controller/admin/ManageShaareController.php
+++ b/application/front/controller/admin/ManageShaareController.php
@@ -152,7 +152,7 @@ class ManageShaareController extends ShaarliAdminController
152 // To preserve backward compatibility with 3rd parties, plugins still use arrays 152 // To preserve backward compatibility with 3rd parties, plugins still use arrays
153 $formatter = $this->container->formatterFactory->getFormatter('raw'); 153 $formatter = $this->container->formatterFactory->getFormatter('raw');
154 $data = $formatter->format($bookmark); 154 $data = $formatter->format($bookmark);
155 $data = $this->executeHooks('save_link', $data); 155 $this->executePageHooks('save_link', $data);
156 156
157 $bookmark->fromArray($data); 157 $bookmark->fromArray($data);
158 $this->container->bookmarkService->set($bookmark); 158 $this->container->bookmarkService->set($bookmark);
@@ -211,7 +211,7 @@ class ManageShaareController extends ShaarliAdminController
211 } 211 }
212 212
213 $data = $formatter->format($bookmark); 213 $data = $formatter->format($bookmark);
214 $this->container->pluginManager->executeHooks('delete_link', $data); 214 $this->executePageHooks('delete_link', $data);
215 $this->container->bookmarkService->remove($bookmark, false); 215 $this->container->bookmarkService->remove($bookmark, false);
216 ++ $count; 216 ++ $count;
217 } 217 }
@@ -283,7 +283,7 @@ class ManageShaareController extends ShaarliAdminController
283 283
284 // To preserve backward compatibility with 3rd parties, plugins still use arrays 284 // To preserve backward compatibility with 3rd parties, plugins still use arrays
285 $data = $formatter->format($bookmark); 285 $data = $formatter->format($bookmark);
286 $this->container->pluginManager->executeHooks('save_link', $data); 286 $this->executePageHooks('save_link', $data);
287 $bookmark->fromArray($data); 287 $bookmark->fromArray($data);
288 288
289 $this->container->bookmarkService->set($bookmark, false); 289 $this->container->bookmarkService->set($bookmark, false);
@@ -325,7 +325,7 @@ class ManageShaareController extends ShaarliAdminController
325 325
326 // To preserve backward compatibility with 3rd parties, plugins still use arrays 326 // To preserve backward compatibility with 3rd parties, plugins still use arrays
327 $data = $formatter->format($bookmark); 327 $data = $formatter->format($bookmark);
328 $this->container->pluginManager->executeHooks('save_link', $data); 328 $this->executePageHooks('save_link', $data);
329 $bookmark->fromArray($data); 329 $bookmark->fromArray($data);
330 330
331 $this->container->bookmarkService->set($bookmark); 331 $this->container->bookmarkService->set($bookmark);
@@ -354,7 +354,7 @@ class ManageShaareController extends ShaarliAdminController
354 'default_private_links' => $this->container->conf->get('privacy.default_private_links', false), 354 'default_private_links' => $this->container->conf->get('privacy.default_private_links', false),
355 ]; 355 ];
356 356
357 $data = $this->executeHooks('render_editlink', $data); 357 $this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
358 358
359 foreach ($data as $key => $value) { 359 foreach ($data as $key => $value) {
360 $this->assignView($key, $value); 360 $this->assignView($key, $value);
@@ -368,19 +368,4 @@ class ManageShaareController extends ShaarliAdminController
368 368
369 return $response->write($this->render(TemplatePage::EDIT_LINK)); 369 return $response->write($this->render(TemplatePage::EDIT_LINK));
370 } 370 }
371
372 /**
373 * @param mixed[] $data Variables passed to the template engine
374 *
375 * @return mixed[] Template data after active plugins render_picwall hook execution.
376 */
377 protected function executeHooks(string $hook, array $data): array
378 {
379 $this->container->pluginManager->executeHooks(
380 $hook,
381 $data
382 );
383
384 return $data;
385 }
386} 371}
diff --git a/application/front/controller/admin/PluginsController.php b/application/front/controller/admin/PluginsController.php
index 1eb7e635..0e09116e 100644
--- a/application/front/controller/admin/PluginsController.php
+++ b/application/front/controller/admin/PluginsController.php
@@ -58,7 +58,7 @@ class PluginsController extends ShaarliAdminController
58 try { 58 try {
59 $parameters = $request->getParams() ?? []; 59 $parameters = $request->getParams() ?? [];
60 60
61 $this->executeHooks($parameters); 61 $this->executePageHooks('save_plugin_parameters', $parameters);
62 62
63 if (isset($parameters['parameters_form'])) { 63 if (isset($parameters['parameters_form'])) {
64 unset($parameters['parameters_form']); 64 unset($parameters['parameters_form']);
@@ -81,19 +81,4 @@ class PluginsController extends ShaarliAdminController
81 81
82 return $this->redirect($response, '/admin/plugins'); 82 return $this->redirect($response, '/admin/plugins');
83 } 83 }
84
85 /**
86 * @param mixed[] $data Variables passed to the template engine
87 *
88 * @return mixed[] Template data after active plugins render_picwall hook execution.
89 */
90 protected function executeHooks(array $data): array
91 {
92 $this->container->pluginManager->executeHooks(
93 'save_plugin_parameters',
94 $data
95 );
96
97 return $data;
98 }
99} 84}
diff --git a/application/front/controller/admin/ToolsController.php b/application/front/controller/admin/ToolsController.php
index a476e898..a87f20d2 100644
--- a/application/front/controller/admin/ToolsController.php
+++ b/application/front/controller/admin/ToolsController.php
@@ -22,7 +22,7 @@ class ToolsController extends ShaarliAdminController
22 'sslenabled' => is_https($this->container->environment), 22 'sslenabled' => is_https($this->container->environment),
23 ]; 23 ];
24 24
25 $data = $this->executeHooks($data); 25 $this->executePageHooks('render_tools', $data, TemplatePage::TOOLS);
26 26
27 foreach ($data as $key => $value) { 27 foreach ($data as $key => $value) {
28 $this->assignView($key, $value); 28 $this->assignView($key, $value);
@@ -32,19 +32,4 @@ class ToolsController extends ShaarliAdminController
32 32
33 return $response->write($this->render(TemplatePage::TOOLS)); 33 return $response->write($this->render(TemplatePage::TOOLS));
34 } 34 }
35
36 /**
37 * @param mixed[] $data Variables passed to the template engine
38 *
39 * @return mixed[] Template data after active plugins render_picwall hook execution.
40 */
41 protected function executeHooks(array $data): array
42 {
43 $this->container->pluginManager->executeHooks(
44 'render_tools',
45 $data
46 );
47
48 return $data;
49 }
50} 35}
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php
index a37a7f6b..23c4fbae 100644
--- a/application/front/controller/visitor/BookmarkListController.php
+++ b/application/front/controller/visitor/BookmarkListController.php
@@ -124,7 +124,7 @@ class BookmarkListController extends ShaarliVisitorController
124 124
125 $data['pagetitle'] = ($data['pagetitle'] ?? '') . $this->container->conf->get('general.title', 'Shaarli'); 125 $data['pagetitle'] = ($data['pagetitle'] ?? '') . $this->container->conf->get('general.title', 'Shaarli');
126 126
127 $this->executeHooks($data); 127 $this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
128 $this->assignAllView($data); 128 $this->assignAllView($data);
129 129
130 return $response->write($this->render(TemplatePage::LINKLIST)); 130 return $response->write($this->render(TemplatePage::LINKLIST));
@@ -153,7 +153,7 @@ class BookmarkListController extends ShaarliVisitorController
153 ] 153 ]
154 ); 154 );
155 155
156 $this->executeHooks($data); 156 $this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
157 $this->assignAllView($data); 157 $this->assignAllView($data);
158 158
159 return $response->write($this->render(TemplatePage::LINKLIST)); 159 return $response->write($this->render(TemplatePage::LINKLIST));
@@ -183,18 +183,6 @@ class BookmarkListController extends ShaarliVisitorController
183 } 183 }
184 184
185 /** 185 /**
186 * @param mixed[] $data Template vars to process in plugins, passed as reference.
187 */
188 protected function executeHooks(array &$data): void
189 {
190 $this->container->pluginManager->executeHooks(
191 'render_linklist',
192 $data,
193 ['loggedin' => $this->container->loginManager->isLoggedIn()]
194 );
195 }
196
197 /**
198 * @return string[] Default template variables without values. 186 * @return string[] Default template variables without values.
199 */ 187 */
200 protected function initializeTemplateVars(): array 188 protected function initializeTemplateVars(): array
diff --git a/application/front/controller/visitor/DailyController.php b/application/front/controller/visitor/DailyController.php
index 05b4f095..808ca5f7 100644
--- a/application/front/controller/visitor/DailyController.php
+++ b/application/front/controller/visitor/DailyController.php
@@ -72,13 +72,11 @@ class DailyController extends ShaarliVisitorController
72 ]; 72 ];
73 73
74 // Hooks are called before column construction so that plugins don't have to deal with columns. 74 // Hooks are called before column construction so that plugins don't have to deal with columns.
75 $data = $this->executeHooks($data); 75 $this->executePageHooks('render_daily', $data, TemplatePage::DAILY);
76 76
77 $data['cols'] = $this->calculateColumns($data['linksToDisplay']); 77 $data['cols'] = $this->calculateColumns($data['linksToDisplay']);
78 78
79 foreach ($data as $key => $value) { 79 $this->assignAllView($data);
80 $this->assignView($key, $value);
81 }
82 80
83 $mainTitle = $this->container->conf->get('general.title', 'Shaarli'); 81 $mainTitle = $this->container->conf->get('general.title', 'Shaarli');
84 $this->assignView( 82 $this->assignView(
@@ -190,20 +188,4 @@ class DailyController extends ShaarliVisitorController
190 188
191 return $columns; 189 return $columns;
192 } 190 }
193
194 /**
195 * @param mixed[] $data Variables passed to the template engine
196 *
197 * @return mixed[] Template data after active plugins render_picwall hook execution.
198 */
199 protected function executeHooks(array $data): array
200 {
201 $this->container->pluginManager->executeHooks(
202 'render_daily',
203 $data,
204 ['loggedin' => $this->container->loginManager->isLoggedIn()]
205 );
206
207 return $data;
208 }
209} 191}
diff --git a/application/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php
index f76f55fd..da2848c2 100644
--- a/application/front/controller/visitor/FeedController.php
+++ b/application/front/controller/visitor/FeedController.php
@@ -46,7 +46,7 @@ class FeedController extends ShaarliVisitorController
46 46
47 $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); 47 $data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
48 48
49 $data = $this->executeHooks($data, $feedType); 49 $this->executePageHooks('render_feed', $data, $feedType);
50 $this->assignAllView($data); 50 $this->assignAllView($data);
51 51
52 $content = $this->render('feed.'. $feedType); 52 $content = $this->render('feed.'. $feedType);
@@ -55,23 +55,4 @@ class FeedController extends ShaarliVisitorController
55 55
56 return $response->write($content); 56 return $response->write($content);
57 } 57 }
58
59 /**
60 * @param mixed[] $data Template data
61 *
62 * @return mixed[] Template data after active plugins hook execution.
63 */
64 protected function executeHooks(array $data, string $feedType): array
65 {
66 $this->container->pluginManager->executeHooks(
67 'render_feed',
68 $data,
69 [
70 'loggedin' => $this->container->loginManager->isLoggedIn(),
71 'target' => $feedType,
72 ]
73 );
74
75 return $data;
76 }
77} 58}
diff --git a/application/front/controller/visitor/PictureWallController.php b/application/front/controller/visitor/PictureWallController.php
index 5ef2cb17..3c57f8dd 100644
--- a/application/front/controller/visitor/PictureWallController.php
+++ b/application/front/controller/visitor/PictureWallController.php
@@ -42,30 +42,13 @@ class PictureWallController extends ShaarliVisitorController
42 } 42 }
43 } 43 }
44 44
45 $data = $this->executeHooks($linksToDisplay); 45 $data = ['linksToDisplay' => $linksToDisplay];
46 $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
47
46 foreach ($data as $key => $value) { 48 foreach ($data as $key => $value) {
47 $this->assignView($key, $value); 49 $this->assignView($key, $value);
48 } 50 }
49 51
50 return $response->write($this->render(TemplatePage::PICTURE_WALL)); 52 return $response->write($this->render(TemplatePage::PICTURE_WALL));
51 } 53 }
52
53 /**
54 * @param mixed[] $linksToDisplay List of formatted bookmarks
55 *
56 * @return mixed[] Template data after active plugins render_picwall hook execution.
57 */
58 protected function executeHooks(array $linksToDisplay): array
59 {
60 $data = [
61 'linksToDisplay' => $linksToDisplay,
62 ];
63 $this->container->pluginManager->executeHooks(
64 'render_picwall',
65 $data,
66 ['loggedin' => $this->container->loginManager->isLoggedIn()]
67 );
68
69 return $data;
70 }
71} 54}
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php
index b494a8e6..47057d97 100644
--- a/application/front/controller/visitor/ShaarliVisitorController.php
+++ b/application/front/controller/visitor/ShaarliVisitorController.php
@@ -60,22 +60,9 @@ 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
76 $this->executeDefaultHooks($template); 63 $this->executeDefaultHooks($template);
77 64
78 return $this->container->pageBuilder->render($template); 65 return $this->container->pageBuilder->render($template, $this->container->basePath);
79 } 66 }
80 67
81 /** 68 /**
@@ -97,13 +84,29 @@ abstract class ShaarliVisitorController
97 $pluginData, 84 $pluginData,
98 [ 85 [
99 'target' => $template, 86 'target' => $template,
100 'loggedin' => $this->container->loginManager->isLoggedIn() 87 'loggedin' => $this->container->loginManager->isLoggedIn(),
88 'basePath' => $this->container->basePath,
101 ] 89 ]
102 ); 90 );
103 $this->assignView('plugins_' . $name, $pluginData); 91 $this->assignView('plugins_' . $name, $pluginData);
104 } 92 }
105 } 93 }
106 94
95 protected function executePageHooks(string $hook, array &$data, string $template = null): void
96 {
97 $params = [
98 'target' => $template,
99 'loggedin' => $this->container->loginManager->isLoggedIn(),
100 'basePath' => $this->container->basePath,
101 ];
102
103 $this->container->pluginManager->executeHooks(
104 $hook,
105 $data,
106 $params
107 );
108 }
109
107 /** 110 /**
108 * Simple helper which prepend the base path to redirect path. 111 * Simple helper which prepend the base path to redirect path.
109 * 112 *
diff --git a/application/front/controller/visitor/TagCloudController.php b/application/front/controller/visitor/TagCloudController.php
index 15b6d7b7..f9c529bc 100644
--- a/application/front/controller/visitor/TagCloudController.php
+++ b/application/front/controller/visitor/TagCloudController.php
@@ -71,10 +71,8 @@ class TagCloudController extends ShaarliVisitorController
71 'search_tags' => $searchTags, 71 'search_tags' => $searchTags,
72 'tags' => $tags, 72 'tags' => $tags,
73 ]; 73 ];
74 $data = $this->executeHooks('tag' . $type, $data); 74 $this->executePageHooks('render_tag' . $type, $data, 'tag.' . $type);
75 foreach ($data as $key => $value) { 75 $this->assignAllView($data);
76 $this->assignView($key, $value);
77 }
78 76
79 $searchTags = !empty($searchTags) ? $searchTags .' - ' : ''; 77 $searchTags = !empty($searchTags) ? $searchTags .' - ' : '';
80 $this->assignView( 78 $this->assignView(
@@ -82,7 +80,7 @@ class TagCloudController extends ShaarliVisitorController
82 $searchTags . t('Tag '. $type) .' - '. $this->container->conf->get('general.title', 'Shaarli') 80 $searchTags . t('Tag '. $type) .' - '. $this->container->conf->get('general.title', 'Shaarli')
83 ); 81 );
84 82
85 return $response->write($this->render('tag.'. $type)); 83 return $response->write($this->render('tag.' . $type));
86 } 84 }
87 85
88 /** 86 /**
@@ -112,20 +110,4 @@ class TagCloudController extends ShaarliVisitorController
112 110
113 return $tagList; 111 return $tagList;
114 } 112 }
115
116 /**
117 * @param mixed[] $data Template data
118 *
119 * @return mixed[] Template data after active plugins hook execution.
120 */
121 protected function executeHooks(string $template, array $data): array
122 {
123 $this->container->pluginManager->executeHooks(
124 'render_'. $template,
125 $data,
126 ['loggedin' => $this->container->loginManager->isLoggedIn()]
127 );
128
129 return $data;
130 }
131} 113}
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php
index 591a9180..b3e8b2f8 100644
--- a/application/plugin/PluginManager.php
+++ b/application/plugin/PluginManager.php
@@ -108,6 +108,10 @@ class PluginManager
108 $data['_LOGGEDIN_'] = $params['loggedin']; 108 $data['_LOGGEDIN_'] = $params['loggedin'];
109 } 109 }
110 110
111 if (isset($params['basePath'])) {
112 $data['_BASE_PATH_'] = $params['basePath'];
113 }
114
111 foreach ($this->loadedPlugins as $plugin) { 115 foreach ($this->loadedPlugins as $plugin) {
112 $hookFunction = $this->buildHookName($hook, $plugin); 116 $hookFunction = $this->buildHookName($hook, $plugin);
113 117
diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php
index 471724c0..7a716673 100644
--- a/application/render/PageBuilder.php
+++ b/application/render/PageBuilder.php
@@ -3,6 +3,7 @@
3namespace Shaarli\Render; 3namespace Shaarli\Render;
4 4
5use Exception; 5use Exception;
6use exceptions\MissingBasePathException;
6use RainTPL; 7use RainTPL;
7use Shaarli\ApplicationUtils; 8use Shaarli\ApplicationUtils;
8use Shaarli\Bookmark\BookmarkServiceInterface; 9use Shaarli\Bookmark\BookmarkServiceInterface;
@@ -156,7 +157,7 @@ class PageBuilder
156 * Affect variable after controller processing. 157 * Affect variable after controller processing.
157 * Used for alert messages. 158 * Used for alert messages.
158 */ 159 */
159 protected function finalize(): void 160 protected function finalize(string $basePath): void
160 { 161 {
161 // TODO: use the SessionManager 162 // TODO: use the SessionManager
162 $messageKeys = [ 163 $messageKeys = [
@@ -170,6 +171,14 @@ class PageBuilder
170 unset($_SESSION[$messageKey]); 171 unset($_SESSION[$messageKey]);
171 } 172 }
172 } 173 }
174
175 $this->assign('base_path', $basePath);
176 $this->assign(
177 'asset_path',
178 $basePath . '/' .
179 rtrim($this->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
180 $this->conf->get('resource.theme', 'default')
181 );
173 } 182 }
174 183
175 /** 184 /**
@@ -210,23 +219,6 @@ class PageBuilder
210 } 219 }
211 220
212 /** 221 /**
213 * Render a specific page (using a template file).
214 * e.g. $pb->renderPage('picwall');
215 *
216 * @param string $page Template filename (without extension).
217 */
218 public function renderPage($page)
219 {
220 if ($this->tpl === false) {
221 $this->initialize();
222 }
223
224 $this->finalize();
225
226 $this->tpl->draw($page);
227 }
228
229 /**
230 * Render a specific page as string (using a template file). 222 * Render a specific page as string (using a template file).
231 * e.g. $pb->render('picwall'); 223 * e.g. $pb->render('picwall');
232 * 224 *
@@ -234,13 +226,13 @@ class PageBuilder
234 * 226 *
235 * @return string Processed template content 227 * @return string Processed template content
236 */ 228 */
237 public function render(string $page): string 229 public function render(string $page, string $basePath): string
238 { 230 {
239 if ($this->tpl === false) { 231 if ($this->tpl === false) {
240 $this->initialize(); 232 $this->initialize();
241 } 233 }
242 234
243 $this->finalize(); 235 $this->finalize($basePath);
244 236
245 return $this->tpl->draw($page, true); 237 return $this->tpl->draw($page, true);
246 } 238 }