|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ffcms\Core\Helper\HTML; |
|
4
|
|
|
|
|
5
|
|
|
use Ffcms\Core\App; |
|
6
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
|
7
|
|
|
use Ffcms\Core\Helper\Type\Obj; |
|
8
|
|
|
use Ffcms\Core\Helper\Type\Str; |
|
9
|
|
|
use Ffcms\Core\Helper\Url; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class HList |
|
13
|
|
|
* @package Ffcms\Core\Helper\HTML |
|
14
|
|
|
*/ |
|
15
|
|
|
class Listing extends NativeGenerator |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Construct listing elements,property's and future's |
|
20
|
|
|
* @param array $elements |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
public static function display($elements) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!Arr::in($elements['type'], ['ul', 'ol']) || count($elements['items']) < 1) { |
|
26
|
|
|
return null; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$orderActiveLink = false; |
|
30
|
|
|
if ($elements['activeOrder'] !== null) { |
|
31
|
|
|
$orderActiveLink = $elements['activeOrder']; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$items = null; |
|
35
|
|
|
// foreach elements and build schema |
|
36
|
|
|
foreach ($elements['items'] as $item) { |
|
37
|
|
|
// type is undefined, skip |
|
38
|
|
|
if (!Arr::in($item['type'], ['text', 'link'])) { |
|
39
|
|
|
continue; |
|
40
|
|
|
} |
|
41
|
|
|
// sounds like a link, try detect active element |
|
42
|
|
|
if ($item['type'] === 'link') { |
|
43
|
|
|
if (!Obj::isArray($item['link']) && !Str::startsWith('http', $item['link']) && !Str::startsWith('#', |
|
44
|
|
|
$item['link']) |
|
45
|
|
|
) { |
|
46
|
|
|
$item['link'] = [$item['link']]; // just controller/action sended, to array |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// check if current element is link and is active |
|
50
|
|
|
if (Obj::isArray($item['link'])) { |
|
51
|
|
|
if (!isset($item['activeClass'])) { |
|
52
|
|
|
$item['activeClass'] = 'active'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$activeItem = self::isCurrentLink($item['link'], $item['activeOn'], $orderActiveLink); |
|
56
|
|
|
|
|
57
|
|
|
// check if it active link for current pathway |
|
58
|
|
|
if ($activeItem) { |
|
59
|
|
|
$item['property']['class'] = Str::length($item['property']['class']) > 0 |
|
60
|
|
|
? $item['activeClass'] . ' ' . $item['property']['class'] |
|
61
|
|
|
: $item['activeClass']; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$innerItem = self::applyEscape($item['text'], $item['html'], $item['!secure']); |
|
67
|
|
|
// sounds like a hyperlink? |
|
68
|
|
|
if ($item['type'] === 'link') { |
|
69
|
|
|
// parse uri-link type to classic link |
|
70
|
|
|
$item['linkProperty']['href'] = self::convertLink($item['link']); |
|
71
|
|
|
// make classic tag inside with text value |
|
72
|
|
|
$innerItem = self::buildContainerTag('a', $item['linkProperty'], $innerItem, $item['html']); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
// store item |
|
75
|
|
|
$items .= self::buildContainerTag('li', $item['property'], $innerItem, true); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// return <ul/> or <ol/> full container |
|
79
|
|
|
return self::buildContainerTag($elements['type'], $elements['property'], $items, true); |
|
80
|
|
|
} |
|
81
|
|
|
} |
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.