1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\About; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
8
|
|
|
|
9
|
|
|
if (!\class_exists('About\Tree')) { |
10
|
|
|
/** |
11
|
|
|
* Class Tree |
12
|
|
|
*/ |
13
|
|
|
class Tree extends \XoopsObjectTree |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Tree constructor. |
17
|
|
|
* @param array $objectArr |
18
|
|
|
* @param null $rootId |
19
|
|
|
*/ |
20
|
|
|
public function __construct($objectArr, $rootId = null) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($objectArr, 'page_id', 'page_pid', $rootId); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param $key |
27
|
|
|
* @param $ret |
28
|
|
|
* @param $prefix_orig |
29
|
|
|
* @param string $prefix_curr |
30
|
|
|
* @param null|array $tags |
31
|
|
|
*/ |
32
|
|
|
public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null) |
33
|
|
|
{ |
34
|
|
|
if ($key > 0) { |
35
|
|
|
if ($tags && \is_array($tags)) { |
36
|
|
|
foreach ($tags as $tag) { |
37
|
|
|
$ret[$key][$tag] = $this->tree[$key]['obj']->getVar($tag); |
38
|
|
|
} |
39
|
|
|
} else { |
40
|
|
|
$ret[$key]['page_title'] = $this->tree[$key]['obj']->getVar('page_title'); |
41
|
|
|
} |
42
|
|
|
$ret[$key]['prefix'] = $prefix_curr; |
43
|
|
|
$prefix_curr .= $prefix_orig; |
44
|
|
|
} |
45
|
|
|
if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) { |
46
|
|
|
foreach ($this->tree[$key]['child'] as $childkey) { |
47
|
|
|
$this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $prefix |
54
|
|
|
* @param int $key |
55
|
|
|
* @param null $tags |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function &makeTree($prefix = '-', $key = 0, $tags = null) |
59
|
|
|
{ |
60
|
|
|
$ret = []; |
61
|
|
|
$this->makeTreeItems($key, $ret, $prefix, '', $tags); |
62
|
|
|
|
63
|
|
|
return $ret; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $name |
68
|
|
|
* @param string $fieldName |
69
|
|
|
* @param string $prefix |
70
|
|
|
* @param string $selected |
71
|
|
|
* @param bool $addEmptyOption |
72
|
|
|
* @param int $key |
73
|
|
|
* @param string $extra |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function makeSelBox( |
77
|
|
|
$name, |
78
|
|
|
$fieldName, |
79
|
|
|
$prefix = '-', |
80
|
|
|
$selected = '', |
81
|
|
|
$addEmptyOption = false, |
82
|
|
|
$key = 0, |
83
|
|
|
$extra = '' |
84
|
|
|
) { |
85
|
|
|
$ret = '<select name=' . $name . '>'; |
86
|
|
|
if (!empty($addEmptyOption)) { |
87
|
|
|
$ret .= '<option value="0">' . (\is_string($addEmptyOption) ? $addEmptyOption : '') . '</option>'; |
88
|
|
|
} |
89
|
|
|
$this->makeSelBoxOptions('page_title', $selected, $key, $ret, $prefix); |
|
|
|
|
90
|
|
|
$ret .= '</select>'; |
91
|
|
|
|
92
|
|
|
return $ret; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $key |
97
|
|
|
* @param $ret |
98
|
|
|
* @param array $tags |
99
|
|
|
* @param int $depth |
100
|
|
|
*/ |
101
|
|
|
public function getAllChildArray($key, &$ret, $tags = [], $depth = 0) |
102
|
|
|
{ |
103
|
|
|
if (0 == --$depth) { |
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if (isset($this->tree[$key]['child'])) { |
108
|
|
|
foreach ($this->tree[$key]['child'] as $childkey) { |
109
|
|
|
if (isset($this->tree[$childkey]['obj'])): |
110
|
|
|
if ($tags && \is_array($tags)) { |
111
|
|
|
foreach ($tags as $tag) { |
112
|
|
|
$ret['child'][$childkey][$tag] = $this->tree[$childkey]['obj']->getVar($tag); |
113
|
|
|
} |
114
|
|
|
} else { |
115
|
|
|
$ret['child'][$childkey]['page_title'] = $this->tree[$childkey]['obj']->getVar('page_title'); |
116
|
|
|
} |
117
|
|
|
endif; |
118
|
|
|
|
119
|
|
|
$this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param int $key |
126
|
|
|
* @param null $tags |
127
|
|
|
* @param int $depth |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
|
|
public function makeArrayTree($key = 0, $tags = null, $depth = 0) |
131
|
|
|
{ |
132
|
|
|
$ret = []; |
133
|
|
|
if ($depth > 0) { |
134
|
|
|
$depth++; |
135
|
|
|
} |
136
|
|
|
$this->getAllChildArray($key, $ret, $tags, $depth); |
137
|
|
|
|
138
|
|
|
return $ret; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.