aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front
diff options
context:
space:
mode:
Diffstat (limited to 'application/front')
-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
10 files changed, 38 insertions, 164 deletions
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}