|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
|
4
|
|
|
|
|
5
|
|
|
// |
|
6
|
|
|
// ------------------------------------------------------------------------ // |
|
7
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
8
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
9
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
10
|
|
|
// (at your option) any later version. // |
|
11
|
|
|
// // |
|
12
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
13
|
|
|
// of supporting developers from this source code or any supporting // |
|
14
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
15
|
|
|
// original comment or credit authors. // |
|
16
|
|
|
// // |
|
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
20
|
|
|
// GNU General Public License for more details. // |
|
21
|
|
|
// // |
|
22
|
|
|
// You should have received a copy of the GNU General Public License // |
|
23
|
|
|
// along with this program; if not, write to the Free Software // |
|
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
25
|
|
|
// ------------------------------------------------------------------------ // |
|
26
|
|
|
// Author: phppp (D.J., [email protected]) // |
|
27
|
|
|
// URL: https://xoops.org // |
|
28
|
|
|
// Project: Article Project // |
|
29
|
|
|
// ------------------------------------------------------------------------ // |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
require_once $GLOBALS['xoops']->path('class/tree.php'); |
|
33
|
|
|
|
|
34
|
|
|
if (!\class_exists('ObjectTree')) { |
|
35
|
|
|
/** |
|
36
|
|
|
* Class ObjectTree |
|
37
|
|
|
*/ |
|
38
|
|
|
class ObjectTree extends \XoopsObjectTree |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @param $objectArr |
|
42
|
|
|
* @param null $rootId |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct($objectArr, $rootId = null) |
|
45
|
|
|
{ |
|
46
|
|
|
parent::__construct($objectArr, 'forum_id', 'parent_forum', $rootId); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Make options for a select box from |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $key ID of the object to display as the root of select options |
|
53
|
|
|
* @param string $ret (reference to a string when called from outside) Result from previous recursions |
|
54
|
|
|
* @param string $prefix_orig String to indent items at deeper levels |
|
55
|
|
|
* @param string $prefix_curr String to indent the current item |
|
56
|
|
|
* @param null|array $tags |
|
57
|
|
|
* @internal param string $fieldName Name of the member variable from the |
|
58
|
|
|
* node objects that should be used as the title for the options. |
|
59
|
|
|
* @internal param string $selected Value to display as selected |
|
60
|
|
|
* @access private |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null) |
|
63
|
|
|
{ |
|
64
|
|
|
if ($key > 0) { |
|
65
|
|
|
if (\count($tags) > 0) { |
|
66
|
|
|
foreach ($tags as $tag) { |
|
67
|
|
|
$ret[$key][$tag] = $this->tree[$key]['obj']->getVar($tag); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
$ret[$key]['forum_name'] = $this->tree[$key]['obj']->getVar('forum_name'); |
|
71
|
|
|
} |
|
72
|
|
|
$ret[$key]['prefix'] = $prefix_curr; |
|
73
|
|
|
$prefix_curr .= $prefix_orig; |
|
74
|
|
|
} |
|
75
|
|
|
if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) { |
|
76
|
|
|
foreach ($this->tree[$key]['child'] as $childkey) { |
|
77
|
|
|
$this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Make a select box with options from the tree |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $prefix String to indent deeper levels |
|
86
|
|
|
* @param int $key ID of the object to display as the root of select options |
|
87
|
|
|
* @param null $tags |
|
|
|
|
|
|
88
|
|
|
* @return array|string HTML select box |
|
89
|
|
|
* @internal param string $name Name of the select box |
|
90
|
|
|
* @internal param string $fieldName Name of the member variable from the |
|
91
|
|
|
* node objects that should be used as the title for the options. |
|
92
|
|
|
* @internal param string $selected Value to display as selected |
|
93
|
|
|
* @internal param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
|
94
|
|
|
*/ |
|
95
|
|
|
public function &makeTree($prefix = '-', $key = 0, $tags = null) |
|
96
|
|
|
{ |
|
97
|
|
|
$ret = []; |
|
98
|
|
|
$this->makeTreeItems($key, $ret, $prefix, '', $tags); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
return $ret; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Make a select box with options from the tree |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $name Name of the select box |
|
107
|
|
|
* @param string $fieldName Name of the member variable from the |
|
108
|
|
|
* node objects that should be used as the title for the options. |
|
109
|
|
|
* @param string $prefix String to indent deeper levels |
|
110
|
|
|
* @param string $selected Value to display as selected |
|
111
|
|
|
* @param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
|
112
|
|
|
* @param int $key ID of the object to display as the root of select options |
|
113
|
|
|
* @param string $extra |
|
114
|
|
|
* @return string HTML select box |
|
115
|
|
|
* |
|
116
|
|
|
* @deprecated since 2.5.9, please use makeSelectElement() |
|
117
|
|
|
*/ |
|
118
|
|
|
public function makeSelBox( |
|
119
|
|
|
$name, |
|
120
|
|
|
$fieldName, |
|
121
|
|
|
$prefix = '-', |
|
122
|
|
|
$selected = '', |
|
123
|
|
|
$addEmptyOption = false, |
|
124
|
|
|
$key = 0, |
|
125
|
|
|
$extra = '' |
|
126
|
|
|
) //makeSelBox($name, $prefix = '-', $selected = '', $EmptyOption = false, $key = 0) |
|
127
|
|
|
{ |
|
128
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
129
|
|
|
\trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},"); |
|
130
|
|
|
|
|
131
|
|
|
$ret = '<select name=' . $name . '>'; |
|
132
|
|
|
if (!empty($addEmptyOption)) { |
|
133
|
|
|
$ret .= '<option value="0">' . (\is_string($addEmptyOption) ? $addEmptyOption : '') . '</option>'; |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
$this->_makeSelBoxOptions('forum_name', $selected, $key, $ret, $prefix); |
|
|
|
|
|
|
136
|
|
|
$ret .= '</select>'; |
|
137
|
|
|
|
|
138
|
|
|
return $ret; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Make a tree for the array of a given category |
|
143
|
|
|
* |
|
144
|
|
|
* @param string $key top key of the tree |
|
145
|
|
|
* @param array $ret the tree |
|
146
|
|
|
* @param int $depth level of subcategories |
|
147
|
|
|
* @internal param array $tags fields to be used |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getAllChildObject($key, &$ret, $depth = 0) |
|
150
|
|
|
{ |
|
151
|
|
|
if (0 == --$depth) { |
|
152
|
|
|
return; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
if (isset($this->tree[$key]['child'])) { |
|
156
|
|
|
foreach ($this->tree[$key]['child'] as $childkey) { |
|
157
|
|
|
if (isset($this->tree[$childkey]['obj'])) { |
|
158
|
|
|
$ret['child'][$childkey] = $this->tree[$childkey]['obj']; |
|
159
|
|
|
} |
|
160
|
|
|
$this->getAllChild_object($childkey, $ret['child'][$childkey], $depth); |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Make a tree for the array |
|
167
|
|
|
* |
|
168
|
|
|
* @param int|string $key top key of the tree |
|
169
|
|
|
* @param int $depth level of subcategories |
|
170
|
|
|
* @return array |
|
171
|
|
|
* @internal param array $tags fields to be used |
|
172
|
|
|
*/ |
|
173
|
|
|
public function &makeObjectTree($key = 0, $depth = 0) |
|
174
|
|
|
{ |
|
175
|
|
|
$ret = []; |
|
176
|
|
|
if ($depth > 0) { |
|
177
|
|
|
++$depth; |
|
178
|
|
|
} |
|
179
|
|
|
$this->getAllChild_object($key, $ret, $depth); |
|
180
|
|
|
|
|
181
|
|
|
return $ret; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Make a tree for the array of a given category |
|
186
|
|
|
* |
|
187
|
|
|
* @param string $key top key of the tree |
|
188
|
|
|
* @param array $ret the tree |
|
189
|
|
|
* @param array $tags fields to be used |
|
190
|
|
|
* @param int $depth level of subcategories |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getAllChildArray($key, &$ret, array $tags = [], $depth = 0) |
|
193
|
|
|
{ |
|
194
|
|
|
if (0 == --$depth) { |
|
195
|
|
|
return; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
if (isset($this->tree[$key]['child'])) { |
|
199
|
|
|
foreach ($this->tree[$key]['child'] as $childkey) { |
|
200
|
|
|
if (isset($this->tree[$childkey]['obj'])) { |
|
201
|
|
|
if (\count($tags) > 0) { |
|
202
|
|
|
foreach ($tags as $tag) { |
|
203
|
|
|
$ret['child'][$childkey][$tag] = $this->tree[$childkey]['obj']->getVar($tag); |
|
204
|
|
|
} |
|
205
|
|
|
} else { |
|
206
|
|
|
$ret['child'][$childkey]['forum_name'] = $this->tree[$childkey]['obj']->getVar('forum_name'); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
$this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Make a tree for the array |
|
217
|
|
|
* |
|
218
|
|
|
* @param int|string $key top key of the tree |
|
219
|
|
|
* @param array $tags fields to be used |
|
220
|
|
|
* @param int $depth level of subcategories |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
223
|
|
|
public function &makeArrayTree($key = 0, $tags = null, $depth = 0) |
|
224
|
|
|
{ |
|
225
|
|
|
$ret = []; |
|
226
|
|
|
if ($depth > 0) { |
|
227
|
|
|
++$depth; |
|
228
|
|
|
} |
|
229
|
|
|
$this->getAllChildArray($key, $ret, $tags, $depth); |
|
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
return $ret; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/**#@+ |
|
235
|
|
|
* get all parent forums |
|
236
|
|
|
* |
|
237
|
|
|
* @param string $key ID of the child object |
|
238
|
|
|
* @param array $ret (empty when called from outside) Result from previous recursions |
|
239
|
|
|
* @param int $uplevel (empty when called from outside) level of recursion |
|
240
|
|
|
* @return array Array of parent nodes. |
|
241
|
|
|
*/ |
|
242
|
|
|
public function &myGetParentForums($key, array $ret = [], $uplevel = 0) |
|
243
|
|
|
{ |
|
244
|
|
|
if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) { |
|
245
|
|
|
$ret[$uplevel] = $this->tree[$this->tree[$key]['parent']]['obj']; |
|
246
|
|
|
if ($this->tree[$key]['parent'] !== $key) { |
|
247
|
|
|
//$parents = $this->getParentForums($this->tree[$key]['parent'], $ret, $uplevel+1); |
|
248
|
|
|
$parents = $this->getParentForums($this->tree[$key]['parent']); |
|
249
|
|
|
foreach (\array_keys($parents) as $newkey) { |
|
250
|
|
|
$ret[$newkey] = $parents[$newkey]; |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
return $ret; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @param $key |
|
260
|
|
|
* @param bool $reverse |
|
261
|
|
|
* @return array |
|
262
|
|
|
*/ |
|
263
|
|
|
public function &getParentForums($key, $reverse = true) |
|
264
|
|
|
{ |
|
265
|
|
|
$ret = []; |
|
266
|
|
|
$pids = []; |
|
267
|
|
|
if (isset($this->tree[$key]['parent']) && isset($this->tree[$this->tree[$key]['parent']]['obj'])) { |
|
268
|
|
|
$pids[] = $this->tree[$this->tree[$key]['parent']]['obj']->getVar($this->myId); |
|
269
|
|
|
$parents = $this->myGetParentForums($this->tree[$key]['parent'], $ret); |
|
270
|
|
|
foreach (\array_keys($parents) as $newkey) { |
|
271
|
|
|
if (!\is_object($newkey)) { |
|
272
|
|
|
continue; |
|
273
|
|
|
} |
|
274
|
|
|
$ret[] = $parents[$newkey]->getVar($this->myId); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
if ($reverse) { |
|
278
|
|
|
$pids = \array_reverse($ret) + $pids; |
|
279
|
|
|
} else { |
|
280
|
|
|
$pids += $ret; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
return $pids; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/**#@-*/ |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|