Completed
Push — release-2.1 ( b61572...c939ca )
by Mathias
15s
created

GenericMenu.template.php ➔ template_generic_menu_mobile()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2017 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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
	template_generic_menu($menu_context);
26
	template_generic_menu_mobile($menu_context);
27
28
	// This is the main table - we need it so we can keep the content to the right of it.
29
	echo '
30
				<div id="admin_content">';
31
32
	// It's possible that some pages have their own tabs they wanna force...
33
// 	if (!empty($context['tabs']))
34
		template_generic_menu_tabs($menu_context);
35
}
36
37
/**
38
 * Part of the admin layer - used with generic_menu_dropdown_above to close the admin content div.
39
 */
40
function template_generic_menu_dropdown_below()
41
{
42
	echo '
43
				</div><!-- #admin_content -->';
44
}
45
46
function template_generic_menu_mobile(&$menu_context)
47
{
48
	global $context, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
49
50
	// Load mobile menu here
51
	echo '
52
		<a class="menu_icon mobile_generic_menu_', $context['cur_menu_id'], '"></a>
53
		<div id="mobile_generic_menu_', $context['cur_menu_id'], '" class="popup_container">
54
			<div class="popup_window description">
55
				<div class="popup_heading">
56
					', $txt['mobile_user_menu'], '
57
					<a href="javascript:void(0);" class="generic_icons hide_popup"></a>
58
				</div>
59
				', template_generic_menu($menu_context), '
60
			</div>
61
		</div>
62
		<script>
63
			$( ".mobile_generic_menu_', $context['cur_menu_id'], '" ).click(function() {
64
				$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).show();
65
				});
66
			$( ".hide_popup" ).click(function() {
67
				$( "#mobile_generic_menu_', $context['cur_menu_id'], '" ).hide();
68
			});
69
		</script>';
70
}
71
72
function template_generic_menu(&$menu_context)
73
{
74
	global $context;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
75
76
	echo '
77
				<div class="generic_menu">';
78
79
	echo '
80
					<ul class="dropmenu dropdown_menu_', $context['cur_menu_id'], '">';
81
82
	// Main areas first.
83
	foreach ($menu_context['sections'] as $section)
84
	{
85
		echo '
86
						<li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'], '</a>
87
							<ul>';
88
89
		// For every area of this section show a link to that area (bold if it's currently selected.)
90
		// @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
91
		foreach ($section['areas'] as $i => $area)
92
		{
93
			// Not supposed to be printed?
94
			if (empty($area['label']))
95
				continue;
96
97
			echo '
98
								<li', !empty($area['subsections']) ? ' class="subsections"' : '', '>';
99
100
			echo '
101
									<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>';
102
103
			// Is this the current area, or just some area?
104
			if (!empty($area['selected']) && empty($context['tabs']))
105
					$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
106
107
			// Are there any subsections?
108
			if (!empty($area['subsections']))
109
			{
110
				echo '
111
									<ul>';
112
113
				foreach ($area['subsections'] as $sa => $sub)
114
				{
115
					if (!empty($sub['disabled']))
116
						continue;
117
118
					$url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
119
120
					echo '
121
										<li>
122
											<a ', !empty($sub['selected']) ? 'class="chosen" ' : '', ' href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], '</a>
123
										</li>';
124
				}
125
126
				echo '
127
									</ul>';
128
			}
129
130
			echo '
131
								</li>';
132
		}
133
		echo '
134
							</ul>
135
						</li>';
136
	}
137
138
	echo '
139
					</ul><!-- .dropmenu -->
140
				</div><!-- .generic_menu -->';
141
}
142
143
/**
144
 * The code for displaying the menu
145
 *
146
 * @param array $menu_context An array of menu context data
147
 */
148
function template_generic_menu_tabs(&$menu_context)
149
{
150
	global $context, $settings, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
151
152
	// Handy shortcut.
153
	$tab_context = &$menu_context['tab_data'];
154
155
	if (!empty($tab_context['title']))
156
	{
157
		echo '
158
					<div class="cat_bar">', (function_exists('template_admin_quick_search') ? '
159
						<form action="' . $scripturl . '?action=admin;area=search" method="post" accept-charset="' . $context['character_set'] . '">' : ''), '
160
							<h3 class="catbg">';
161
162
		// The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available
163
		if (function_exists('template_admin_quick_search'))
164
			template_admin_quick_search();
165
166
		// Exactly how many tabs do we have?
167
		if (!empty($context['tabs']))
168
		{
169
			foreach ($context['tabs'] as $id => $tab)
170
			{
171
				// Can this not be accessed?
172
				if (!empty($tab['disabled']))
173
				{
174
					$tab_context['tabs'][$id]['disabled'] = true;
175
					continue;
176
				}
177
178
				// Did this not even exist - or do we not have a label?
179
				if (!isset($tab_context['tabs'][$id]))
180
					$tab_context['tabs'][$id] = array('label' => $tab['label']);
181 View Code Duplication
				elseif (!isset($tab_context['tabs'][$id]['label']))
182
					$tab_context['tabs'][$id]['label'] = $tab['label'];
183
184
				// Has a custom URL defined in the main admin structure?
185 View Code Duplication
				if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
186
					$tab_context['tabs'][$id]['url'] = $tab['url'];
187
188
				// Any additional paramaters for the url?
189 View Code Duplication
				if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
190
					$tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
191
192
				// Has it been deemed selected?
193 View Code Duplication
				if (!empty($tab['is_selected']))
194
					$tab_context['tabs'][$id]['is_selected'] = true;
195
196
				// Does it have its own help?
197 View Code Duplication
				if (!empty($tab['help']))
198
					$tab_context['tabs'][$id]['help'] = $tab['help'];
199
200
				// Is this the last one?
201
				if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
202
					$tab_context['tabs'][$id]['is_last'] = true;
203
			}
204
205
			// Find the selected tab
206
			foreach ($tab_context['tabs'] as $sa => $tab)
207
			{
208 View Code Duplication
				if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
209
				{
210
					$selected_tab = $tab;
211
					$tab_context['tabs'][$sa]['is_selected'] = true;
212
				}
213
			}
214
		}
215
216
		// Show an icon and/or a help item?
217
		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']))
218
		{
219
			if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']))
220
				echo '
221
								<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
222 View Code Duplication
			elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
223
				echo '
224
								<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';
225
226 View Code Duplication
			if (!empty($selected_tab['help']) || !empty($tab_context['help']))
227
				echo '
228
								<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>';
229
230
			echo $tab_context['title'];
231
		}
232
		else
233
		{
234
			echo '
235
								', $tab_context['title'];
236
		}
237
238
		echo '
239
							</h3>', (function_exists('template_admin_quick_search') ? '
240
						</form>' : ''), '
241
					</div><!-- .cat_bar -->';
242
	}
243
244
	// Shall we use the tabs? Yes, it's the only known way!
245
	if (!empty($selected_tab['description']) || !empty($tab_context['description']))
246
		echo '
247
					<p class="information">
248
						', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
249
					</p>';
250
251
	// Print out all the items in this tab (if any).
252
	if (!empty($context['tabs']))
253
	{
254
		// The admin tabs.
255
		echo '
256
					<div id="adm_submenus">
257
						<ul class="dropmenu">';
258
259
		foreach ($tab_context['tabs'] as $sa => $tab)
260
		{
261
			if (!empty($tab['disabled']))
262
				continue;
263
264
			if (!empty($tab['is_selected']))
265
			{
266
				echo '
267
							<li>
268
								<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>
269
							</li>';
270
			}
271
			else
272
				echo '
273
							<li>
274
								<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>
275
							</li>';
276
		}
277
278
		// The end of tabs
279
		echo '
280
						</ul>
281
					</div><!-- #adm_submenus -->';
282
283
	}
284
}
285
286
?>