1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This class contains a standard way of displaying side/drop down menus. |
||
5 | * |
||
6 | * @package ElkArte Forum |
||
7 | * @copyright ElkArte Forum contributors |
||
8 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
9 | * |
||
10 | * @version 2.0 dev |
||
11 | * |
||
12 | */ |
||
13 | |||
14 | namespace ElkArte\Menu; |
||
15 | |||
16 | use ElkArte\Errors\Errors; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | /** |
||
19 | * Class MenuArea |
||
20 | * |
||
21 | * This class will set and access the menu area options. The supported options are: |
||
22 | * |
||
23 | * areas is a named index as follows: |
||
24 | * - array $permission => Array of permissions to determine who can access this area |
||
25 | * - string $label => Optional text string for link (Otherwise $txt[$index] will be used) |
||
26 | * - string $controller => Name of controller required for this area |
||
27 | * - string $function => Method in controller to call when area is selected |
||
28 | * - string $icon => File name of an icon to use on the menu, if using a class set as transparent.png |
||
29 | * - string $class => CSS class name to apply to the icon img, used to apply a sprite icon |
||
30 | * - string $custom_url => URL to call for this menu item |
||
31 | * - string $token => token name to use |
||
32 | * - string $token_type => where to look for the returned token (get/post) |
||
33 | * - string $sc => session check where to look for returned session data (get/post) |
||
34 | * - bool $password => if the user will be required to enter login password |
||
35 | * - bool $enabled => Should this area even be enabled / accessible? |
||
36 | * - bool $hidden => If the area is visible in the menu |
||
37 | * - string $select => If set, references another area |
||
38 | * - array $subsections => Array of subsections for this menu area see MenuSubsections |
||
39 | * |
||
40 | * @package ElkArte\Menu |
||
41 | */ |
||
42 | class MenuArea extends MenuItem |
||
43 | { |
||
44 | /** @var string $select References another area to be highlighted while this one is active */ |
||
45 | protected $select = ''; |
||
46 | |||
47 | /** @var string $controller URL to use for this menu item. */ |
||
48 | protected $controller = ''; |
||
49 | |||
50 | /** @var callable $function function to call when area is selected. */ |
||
51 | protected $function; |
||
52 | |||
53 | /** @var string $icon File name of an icon to use on the menu, if using the sprite class, set as transparent.png */ |
||
54 | protected $icon = ''; |
||
55 | |||
56 | /** @var string $class Class name to apply to the icon img, used to apply a sprite icon */ |
||
57 | protected $class = ''; |
||
58 | |||
59 | /** @var bool $hidden Should this area be visible? */ |
||
60 | protected $hidden = false; |
||
61 | |||
62 | /** @var string $token Name of the token to validate */ |
||
63 | protected $token = ''; |
||
64 | |||
65 | /** @var string $tokenType where to look for our token, get, request, post. */ |
||
66 | protected $tokenType = ''; |
||
67 | |||
68 | /** @var string $sc session check where to look for the session data, get or post */ |
||
69 | protected $sc = ''; |
||
70 | |||
71 | /** @var string $customUrl custom URL to use for this menu item. */ |
||
72 | protected $customUrl; |
||
73 | |||
74 | /** @var bool $password is the user password required to make a change, profile only use? */ |
||
75 | protected $password = false; |
||
76 | |||
77 | /** @var array $subsections Array of subsections from this area. */ |
||
78 | private $subsections = []; |
||
79 | |||
80 | /** |
||
81 | * @return callable |
||
82 | */ |
||
83 | 2 | public function getFunction() |
|
84 | { |
||
85 | 2 | return $this->function; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param callable $function |
||
90 | * |
||
91 | * @return MenuArea |
||
92 | */ |
||
93 | 62 | public function setFunction($function) |
|
94 | { |
||
95 | 62 | $this->function = $function; |
|
96 | |||
97 | 62 | return $this; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | 56 | public function getIcon() |
|
104 | { |
||
105 | 56 | return $this->icon; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param string $icon |
||
110 | * |
||
111 | * @return MenuArea |
||
112 | */ |
||
113 | 62 | public function setIcon($icon) |
|
114 | { |
||
115 | 62 | $this->icon = $icon; |
|
116 | |||
117 | 62 | return $this; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | 2 | public function getController() |
|
124 | { |
||
125 | 2 | return $this->controller; |
|
126 | } |
||
127 | |||
128 | /** |
||
129 | * @param string $controller |
||
130 | * |
||
131 | * @return MenuArea |
||
132 | */ |
||
133 | 62 | public function setController($controller) |
|
134 | { |
||
135 | 62 | $this->controller = $controller; |
|
136 | |||
137 | 62 | return $this; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | 56 | public function getSelect() |
|
144 | { |
||
145 | 56 | return $this->select; |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param string $select |
||
150 | * |
||
151 | * @return MenuArea |
||
152 | */ |
||
153 | 62 | public function setSelect($select) |
|
154 | { |
||
155 | 62 | $this->select = $select; |
|
156 | |||
157 | 62 | return $this; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return string |
||
162 | */ |
||
163 | 18 | public function getClass() |
|
164 | { |
||
165 | 18 | return $this->class; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @param string $class |
||
170 | * |
||
171 | * @return MenuArea |
||
172 | */ |
||
173 | 62 | public function setClass($class) |
|
174 | { |
||
175 | 62 | $this->class = $class; |
|
176 | |||
177 | 62 | return $this; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * Set the url value |
||
182 | * |
||
183 | * @param string $url |
||
184 | * |
||
185 | * @return MenuItem |
||
186 | */ |
||
187 | 62 | public function setCustomUrl($url) |
|
188 | { |
||
189 | 62 | $this->customUrl = $url; |
|
190 | |||
191 | 62 | return $this; |
|
192 | } |
||
193 | |||
194 | /** |
||
195 | * @return bool |
||
196 | */ |
||
197 | 56 | public function isHidden() |
|
198 | { |
||
199 | 56 | return $this->hidden; |
|
200 | } |
||
201 | |||
202 | /** |
||
203 | * @param bool $hidden |
||
204 | * |
||
205 | * @return MenuArea |
||
206 | */ |
||
207 | 62 | public function setHidden($hidden) |
|
208 | { |
||
209 | 62 | $this->hidden = $hidden; |
|
210 | |||
211 | 62 | return $this; |
|
212 | } |
||
213 | |||
214 | /** |
||
215 | * @return bool |
||
216 | */ |
||
217 | public function isPassword() |
||
218 | { |
||
219 | return $this->password; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @param bool $password |
||
224 | * |
||
225 | * @return MenuArea |
||
226 | */ |
||
227 | 62 | public function setPassword($password) |
|
228 | { |
||
229 | 62 | $this->password = $password; |
|
230 | |||
231 | 62 | return $this; |
|
232 | } |
||
233 | |||
234 | /** |
||
235 | * Converts an object and any branches to an array, recursive. |
||
236 | * |
||
237 | * @param mixed $obj |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | 56 | public function toArray($obj) |
|
242 | { |
||
243 | 56 | if (!is_object($obj) && !is_array($obj)) |
|
244 | { |
||
245 | 56 | return $obj; |
|
246 | } |
||
247 | |||
248 | 56 | return array_map([$this, 'toArray'], is_array($obj) ? $obj : get_object_vars($obj)); |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * Get the subsections of the MenuArea |
||
253 | * |
||
254 | 58 | * @return array The array of subsections |
|
255 | */ |
||
256 | 58 | public function getSubsections() |
|
257 | { |
||
258 | return $this->subsections; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Get the token for this instance |
||
263 | * |
||
264 | * @return string The token for this instance |
||
265 | */ |
||
266 | public function getToken() |
||
267 | { |
||
268 | return $this->token; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | 62 | * Sets the token for authentication. |
|
273 | * |
||
274 | 62 | * @param string $token The authentication token. |
|
275 | * |
||
276 | 62 | * @return MenuArea |
|
277 | */ |
||
278 | public function setToken($token) |
||
279 | { |
||
280 | $this->token = $token; |
||
281 | |||
282 | return $this; |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * Get the token type of this instance. |
||
287 | * |
||
288 | * @return string The token type. |
||
289 | */ |
||
290 | public function getTokenType() |
||
291 | { |
||
292 | 62 | return $this->tokenType; |
|
293 | } |
||
294 | 62 | ||
295 | /** |
||
296 | 62 | * Set the token type for this object. |
|
297 | * |
||
298 | * @param string $tokenType The token type to be set. |
||
299 | * |
||
300 | * @return MenuArea |
||
301 | */ |
||
302 | public function setTokenType($tokenType) |
||
303 | { |
||
304 | $this->tokenType = $tokenType; |
||
305 | |||
306 | return $this; |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * Get the value of sc |
||
311 | * |
||
312 | 62 | * @return string The value of sc |
|
313 | */ |
||
314 | 62 | public function getSc() |
|
315 | { |
||
316 | 62 | return $this->sc; |
|
317 | } |
||
318 | |||
319 | /** |
||
320 | * Sets the value of sc property |
||
321 | * |
||
322 | * @param mixed $sc The value to set for sc property |
||
323 | * |
||
324 | * @return MenuArea |
||
325 | */ |
||
326 | public function setSc($sc) |
||
327 | 62 | { |
|
328 | $this->sc = $sc; |
||
329 | 62 | ||
330 | return $this; |
||
331 | 62 | } |
|
332 | |||
333 | 62 | /** |
|
334 | * Account for unique setter/getter items for this area |
||
335 | 60 | * |
|
336 | * @param array $arr |
||
337 | * |
||
338 | * @return MenuArea |
||
339 | * @throws \Exception |
||
340 | 62 | */ |
|
341 | protected function buildMoreFromArray($arr) |
||
342 | 62 | { |
|
343 | $this->url = $this->customUrl ?: $this->url; |
||
344 | |||
345 | if (isset($arr['subsections'])) |
||
346 | { |
||
347 | foreach ($arr['subsections'] as $var => $subsection) |
||
348 | { |
||
349 | $this->addSubsection($var, $subsection); |
||
350 | } |
||
351 | } |
||
352 | 62 | ||
353 | // Anything left over, currently for debug purposes |
||
354 | 62 | $this->anythingMissed($arr); |
|
355 | 62 | ||
356 | return $this; |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * Right now this is here just for debug. Do any addons create keys that we have not accounted for |
||
361 | * in the class? Should we simply just set anything that is not a defined var? |
||
362 | * |
||
363 | 62 | * @param array $arr |
|
364 | */ |
||
365 | private function anythingMissed($arr) |
||
366 | { |
||
367 | $missing = array_diff_key($arr, get_object_vars($this)); |
||
368 | foreach ($missing as $key => $value) |
||
369 | { |
||
370 | // Excluding our private key, anything missed? |
||
371 | 60 | if (!in_array($key, ['subsections', 'messages'])) |
|
372 | { |
||
373 | 60 | Errors::instance()->log_error('Depreciated: menu key: ' . $key . ' value: ' . $value, 'depreciated'); |
|
374 | } |
||
375 | 60 | } |
|
376 | } |
||
377 | |||
378 | /** |
||
379 | * Add a subsection to the menu area |
||
380 | * |
||
381 | * @param mixed $id The identifier of the subsection |
||
382 | * @param mixed $subsection The subsection to be added |
||
383 | * |
||
384 | * @return MenuArea Returns the current instance of MenuArea |
||
385 | */ |
||
386 | public function addSubsection($id, $subsection) |
||
387 | { |
||
388 | $this->subsections[$id] = $subsection; |
||
389 | |||
390 | return $this; |
||
391 | } |
||
392 | } |
||
393 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths