1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020-2021 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Cms\Page; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of cms page section HTML clients. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
22
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** client/html/cms/page/subparts |
25
|
|
|
* List of HTML sub-clients rendered within the cms page section |
26
|
|
|
* |
27
|
|
|
* The output of the frontend is composed of the code generated by the HTML |
28
|
|
|
* clients. Each HTML client can consist of serveral (or none) sub-clients |
29
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
30
|
|
|
* sub-clients can contain HTML clients themselves and therefore a |
31
|
|
|
* hierarchical tree of HTML clients is composed. Each HTML client creates |
32
|
|
|
* the output that is placed inside the container of its parent. |
33
|
|
|
* |
34
|
|
|
* At first, always the HTML code generated by the parent is printed, then |
35
|
|
|
* the HTML code of its sub-clients. The order of the HTML sub-clients |
36
|
|
|
* determines the order of the output of these sub-clients inside the parent |
37
|
|
|
* container. If the configured list of clients is |
38
|
|
|
* |
39
|
|
|
* array( "subclient1", "subclient2" ) |
40
|
|
|
* |
41
|
|
|
* you can easily change the order of the output by reordering the subparts: |
42
|
|
|
* |
43
|
|
|
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
44
|
|
|
* |
45
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
46
|
|
|
* |
47
|
|
|
* client/html/<clients>/subparts = array( "subclient1" ) |
48
|
|
|
* |
49
|
|
|
* As the clients only generates structural HTML, the layout defined via CSS |
50
|
|
|
* should support adding, removing or reordering content by a fluid like |
51
|
|
|
* design. |
52
|
|
|
* |
53
|
|
|
* @param array List of sub-client names |
54
|
|
|
* @since 2021.04 |
55
|
|
|
* @category Developer |
56
|
|
|
*/ |
57
|
|
|
private $subPartPath = 'client/html/cms/page/subparts'; |
58
|
|
|
private $subPartNames = []; |
59
|
|
|
|
60
|
|
|
private $tags = []; |
61
|
|
|
private $expire; |
62
|
|
|
private $view; |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the HTML code for insertion into the body. |
67
|
|
|
* |
68
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
69
|
|
|
* @return string HTML code |
70
|
|
|
*/ |
71
|
|
|
public function getBody( string $uid = '' ) : string |
72
|
|
|
{ |
73
|
|
|
$prefixes = ['path']; |
74
|
|
|
$context = $this->getContext(); |
75
|
|
|
|
76
|
|
|
/** client/html/cms/page/cache |
77
|
|
|
* Enables or disables caching only for the cms page component |
78
|
|
|
* |
79
|
|
|
* Disable caching for components can be useful if you would have too much |
80
|
|
|
* entries to cache or if the component contains non-cacheable parts that |
81
|
|
|
* can't be replaced using the modifyBody() and modifyHeader() methods. |
82
|
|
|
* |
83
|
|
|
* @param boolean True to enable caching, false to disable |
84
|
|
|
* @category Developer |
85
|
|
|
* @category User |
86
|
|
|
* @see client/html/cms/page/cache |
87
|
|
|
* @see client/html/cms/filter/cache |
88
|
|
|
* @see client/html/cms/lists/cache |
89
|
|
|
*/ |
90
|
|
|
|
91
|
|
|
/** client/html/cms/page |
92
|
|
|
* All parameters defined for the cms page component and its subparts |
93
|
|
|
* |
94
|
|
|
* This returns all settings related to the page component. |
95
|
|
|
* Please refer to the single settings for pages. |
96
|
|
|
* |
97
|
|
|
* @param array Associative list of name/value settings |
98
|
|
|
* @category Developer |
99
|
|
|
* @see client/html/cms#page |
100
|
|
|
*/ |
101
|
|
|
$confkey = 'client/html/cms/page'; |
102
|
|
|
|
103
|
|
|
if( ( $html = $this->getCached( 'body', $uid, $prefixes, $confkey ) ) === null ) |
104
|
|
|
{ |
105
|
|
|
$view = $this->getView(); |
106
|
|
|
|
107
|
|
|
/** client/html/cms/page/template-body |
108
|
|
|
* Relative path to the HTML body template of the cms page client. |
109
|
|
|
* |
110
|
|
|
* The template file contains the HTML code and processing instructions |
111
|
|
|
* to generate the result shown in the body of the frontend. The |
112
|
|
|
* configuration string is the path to the template file relative |
113
|
|
|
* to the templates directory (usually in client/html/templates). |
114
|
|
|
* |
115
|
|
|
* You can overwrite the template file configuration in extensions and |
116
|
|
|
* provide alternative templates. These alternative templates should be |
117
|
|
|
* named like the default one but with the string "standard" replaced by |
118
|
|
|
* an unique name. You may use the name of your project for this. If |
119
|
|
|
* you've implemented an alternative client class as well, "standard" |
120
|
|
|
* should be replaced by the name of the new class. |
121
|
|
|
* |
122
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
123
|
|
|
* @since 2021.04 |
124
|
|
|
* @category Developer |
125
|
|
|
* @see client/html/cms/page/template-header |
126
|
|
|
*/ |
127
|
|
|
$tplconf = 'client/html/cms/page/template-body'; |
128
|
|
|
$default = 'cms/page/body-standard'; |
129
|
|
|
|
130
|
|
|
try |
131
|
|
|
{ |
132
|
|
|
$html = ''; |
133
|
|
|
|
134
|
|
|
if( !isset( $this->view ) ) { |
135
|
|
|
$view = $this->view = $this->getObject()->addData( $view, $this->tags, $this->expire ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
139
|
|
|
$html .= $subclient->setView( $view )->getBody( $uid ); |
140
|
|
|
} |
141
|
|
|
$view->pageBody = $html; |
142
|
|
|
|
143
|
|
|
$html = $view->render( $view->config( $tplconf, $default ) ); |
144
|
|
|
$this->setCached( 'body', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
145
|
|
|
|
146
|
|
|
return $html; |
147
|
|
|
} |
148
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
149
|
|
|
{ |
150
|
|
|
$error = array( $context->getI18n()->dt( 'client', $e->getMessage() ) ); |
151
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
152
|
|
|
} |
153
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
154
|
|
|
{ |
155
|
|
|
$error = array( $context->getI18n()->dt( 'controller/frontend', $e->getMessage() ) ); |
156
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
157
|
|
|
} |
158
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
159
|
|
|
{ |
160
|
|
|
$error = array( $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
161
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
162
|
|
|
} |
163
|
|
|
catch( \Exception $e ) |
164
|
|
|
{ |
165
|
|
|
$error = array( $context->getI18n()->dt( 'client', 'A non-recoverable error occured' ) ); |
166
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
167
|
|
|
$this->logException( $e ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
$html = $view->render( $view->config( $tplconf, $default ) ); |
171
|
|
|
} |
172
|
|
|
else |
173
|
|
|
{ |
174
|
|
|
$html = $this->modifyBody( $html, $uid ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $html; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Returns the HTML string for insertion into the header. |
183
|
|
|
* |
184
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
185
|
|
|
* @return string|null String including HTML tags for the header on error |
186
|
|
|
*/ |
187
|
|
|
public function getHeader( string $uid = '' ) : ?string |
188
|
|
|
{ |
189
|
|
|
$prefixes = ['page']; |
190
|
|
|
$confkey = 'client/html/cms/page'; |
191
|
|
|
|
192
|
|
|
if( ( $html = $this->getCached( 'header', $uid, $prefixes, $confkey ) ) === null ) |
193
|
|
|
{ |
194
|
|
|
$view = $this->getView(); |
195
|
|
|
|
196
|
|
|
/** client/html/cms/page/template-header |
197
|
|
|
* Relative path to the HTML header template of the cms page client. |
198
|
|
|
* |
199
|
|
|
* The template file contains the HTML code and processing instructions |
200
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
201
|
|
|
* of the rendered page in the frontend. The configuration string is the |
202
|
|
|
* path to the template file relative to the templates directory (usually |
203
|
|
|
* in client/html/templates). |
204
|
|
|
* |
205
|
|
|
* You can overwrite the template file configuration in extensions and |
206
|
|
|
* provide alternative templates. These alternative templates should be |
207
|
|
|
* named like the default one but with the string "standard" replaced by |
208
|
|
|
* an unique name. You may use the name of your project for this. If |
209
|
|
|
* you've implemented an alternative client class as well, "standard" |
210
|
|
|
* should be replaced by the name of the new class. |
211
|
|
|
* |
212
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
213
|
|
|
* @since 2021.04 |
214
|
|
|
* @category Developer |
215
|
|
|
* @see client/html/cms/page/template-body |
216
|
|
|
*/ |
217
|
|
|
$tplconf = 'client/html/cms/page/template-header'; |
218
|
|
|
$default = 'cms/page/header-standard'; |
219
|
|
|
|
220
|
|
|
try |
221
|
|
|
{ |
222
|
|
|
$html = ''; |
223
|
|
|
|
224
|
|
|
if( !isset( $this->view ) ) { |
225
|
|
|
$view = $this->view = $this->getObject()->addData( $view, $this->tags, $this->expire ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
229
|
|
|
$html .= $subclient->setView( $view )->getHeader( $uid ); |
230
|
|
|
} |
231
|
|
|
$view->pageHeader = $html; |
232
|
|
|
|
233
|
|
|
$html = $view->render( $view->config( $tplconf, $default ) ); |
234
|
|
|
$this->setCached( 'header', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
235
|
|
|
|
236
|
|
|
return $html; |
237
|
|
|
} |
238
|
|
|
catch( \Exception $e ) |
239
|
|
|
{ |
240
|
|
|
$this->logException( $e ); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
else |
244
|
|
|
{ |
245
|
|
|
$html = $this->modifyHeader( $html, $uid ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
return $html; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Returns the sub-client given by its name. |
254
|
|
|
* |
255
|
|
|
* @param string $type Name of the client type |
256
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
257
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
258
|
|
|
*/ |
259
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
260
|
|
|
{ |
261
|
|
|
/** client/html/cms/page/decorators/excludes |
262
|
|
|
* Excludes decorators added by the "common" option from the cms page html client |
263
|
|
|
* |
264
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
265
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
266
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
267
|
|
|
* modify what is returned to the caller. |
268
|
|
|
* |
269
|
|
|
* This option allows you to remove a decorator added via |
270
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
271
|
|
|
* around the html client. |
272
|
|
|
* |
273
|
|
|
* client/html/cms/page/decorators/excludes = array( 'decorator1' ) |
274
|
|
|
* |
275
|
|
|
* This would remove the decorator named "decorator1" from the list of |
276
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
277
|
|
|
* "client/html/common/decorators/default" to the html client. |
278
|
|
|
* |
279
|
|
|
* @param array List of decorator names |
280
|
|
|
* @since 2021.04 |
281
|
|
|
* @category Developer |
282
|
|
|
* @see client/html/common/decorators/default |
283
|
|
|
* @see client/html/cms/page/decorators/global |
284
|
|
|
* @see client/html/cms/page/decorators/local |
285
|
|
|
*/ |
286
|
|
|
|
287
|
|
|
/** client/html/cms/page/decorators/global |
288
|
|
|
* Adds a list of globally available decorators only to the cms page html client |
289
|
|
|
* |
290
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
291
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
292
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
293
|
|
|
* modify what is returned to the caller. |
294
|
|
|
* |
295
|
|
|
* This option allows you to wrap global decorators |
296
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
297
|
|
|
* |
298
|
|
|
* client/html/cms/page/decorators/global = array( 'decorator1' ) |
299
|
|
|
* |
300
|
|
|
* This would add the decorator named "decorator1" defined by |
301
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
302
|
|
|
* |
303
|
|
|
* @param array List of decorator names |
304
|
|
|
* @since 2021.04 |
305
|
|
|
* @category Developer |
306
|
|
|
* @see client/html/common/decorators/default |
307
|
|
|
* @see client/html/cms/page/decorators/excludes |
308
|
|
|
* @see client/html/cms/page/decorators/local |
309
|
|
|
*/ |
310
|
|
|
|
311
|
|
|
/** client/html/cms/page/decorators/local |
312
|
|
|
* Adds a list of local decorators only to the cms page html client |
313
|
|
|
* |
314
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
315
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
316
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
317
|
|
|
* modify what is returned to the caller. |
318
|
|
|
* |
319
|
|
|
* This option allows you to wrap local decorators |
320
|
|
|
* ("\Aimeos\Client\Html\Cms\Decorator\*") around the html client. |
321
|
|
|
* |
322
|
|
|
* client/html/cms/page/decorators/local = array( 'decorator2' ) |
323
|
|
|
* |
324
|
|
|
* This would add the decorator named "decorator2" defined by |
325
|
|
|
* "\Aimeos\Client\Html\Cms\Decorator\Decorator2" only to the html client. |
326
|
|
|
* |
327
|
|
|
* @param array List of decorator names |
328
|
|
|
* @since 2021.04 |
329
|
|
|
* @category Developer |
330
|
|
|
* @see client/html/common/decorators/default |
331
|
|
|
* @see client/html/cms/page/decorators/excludes |
332
|
|
|
* @see client/html/cms/page/decorators/global |
333
|
|
|
*/ |
334
|
|
|
return $this->createSubClient( 'cms/page/' . $type, $name ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Processes the input, e.g. store given values. |
340
|
|
|
* |
341
|
|
|
* A view must be available and this method doesn't generate any output |
342
|
|
|
* besides setting view variables if necessary. |
343
|
|
|
*/ |
344
|
|
|
public function process() |
345
|
|
|
{ |
346
|
|
|
$view = $this->getView(); |
347
|
|
|
$context = $this->getContext(); |
348
|
|
|
|
349
|
|
|
try |
350
|
|
|
{ |
351
|
|
|
parent::process(); |
352
|
|
|
} |
353
|
|
|
catch( \Aimeos\Client\Html\Exception $e ) |
354
|
|
|
{ |
355
|
|
|
$error = array( $context->getI18n()->dt( 'client', $e->getMessage() ) ); |
356
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
357
|
|
|
} |
358
|
|
|
catch( \Aimeos\Controller\Frontend\Exception $e ) |
359
|
|
|
{ |
360
|
|
|
$error = array( $context->getI18n()->dt( 'controller/frontend', $e->getMessage() ) ); |
361
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
362
|
|
|
} |
363
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
364
|
|
|
{ |
365
|
|
|
$error = array( $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
366
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
367
|
|
|
} |
368
|
|
|
catch( \Exception $e ) |
369
|
|
|
{ |
370
|
|
|
$error = array( $context->getI18n()->dt( 'client', 'A non-recoverable error occured' ) ); |
371
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
372
|
|
|
$this->logException( $e ); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Returns the list of sub-client names configured for the client. |
379
|
|
|
* |
380
|
|
|
* @return array List of HTML client names |
381
|
|
|
*/ |
382
|
|
|
protected function getSubClientNames() : array |
383
|
|
|
{ |
384
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Sets the necessary parameter values in the view. |
390
|
|
|
* |
391
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
392
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
393
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
394
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
395
|
|
|
*/ |
396
|
|
|
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
397
|
|
|
{ |
398
|
|
|
$context = $this->getContext(); |
399
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $context, 'cms' ); |
400
|
|
|
|
401
|
|
|
/** client/html/cms/page/domains |
402
|
|
|
* A list of domain names whose items should be available in the cms page view template |
403
|
|
|
* |
404
|
|
|
* The templates rendering the cms page section use the texts and |
405
|
|
|
* maybe images and attributes associated to the categories. You can |
406
|
|
|
* configure your own list of domains (attribute, media, price, product, |
407
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
408
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
409
|
|
|
* the more time is required for fetching the content! |
410
|
|
|
* |
411
|
|
|
* @param array List of domain names |
412
|
|
|
* @since 2021.04 |
413
|
|
|
*/ |
414
|
|
|
$domains = $context->getConfig()->get( 'client/html/cms/page/domains', ['media', 'text'] ); |
415
|
|
|
|
416
|
|
|
$page = $controller->uses( $domains )->find( $view->param( 'path', '/' ) ); |
|
|
|
|
417
|
|
|
|
418
|
|
|
$this->addMetaItems( $page, $expire, $tags ); |
419
|
|
|
|
420
|
|
|
$view->pageCmsItem = $page; |
421
|
|
|
|
422
|
|
|
return parent::addData( $view, $tags, $expire ); |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|