1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Template; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Config; |
6
|
|
|
use Redaxscript\Console; |
7
|
|
|
use Redaxscript\Filesystem; |
8
|
|
|
use Redaxscript\Head; |
9
|
|
|
use Redaxscript\Language; |
10
|
|
|
use Redaxscript\Model; |
11
|
|
|
use Redaxscript\Navigation; |
12
|
|
|
use Redaxscript\Registry; |
13
|
|
|
use Redaxscript\Request; |
14
|
|
|
use Redaxscript\Router; |
15
|
|
|
use Redaxscript\View; |
16
|
|
|
use function ceil; |
17
|
|
|
use function htmlentities; |
18
|
|
|
use function strlen; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* parent class to provide template tags |
22
|
|
|
* |
23
|
|
|
* @since 3.0.0 |
24
|
|
|
* |
25
|
|
|
* @package Redaxscript |
26
|
|
|
* @category Template |
27
|
|
|
* @author Henry Ruhs |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
class Tag |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* base |
34
|
|
|
* |
35
|
|
|
* @since 3.0.0 |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
|
40
|
1 |
|
public static function base() : string |
41
|
|
|
{ |
42
|
1 |
|
$base = new Head\Base(Registry::getInstance()); |
43
|
1 |
|
return $base->render(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* title |
48
|
|
|
* |
49
|
|
|
* @since 3.0.0 |
50
|
|
|
* |
51
|
|
|
* @param string $text |
52
|
|
|
* |
53
|
|
|
* @return string|null |
54
|
|
|
*/ |
55
|
|
|
|
56
|
1 |
|
public static function title(string $text = null) : ?string |
57
|
|
|
{ |
58
|
1 |
|
$title = new Head\Title(); |
59
|
1 |
|
return $title->render($text); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* link |
64
|
|
|
* |
65
|
|
|
* @since 3.0.0 |
66
|
|
|
* |
67
|
|
|
* @return Head\Link |
68
|
|
|
*/ |
69
|
|
|
|
70
|
1 |
|
public static function link() : Head\Link |
71
|
|
|
{ |
72
|
1 |
|
return Head\Link::getInstance(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* meta |
77
|
|
|
* |
78
|
|
|
* @since 3.0.0 |
79
|
|
|
* |
80
|
|
|
* @return Head\Meta |
81
|
|
|
*/ |
82
|
|
|
|
83
|
1 |
|
public static function meta() : Head\Meta |
84
|
|
|
{ |
85
|
1 |
|
return Head\Meta::getInstance(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* script |
90
|
|
|
* |
91
|
|
|
* @since 3.0.0 |
92
|
|
|
* |
93
|
|
|
* @return Head\Script |
94
|
|
|
*/ |
95
|
|
|
|
96
|
1 |
|
public static function script() : Head\Script |
97
|
|
|
{ |
98
|
1 |
|
return Head\Script::getInstance(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* style |
103
|
|
|
* |
104
|
|
|
* @since 3.0.0 |
105
|
|
|
* |
106
|
|
|
* @return Head\Style |
107
|
|
|
*/ |
108
|
|
|
|
109
|
1 |
|
public static function style() : Head\Style |
110
|
|
|
{ |
111
|
1 |
|
return Head\Style::getInstance(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* breadcrumb |
116
|
|
|
* |
117
|
|
|
* @since 2.3.0 |
118
|
|
|
* |
119
|
|
|
* @param array $optionArray options of the breadcrumb |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
|
124
|
1 |
|
public static function breadcrumb(array $optionArray = []) : string |
125
|
|
|
{ |
126
|
1 |
|
$breadcrumb = new View\Helper\Breadcrumb(Registry::getInstance(), Language::getInstance()); |
127
|
1 |
|
return $breadcrumb->init($optionArray)->render(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* partial |
132
|
|
|
* |
133
|
|
|
* @since 3.2.0 |
134
|
|
|
* |
135
|
|
|
* @param string|array $partial |
136
|
|
|
* |
137
|
|
|
* @return string|null |
138
|
|
|
*/ |
139
|
|
|
|
140
|
1 |
|
public static function partial($partial = null) : ?string |
141
|
|
|
{ |
142
|
1 |
|
$output = null; |
143
|
|
|
|
144
|
|
|
/* template filesystem */ |
145
|
|
|
|
146
|
1 |
|
$templateFilesystem = new Filesystem\File(); |
147
|
1 |
|
$templateFilesystem->init('templates'); |
148
|
|
|
|
149
|
|
|
/* process partial */ |
150
|
|
|
|
151
|
1 |
|
foreach ((array)$partial as $file) |
152
|
|
|
{ |
153
|
1 |
|
$output .= $templateFilesystem->renderFile($file); |
154
|
|
|
} |
155
|
1 |
|
return $output; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* content |
160
|
|
|
* |
161
|
|
|
* @since 4.0.0 |
162
|
|
|
* |
163
|
|
|
* @return string|null |
164
|
|
|
*/ |
165
|
|
|
|
166
|
|
|
public static function content() : ?string |
167
|
|
|
{ |
168
|
|
|
$adminContent = self::_renderAdminContent(); |
169
|
|
|
return $adminContent ? : self::_renderContent(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* render the admin content |
174
|
|
|
* |
175
|
|
|
* @since 3.3.0 |
176
|
|
|
* |
177
|
|
|
* @return string|null |
178
|
|
|
*/ |
179
|
|
|
|
180
|
|
|
protected static function _renderAdminContent() : ?string |
181
|
|
|
{ |
182
|
|
|
$registry = Registry::getInstance(); |
183
|
|
|
if ($registry->get('token') === $registry->get('loggedIn')) |
184
|
|
|
{ |
185
|
|
|
$adminRouter = new Admin\Router\Router(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
186
|
|
|
$adminRouter->init(); |
187
|
|
|
return $adminRouter->routeContent(); |
188
|
|
|
} |
189
|
|
|
return null; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* render the content |
194
|
|
|
* |
195
|
|
|
* @since 4.0.0 |
196
|
|
|
* |
197
|
|
|
* @return string|null |
198
|
|
|
*/ |
199
|
|
|
|
200
|
|
|
protected static function _renderContent() : ?string |
201
|
|
|
{ |
202
|
|
|
$router = new Router\Router(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
203
|
|
|
$router->init(); |
204
|
|
|
return $router->routeContent(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* article |
209
|
|
|
* |
210
|
|
|
* @since 4.0.0 |
211
|
|
|
* |
212
|
|
|
* @param int $categoryId identifier of the category |
213
|
|
|
* @param int $articleId identifier of the article |
214
|
|
|
* @param array $optionArray options of the content |
215
|
|
|
* |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
|
219
|
|
|
public static function article(int $categoryId = null, int $articleId = null, array $optionArray = []) : string |
220
|
|
|
{ |
221
|
|
|
$article = new View\Article(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
222
|
|
|
return $article->init($optionArray)->render($categoryId, $articleId); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* comment |
227
|
|
|
* |
228
|
|
|
* @since 4.0.0 |
229
|
|
|
* |
230
|
|
|
* @param int $articleId identifier of the article |
231
|
|
|
* @param array $optionArray options of the comment |
232
|
|
|
* |
233
|
|
|
* @return string|null |
234
|
|
|
*/ |
235
|
|
|
|
236
|
|
|
public static function comment(int $articleId = null, array $optionArray = []) : ?string |
237
|
|
|
{ |
238
|
|
|
$articleModel = new Model\Article(); |
239
|
|
|
$article = $articleModel->getById($articleId); |
240
|
|
|
if ($article->comments) |
241
|
|
|
{ |
242
|
|
|
$comment = new View\Comment(Registry::getInstance(), Language::getInstance()); |
243
|
|
|
return $comment->init($optionArray)->render($articleId); |
244
|
|
|
} |
245
|
|
|
return null; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* extra |
250
|
|
|
* |
251
|
|
|
* @since 4.0.0 |
252
|
|
|
* |
253
|
|
|
* @param int $extraId identifier of the extra |
254
|
|
|
* @param array $optionArray options of the extra |
255
|
|
|
* |
256
|
|
|
* @return string |
257
|
|
|
*/ |
258
|
|
|
|
259
|
|
|
public static function extra(int $extraId = null, array $optionArray = []) : string |
260
|
|
|
{ |
261
|
|
|
$extra = new View\Extra(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
262
|
|
|
return $extra->init($optionArray)->render($extraId); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* pagination |
267
|
|
|
* |
268
|
|
|
* @since 4.0.0 |
269
|
|
|
* |
270
|
|
|
* @param string $type type of the pagination |
271
|
|
|
* @param int $parentId identifier of the parent |
272
|
|
|
* @param array $optionArray options of the pagination |
273
|
|
|
* |
274
|
|
|
* @return string|null |
275
|
|
|
*/ |
276
|
|
|
|
277
|
3 |
|
public static function pagination(string $type = null, int $parentId, array $optionArray = []) : ?string |
278
|
|
|
{ |
279
|
3 |
|
$settingModel = new Model\Setting(); |
280
|
3 |
|
if ($settingModel->get('pagination')) |
|
|
|
|
281
|
|
|
{ |
282
|
3 |
|
$categoryModel = new Model\Category(); |
283
|
3 |
|
$articleModel = new Model\Article(); |
284
|
3 |
|
$commentModel = new Model\Comment(); |
285
|
3 |
|
$registry = Registry::getInstance(); |
286
|
3 |
|
$language = $registry->get('language'); |
287
|
3 |
|
$route = null; |
288
|
3 |
|
$total = null; |
289
|
3 |
|
$current = $registry->get('lastSubParameter') ? : 1; |
290
|
3 |
|
if ($type === 'articles') |
291
|
|
|
{ |
292
|
1 |
|
$route = $categoryModel->getRouteById($parentId); |
293
|
1 |
|
$total = ceil($articleModel->countByCategoryAndLanguage($parentId, $language) / $settingModel->get('limit')); |
294
|
|
|
} |
295
|
3 |
|
if ($type === 'comments') |
296
|
|
|
{ |
297
|
1 |
|
$route = $articleModel->getRouteById($parentId); |
298
|
1 |
|
$total = ceil($commentModel->countByArticleAndLanguage($parentId, $language) / $settingModel->get('limit')); |
299
|
|
|
} |
300
|
3 |
|
if ($total > 1) |
301
|
|
|
{ |
302
|
2 |
|
$pagination = new View\Helper\Pagination(Registry::getInstance(), Language::getInstance()); |
303
|
2 |
|
return $pagination->init($optionArray)->render($route, $current, $total); |
304
|
|
|
} |
305
|
|
|
} |
306
|
1 |
|
return null; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* navigation |
311
|
|
|
* |
312
|
|
|
* @since 3.0.0 |
313
|
|
|
* |
314
|
|
|
* @param string $type type of the navigation |
315
|
|
|
* @param array $optionArray options of the navigation |
316
|
|
|
* |
317
|
|
|
* @return string|null |
318
|
|
|
*/ |
319
|
|
|
|
320
|
6 |
|
public static function navigation(string $type = null, array $optionArray = []) : ?string |
321
|
|
|
{ |
322
|
6 |
|
if ($type === 'articles') |
323
|
|
|
{ |
324
|
1 |
|
$navigation = new Navigation\Article(Registry::getInstance(), Language::getInstance()); |
325
|
1 |
|
return $navigation->init($optionArray)->render(); |
326
|
|
|
} |
327
|
5 |
|
if ($type === 'categories') |
328
|
|
|
{ |
329
|
1 |
|
$navigation = new Navigation\Category(Registry::getInstance(), Language::getInstance()); |
330
|
1 |
|
return $navigation->init($optionArray)->render(); |
331
|
|
|
} |
332
|
4 |
|
if ($type === 'comments') |
333
|
|
|
{ |
334
|
1 |
|
$navigation = new Navigation\Comment(Registry::getInstance(), Language::getInstance()); |
335
|
1 |
|
return $navigation->init($optionArray)->render(); |
336
|
|
|
} |
337
|
3 |
|
if ($type === 'languages') |
338
|
|
|
{ |
339
|
1 |
|
$navigation = new Navigation\Language(Registry::getInstance(), Language::getInstance()); |
340
|
1 |
|
return $navigation->init($optionArray)->render(); |
341
|
|
|
} |
342
|
2 |
|
if ($type === 'templates') |
343
|
|
|
{ |
344
|
1 |
|
$navigation = new Navigation\Template(Registry::getInstance(), Language::getInstance()); |
345
|
1 |
|
return $navigation->init($optionArray)->render(); |
346
|
|
|
} |
347
|
1 |
|
return null; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* console |
352
|
|
|
* |
353
|
|
|
* @since 3.0.0 |
354
|
|
|
* |
355
|
|
|
* @return string|null |
356
|
|
|
*/ |
357
|
|
|
|
358
|
2 |
|
public static function console() : ?string |
359
|
|
|
{ |
360
|
2 |
|
$console = new Console\Console(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
361
|
2 |
|
$output = $console->init('template'); |
362
|
2 |
|
if (strlen($output)) |
363
|
|
|
{ |
364
|
1 |
|
return htmlentities($output, ENT_QUOTES); |
365
|
|
|
} |
366
|
1 |
|
return null; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* console form |
371
|
|
|
* |
372
|
|
|
* @since 3.0.0 |
373
|
|
|
* |
374
|
|
|
* @return string|null |
375
|
|
|
*/ |
376
|
|
|
|
377
|
1 |
|
public static function consoleForm() : string |
378
|
|
|
{ |
379
|
1 |
|
$consoleForm = new View\ConsoleForm(Registry::getInstance(), Language::getInstance()); |
380
|
1 |
|
return $consoleForm->render(); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* comment form |
385
|
|
|
* |
386
|
|
|
* @since 4.0.0 |
387
|
|
|
* |
388
|
|
|
* @param int $articleId identifier of the article |
389
|
|
|
* |
390
|
|
|
* @return string |
391
|
|
|
*/ |
392
|
|
|
|
393
|
1 |
|
public static function commentForm(int $articleId = null) : ?string |
394
|
|
|
{ |
395
|
1 |
|
$articleModel = new Model\Article(); |
396
|
1 |
|
$article = $articleModel->getById($articleId); |
397
|
1 |
|
if ($article->comments) |
398
|
|
|
{ |
399
|
1 |
|
$commentForm = new View\CommentForm(Registry::getInstance(), Language::getInstance()); |
400
|
1 |
|
return $commentForm->render($articleId); |
401
|
|
|
} |
402
|
|
|
return null; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* search form |
407
|
|
|
* |
408
|
|
|
* @since 3.0.0 |
409
|
|
|
* |
410
|
|
|
* @param string $table name of the table |
411
|
|
|
* |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
|
|
|
415
|
1 |
|
public static function searchForm(string $table = null) : string |
416
|
|
|
{ |
417
|
1 |
|
$searchForm = new View\SearchForm(Registry::getInstance(), Language::getInstance()); |
418
|
1 |
|
return $searchForm->render($table); |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: