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