-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericMenu.template.php
279 lines (238 loc) · 10 KB
/
GenericMenu.template.php
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2022 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1.0
*/
/**
* This contains the HTML for the menu bar at the top of the admin center.
*/
function template_generic_menu_dropdown_above()
{
global $context, $txt;
// Which menu are we rendering?
$context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
$menu_context = &$context['menu_data_' . $context['cur_menu_id']];
$menu_label = isset($context['admin_menu_name']) ? $txt['admin_center'] : (isset($context['moderation_menu_name']) ? $txt['moderation_center'] : '');
// Load the menu
echo '
<nav id="genericmenu" class="navbar navbar-expand-lg" aria-label="', sprintf($txt['mobile_generic_menu'], $menu_label), '">
<a class="navbar-brand d-lg-none">', sprintf($txt['mobile_generic_menu'], $menu_label), '</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#genericNavbar" aria-controls="genericNavbar" aria-expanded="false" aria-label="', $txt['st_menu_toggle'], '">
<i class="fa fa-bars"></i>
</button>
', template_generic_menu($menu_context, $menu_label), '
</nav>
<script>
$( ".mobile_generic_menu_', $context['cur_menu_id'], '" ).click(function() {
$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).show();
});
$( ".hide_popup" ).click(function() {
$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).hide();
});
</script>';
echo '
<div id="admin_content">
', template_generic_menu_tabs($menu_context);
}
/**
* Part of the admin layer - used with generic_menu_dropdown_above to close the admin content div.
*/
function template_generic_menu_dropdown_below()
{
echo '
</div><!-- #admin_content -->';
}
/**
* The template for displaying a menu
*
* @param array $menu_context An array of menu information
*/
function template_generic_menu(&$menu_context)
{
global $context;
echo '
<div class="collapse navbar-collapse" id="genericNavbar">
<ul class="navbar-nav dropdown_menu_', $context['cur_menu_id'], '">';
// Main areas first.
foreach ($menu_context['sections'] as $section)
{
echo '
<li class="nav-item', !empty($section['areas']) ? ' dropdown' : '', '">
<a class="nav-link', !empty($section['areas']) ? ' dropdown-toggle' : '', !empty($section['selected']) ? ' active' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '"', !empty($section['areas']) ? ' role="button" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside"' : '', '>
<span class="textmenu">', $section['title'], '</span>
', !empty($section['amt']) ? ' <span class="amt">' . $section['amt'] . '</span>' : '', '
</a>
<ul class="dropdown-menu">';
// For every area of this section show a link to that area (bold if it's currently selected.)
// @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
foreach ($section['areas'] as $i => $area)
{
// Not supposed to be printed?
if (empty($area['label']))
continue;
echo '
<li class="dropend">
<a class="dropdown-item ', $area['icon_class'], !empty($area['selected']) ? ' active' : '', !empty($area['subsections']) && empty($area['hide_subsections']) ? ' dropdown-toggle' : '', '" href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '"', !empty($area['subsections']) && empty($area['hide_subsections']) ? ' role="button" data-bs-toggle="dropdown" aria-expanded="false"' : '', '>
', $area['icon'], '
<span class="textmenu">', $area['label'],'</span>
', !empty($area['amt']) ? ' <span class="amt">' . $area['amt'] . '</span>' : '', '
</a>';
// Is this the current area, or just some area?
if (!empty($area['selected']) && empty($context['tabs']))
$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
// Are there any subsections?
if (!empty($area['subsections']) && empty($area['hide_subsections']))
{
echo '
<ul class="dropdown-menu">';
foreach ($area['subsections'] as $sa => $sub)
{
if (!empty($sub['disabled']))
continue;
$url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
echo '
<li>
<a class="dropdown-item', !empty($sub['selected']) ? ' active' : '', '" href="', $url, $menu_context['extra_parameters'], '">
<span class="textmenu">', $sub['label'], '</span>
', !empty($sub['amt']) ? ' <span class="amt">' . $sub['amt'] . '</span>' : '', '
</a>
</li>';
}
echo '
</ul>';
}
echo '
</li>';
}
echo '
</ul>
</li>';
}
echo '
</ul>
</div>';
}
/**
* The code for displaying the menu
*
* @param array $menu_context An array of menu context data
*/
function template_generic_menu_tabs(&$menu_context)
{
global $context, $settings, $scripturl, $txt;
// Handy shortcut.
$tab_context = &$menu_context['tab_data'];
if (!empty($tab_context['title']))
{
echo '
<div class="cat_bar">
<h3 class="catbg">';
// Exactly how many tabs do we have?
if (!empty($context['tabs']))
{
foreach ($context['tabs'] as $id => $tab)
{
// Can this not be accessed?
if (!empty($tab['disabled']))
{
$tab_context['tabs'][$id]['disabled'] = true;
continue;
}
// Did this not even exist - or do we not have a label?
if (!isset($tab_context['tabs'][$id]))
$tab_context['tabs'][$id] = array('label' => $tab['label']);
elseif (!isset($tab_context['tabs'][$id]['label']))
$tab_context['tabs'][$id]['label'] = $tab['label'];
// Has a custom URL defined in the main admin structure?
if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
$tab_context['tabs'][$id]['url'] = $tab['url'];
// Any additional parameters for the url?
if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
$tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
// Has it been deemed selected?
if (!empty($tab['is_selected']))
$tab_context['tabs'][$id]['is_selected'] = true;
// Does it have its own help?
if (!empty($tab['help']))
$tab_context['tabs'][$id]['help'] = $tab['help'];
// Is this the last one?
if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
$tab_context['tabs'][$id]['is_last'] = true;
}
// Find the selected tab
foreach ($tab_context['tabs'] as $sa => $tab)
{
if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
{
$selected_tab = $tab;
$tab_context['tabs'][$sa]['is_selected'] = true;
}
}
}
// Show an icon and/or a help item?
if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']) || !empty($selected_tab['icon']) || !empty($tab_context['icon']) || !empty($selected_tab['help']) || !empty($tab_context['help']))
{
if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']))
echo '
<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
echo '
<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';
if (!empty($selected_tab['help']) || !empty($tab_context['help']))
echo '
<a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="', $txt['help'], '"></span></a>';
echo $tab_context['title'];
}
else
echo '
', $tab_context['title'];
echo '
</h3>';
// The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available
if (function_exists('template_admin_quick_search'))
template_admin_quick_search();
echo '
</div>';
}
// Shall we use the tabs? Yes, it's the only known way!
if (!empty($selected_tab['description']) || !empty($tab_context['description']))
echo '
<p class="information">
', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
</p>';
// Print out all the items in this tab (if any).
if (!empty($context['tabs']))
{
// The admin tabs.
echo '
<nav id="adm_submenus" class="navbar navbar-expand-lg" aria-label="', sprintf($txt['mobile_generic_menu'], $tab_context['title']), '">
<a class="navbar-brand d-lg-none">', sprintf($txt['mobile_generic_menu'], $tab_context['title']), '</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#genericSubmenu" aria-controls="genericSubmenu" aria-expanded="false" aria-label="', $txt['st_menu_toggle'], '">
<i class="fa fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="genericSubmenu">
<ul class="navbar-nav dropdown_menu_', $context['cur_menu_id'], '_tabs">';
foreach ($tab_context['tabs'] as $sa => $tab)
{
if (!empty($tab['disabled']))
continue;
echo '
<li class="nav-item">
<a class="nav-link', !empty($tab['is_selected']) ? ' active"' : '', '" href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">
<span class="textmenu">', $tab['label'], '</span>
</a>
</li>';
}
// The end of tabs
echo '
</ul>
</div>
</nav><!-- #adm_submenus -->';
}
}