1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * @package Ultimate Menu mod |
||||||
5 | * @version 1.0.3 |
||||||
6 | * @author John Rayes <[email protected]> |
||||||
7 | * @copyright Copyright (c) 2014, John Rayes |
||||||
8 | * @license http://opensource.org/licenses/MIT MIT |
||||||
9 | */ |
||||||
10 | |||||||
11 | if (!defined('SMF')) |
||||||
12 | die('Hacking attempt...'); |
||||||
13 | |||||||
14 | function um_load_menu(&$menu_buttons) |
||||||
15 | { |
||||||
16 | global $smcFunc, $user_info, $scripturl, $context, $modSettings; |
||||||
17 | |||||||
18 | // Make damn sure we ALWAYS losd last. Priority: 100! |
||||||
19 | $hooks = explode(',', $modSettings['integrate_menu_buttons']); |
||||||
20 | $hook = end($hooks); |
||||||
21 | if (strpos($hook, 'um_load_menu') !== false) |
||||||
22 | { |
||||||
23 | remove_integration_function('integrate_menu_buttons', 'um_load_menu'); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
24 | add_integration_function('integrate_menu_buttons', 'um_load_menu'); |
||||||
0 ignored issues
–
show
The function
add_integration_function was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
25 | } |
||||||
26 | |||||||
27 | $db_buttons = @unserialize($modSettings['um_menu']); |
||||||
28 | |||||||
29 | if (empty($db_buttons)) |
||||||
30 | return $menu_buttons; |
||||||
31 | |||||||
32 | foreach ($db_buttons as $key => $row) |
||||||
33 | { |
||||||
34 | $temp_menu = array( |
||||||
35 | 'title' => $row['name'], |
||||||
36 | 'href' => ($row['type'] == 'forum' ? $scripturl . '?' : '') . $row['link'], |
||||||
37 | 'target' => $row['target'], |
||||||
38 | 'show' => (allowedTo('admin_forum') || count(array_intersect($user_info['groups'], explode(',', $row['permissions']))) >= 1) && $row['status'] == 'active', |
||||||
0 ignored issues
–
show
The function
allowedTo was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
39 | ); |
||||||
40 | |||||||
41 | foreach ($menu_buttons as $area => &$info) |
||||||
42 | { |
||||||
43 | if ($area == $row['parent']) |
||||||
44 | { |
||||||
45 | if ($row['position'] == 'before' || $row['position'] == 'after') |
||||||
46 | { |
||||||
47 | if (array_key_exists($row['parent'], $menu_buttons)) |
||||||
48 | { |
||||||
49 | insert_button(array($row['slug'] => $temp_menu), $menu_buttons, $row['parent'], $row['position']); |
||||||
50 | break; |
||||||
51 | } |
||||||
52 | } |
||||||
53 | |||||||
54 | if ($row['position'] == 'child_of') |
||||||
55 | { |
||||||
56 | $info['sub_buttons'][$row['slug']] = $temp_menu; |
||||||
57 | break; |
||||||
58 | } |
||||||
59 | } |
||||||
60 | |||||||
61 | if (isset($info['sub_buttons'][$row['parent']])) |
||||||
62 | { |
||||||
63 | if ($row['position'] == 'before' || $row['position'] == 'after') |
||||||
64 | { |
||||||
65 | insert_button(array($row['slug'] => $temp_menu), $info['sub_buttons'], $row['parent'], $row['position']); |
||||||
66 | break; |
||||||
67 | } |
||||||
68 | if ($row['position'] == 'child_of') |
||||||
69 | { |
||||||
70 | $info['sub_buttons'][$row['parent']]['sub_buttons'][$row['slug']] = $temp_menu; |
||||||
71 | break; |
||||||
72 | } |
||||||
73 | } |
||||||
74 | } |
||||||
75 | } |
||||||
76 | } |
||||||
77 | |||||||
78 | /** |
||||||
79 | * Gets all membergroups and filters them according to the parameters. |
||||||
80 | * |
||||||
81 | * @param string $checked comma-seperated list of all id_groups to be checked (have a mark in the checkbox). Default is an empty array. |
||||||
82 | * @param string $disallowed comma-seperated list of all id_groups that are skipped. Default is an empty array. |
||||||
83 | * @param bool $inherited whether or not to filter out the inherited groups. Default is false. |
||||||
84 | * @return array all the membergroups filtered according to the parameters; empty array if something went wrong. |
||||||
85 | * @since 1.0 |
||||||
86 | */ |
||||||
87 | function list_groups($checked, $disallowed = '', $inherited = false, $permission = null, $board_id = null) |
||||||
88 | { |
||||||
89 | global $context, $modSettings, $smcFunc, $sourcedir, $txt; |
||||||
90 | |||||||
91 | // We'll need this for loading up the names of each group. |
||||||
92 | if (!loadLanguage('ManageBoards')) |
||||||
0 ignored issues
–
show
The function
loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
93 | loadLanguage('ManageBoards'); |
||||||
94 | |||||||
95 | $checked = explode(',', $checked); |
||||||
96 | $disallowed = explode(',', $disallowed); |
||||||
97 | |||||||
98 | // Are we also looking up permissions? |
||||||
99 | if ($permission !== null) |
||||||
100 | { |
||||||
101 | require_once($sourcedir . '/Subs-Members.php'); |
||||||
102 | $member_groups = groupsAllowedTo($permission, $board_id); |
||||||
0 ignored issues
–
show
The function
groupsAllowedTo was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
103 | $disallowed = array_diff(array_keys(list_groups(-3)), $member_groups['allowed']); |
||||||
104 | } |
||||||
105 | |||||||
106 | $groups = array(); |
||||||
107 | |||||||
108 | if (!in_array(-1, $disallowed)) |
||||||
109 | // Guests |
||||||
110 | $groups[-1] = array( |
||||||
111 | 'id' => -1, |
||||||
112 | 'name' => $txt['parent_guests_only'], |
||||||
113 | 'checked' => in_array(-1, $checked) || in_array(-3, $checked), |
||||||
114 | 'is_post_group' => false, |
||||||
115 | ); |
||||||
116 | |||||||
117 | if (!in_array(0, $disallowed)) |
||||||
118 | // Regular Members |
||||||
119 | $groups[0] = array( |
||||||
120 | 'id' => 0, |
||||||
121 | 'name' => $txt['parent_members_only'], |
||||||
122 | 'checked' => in_array(0, $checked) || in_array(-3, $checked), |
||||||
123 | 'is_post_group' => false, |
||||||
124 | ); |
||||||
125 | |||||||
126 | // Load membergroups. |
||||||
127 | $request = $smcFunc['db_query']('', ' |
||||||
128 | SELECT group_name, id_group, min_posts |
||||||
129 | FROM {db_prefix}membergroups |
||||||
130 | WHERE id_group > {int:is_zero}' . (!$inherited ? ' |
||||||
131 | AND id_parent = {int:not_inherited}' : '') . (!$inherited && empty($modSettings['permission_enable_postgroups']) ? ' |
||||||
132 | AND min_posts = {int:min_posts}' : ''), |
||||||
133 | array( |
||||||
134 | 'is_zero' => 0, |
||||||
135 | 'not_inherited' => -2, |
||||||
136 | 'min_posts' => -1, |
||||||
137 | ) |
||||||
138 | ); |
||||||
139 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||||||
140 | if (!in_array($row['id_group'], $disallowed)) |
||||||
141 | $groups[(int) $row['id_group']] = array( |
||||||
142 | 'id' => $row['id_group'], |
||||||
143 | 'name' => trim($row['group_name']), |
||||||
144 | 'checked' => in_array($row['id_group'], $checked) || in_array(-3, $checked), |
||||||
145 | 'is_post_group' => $row['min_posts'] != -1, |
||||||
146 | ); |
||||||
147 | $smcFunc['db_free_result']($request); |
||||||
148 | |||||||
149 | asort($groups); |
||||||
150 | |||||||
151 | return $groups; |
||||||
152 | } |
||||||
153 | |||||||
154 | function insert_button($needle, &$haystack, $insertion_point, $where = 'after') |
||||||
155 | { |
||||||
156 | if (array_key_exists($insertion_point, $haystack)) |
||||||
157 | { |
||||||
158 | $offset = 0; |
||||||
159 | |||||||
160 | foreach ($haystack as $area => $dummy) |
||||||
161 | if (++$offset && $area == $insertion_point) |
||||||
162 | break; |
||||||
163 | |||||||
164 | if ($where == 'before') |
||||||
165 | $offset--; |
||||||
166 | |||||||
167 | $haystack = array_slice($haystack, 0, $offset, true) + $needle + array_slice($haystack, $offset, null, true); |
||||||
168 | } |
||||||
169 | else |
||||||
170 | foreach ($haystack as $stack) |
||||||
171 | if (array_key_exists($insertion_point, $haystack[$stack])) |
||||||
172 | { |
||||||
173 | $offset = 0; |
||||||
174 | |||||||
175 | foreach ($haystack[$stack] as $area => $dummy) |
||||||
176 | if (++$offset && $area == $insertion_point) |
||||||
177 | break; |
||||||
178 | |||||||
179 | if ($where == 'before') |
||||||
180 | $offset--; |
||||||
181 | |||||||
182 | $haystack[$stack] = array_slice($haystack[$stack], 0, $offset, true) + $needle + array_slice($haystack[$stack], $offset, null, true); |
||||||
183 | break; |
||||||
184 | } |
||||||
185 | } |
||||||
186 | |||||||
187 | function um_admin_areas(&$admin_areas) |
||||||
188 | { |
||||||
189 | global $txt; |
||||||
190 | |||||||
191 | loadLanguage('ManageUltimateMenu'); |
||||||
0 ignored issues
–
show
The function
loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
192 | $admin_areas['config']['areas']['umen'] = array( |
||||||
193 | 'label' => $txt['um_admin_menu'], |
||||||
194 | 'file' => 'ManageUltimateMenu.php', |
||||||
195 | 'function' => 'Menu', |
||||||
196 | 'icon' => 'umen.png', |
||||||
197 | 'subsections' => array( |
||||||
198 | 'manmenu' => array($txt['um_admin_manage_menu'], ''), |
||||||
199 | 'addbutton' => array($txt['um_admin_add_button'], ''), |
||||||
200 | ), |
||||||
201 | ); |
||||||
202 | } |
||||||
203 | |||||||
204 | ?> |
||||||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||||||
205 |