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 load last. Priority: 100! |
19
|
|
|
if (substr($modSettings['integrate_menu_buttons'], -12) !== 'um_load_menu') |
20
|
|
|
{ |
21
|
|
|
remove_integration_function('integrate_menu_buttons', 'um_load_menu'); |
22
|
|
|
add_integration_function('integrate_menu_buttons', 'um_load_menu'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$num_buttons = isset($modSettings['um_count']) |
26
|
|
|
? $modSettings['um_count'] |
27
|
|
|
: 0; |
28
|
|
|
|
29
|
|
|
for ($i = 1; $i <= $num_buttons; $i++) |
30
|
|
|
{ |
31
|
|
|
$key = 'um_button_' . $i; |
32
|
|
|
if (!isset($modSettings[$key])) |
33
|
|
|
break; |
34
|
|
|
$row = json_decode($modSettings[$key], true); |
35
|
|
|
$temp_menu = array( |
36
|
|
|
'title' => $row['name'], |
37
|
|
|
'href' => ($row['type'] == 'forum' ? $scripturl . '?' : '') . $row['link'], |
38
|
|
|
'target' => $row['target'], |
39
|
|
|
'show' => (allowedTo('admin_forum') || count(array_intersect($user_info['groups'], explode(',', $row['permissions']))) >= 1) && $row['status'] == 'active', |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
recursive_button($temp_menu, $menu_buttons, $row['parent'], $row['position'], $key); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function recursive_button(array $needle, array &$haystack, $insertion_point, $where, $key) |
47
|
|
|
{ |
48
|
|
|
foreach ($haystack as $area => &$info) |
49
|
|
|
{ |
50
|
|
|
if ($area == $insertion_point) |
51
|
|
|
{ |
52
|
|
|
if ($where == 'before' || $where == 'after') |
53
|
|
|
{ |
54
|
|
|
insert_button(array($key => $needle), $haystack, $insertion_point, $where); |
55
|
|
|
break; |
56
|
|
|
} |
57
|
|
|
elseif ($where == 'child_of') |
58
|
|
|
{ |
59
|
|
|
$info['sub_buttons'][$key] = $needle; |
60
|
|
|
break; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
elseif (!empty($info['sub_buttons'])) |
64
|
|
|
recursive_button($needle, $info['sub_buttons'], $insertion_point, $where, $key); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function insert_button(array $needle, array &$haystack, $insertion_point, $where = 'after') |
69
|
|
|
{ |
70
|
|
|
$offset = 0; |
71
|
|
|
|
72
|
|
|
foreach ($haystack as $area => $dummy) |
73
|
|
|
if (++$offset && $area == $insertion_point) |
74
|
|
|
break; |
75
|
|
|
|
76
|
|
|
if ($where == 'before') |
77
|
|
|
$offset--; |
78
|
|
|
|
79
|
|
|
$haystack = array_slice($haystack, 0, $offset, true) + $needle + array_slice($haystack, $offset, null, true); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function um_admin_areas(&$admin_areas) |
83
|
|
|
{ |
84
|
|
|
global $txt; |
85
|
|
|
|
86
|
|
|
loadLanguage('ManageUltimateMenu'); |
87
|
|
|
$admin_areas['config']['areas']['umen'] = array( |
88
|
|
|
'label' => $txt['um_admin_menu'], |
89
|
|
|
'file' => 'ManageUltimateMenu.php', |
90
|
|
|
'function' => function () { |
91
|
|
|
new ManageUltimateMenu; |
92
|
|
|
}, |
93
|
|
|
'icon' => 'umen.png', |
94
|
|
|
'subsections' => array( |
95
|
|
|
'manmenu' => array($txt['um_admin_manage_menu'], ''), |
96
|
|
|
'addbutton' => array($txt['um_admin_add_button'], ''), |
97
|
|
|
), |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
?> |
102
|
|
|
|