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