Issues (1061)

Themes/default/GenericMenu.template.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines https://www.simplemachines.org
7
 * @copyright 2020 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC2
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="main_icons hide_popup"></a>
34
				</div>
35
				', template_generic_menu($menu_context), '
0 ignored issues
show
Are you sure the usage of template_generic_menu($menu_context) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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
/**
67
 * The template for displaying a menu
68
 *
69
 * @param array $menu_context An array of menu information
70
 */
71
function template_generic_menu(&$menu_context)
72
{
73
	global $context;
74
75
	echo '
76
				<div class="generic_menu">
77
					<ul class="dropmenu dropdown_menu_', $context['cur_menu_id'], '">';
78
79
	// Main areas first.
80
	foreach ($menu_context['sections'] as $section)
81
	{
82
		echo '
83
						<li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'], !empty($section['amt']) ? ' <span class="amt">' . $section['amt'] . '</span>' : '', '</a>
84
							<ul>';
85
86
		// For every area of this section show a link to that area (bold if it's currently selected.)
87
		// @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
88
		foreach ($section['areas'] as $i => $area)
89
		{
90
			// Not supposed to be printed?
91
			if (empty($area['label']))
92
				continue;
93
94
			echo '
95
								<li', !empty($area['subsections']) && empty($area['hide_subsections']) ? ' class="subsections"' : '', '>
96
									<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'], !empty($area['amt']) ? ' <span class="amt">' . $area['amt'] . '</span>' : '', '</a>';
97
98
			// Is this the current area, or just some area?
99
			if (!empty($area['selected']) && empty($context['tabs']))
100
				$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
101
102
			// Are there any subsections?
103
			if (!empty($area['subsections']) && empty($area['hide_subsections']))
104
			{
105
				echo '
106
									<ul>';
107
108
				foreach ($area['subsections'] as $sa => $sub)
109
				{
110
					if (!empty($sub['disabled']))
111
						continue;
112
113
					$url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
114
115
					echo '
116
										<li>
117
											<a ', !empty($sub['selected']) ? 'class="chosen" ' : '', ' href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], !empty($sub['amt']) ? ' <span class="amt">' . $sub['amt'] . '</span>' : '', '</a>
118
										</li>';
119
				}
120
121
				echo '
122
									</ul>';
123
			}
124
125
			echo '
126
								</li>';
127
		}
128
		echo '
129
							</ul>
130
						</li>';
131
	}
132
133
	echo '
134
					</ul><!-- .dropmenu -->
135
				</div><!-- .generic_menu -->';
136
}
137
138
/**
139
 * The code for displaying the menu
140
 *
141
 * @param array $menu_context An array of menu context data
142
 */
143
function template_generic_menu_tabs(&$menu_context)
144
{
145
	global $context, $settings, $scripturl, $txt;
146
147
	// Handy shortcut.
148
	$tab_context = &$menu_context['tab_data'];
149
150
	if (!empty($tab_context['title']))
151
	{
152
		echo '
153
					<div class="cat_bar">', (function_exists('template_admin_quick_search') ? '
154
						<form action="' . $scripturl . '?action=admin;area=search" method="post" accept-charset="' . $context['character_set'] . '">' : ''), '
155
							<h3 class="catbg">';
156
157
		// The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available
158
		if (function_exists('template_admin_quick_search'))
159
			template_admin_quick_search();
160
161
		// Exactly how many tabs do we have?
162
		if (!empty($context['tabs']))
163
		{
164
			foreach ($context['tabs'] as $id => $tab)
165
			{
166
				// Can this not be accessed?
167
				if (!empty($tab['disabled']))
168
				{
169
					$tab_context['tabs'][$id]['disabled'] = true;
170
					continue;
171
				}
172
173
				// Did this not even exist - or do we not have a label?
174
				if (!isset($tab_context['tabs'][$id]))
175
					$tab_context['tabs'][$id] = array('label' => $tab['label']);
176
				elseif (!isset($tab_context['tabs'][$id]['label']))
177
					$tab_context['tabs'][$id]['label'] = $tab['label'];
178
179
				// Has a custom URL defined in the main admin structure?
180
				if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
181
					$tab_context['tabs'][$id]['url'] = $tab['url'];
182
183
				// Any additional parameters for the url?
184
				if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
185
					$tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
186
187
				// Has it been deemed selected?
188
				if (!empty($tab['is_selected']))
189
					$tab_context['tabs'][$id]['is_selected'] = true;
190
191
				// Does it have its own help?
192
				if (!empty($tab['help']))
193
					$tab_context['tabs'][$id]['help'] = $tab['help'];
194
195
				// Is this the last one?
196
				if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
197
					$tab_context['tabs'][$id]['is_last'] = true;
198
			}
199
200
			// Find the selected tab
201
			foreach ($tab_context['tabs'] as $sa => $tab)
202
			{
203
				if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
204
				{
205
					$selected_tab = $tab;
206
					$tab_context['tabs'][$sa]['is_selected'] = true;
207
				}
208
			}
209
		}
210
211
		// Show an icon and/or a help item?
212
		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']))
213
		{
214
			if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']))
215
				echo '
216
								<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
217
			elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
218
				echo '
219
								<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';
220
221
			if (!empty($selected_tab['help']) || !empty($tab_context['help']))
222
				echo '
223
								<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>';
224
225
			echo $tab_context['title'];
226
		}
227
		else
228
			echo '
229
								', $tab_context['title'];
230
231
		echo '
232
							</h3>', (function_exists('template_admin_quick_search') ? '
233
						</form>' : ''), '
234
					</div><!-- .cat_bar -->';
235
	}
236
237
	// Shall we use the tabs? Yes, it's the only known way!
238
	if (!empty($selected_tab['description']) || !empty($tab_context['description']))
239
		echo '
240
					<p class="information">
241
						', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
242
					</p>';
243
244
	// Print out all the items in this tab (if any).
245
	if (!empty($context['tabs']))
246
	{
247
		// The admin tabs.
248
		echo '
249
					<div id="adm_submenus">
250
						<ul class="dropmenu">';
251
252
		foreach ($tab_context['tabs'] as $sa => $tab)
253
		{
254
			if (!empty($tab['disabled']))
255
				continue;
256
257
			if (!empty($tab['is_selected']))
258
				echo '
259
							<li>
260
								<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>
261
							</li>';
262
			else
263
				echo '
264
							<li>
265
								<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>
266
							</li>';
267
		}
268
269
		// The end of tabs
270
		echo '
271
						</ul>
272
					</div><!-- #adm_submenus -->';
273
	}
274
}
275
276
?>