These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | $breadcrumb->init($optionArray); |
|
128 | 1 | return $breadcrumb->render(); |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * partial |
||
133 | * |
||
134 | * @since 3.2.0 |
||
135 | * |
||
136 | * @param string|array $partial |
||
137 | * |
||
138 | * @return string|null |
||
139 | */ |
||
140 | |||
141 | 1 | public static function partial($partial = null) : ?string |
|
142 | { |
||
143 | 1 | $output = null; |
|
144 | |||
145 | /* template filesystem */ |
||
146 | |||
147 | 1 | $templateFilesystem = new Filesystem\File(); |
|
148 | 1 | $templateFilesystem->init('templates'); |
|
149 | |||
150 | /* process partial */ |
||
151 | |||
152 | 1 | foreach ((array)$partial as $file) |
|
153 | { |
||
154 | 1 | $output .= $templateFilesystem->renderFile($file); |
|
155 | } |
||
156 | 1 | return $output; |
|
157 | } |
||
158 | |||
159 | /** |
||
160 | * content |
||
161 | * |
||
162 | * @since 4.0.0 |
||
163 | * |
||
164 | * @return string|null |
||
165 | */ |
||
166 | |||
167 | public static function content() : ?string |
||
168 | { |
||
169 | $adminContent = self::_renderAdminContent(); |
||
170 | return $adminContent ? : self::_renderContent(); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * render the admin content |
||
175 | * |
||
176 | * @since 3.3.0 |
||
177 | * |
||
178 | * @return string|null |
||
179 | */ |
||
180 | |||
181 | protected static function _renderAdminContent() : ?string |
||
182 | { |
||
183 | $registry = Registry::getInstance(); |
||
184 | if ($registry->get('token') === $registry->get('loggedIn')) |
||
185 | { |
||
186 | $adminRouter = new Admin\Router\Router(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
||
187 | $adminRouter->init(); |
||
188 | return $adminRouter->routeContent(); |
||
189 | } |
||
190 | return null; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * render the content |
||
195 | * |
||
196 | * @since 4.0.0 |
||
197 | * |
||
198 | * @return string|null |
||
199 | */ |
||
200 | |||
201 | protected static function _renderContent() : ?string |
||
202 | { |
||
203 | $router = new Router\Router(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
||
204 | $router->init(); |
||
205 | return $router->routeContent(); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * article |
||
210 | * |
||
211 | * @since 4.0.0 |
||
212 | * |
||
213 | * @param int $categoryId identifier of the category |
||
214 | * @param int $articleId identifier of the article |
||
215 | * @param array $optionArray options of the content |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | |||
220 | public static function article(int $categoryId = null, int $articleId = null, array $optionArray = []) : string |
||
221 | { |
||
222 | $article = new View\Article(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
||
223 | $article->init($optionArray); |
||
224 | return $article->render($categoryId, $articleId); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * comment |
||
229 | * |
||
230 | * @since 4.0.0 |
||
231 | * |
||
232 | * @param int $articleId identifier of the article |
||
233 | * @param array $optionArray options of the comment |
||
234 | * |
||
235 | * @return string|null |
||
236 | */ |
||
237 | |||
238 | public static function comment(int $articleId = null, array $optionArray = []) : ?string |
||
239 | { |
||
240 | $articleModel = new Model\Article(); |
||
241 | $article = $articleModel->getById($articleId); |
||
242 | if ($article->comments) |
||
243 | { |
||
244 | $comment = new View\Comment(Registry::getInstance(), Language::getInstance()); |
||
245 | $comment->init($optionArray); |
||
246 | return $comment->render($articleId); |
||
247 | } |
||
248 | return null; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * extra |
||
253 | * |
||
254 | * @since 4.0.0 |
||
255 | * |
||
256 | * @param int $extraId identifier of the extra |
||
257 | * @param array $optionArray options of the extra |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | |||
262 | public static function extra(int $extraId = null, array $optionArray = []) : string |
||
263 | { |
||
264 | $extra = new View\Extra(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
||
265 | $extra->init($optionArray); |
||
266 | return $extra->render($extraId); |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * pagination |
||
271 | * |
||
272 | * @since 4.0.0 |
||
273 | * |
||
274 | * @param string $type type of the pagination |
||
275 | * @param int $parentId identifier of the parent |
||
276 | * @param array $optionArray options of the pagination |
||
277 | * |
||
278 | * @return string|null |
||
279 | */ |
||
280 | |||
281 | 3 | public static function pagination(string $type = null, int $parentId, array $optionArray = []) : ?string |
|
282 | { |
||
283 | 3 | $settingModel = new Model\Setting(); |
|
284 | 3 | if ($settingModel->get('pagination')) |
|
285 | { |
||
286 | 3 | $categoryModel = new Model\Category(); |
|
287 | 3 | $articleModel = new Model\Article(); |
|
288 | 3 | $commentModel = new Model\Comment(); |
|
289 | 3 | $registry = Registry::getInstance(); |
|
290 | 3 | $language = $registry->get('language'); |
|
291 | 3 | $route = null; |
|
292 | 3 | $total = null; |
|
293 | 3 | $current = $registry->get('lastSubParameter') ? : 1; |
|
294 | 3 | if ($type === 'articles') |
|
295 | { |
||
296 | 1 | $route = $categoryModel->getRouteById($parentId); |
|
297 | 1 | $total = ceil($articleModel->countByCategoryAndLanguage($parentId, $language) / $settingModel->get('limit')); |
|
0 ignored issues
–
show
|
|||
298 | } |
||
299 | 3 | if ($type === 'comments') |
|
300 | { |
||
301 | 1 | $route = $articleModel->getRouteById($parentId); |
|
302 | 1 | $total = ceil($commentModel->countByArticleAndLanguage($parentId, $language) / $settingModel->get('limit')); |
|
0 ignored issues
–
show
It seems like
$language defined by $registry->get('language') on line 290 can also be of type array ; however, Redaxscript\Model\Commen...tByArticleAndLanguage() does only seem to accept null|string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
303 | } |
||
304 | 3 | if ($total > 1) |
|
305 | { |
||
306 | 2 | $pagination = new View\Helper\Pagination(Registry::getInstance(), Language::getInstance()); |
|
307 | 2 | $pagination->init($optionArray); |
|
308 | 2 | return $pagination->render($route, $current, $total); |
|
309 | } |
||
310 | } |
||
311 | 1 | return null; |
|
312 | } |
||
313 | |||
314 | /** |
||
315 | * navigation |
||
316 | * |
||
317 | * @since 3.0.0 |
||
318 | * |
||
319 | * @param string $type type of the navigation |
||
320 | * @param array $optionArray options of the navigation |
||
321 | * |
||
322 | * @return string|null |
||
323 | */ |
||
324 | |||
325 | 6 | public static function navigation(string $type = null, array $optionArray = []) : ?string |
|
326 | { |
||
327 | 6 | if ($type === 'articles') |
|
328 | { |
||
329 | 1 | $navigation = new Navigation\Article(Registry::getInstance(), Language::getInstance()); |
|
330 | 1 | $navigation->init($optionArray); |
|
331 | 1 | return $navigation->render(); |
|
332 | } |
||
333 | 5 | if ($type === 'categories') |
|
334 | { |
||
335 | 1 | $navigation = new Navigation\Category(Registry::getInstance(), Language::getInstance()); |
|
336 | 1 | $navigation->init($optionArray); |
|
337 | 1 | return $navigation->render(); |
|
338 | } |
||
339 | 4 | if ($type === 'comments') |
|
340 | { |
||
341 | 1 | $navigation = new Navigation\Comment(Registry::getInstance(), Language::getInstance()); |
|
342 | 1 | $navigation->init($optionArray); |
|
343 | 1 | return $navigation->render(); |
|
344 | } |
||
345 | 3 | if ($type === 'languages') |
|
346 | { |
||
347 | 1 | $navigation = new Navigation\Language(Registry::getInstance(), Language::getInstance()); |
|
348 | 1 | $navigation->init($optionArray); |
|
349 | 1 | return $navigation->render(); |
|
350 | } |
||
351 | 2 | if ($type === 'templates') |
|
352 | { |
||
353 | 1 | $navigation = new Navigation\Template(Registry::getInstance(), Language::getInstance()); |
|
354 | 1 | $navigation->init($optionArray); |
|
355 | 1 | return $navigation->render(); |
|
356 | } |
||
357 | 1 | return null; |
|
358 | } |
||
359 | |||
360 | /** |
||
361 | * console |
||
362 | * |
||
363 | * @since 3.0.0 |
||
364 | * |
||
365 | * @return string|null |
||
366 | */ |
||
367 | |||
368 | 2 | public static function console() : ?string |
|
369 | { |
||
370 | 2 | $console = new Console\Console(Registry::getInstance(), Request::getInstance(), Language::getInstance(), Config::getInstance()); |
|
371 | 2 | $output = $console->init('template'); |
|
372 | 2 | if (strlen($output)) |
|
373 | { |
||
374 | 1 | return htmlentities($output, ENT_QUOTES); |
|
375 | } |
||
376 | 1 | return null; |
|
377 | } |
||
378 | |||
379 | /** |
||
380 | * console form |
||
381 | * |
||
382 | * @since 3.0.0 |
||
383 | * |
||
384 | * @return string|null |
||
385 | */ |
||
386 | |||
387 | 1 | public static function consoleForm() : string |
|
388 | { |
||
389 | 1 | $consoleForm = new View\ConsoleForm(Registry::getInstance(), Language::getInstance()); |
|
390 | 1 | return $consoleForm->render(); |
|
391 | } |
||
392 | |||
393 | /** |
||
394 | * comment form |
||
395 | * |
||
396 | * @since 4.0.0 |
||
397 | * |
||
398 | * @param int $articleId identifier of the article |
||
399 | * |
||
400 | * @return string |
||
401 | */ |
||
402 | |||
403 | 1 | public static function commentForm(int $articleId = null) : ?string |
|
404 | { |
||
405 | 1 | $articleModel = new Model\Article(); |
|
406 | 1 | $article = $articleModel->getById($articleId); |
|
407 | 1 | if ($article->comments) |
|
408 | { |
||
409 | 1 | $commentForm = new View\CommentForm(Registry::getInstance(), Language::getInstance()); |
|
410 | 1 | return $commentForm->render($articleId); |
|
411 | } |
||
412 | return null; |
||
413 | } |
||
414 | |||
415 | /** |
||
416 | * search form |
||
417 | * |
||
418 | * @since 3.0.0 |
||
419 | * |
||
420 | * @param string $table name of the table |
||
421 | * |
||
422 | * @return string |
||
423 | */ |
||
424 | |||
425 | 1 | public static function searchForm(string $table = null) : string |
|
426 | { |
||
427 | 1 | $searchForm = new View\SearchForm(Registry::getInstance(), Language::getInstance()); |
|
428 | 1 | return $searchForm->render($table); |
|
429 | } |
||
430 | } |
||
431 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.