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