blob: 288ad2d06502ecc47e50c2115f8904e32979fce3 (
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
|
<?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 = [];
public function __construct(array $datas = [])
{
$this->hydrate($datas);
$this->readoptions();
}
public function readoptions()
{
parse_str($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()
{
$filteredsum = [];
foreach ($this->sum as $key => $menu) {
$deepness = array_keys($menu)[0];
if($deepness >= $this->min && $deepness <= $this->max) {
$filteredsum[$key] = $menu;
}
}
$sumstring = '';
$last = 0;
foreach ($filteredsum as $title => $list) {
foreach ($list as $h => $link) {
if ($h > $last) {
for ($i = 1; $i <= ($h - $last); $i++) {
$sumstring .= '<ul>';
}
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
} elseif ($h < $last) {
for ($i = 1; $i <= ($last - $h); $i++) {
$sumstring .= '</ul>';
}
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
} elseif ($h = $last) {
$sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>';
}
$last = $h;
}
}
for ($i = 1; $i <= ($last); $i++) {
$sumstring .= '</ul>';
}
return $sumstring;
}
// __________________________________________________ G E T ____________________________________________________________
public function fullmatch()
{
return $this->fullmatch;
}
public function options()
{
return $this->options;
}
// __________________________________________________ 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;
}
}
?>
|