This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.php
More file actions
executable file
·117 lines (101 loc) · 2.81 KB
/
Menu.php
File metadata and controls
executable file
·117 lines (101 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* ======================================================================
* LICENSE: This file is subject to the terms and conditions defined in *
* file 'license.txt', which is part of this source code package. *
* ======================================================================
*/
/**
* Menu object
*
* @package AAM
* @author Vasyl Martyniuk <[email protected]>
*/
class AAM_Core_Object_Menu extends AAM_Core_Object {
/**
* Constructor
*
* @param AAM_Core_Subject $subject
*
* @return void
*
* @access public
*/
public function __construct(AAM_Core_Subject $subject) {
parent::__construct($subject);
$option = $this->getSubject()->readOption('menu');
if (empty($option)) {
$option = $this->getSubject()->inheritFromParent('menu');
}
$this->setOption($option);
}
/**
* Filter Menu List
*
* Keep in mind that this funciton only filter the menu items but do not
* restrict access to them. You have to explore roles and capabilities to
* control the full access to menus.
*
* @global array $menu
* @global array $submenu
*
* @return void
*
* @access public
*/
public function filter() {
global $menu, $submenu;
foreach ($menu as $id => $item) {
if ($this->has('menu-' . $item[2])) {
unset($menu[$id]);
}
if (!empty($submenu[$item[2]])) {
$this->filterSubmenu($item[2]);
}
}
}
/**
* Filter submenu
*
* @param string $parent
*
* @return void
*
* @access protected
* @global array $menu
* @global array $submenu
*/
protected function filterSubmenu($parent) {
global $submenu;
foreach ($submenu[$parent] as $id => $item) {
if ($this->has($item[2])) {
unset($submenu[$parent][$id]);
}
}
}
/**
* Check is menu defined
*
* Check if menu defined in options based on the id
*
* @param string $menu
*
* @return boolean
*
* @access public
*/
public function has($menu) {
//decode URL in case of any special characters like &
$decoded = htmlspecialchars_decode($menu);
$options = $this->getOption();
return !empty($options[$decoded]);
}
/**
* @inheritdoc
*/
public function save($menu, $granted) {
$option = $this->getOption();
$option[$menu] = $granted;
return $this->getSubject()->updateOption($option, 'menu');
}
}