1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
4
|
|
|
|
5
|
|
|
require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
6
|
|
|
|
7
|
|
|
if (!class_exists('AboutTree')) { |
8
|
|
|
/** |
9
|
|
|
* Class AboutTree |
10
|
|
|
*/ |
11
|
|
|
class AboutTree extends XoopsObjectTree |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* AboutTree constructor. |
15
|
|
|
* @param array $objectArr |
16
|
|
|
* @param null $rootId |
17
|
|
|
*/ |
18
|
|
|
public function __construct(&$objectArr, $rootId = null) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($objectArr, 'page_id', 'page_pid', $rootId); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param $key |
25
|
|
|
* @param $ret |
26
|
|
|
* @param $prefix_orig |
27
|
|
|
* @param string $prefix_curr |
28
|
|
|
* @param null $tags |
29
|
|
|
*/ |
30
|
|
|
public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null) |
31
|
|
|
{ |
32
|
|
|
if ($key > 0) { |
33
|
|
View Code Duplication |
if (count($tags) > 0) { |
|
|
|
|
34
|
|
|
foreach ($tags as $tag) { |
|
|
|
|
35
|
|
|
$ret[$key][$tag] = $this->_tree[$key]['obj']->getVar($tag); |
36
|
|
|
} |
37
|
|
|
} else { |
38
|
|
|
$ret[$key]['page_title'] = $this->_tree[$key]['obj']->getVar('page_title'); |
39
|
|
|
} |
40
|
|
|
$ret[$key]['prefix'] = $prefix_curr; |
41
|
|
|
$prefix_curr .= $prefix_orig; |
42
|
|
|
} |
43
|
|
|
if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) { |
44
|
|
|
foreach ($this->_tree[$key]['child'] as $childkey) { |
45
|
|
|
$this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $prefix |
52
|
|
|
* @param int $key |
53
|
|
|
* @param null $tags |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function &makeTree($prefix = '-', $key = 0, $tags = null) |
57
|
|
|
{ |
58
|
|
|
$ret = array(); |
59
|
|
|
$this->makeTreeItems($key, $ret, $prefix, '', $tags); |
60
|
|
|
|
61
|
|
|
return $ret; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $name |
66
|
|
|
* @param string $fieldName |
67
|
|
|
* @param string $prefix |
68
|
|
|
* @param string $selected |
69
|
|
|
* @param bool $addEmptyOption |
70
|
|
|
* @param int $key |
71
|
|
|
* @param string $extra |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function makeSelBox($name, $fieldName, $prefix = '-', $selected = '', $addEmptyOption = false, $key = 0, $extra = '') |
75
|
|
|
{ |
76
|
|
|
$ret = '<select name=' . $name . '>'; |
77
|
|
|
if (!empty($addEmptyOption)) { |
78
|
|
|
$ret .= '<option value="0">' . (is_string($EmptyOption) ? $EmptyOption : '') . '</option>'; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
$this->_makeSelBoxOptions('page_title', $selected, $key, $ret, $prefix); |
81
|
|
|
$ret .= '</select>'; |
82
|
|
|
|
83
|
|
|
return $ret; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $key |
88
|
|
|
* @param $ret |
89
|
|
|
* @param array $tags |
90
|
|
|
* @param int $depth |
91
|
|
|
*/ |
92
|
|
|
public function getAllChildArray($key, &$ret, $tags = array(), $depth = 0) |
93
|
|
|
{ |
94
|
|
|
if (--$depth == 0) { |
95
|
|
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (isset($this->_tree[$key]['child'])) { |
99
|
|
|
foreach ($this->_tree[$key]['child'] as $childkey) { |
100
|
|
|
if (isset($this->_tree[$childkey]['obj'])): |
101
|
|
View Code Duplication |
if (count($tags) > 0) { |
|
|
|
|
102
|
|
|
foreach ($tags as $tag) { |
103
|
|
|
$ret['child'][$childkey][$tag] = $this->_tree[$childkey]['obj']->getVar($tag); |
104
|
|
|
} |
105
|
|
|
} else { |
106
|
|
|
$ret['child'][$childkey]['page_title'] = $this->_tree[$childkey]['obj']->getVar('page_title'); |
107
|
|
|
} |
108
|
|
|
endif; |
109
|
|
|
|
110
|
|
|
$this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param int $key |
117
|
|
|
* @param null $tags |
118
|
|
|
* @param int $depth |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public function &makeArrayTree($key = 0, $tags = null, $depth = 0) |
122
|
|
|
{ |
123
|
|
|
$ret = array(); |
124
|
|
|
if ($depth > 0) { |
125
|
|
|
$depth++; |
126
|
|
|
} |
127
|
|
|
$this->getAllChildArray($key, $ret, $tags, $depth); |
128
|
|
|
|
129
|
|
|
return $ret; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.