blob: 373fb330ba1dcdba879749dd3312c98504be460e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
<?php
namespace Wcms;
class Summary extends Item
{
/** @var string full regex match */
protected $fullmatch;
/** @var string full options code line */
protected $options = '';
/** @var int Minimum summary level*/
protected $min = 1;
/** @var int Maximum summary level*/
protected $max = 6;
/** @var array Headers datas */
protected $sum = [];
/** @var string Name of element to display */
protected $element = null;
public function __construct(array $datas = [])
{
$this->hydrate($datas);
$this->readoptions();
}
public function readoptions()
{
parse_str(htmlspecialchars_decode($this->options), $datas);
$this->hydrate($datas);
}
/**
* Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text
*
* @return string html list with anchor link
*/
public function sumparser()
{
$sumstring = '';
foreach ($this->sum as $type => $element) {
if(!empty($element) && (empty($this->element) || $type === $this->element)) {
$filteredsum = [];
foreach ($element as $key => $menu) {
$deepness = array_keys($menu)[0];
if($deepness >= $this->min && $deepness <= $this->max) {
$filteredsum[$key] = $menu;
}
}
$last = 0;
foreach ($filteredsum as $title => $list) {
foreach ($list as $h => $link) {
if ($h > $last) {
for ($i = 1; $i <= ($h - $last); $i++) {
$sumstring .= '<ul>' . PHP_EOL;
}
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>' . PHP_EOL;
} elseif ($h < $last) {
for ($i = 1; $i <= ($last - $h); $i++) {
$sumstring .= '</ul>' . PHP_EOL;
}
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>' . PHP_EOL;
} elseif ($h = $last) {
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>' . PHP_EOL;
}
$last = $h;
}
}
for ($i = 1; $i <= ($last); $i++) {
$sumstring .= '</ul>' . PHP_EOL;
}
}
}
return $sumstring;
}
// __________________________________________________ G E T ____________________________________________________________
public function fullmatch()
{
return $this->fullmatch;
}
public function options()
{
return $this->options;
}
public function element()
{
return $this->element;
}
// __________________________________________________ S E T ____________________________________________________________
public function setfullmatch(string $fullmatch)
{
$this->fullmatch = $fullmatch;
}
public function setoptions(string $options)
{
if (!empty($options)) {
$this->options = $options;
}
}
public function setmin($min)
{
$min = intval($min);
if($min >= 1 && $min <= 6) {
$this->min = $min;
}
}
public function setmax($max)
{
$max = intval($max);
if($max >= 1 && $max <= 6) {
$this->max = $max;
}
}
public function setsum(array $sum)
{
$this->sum = $sum;
}
public function setelement(string $element)
{
if(in_array($element, Model::TEXT_ELEMENTS)) {
$this->element = $element;
}
}
}
|