1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Simple Machines Forum (SMF) |
4
|
|
|
* |
5
|
|
|
* @package SMF |
6
|
|
|
* @author Simple Machines http://www.simplemachines.org |
7
|
|
|
* @copyright 2018 Simple Machines and individual contributors |
8
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
9
|
|
|
* |
10
|
|
|
* @version 2.1 Beta 4 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This contains the HTML for the menu bar at the top of the admin center. |
15
|
|
|
*/ |
16
|
|
|
function template_generic_menu_dropdown_above() |
17
|
|
|
{ |
18
|
|
|
global $context, $txt; |
|
|
|
|
19
|
|
|
|
20
|
|
|
// Which menu are we rendering? |
21
|
|
|
$context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1; |
22
|
|
|
$menu_context = &$context['menu_data_' . $context['cur_menu_id']]; |
23
|
|
|
|
24
|
|
|
// Load the menu |
25
|
|
|
// Add mobile menu as well |
26
|
|
|
echo ' |
27
|
|
|
<a class="menu_icon mobile_generic_menu_', $context['cur_menu_id'], '"></a> |
28
|
|
|
<div id="genericmenu"> |
29
|
|
|
<div id="mobile_generic_menu_', $context['cur_menu_id'], '" class="popup_container"> |
30
|
|
|
<div class="popup_window description"> |
31
|
|
|
<div class="popup_heading"> |
32
|
|
|
', $txt['mobile_user_menu'], ' |
33
|
|
|
<a href="javascript:void(0);" class="generic_icons hide_popup"></a> |
34
|
|
|
</div> |
35
|
|
|
', template_generic_menu($menu_context), ' |
36
|
|
|
</div> |
37
|
|
|
</div> |
38
|
|
|
</div> |
39
|
|
|
<script> |
40
|
|
|
$( ".mobile_generic_menu_', $context['cur_menu_id'], '" ).click(function() { |
41
|
|
|
$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).show(); |
42
|
|
|
}); |
43
|
|
|
$( ".hide_popup" ).click(function() { |
44
|
|
|
$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).hide(); |
45
|
|
|
}); |
46
|
|
|
</script>'; |
47
|
|
|
|
48
|
|
|
// This is the main table - we need it so we can keep the content to the right of it. |
49
|
|
|
echo ' |
50
|
|
|
<div id="admin_content">'; |
51
|
|
|
|
52
|
|
|
// It's possible that some pages have their own tabs they wanna force... |
53
|
|
|
// if (!empty($context['tabs'])) |
54
|
|
|
template_generic_menu_tabs($menu_context); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Part of the admin layer - used with generic_menu_dropdown_above to close the admin content div. |
59
|
|
|
*/ |
60
|
|
|
function template_generic_menu_dropdown_below() |
61
|
|
|
{ |
62
|
|
|
echo ' |
63
|
|
|
</div><!-- #admin_content -->'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function template_generic_menu(&$menu_context) |
67
|
|
|
{ |
68
|
|
|
global $context; |
|
|
|
|
69
|
|
|
|
70
|
|
|
echo ' |
71
|
|
|
<div class="generic_menu"> |
72
|
|
|
<ul class="dropmenu dropdown_menu_', $context['cur_menu_id'], '">'; |
73
|
|
|
|
74
|
|
|
// Main areas first. |
75
|
|
|
foreach ($menu_context['sections'] as $section) |
76
|
|
|
{ |
77
|
|
|
echo ' |
78
|
|
|
<li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'], '</a> |
79
|
|
|
<ul>'; |
80
|
|
|
|
81
|
|
|
// For every area of this section show a link to that area (bold if it's currently selected.) |
82
|
|
|
// @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required. |
|
|
|
|
83
|
|
|
foreach ($section['areas'] as $i => $area) |
84
|
|
|
{ |
85
|
|
|
// Not supposed to be printed? |
86
|
|
|
if (empty($area['label'])) |
87
|
|
|
continue; |
88
|
|
|
|
89
|
|
|
echo ' |
90
|
|
|
<li', !empty($area['subsections']) ? ' class="subsections"' : '', '> |
91
|
|
|
<a class="', $area['icon_class'], !empty($area['selected']) ? ' chosen ' : '', '" href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '">', $area['icon'], $area['label'], '</a>'; |
92
|
|
|
|
93
|
|
|
// Is this the current area, or just some area? |
94
|
|
|
if (!empty($area['selected']) && empty($context['tabs'])) |
95
|
|
|
$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array(); |
96
|
|
|
|
97
|
|
|
// Are there any subsections? |
98
|
|
|
if (!empty($area['subsections'])) |
99
|
|
|
{ |
100
|
|
|
echo ' |
101
|
|
|
<ul>'; |
102
|
|
|
|
103
|
|
|
foreach ($area['subsections'] as $sa => $sub) |
104
|
|
|
{ |
105
|
|
|
if (!empty($sub['disabled'])) |
106
|
|
|
continue; |
107
|
|
|
|
108
|
|
|
$url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa; |
109
|
|
|
|
110
|
|
|
echo ' |
111
|
|
|
<li> |
112
|
|
|
<a ', !empty($sub['selected']) ? 'class="chosen" ' : '', ' href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], '</a> |
113
|
|
|
</li>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
echo ' |
117
|
|
|
</ul>'; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
echo ' |
121
|
|
|
</li>'; |
122
|
|
|
} |
123
|
|
|
echo ' |
124
|
|
|
</ul> |
125
|
|
|
</li>'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
echo ' |
129
|
|
|
</ul><!-- .dropmenu --> |
130
|
|
|
</div><!-- .generic_menu -->'; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* The code for displaying the menu |
135
|
|
|
* |
136
|
|
|
* @param array $menu_context An array of menu context data |
137
|
|
|
*/ |
138
|
|
|
function template_generic_menu_tabs(&$menu_context) |
139
|
|
|
{ |
140
|
|
|
global $context, $settings, $scripturl, $txt; |
|
|
|
|
141
|
|
|
|
142
|
|
|
// Handy shortcut. |
143
|
|
|
$tab_context = &$menu_context['tab_data']; |
144
|
|
|
|
145
|
|
|
if (!empty($tab_context['title'])) |
146
|
|
|
{ |
147
|
|
|
echo ' |
148
|
|
|
<div class="cat_bar">', (function_exists('template_admin_quick_search') ? ' |
149
|
|
|
<form action="' . $scripturl . '?action=admin;area=search" method="post" accept-charset="' . $context['character_set'] . '">' : ''), ' |
150
|
|
|
<h3 class="catbg">'; |
151
|
|
|
|
152
|
|
|
// The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available |
153
|
|
|
if (function_exists('template_admin_quick_search')) |
154
|
|
|
template_admin_quick_search(); |
155
|
|
|
|
156
|
|
|
// Exactly how many tabs do we have? |
157
|
|
|
if (!empty($context['tabs'])) |
158
|
|
|
{ |
159
|
|
|
foreach ($context['tabs'] as $id => $tab) |
160
|
|
|
{ |
161
|
|
|
// Can this not be accessed? |
162
|
|
|
if (!empty($tab['disabled'])) |
163
|
|
|
{ |
164
|
|
|
$tab_context['tabs'][$id]['disabled'] = true; |
165
|
|
|
continue; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
// Did this not even exist - or do we not have a label? |
169
|
|
|
if (!isset($tab_context['tabs'][$id])) |
170
|
|
|
$tab_context['tabs'][$id] = array('label' => $tab['label']); |
171
|
|
View Code Duplication |
elseif (!isset($tab_context['tabs'][$id]['label'])) |
172
|
|
|
$tab_context['tabs'][$id]['label'] = $tab['label']; |
173
|
|
|
|
174
|
|
|
// Has a custom URL defined in the main admin structure? |
175
|
|
View Code Duplication |
if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url'])) |
176
|
|
|
$tab_context['tabs'][$id]['url'] = $tab['url']; |
177
|
|
|
|
178
|
|
|
// Any additional paramaters for the url? |
179
|
|
View Code Duplication |
if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params'])) |
180
|
|
|
$tab_context['tabs'][$id]['add_params'] = $tab['add_params']; |
181
|
|
|
|
182
|
|
|
// Has it been deemed selected? |
183
|
|
View Code Duplication |
if (!empty($tab['is_selected'])) |
184
|
|
|
$tab_context['tabs'][$id]['is_selected'] = true; |
185
|
|
|
|
186
|
|
|
// Does it have its own help? |
187
|
|
View Code Duplication |
if (!empty($tab['help'])) |
188
|
|
|
$tab_context['tabs'][$id]['help'] = $tab['help']; |
189
|
|
|
|
190
|
|
|
// Is this the last one? |
191
|
|
|
if (!empty($tab['is_last']) && !isset($tab_context['override_last'])) |
192
|
|
|
$tab_context['tabs'][$id]['is_last'] = true; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// Find the selected tab |
196
|
|
|
foreach ($tab_context['tabs'] as $sa => $tab) |
197
|
|
|
{ |
198
|
|
View Code Duplication |
if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa)) |
199
|
|
|
{ |
200
|
|
|
$selected_tab = $tab; |
201
|
|
|
$tab_context['tabs'][$sa]['is_selected'] = true; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
// Show an icon and/or a help item? |
207
|
|
|
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'])) |
208
|
|
|
{ |
209
|
|
|
if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class'])) |
210
|
|
|
echo ' |
211
|
|
|
<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>'; |
212
|
|
View Code Duplication |
elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon'])) |
213
|
|
|
echo ' |
214
|
|
|
<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">'; |
215
|
|
|
|
216
|
|
View Code Duplication |
if (!empty($selected_tab['help']) || !empty($tab_context['help'])) |
217
|
|
|
echo ' |
218
|
|
|
<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="generic_icons help" title="', $txt['help'], '"></span></a>'; |
219
|
|
|
|
220
|
|
|
echo $tab_context['title']; |
221
|
|
|
} |
222
|
|
|
else |
223
|
|
|
echo ' |
224
|
|
|
', $tab_context['title']; |
225
|
|
|
|
226
|
|
|
echo ' |
227
|
|
|
</h3>', (function_exists('template_admin_quick_search') ? ' |
228
|
|
|
</form>' : ''), ' |
229
|
|
|
</div><!-- .cat_bar -->'; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// Shall we use the tabs? Yes, it's the only known way! |
233
|
|
|
if (!empty($selected_tab['description']) || !empty($tab_context['description'])) |
234
|
|
|
echo ' |
235
|
|
|
<p class="information"> |
236
|
|
|
', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], ' |
237
|
|
|
</p>'; |
238
|
|
|
|
239
|
|
|
// Print out all the items in this tab (if any). |
240
|
|
|
if (!empty($context['tabs'])) |
241
|
|
|
{ |
242
|
|
|
// The admin tabs. |
243
|
|
|
echo ' |
244
|
|
|
<div id="adm_submenus"> |
245
|
|
|
<ul class="dropmenu">'; |
246
|
|
|
|
247
|
|
|
foreach ($tab_context['tabs'] as $sa => $tab) |
248
|
|
|
{ |
249
|
|
|
if (!empty($tab['disabled'])) |
250
|
|
|
continue; |
251
|
|
|
|
252
|
|
|
if (!empty($tab['is_selected'])) |
253
|
|
|
echo ' |
254
|
|
|
<li> |
255
|
|
|
<a class="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'] : '', '">', $tab['label'], '</a> |
256
|
|
|
</li>'; |
257
|
|
|
else |
258
|
|
|
echo ' |
259
|
|
|
<li> |
260
|
|
|
<a 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'] : '', '">', $tab['label'], '</a> |
261
|
|
|
</li>'; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// The end of tabs |
265
|
|
|
echo ' |
266
|
|
|
</ul> |
267
|
|
|
</div><!-- #adm_submenus -->'; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
?> |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state