Passed
Pull Request — release-2.1 (#7267)
by Jon
05:13
created

template_menu()   D

Complexity

Conditions 18
Paths 3

Size

Total Lines 58
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 25
nc 3
nop 0
dl 0
loc 58
rs 4.8666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines https://www.simplemachines.org
7
 * @copyright 2022 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC4
11
 */
12
13
/*	This template is, perhaps, the most important template in the theme. It
14
	contains the main template layer that displays the header and footer of
15
	the forum, namely with main_above and main_below. It also contains the
16
	menu sub template, which appropriately displays the menu; the init sub
17
	template, which is there to set the theme up; (init can be missing.) and
18
	the linktree sub template, which sorts out the link tree.
19
20
	The init sub template should load any data and set any hardcoded options.
21
22
	The main_above sub template is what is shown above the main content, and
23
	should contain anything that should be shown up there.
24
25
	The main_below sub template, conversely, is shown after the main content.
26
	It should probably contain the copyright statement and some other things.
27
28
	The linktree sub template should display the link tree, using the data
29
	in the $context['linktree'] variable.
30
31
	The menu sub template should display all the relevant buttons the user
32
	wants and or needs.
33
34
	For more information on the templating system, please see the site at:
35
	https://www.simplemachines.org/
36
*/
37
38
/**
39
 * Initialize the template... mainly little settings.
40
 */
41
function template_init()
42
{
43
	global $settings, $txt;
44
45
	/* $context, $options and $txt may be available for use, but may not be fully populated yet. */
46
47
	// The version this template/theme is for. This should probably be the version of SMF it was created for.
48
	$settings['theme_version'] = '2.1';
49
50
	// Set the following variable to true if this theme requires the optional theme strings file to be loaded.
51
	$settings['require_theme_strings'] = false;
52
53
	// Set the following variable to true if this theme wants to display the avatar of the user that posted the last and the first post on the message index and recent pages.
54
	$settings['avatars_on_indexes'] = false;
55
56
	// Set the following variable to true if this theme wants to display the avatar of the user that posted the last post on the board index.
57
	$settings['avatars_on_boardIndex'] = false;
58
59
	// Set the following variable to true if this theme wants to display the login and register buttons in the main forum menu.
60
	$settings['login_main_menu'] = false;
61
62
	// This defines the formatting for the page indexes used throughout the forum.
63
	$settings['page_index'] = array(
64
		'extra_before' => '<span class="pages">' . $txt['pages'] . '</span>',
65
		'previous_page' => '<span class="main_icons previous_page"></span>',
66
		'current_page' => '<span class="current_page">%1$d</span> ',
67
		'page' => '<a class="nav_page" href="{URL}">%2$s</a> ',
68
		'expand_pages' => '<span class="expand_pages" onclick="expandPages(this, {LINK}, {FIRST_PAGE}, {LAST_PAGE}, {PER_PAGE});"> ... </span>',
69
		'next_page' => '<span class="main_icons next_page"></span>',
70
		'extra_after' => '',
71
	);
72
73
	// Allow css/js files to be disabled for this specific theme.
74
	// Add the identifier as an array key. IE array('smf_script'); Some external files might not add identifiers, on those cases SMF uses its filename as reference.
75
	if (!isset($settings['disable_files']))
76
		$settings['disable_files'] = array();
77
}
78
79
/**
80
 * The main sub template above the content.
81
 */
82
function template_html_above()
83
{
84
	global $context, $scripturl, $txt, $modSettings;
85
86
	// Show right to left, the language code, and the character set for ease of translating.
87
	echo '<!DOCTYPE html>
88
<html', $context['right_to_left'] ? ' dir="rtl"' : '', !empty($txt['lang_locale']) ? ' lang="' . str_replace("_", "-", substr($txt['lang_locale'], 0, strcspn($txt['lang_locale'], "."))) . '"' : '', '>
89
<head>
90
	<meta charset="', $context['character_set'], '">';
91
92
	/*
93
		You don't need to manually load index.css, this will be set up for you.
94
		Note that RTL will also be loaded for you.
95
		To load other CSS and JS files you should use the functions
96
		loadCSSFile() and loadJavaScriptFile() respectively.
97
		This approach will let you take advantage of SMF's automatic CSS
98
		minimization and other benefits. You can, of course, manually add any
99
		other files you want after template_css() has been run.
100
101
	*	Short example:
102
			- CSS: loadCSSFile('filename.css', array('minimize' => true));
103
			- JS:  loadJavaScriptFile('filename.js', array('minimize' => true));
104
			You can also read more detailed usages of the parameters for these
105
			functions on the SMF wiki.
106
107
	*	Themes:
108
			The most efficient way of writing multi themes is to use a master
109
			index.css plus variant.css files. If you've set them up properly
110
			(through $settings['theme_variants']), the variant files will be loaded
111
			for you automatically.
112
			Additionally, tweaking the CSS for the editor requires you to include
113
			a custom 'jquery.sceditor.theme.css' file in the css folder if you need it.
114
115
	*	MODs:
116
			If you want to load CSS or JS files in here, the best way is to use the
117
			'integrate_load_theme' hook for adding multiple files, or using
118
			'integrate_pre_css_output', 'integrate_pre_javascript_output' for a single file.
119
	*/
120
121
	// load in any css from mods or themes so they can overwrite if wanted
122
	template_css();
123
124
	// load in any javascript files from mods and themes
125
	template_javascript();
126
127
	echo '
128
	<title>', $context['page_title_html_safe'], '</title>
129
	<meta name="viewport" content="width=device-width, initial-scale=1">';
130
131
	// Content related meta tags, like description, keywords, Open Graph stuff, etc...
132
	foreach ($context['meta_tags'] as $meta_tag)
133
	{
134
		echo '
135
	<meta';
136
137
		foreach ($meta_tag as $meta_key => $meta_value)
138
			echo ' ', $meta_key, '="', $meta_value, '"';
139
140
		echo '>';
141
	}
142
143
	/*	What is your Lollipop's color?
144
		Theme Authors, you can change the color here to make sure your theme's main color gets visible on tab */
145
	echo '
146
	<meta name="theme-color" content="#557EA0">';
147
148
	// Please don't index these Mr Robot.
149
	if (!empty($context['robot_no_index']))
150
		echo '
151
	<meta name="robots" content="noindex">';
152
153
	// Present a canonical url for search engines to prevent duplicate content in their indices.
154
	if (!empty($context['canonical_url']))
155
		echo '
156
	<link rel="canonical" href="', $context['canonical_url'], '">';
157
158
	// Show all the relative links, such as help, search, contents, and the like.
159
	echo '
160
	<link rel="help" href="', $scripturl, '?action=help">
161
	<link rel="contents" href="', $scripturl, '">', ($context['allow_search'] ? '
162
	<link rel="search" href="' . $scripturl . '?action=search">' : '');
163
164
	// If RSS feeds are enabled, advertise the presence of one.
165
	if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
166
		echo '
167
	<link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?action=.xml;type=rss2', !empty($context['current_board']) ? ';board=' . $context['current_board'] : '', '">
168
	<link rel="alternate" type="application/atom+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['atom'], '" href="', $scripturl, '?action=.xml;type=atom', !empty($context['current_board']) ? ';board=' . $context['current_board'] : '', '">';
169
170
	// If we're viewing a topic, these should be the previous and next topics, respectively.
171
	if (!empty($context['links']['next']))
172
		echo '
173
	<link rel="next" href="', $context['links']['next'], '">';
174
175
	if (!empty($context['links']['prev']))
176
		echo '
177
	<link rel="prev" href="', $context['links']['prev'], '">';
178
179
	// If we're in a board, or a topic for that matter, the index will be the board's index.
180
	if (!empty($context['current_board']))
181
		echo '
182
	<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0">';
183
184
	// Output any remaining HTML headers. (from mods, maybe?)
185
	echo $context['html_headers'];
186
187
	echo '
188
</head>
189
<body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? $context['current_action'] : (!empty($context['current_board']) ?
190
		'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . $context['current_board'] : '', '">
191
<div id="footerfix">';
192
}
193
194
/**
195
 * The upper part of the main template layer. This is the stuff that shows above the main forum content.
196
 */
197
function template_body_above()
198
{
199
	global $context, $settings, $scripturl, $txt, $modSettings, $maintenance;
200
201
	// Wrapper div now echoes permanently for better layout options. h1 a is now target for "Go up" links.
202
	echo '
203
	<div id="top_section">
204
		<div class="inner_wrap">';
205
206
	// If the user is logged in, display some things that might be useful.
207
	if ($context['user']['is_logged'])
208
	{
209
		// Firstly, the user's menu
210
		echo '
211
			<ul class="floatleft" id="top_info">
212
				<li>
213
					<a href="', $scripturl, '?action=profile"', !empty($context['self_profile']) ? ' class="active"' : '', ' id="profile_menu_top" onclick="return false;">';
214
215
		if (!empty($context['user']['avatar']))
216
			echo $context['user']['avatar']['image'];
217
218
		echo $context['user']['name'], '</a>
219
					<div id="profile_menu" class="top_menu"></div>
220
				</li>';
221
222
		// Secondly, PMs if we're doing them
223
		if ($context['allow_pm'])
224
			echo '
225
				<li>
226
					<a href="', $scripturl, '?action=pm"', !empty($context['self_pm']) ? ' class="active"' : '', ' id="pm_menu_top">', $txt['pm_short'], !empty($context['user']['unread_messages']) ? ' <span class="amt">' . $context['user']['unread_messages'] . '</span>' : '', '</a>
227
					<div id="pm_menu" class="top_menu scrollable"></div>
228
				</li>';
229
230
		// Thirdly, alerts
231
		echo '
232
				<li>
233
					<a href="', $scripturl, '?action=profile;area=showalerts;u=', $context['user']['id'], '"', !empty($context['self_alerts']) ? ' class="active"' : '', ' id="alerts_menu_top">', $txt['alerts'], !empty($context['user']['alerts']) ? ' <span class="amt">' . $context['user']['alerts'] . '</span>' : '', '</a>
234
					<div id="alerts_menu" class="top_menu scrollable"></div>
235
				</li>';
236
237
		// A logout button for people without JavaScript.
238
		if (empty($settings['login_main_menu']))
239
			echo '
240
				<li id="nojs_logout">
241
					<a href="', $scripturl, '?action=logout;', $context['session_var'], '=', $context['session_id'], '">', $txt['logout'], '</a>
242
					<script>document.getElementById("nojs_logout").style.display = "none";</script>
243
				</li>';
244
245
		// And now we're done.
246
		echo '
247
			</ul>';
248
	}
249
	// Otherwise they're a guest. Ask them to either register or login.
250
	elseif (empty($maintenance))
251
	{
252
		// Some people like to do things the old-fashioned way.
253
		if (!empty($settings['login_main_menu']))
254
		{
255
			echo '
256
			<ul class="floatleft">
257
				<li class="welcome">', sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'), '</li>
258
			</ul>';
259
		}
260
		else
261
		{
262
			echo '
263
			<ul class="floatleft" id="top_info">
264
				<li class="welcome">
265
					', sprintf($txt['welcome_to_forum'], $context['forum_name_html_safe']), '
266
				</li>
267
				<li class="button_login">
268
					<a href="', $scripturl, '?action=login" class="', $context['current_action'] == 'login' ? 'active' : 'open','" onclick="return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');">
269
						<span class="main_icons login"></span>
270
						<span class="textmenu">', $txt['login'], '</span>
271
					</a>
272
				</li>
273
				<li class="button_signup">
274
					<a href="', $scripturl, '?action=signup" class="', $context['current_action'] == 'signup' ? 'active' : 'open','">
275
						<span class="main_icons regcenter"></span>
276
						<span class="textmenu">', $txt['register'], '</span>
277
					</a>
278
				</li>
279
			</ul>';
280
		}
281
	}
282
	else
283
		// In maintenance mode, only login is allowed and don't show OverlayDiv
284
		echo '
285
			<ul class="floatleft welcome">
286
				<li>', sprintf($txt['welcome_guest'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return true;'), '</li>
287
			</ul>';
288
289
	if (!empty($modSettings['userLanguage']) && !empty($context['languages']) && count($context['languages']) > 1)
290
	{
291
		echo '
292
			<form id="languages_form" method="get" class="floatright">
293
				<select id="language_select" name="language" onchange="this.form.submit()">';
294
295
		foreach ($context['languages'] as $language)
296
			echo '
297
					<option value="', $language['filename'], '"', isset($context['user']['language']) && $context['user']['language'] == $language['filename'] ? ' selected="selected"' : '', '>', str_replace('-utf8', '', $language['name']), '</option>';
298
299
		echo '
300
				</select>
301
				<noscript>
302
					<input type="submit" value="', $txt['quick_mod_go'], '">
303
				</noscript>
304
			</form>';
305
	}
306
307
	if ($context['allow_search'])
308
	{
309
		echo '
310
			<form id="search_form" class="floatright" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
311
				<input type="search" name="search" value="">&nbsp;';
312
313
		// Using the quick search dropdown?
314
		$selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
315
316
		echo '
317
				<select name="search_selection">
318
					<option value="all"', ($selected == 'all' ? ' selected' : ''), '>', $txt['search_entireforum'], ' </option>';
319
320
		// Can't limit it to a specific topic if we are not in one
321
		if (!empty($context['current_topic']))
322
			echo '
323
					<option value="topic"', ($selected == 'current_topic' ? ' selected' : ''), '>', $txt['search_thistopic'], '</option>';
324
325
		// Can't limit it to a specific board if we are not in one
326
		if (!empty($context['current_board']))
327
			echo '
328
					<option value="board"', ($selected == 'current_board' ? ' selected' : ''), '>', $txt['search_thisboard'], '</option>';
329
330
		// Can't search for members if we can't see the memberlist
331
		if (!empty($context['allow_memberlist']))
332
			echo '
333
					<option value="members"', ($selected == 'members' ? ' selected' : ''), '>', $txt['search_members'], ' </option>';
334
335
		echo '
336
				</select>';
337
338
		// Search within current topic?
339
		if (!empty($context['current_topic']))
340
			echo '
341
				<input type="hidden" name="sd_topic" value="', $context['current_topic'], '">';
342
343
		// If we're on a certain board, limit it to this board ;).
344
		elseif (!empty($context['current_board']))
345
			echo '
346
				<input type="hidden" name="sd_brd" value="', $context['current_board'], '">';
347
348
		echo '
349
				<input type="submit" name="search2" value="', $txt['search'], '" class="button">
350
				<input type="hidden" name="advanced" value="0">
351
			</form>';
352
	}
353
354
	echo '
355
		</div><!-- .inner_wrap -->
356
	</div><!-- #top_section -->';
357
358
	echo '
359
	<div id="header">
360
		<h1 class="forumtitle">
361
			<a id="top" href="', $scripturl, '">', empty($context['header_logo_url_html_safe']) ? $context['forum_name_html_safe'] : '<img src="' . $context['header_logo_url_html_safe'] . '" alt="' . $context['forum_name_html_safe'] . '">', '</a>
362
		</h1>';
363
364
	echo '
365
		', empty($settings['site_slogan']) ? '<img id="smflogo" src="' . $settings['images_url'] . '/smflogo.svg" alt="Simple Machines Forum" title="Simple Machines Forum">' : '<div id="siteslogan">' . $settings['site_slogan'] . '</div>', '';
366
367
	echo '
368
	</div>
369
	<div id="wrapper">
370
		<div id="upper_section">
371
			<div id="inner_section">
372
				<div id="inner_wrap">
373
					<div class="user">
374
						', $context['current_time'], '
375
					</div>';
376
377
	// Show a random news item? (or you could pick one from news_lines...)
378
	if (!empty($settings['enable_news']) && !empty($context['random_news_line']))
379
		echo '
380
					<div class="news">
381
						<h2>', $txt['news'], ': </h2>
382
						<p>', $context['random_news_line'], '</p>
383
					</div>';
384
385
	echo '
386
					<hr class="clear">
387
				</div>';
388
389
	// Show the menu here, according to the menu sub template, followed by the navigation tree.
390
	// Load mobile menu here
391
	echo '
392
				<a class="menu_icon mobile_user_menu"></a>
393
				<div id="main_menu">
394
					<div id="mobile_user_menu" class="popup_container">
395
						<div class="popup_window description">
396
							<div class="popup_heading">', $txt['mobile_user_menu'], '
397
								<a href="javascript:void(0);" class="main_icons hide_popup"></a>
398
							</div>
399
							', template_menu(), '
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_menu() 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...
400
						</div>
401
					</div>
402
				</div>';
403
404
	theme_linktree();
405
406
	echo '
407
			</div><!-- #inner_section -->
408
		</div><!-- #upper_section -->';
409
410
	// The main content should go here.
411
	echo '
412
		<div id="content_section">
413
			<div id="main_content_section">';
414
}
415
416
/**
417
 * The stuff shown immediately below the main content, including the footer
418
 */
419
function template_body_below()
420
{
421
	global $context, $txt, $scripturl, $modSettings;
422
423
	echo '
424
			</div><!-- #main_content_section -->
425
		</div><!-- #content_section -->
426
	</div><!-- #wrapper -->
427
</div><!-- #footerfix -->';
428
429
	// Show the footer with copyright, terms and help links.
430
	echo '
431
	<div id="footer">
432
		<div class="inner_wrap">';
433
434
	// There is now a global "Go to top" link at the right.
435
	echo '
436
		<ul>
437
			<li class="floatright"><a href="', $scripturl, '?action=help">', $txt['help'], '</a> ', (!empty($modSettings['requireAgreement'])) ? '| <a href="' . $scripturl . '?action=agreement">' . $txt['terms_and_rules'] . '</a>' : '', ' | <a href="#top_section">', $txt['go_up'], ' &#9650;</a></li>
438
			<li class="copyright">', theme_copyright(), '</li>
0 ignored issues
show
Bug introduced by
Are you sure the usage of theme_copyright() 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...
439
		</ul>';
440
441
	// Show the load time?
442
	if ($context['show_load_time'])
443
		echo '
444
		<p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
445
446
	echo '
447
		</div>
448
	</div><!-- #footer -->';
449
450
}
451
452
/**
453
 * This shows any deferred JavaScript and closes out the HTML
454
 */
455
function template_html_below()
456
{
457
	// Load in any javascipt that could be deferred to the end of the page
458
	template_javascript(true);
459
460
	echo '
461
</body>
462
</html>';
463
}
464
465
/**
466
 * Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
467
 *
468
 * @param bool $force_show Whether to force showing it even if settings say otherwise
469
 */
470
function theme_linktree($force_show = false)
471
{
472
	global $context, $shown_linktree, $scripturl, $txt;
473
474
	// If linktree is empty, just return - also allow an override.
475
	if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
476
		return;
477
	echo '
478
				<div class="navigate_section">
479
					<ul>';
480
481
	if ($context['user']['is_logged'])
482
		echo '
483
						<li class="unread_links">
484
							<a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a>
485
							<a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a>
486
						</li>';
487
488
	// Each tree item has a URL and name. Some may have extra_before and extra_after.
489
	foreach ($context['linktree'] as $link_num => $tree)
490
	{
491
		echo '
492
						<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
493
494
		// Don't show a separator for the first one.
495
		// Better here. Always points to the next level when the linktree breaks to a second line.
496
		// Picked a better looking HTML entity, and added support for RTL plus a span for styling.
497
		if ($link_num != 0)
498
			echo '
499
							<span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';
500
501
		// Show something before the link?
502
		if (isset($tree['extra_before']))
503
			echo $tree['extra_before'], ' ';
504
505
		// Show the link, including a URL if it should have one.
506
		if (isset($tree['url']))
507
			echo '
508
							<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>';
509
		else
510
			echo '
511
							<span>' . $tree['name'] . '</span>';
512
513
		// Show something after the link...?
514
		if (isset($tree['extra_after']))
515
			echo ' ', $tree['extra_after'];
516
517
		echo '
518
						</li>';
519
	}
520
521
	echo '
522
					</ul>
523
				</div><!-- .navigate_section -->';
524
525
	$shown_linktree = true;
526
}
527
528
/**
529
 * Show the menu up top. Something like [home] [help] [profile] [logout]...
530
 */
531
function template_menu()
532
{
533
	global $context;
534
535
	echo '
536
					<ul class="dropmenu menu_nav">';
537
538
	// Note: Menu markup has been cleaned up to remove unnecessary spans and classes.
539
	foreach ($context['menu_buttons'] as $act => $button)
540
	{
541
		echo '
542
						<li class="button_', $act, '', !empty($button['sub_buttons']) ? ' subsections"' : '"', '>
543
							<a', $button['active_button'] ? ' class="active"' : '', ' href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', isset($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : '', '>
544
								', $button['icon'], '<span class="textmenu">', $button['title'], !empty($button['amt']) ? ' <span class="amt">' . $button['amt'] . '</span>' : '', '</span>
545
							</a>';
546
547
		// 2nd level menus
548
		if (!empty($button['sub_buttons']))
549
		{
550
			echo '
551
							<ul>';
552
553
			foreach ($button['sub_buttons'] as $childbutton)
554
			{
555
				echo '
556
								<li', !empty($childbutton['sub_buttons']) ? ' class="subsections"' : '', '>
557
									<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', isset($childbutton['onclick']) ? ' onclick="' . $childbutton['onclick'] . '"' : '', '>
558
										', $childbutton['title'], !empty($childbutton['amt']) ? ' <span class="amt">' . $childbutton['amt'] . '</span>' : '', '
559
									</a>';
560
				// 3rd level menus :)
561
				if (!empty($childbutton['sub_buttons']))
562
				{
563
					echo '
564
									<ul>';
565
566
					foreach ($childbutton['sub_buttons'] as $grandchildbutton)
567
						echo '
568
										<li>
569
											<a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', isset($grandchildbutton['onclick']) ? ' onclick="' . $grandchildbutton['onclick'] . '"' : '', '>
570
												', $grandchildbutton['title'], !empty($grandchildbutton['amt']) ? ' <span class="amt">' . $grandchildbutton['amt'] . '</span>' : '', '
571
											</a>
572
										</li>';
573
574
					echo '
575
									</ul>';
576
				}
577
578
				echo '
579
								</li>';
580
			}
581
			echo '
582
							</ul>';
583
		}
584
		echo '
585
						</li>';
586
	}
587
588
	echo '
589
					</ul><!-- .menu_nav -->';
590
}
591
592
/**
593
 * Generate a strip of buttons.
594
 *
595
 * @param array $button_strip An array with info for displaying the strip
596
 * @param string $direction The direction
597
 * @param array $strip_options Options for the button strip
598
 */
599
function template_button_strip($button_strip, $direction = '', $strip_options = array())
600
{
601
	global $context, $txt;
602
603
	if (!is_array($strip_options))
0 ignored issues
show
introduced by
The condition is_array($strip_options) is always true.
Loading history...
604
		$strip_options = array();
605
606
	// Create the buttons...
607
	$buttons = array();
608
	foreach ($button_strip as $key => $value)
609
	{
610
		// As of 2.1, the 'test' for each button happens while the array is being generated. The extra 'test' check here is deprecated but kept for backward compatibility (update your mods, folks!)
611
		if (!isset($value['test']) || !empty($context[$value['test']]))
612
		{
613
			if (!isset($value['id']))
614
				$value['id'] = $key;
615
616
			$button = '
617
				<a class="button button_strip_' . $key . (!empty($value['active']) ? ' active' : '') . (isset($value['class']) ? ' ' . $value['class'] : '') . '" ' . (!empty($value['url']) ? 'href="' . $value['url'] . '"' : '') . ' ' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '>'.(!empty($value['icon']) ? '<span class="main_icons '.$value['icon'].'"></span>' : '').'' . $txt[$value['text']] . '</a>';
618
619
			if (!empty($value['sub_buttons']))
620
			{
621
				$button .= '
622
					<div class="top_menu dropmenu ' . $key . '_dropdown">
623
						<div class="viewport">
624
							<div class="overview">';
625
				foreach ($value['sub_buttons'] as $element)
626
				{
627
					if (isset($element['test']) && empty($context[$element['test']]))
628
						continue;
629
630
					$button .= '
631
								<a href="' . $element['url'] . '"><strong>' . $txt[$element['text']] . '</strong>';
632
					if (isset($txt[$element['text'] . '_desc']))
633
						$button .= '<br><span>' . $txt[$element['text'] . '_desc'] . '</span>';
634
					$button .= '</a>';
635
				}
636
				$button .= '
637
							</div><!-- .overview -->
638
						</div><!-- .viewport -->
639
					</div><!-- .top_menu -->';
640
			}
641
642
			$buttons[] = $button;
643
		}
644
	}
645
646
	// No buttons? No button strip either.
647
	if (empty($buttons))
648
		return;
649
650
	echo '
651
		<div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"' : ''), '>
652
			', implode('', $buttons), '
653
		</div>';
654
}
655
656
/**
657
 * Generate a list of quickbuttons.
658
 *
659
 * @param array $list_items An array with info for displaying the strip
660
 * @param string $list_class Used for integration hooks and as a class name
661
 * @param string $output_method The output method. If 'echo', simply displays the buttons, otherwise returns the HTML for them
662
 * @return void|string Returns nothing unless output_method is something other than 'echo'
663
 */
664
function template_quickbuttons($list_items, $list_class = null, $output_method = 'echo')
665
{
666
	global $txt;
667
668
	// Enable manipulation with hooks
669
	if (!empty($list_class))
670
		call_integration_hook('integrate_' . $list_class . '_quickbuttons', array(&$list_items));
671
672
	// Make sure the list has at least one shown item
673
	foreach ($list_items as $key => $li)
674
	{
675
		// Is there a sublist, and does it have any shown items
676
		if ($key == 'more')
677
		{
678
			foreach ($li as $subkey => $subli)
679
				if (isset($subli['show']) && !$subli['show'])
680
					unset($list_items[$key][$subkey]);
681
682
			if (empty($list_items[$key]))
683
				unset($list_items[$key]);
684
		}
685
		// A normal list item
686
		elseif (isset($li['show']) && !$li['show'])
687
			unset($list_items[$key]);
688
	}
689
690
	// Now check if there are any items left
691
	if (empty($list_items))
692
		return;
693
694
	// Print the quickbuttons
695
	$output = '
696
		<ul class="quickbuttons' . (!empty($list_class) ? ' quickbuttons_' . $list_class : '') . '">';
697
698
	// This is used for a list item or a sublist item
699
	$list_item_format = function($li)
700
	{
701
		$html = '
702
			<li' . (!empty($li['class']) ? ' class="' . $li['class'] . '"' : '') . (!empty($li['id']) ? ' id="' . $li['id'] . '"' : '') . (!empty($li['custom']) ? ' ' . $li['custom'] : '') . '>';
703
704
		if (isset($li['content']))
705
			$html .= $li['content'];
706
		else
707
			$html .= '
708
				<a href="' . (!empty($li['href']) ? $li['href'] : 'javascript:void(0);') . '"' . (!empty($li['javascript']) ? ' ' . $li['javascript'] : '') . '>
709
					' . (!empty($li['icon']) ? '<span class="main_icons ' . $li['icon'] . '"></span>' : '') . (!empty($li['label']) ? $li['label'] : '') . '
710
				</a>';
711
712
		$html .= '
713
			</li>';
714
715
		return $html;
716
	};
717
718
	foreach ($list_items as $key => $li)
719
	{
720
		// Handle the sublist
721
		if ($key == 'more')
722
		{
723
			$output .= '
724
			<li class="post_options">
725
				<a href="javascript:void(0);">' . $txt['post_options'] . '</a>
726
				<ul>';
727
728
			foreach ($li as $subli)
729
				$output .= $list_item_format($subli);
730
731
			$output .= '
732
				</ul>
733
			</li>';
734
		}
735
		// Ordinary list item
736
		else
737
			$output .= $list_item_format($li);
738
	}
739
740
	$output .= '
741
		</ul><!-- .quickbuttons -->';
742
743
	// There are a few spots where the result needs to be returned
744
	if ($output_method == 'echo')
745
		echo $output;
746
	else
747
		return $output;
748
}
749
750
/**
751
 * The upper part of the maintenance warning box
752
 */
753
function template_maint_warning_above()
754
{
755
	global $txt, $context, $scripturl;
756
757
	echo '
758
	<div class="errorbox" id="errors">
759
		<dl>
760
			<dt>
761
				<strong id="error_serious">', $txt['forum_in_maintenance'], '</strong>
762
			</dt>
763
			<dd class="error" id="error_list">
764
				', sprintf($txt['maintenance_page'], $scripturl . '?action=admin;area=serversettings;' . $context['session_var'] . '=' . $context['session_id']), '
765
			</dd>
766
		</dl>
767
	</div>';
768
}
769
770
/**
771
 * The lower part of the maintenance warning box.
772
 */
773
function template_maint_warning_below()
774
{
775
776
}
777
778
?>