Passed
Push — release-2.1 ( 54b854...39d094 )
by Mathias
08:02 queued 11s
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
c 0
b 0
f 0
nop 0
dl 0
loc 58
rs 4.8666
nc 3

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 '<span class="textmenu">', $context['user']['name'], '</span></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">
227
						<span class="main_icons inbox"></span>
228
						<span class="textmenu">', $txt['pm_short'], '</span>', !empty($context['user']['unread_messages']) ? '
229
						<span class="amt">' . $context['user']['unread_messages'] . '</span>' : '', '
230
					</a>
231
					<div id="pm_menu" class="top_menu scrollable"></div>
232
				</li>';
233
234
		// Thirdly, alerts
235
		echo '
236
				<li>
237
					<a href="', $scripturl, '?action=profile;area=showalerts;u=', $context['user']['id'], '"', !empty($context['self_alerts']) ? ' class="active"' : '', ' id="alerts_menu_top">
238
						<span class="main_icons alerts"></span>
239
						<span class="textmenu">', $txt['alerts'], '</span>', !empty($context['user']['alerts']) ? '
240
						<span class="amt">' . $context['user']['alerts'] . '</span>' : '', '
241
					</a>
242
					<div id="alerts_menu" class="top_menu scrollable"></div>
243
				</li>';
244
245
		// A logout button for people without JavaScript.
246
		if (empty($settings['login_main_menu']))
247
			echo '
248
				<li id="nojs_logout">
249
					<a href="', $scripturl, '?action=logout;', $context['session_var'], '=', $context['session_id'], '">', $txt['logout'], '</a>
250
					<script>document.getElementById("nojs_logout").style.display = "none";</script>
251
				</li>';
252
253
		// And now we're done.
254
		echo '
255
			</ul>';
256
	}
257
	// Otherwise they're a guest. Ask them to either register or login.
258
	elseif (empty($maintenance))
259
	{
260
		// Some people like to do things the old-fashioned way.
261
		if (!empty($settings['login_main_menu']))
262
		{
263
			echo '
264
			<ul class="floatleft">
265
				<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']) . ', \'login\');', $scripturl . '?action=signup'), '</li>
266
			</ul>';
267
		}
268
		else
269
		{
270
			echo '
271
			<ul class="floatleft" id="top_info">
272
				<li class="welcome">
273
					', sprintf($txt['welcome_to_forum'], $context['forum_name_html_safe']), '
274
				</li>
275
				<li class="button_login">
276
					<a href="', $scripturl, '?action=login" class="', $context['current_action'] == 'login' ? 'active' : 'open','" onclick="return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ', \'login\');">
277
						<span class="main_icons login"></span>
278
						<span class="textmenu">', $txt['login'], '</span>
279
					</a>
280
				</li>
281
				<li class="button_signup">
282
					<a href="', $scripturl, '?action=signup" class="', $context['current_action'] == 'signup' ? 'active' : 'open','">
283
						<span class="main_icons regcenter"></span>
284
						<span class="textmenu">', $txt['register'], '</span>
285
					</a>
286
				</li>
287
			</ul>';
288
		}
289
	}
290
	else
291
		// In maintenance mode, only login is allowed and don't show OverlayDiv
292
		echo '
293
			<ul class="floatleft welcome">
294
				<li>', sprintf($txt['welcome_guest'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return true;'), '</li>
295
			</ul>';
296
297
	if (!empty($modSettings['userLanguage']) && !empty($context['languages']) && count($context['languages']) > 1)
298
	{
299
		echo '
300
			<form id="languages_form" method="get" class="floatright">
301
				<select id="language_select" name="language" onchange="this.form.submit()">';
302
303
		foreach ($context['languages'] as $language)
304
			echo '
305
					<option value="', $language['filename'], '"', isset($context['user']['language']) && $context['user']['language'] == $language['filename'] ? ' selected="selected"' : '', '>', str_replace('-utf8', '', $language['name']), '</option>';
306
307
		echo '
308
				</select>
309
				<noscript>
310
					<input type="submit" value="', $txt['quick_mod_go'], '">
311
				</noscript>
312
			</form>';
313
	}
314
315
	if ($context['allow_search'])
316
	{
317
		echo '
318
			<form id="search_form" class="floatright" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
319
				<input type="search" name="search" value="">&nbsp;';
320
321
		// Using the quick search dropdown?
322
		$selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
323
324
		echo '
325
				<select name="search_selection">
326
					<option value="all"', ($selected == 'all' ? ' selected' : ''), '>', $txt['search_entireforum'], ' </option>';
327
328
		// Can't limit it to a specific topic if we are not in one
329
		if (!empty($context['current_topic']))
330
			echo '
331
					<option value="topic"', ($selected == 'current_topic' ? ' selected' : ''), '>', $txt['search_thistopic'], '</option>';
332
333
		// Can't limit it to a specific board if we are not in one
334
		if (!empty($context['current_board']))
335
			echo '
336
					<option value="board"', ($selected == 'current_board' ? ' selected' : ''), '>', $txt['search_thisboard'], '</option>';
337
338
		// Can't search for members if we can't see the memberlist
339
		if (!empty($context['allow_memberlist']))
340
			echo '
341
					<option value="members"', ($selected == 'members' ? ' selected' : ''), '>', $txt['search_members'], ' </option>';
342
343
		echo '
344
				</select>';
345
346
		// Search within current topic?
347
		if (!empty($context['current_topic']))
348
			echo '
349
				<input type="hidden" name="sd_topic" value="', $context['current_topic'], '">';
350
351
		// If we're on a certain board, limit it to this board ;).
352
		elseif (!empty($context['current_board']))
353
			echo '
354
				<input type="hidden" name="sd_brd" value="', $context['current_board'], '">';
355
356
		echo '
357
				<input type="submit" name="search2" value="', $txt['search'], '" class="button">
358
				<input type="hidden" name="advanced" value="0">
359
			</form>';
360
	}
361
362
	echo '
363
		</div><!-- .inner_wrap -->
364
	</div><!-- #top_section -->';
365
366
	echo '
367
	<div id="header">
368
		<h1 class="forumtitle">
369
			<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>
370
		</h1>';
371
372
	echo '
373
		', 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>', '';
374
375
	echo '
376
	</div>
377
	<div id="wrapper">
378
		<div id="upper_section">
379
			<div id="inner_section">
380
				<div id="inner_wrap"', !$context['user']['is_logged'] ? ' class="hide_720"' : '', '>
381
					<div class="user">
382
						<time datetime="', smf_gmstrftime('%FT%TZ'), '">', $context['current_time'], '</time>';
383
384
	if ($context['user']['is_logged'])
385
		echo '
386
						<ul class="unread_links">
387
							<li>
388
								<a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a>
389
							</li>
390
							<li>
391
								<a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a>
392
							</li>
393
						</ul>';
394
395
	echo '
396
					</div>';
397
398
	// Show a random news item? (or you could pick one from news_lines...)
399
	if (!empty($settings['enable_news']) && !empty($context['random_news_line']))
400
		echo '
401
					<div class="news">
402
						<h2>', $txt['news'], ': </h2>
403
						<p>', $context['random_news_line'], '</p>
404
					</div>';
405
406
	echo '
407
				</div>';
408
409
	// Show the menu here, according to the menu sub template, followed by the navigation tree.
410
	// Load mobile menu here
411
	echo '
412
				<a class="mobile_user_menu">
413
					<span class="menu_icon"></span>
414
					<span class="text_menu">', $txt['mobile_user_menu'], '</span>
415
				</a>
416
				<div id="main_menu">
417
					<div id="mobile_user_menu" class="popup_container">
418
						<div class="popup_window description">
419
							<div class="popup_heading">', $txt['mobile_user_menu'], '
420
								<a href="javascript:void(0);" class="main_icons hide_popup"></a>
421
							</div>
422
							', 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...
423
						</div>
424
					</div>
425
				</div>';
426
427
	theme_linktree();
428
429
	echo '
430
			</div><!-- #inner_section -->
431
		</div><!-- #upper_section -->';
432
433
	// The main content should go here.
434
	echo '
435
		<div id="content_section">
436
			<div id="main_content_section">';
437
}
438
439
/**
440
 * The stuff shown immediately below the main content, including the footer
441
 */
442
function template_body_below()
443
{
444
	global $context, $txt, $scripturl, $modSettings;
445
446
	echo '
447
			</div><!-- #main_content_section -->
448
		</div><!-- #content_section -->
449
	</div><!-- #wrapper -->
450
</div><!-- #footerfix -->';
451
452
	// Show the footer with copyright, terms and help links.
453
	echo '
454
	<div id="footer">
455
		<div class="inner_wrap">';
456
457
	// There is now a global "Go to top" link at the right.
458
	echo '
459
		<ul>
460
			<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>
461
			<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...
462
		</ul>';
463
464
	// Show the load time?
465
	if ($context['show_load_time'])
466
		echo '
467
		<p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
468
469
	echo '
470
		</div>
471
	</div><!-- #footer -->';
472
473
}
474
475
/**
476
 * This shows any deferred JavaScript and closes out the HTML
477
 */
478
function template_html_below()
479
{
480
	// Load in any javascipt that could be deferred to the end of the page
481
	template_javascript(true);
482
483
	echo '
484
</body>
485
</html>';
486
}
487
488
/**
489
 * Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
490
 *
491
 * @param bool $force_show Whether to force showing it even if settings say otherwise
492
 */
493
function theme_linktree($force_show = false)
494
{
495
	global $context, $shown_linktree, $scripturl, $txt;
496
497
	// If linktree is empty, just return - also allow an override.
498
	if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
499
		return;
500
501
	echo '
502
				<div class="navigate_section">
503
					<ul>';
504
505
	// Each tree item has a URL and name. Some may have extra_before and extra_after.
506
	foreach ($context['linktree'] as $link_num => $tree)
507
	{
508
		echo '
509
						<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
510
511
		// Don't show a separator for the first one.
512
		// Better here. Always points to the next level when the linktree breaks to a second line.
513
		// Picked a better looking HTML entity, and added support for RTL plus a span for styling.
514
		if ($link_num != 0)
515
			echo '
516
							<span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';
517
518
		// Show something before the link?
519
		if (isset($tree['extra_before']))
520
			echo $tree['extra_before'], ' ';
521
522
		// Show the link, including a URL if it should have one.
523
		if (isset($tree['url']))
524
			echo '
525
							<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>';
526
		else
527
			echo '
528
							<span>' . $tree['name'] . '</span>';
529
530
		// Show something after the link...?
531
		if (isset($tree['extra_after']))
532
			echo ' ', $tree['extra_after'];
533
534
		echo '
535
						</li>';
536
	}
537
538
	echo '
539
					</ul>
540
				</div><!-- .navigate_section -->';
541
542
	$shown_linktree = true;
543
}
544
545
/**
546
 * Show the menu up top. Something like [home] [help] [profile] [logout]...
547
 */
548
function template_menu()
549
{
550
	global $context;
551
552
	echo '
553
					<ul class="dropmenu menu_nav">';
554
555
	// Note: Menu markup has been cleaned up to remove unnecessary spans and classes.
556
	foreach ($context['menu_buttons'] as $act => $button)
557
	{
558
		echo '
559
						<li class="button_', $act, '', !empty($button['sub_buttons']) ? ' subsections"' : '"', '>
560
							<a', $button['active_button'] ? ' class="active"' : '', ' href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', isset($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : '', '>
561
								', $button['icon'], '<span class="textmenu">', $button['title'], !empty($button['amt']) ? ' <span class="amt">' . $button['amt'] . '</span>' : '', '</span>
562
							</a>';
563
564
		// 2nd level menus
565
		if (!empty($button['sub_buttons']))
566
		{
567
			echo '
568
							<ul>';
569
570
			foreach ($button['sub_buttons'] as $childbutton)
571
			{
572
				echo '
573
								<li', !empty($childbutton['sub_buttons']) ? ' class="subsections"' : '', '>
574
									<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', isset($childbutton['onclick']) ? ' onclick="' . $childbutton['onclick'] . '"' : '', '>
575
										', $childbutton['title'], !empty($childbutton['amt']) ? ' <span class="amt">' . $childbutton['amt'] . '</span>' : '', '
576
									</a>';
577
				// 3rd level menus :)
578
				if (!empty($childbutton['sub_buttons']))
579
				{
580
					echo '
581
									<ul>';
582
583
					foreach ($childbutton['sub_buttons'] as $grandchildbutton)
584
						echo '
585
										<li>
586
											<a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', isset($grandchildbutton['onclick']) ? ' onclick="' . $grandchildbutton['onclick'] . '"' : '', '>
587
												', $grandchildbutton['title'], !empty($grandchildbutton['amt']) ? ' <span class="amt">' . $grandchildbutton['amt'] . '</span>' : '', '
588
											</a>
589
										</li>';
590
591
					echo '
592
									</ul>';
593
				}
594
595
				echo '
596
								</li>';
597
			}
598
			echo '
599
							</ul>';
600
		}
601
		echo '
602
						</li>';
603
	}
604
605
	echo '
606
					</ul><!-- .menu_nav -->';
607
}
608
609
/**
610
 * Generate a strip of buttons.
611
 *
612
 * @param array $button_strip An array with info for displaying the strip
613
 * @param string $direction The direction
614
 * @param array $strip_options Options for the button strip
615
 */
616
function template_button_strip($button_strip, $direction = '', $strip_options = array())
617
{
618
	global $context, $txt;
619
620
	if (!is_array($strip_options))
0 ignored issues
show
introduced by
The condition is_array($strip_options) is always true.
Loading history...
621
		$strip_options = array();
622
623
	// Create the buttons...
624
	$buttons = array();
625
	foreach ($button_strip as $key => $value)
626
	{
627
		// 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!)
628
		if (!isset($value['test']) || !empty($context[$value['test']]))
629
		{
630
			if (!isset($value['id']))
631
				$value['id'] = $key;
632
633
			$button = '
634
				<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>';
635
636
			if (!empty($value['sub_buttons']))
637
			{
638
				$button .= '
639
					<div class="top_menu dropmenu ' . $key . '_dropdown">
640
						<div class="viewport">
641
							<div class="overview">';
642
				foreach ($value['sub_buttons'] as $element)
643
				{
644
					if (isset($element['test']) && empty($context[$element['test']]))
645
						continue;
646
647
					$button .= '
648
								<a href="' . $element['url'] . '"><strong>' . $txt[$element['text']] . '</strong>';
649
					if (isset($txt[$element['text'] . '_desc']))
650
						$button .= '<br><span>' . $txt[$element['text'] . '_desc'] . '</span>';
651
					$button .= '</a>';
652
				}
653
				$button .= '
654
							</div><!-- .overview -->
655
						</div><!-- .viewport -->
656
					</div><!-- .top_menu -->';
657
			}
658
659
			$buttons[] = $button;
660
		}
661
	}
662
663
	// No buttons? No button strip either.
664
	if (empty($buttons))
665
		return;
666
667
	echo '
668
		<div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"' : ''), '>
669
			', implode('', $buttons), '
670
		</div>';
671
}
672
673
/**
674
 * Generate a list of quickbuttons.
675
 *
676
 * @param array $list_items An array with info for displaying the strip
677
 * @param string $list_class Used for integration hooks and as a class name
678
 * @param string $output_method The output method. If 'echo', simply displays the buttons, otherwise returns the HTML for them
679
 * @return void|string Returns nothing unless output_method is something other than 'echo'
680
 */
681
function template_quickbuttons($list_items, $list_class = null, $output_method = 'echo')
682
{
683
	global $txt;
684
685
	// Enable manipulation with hooks
686
	if (!empty($list_class))
687
		call_integration_hook('integrate_' . $list_class . '_quickbuttons', array(&$list_items));
688
689
	// Make sure the list has at least one shown item
690
	foreach ($list_items as $key => $li)
691
	{
692
		// Is there a sublist, and does it have any shown items
693
		if ($key == 'more')
694
		{
695
			foreach ($li as $subkey => $subli)
696
				if (isset($subli['show']) && !$subli['show'])
697
					unset($list_items[$key][$subkey]);
698
699
			if (empty($list_items[$key]))
700
				unset($list_items[$key]);
701
		}
702
		// A normal list item
703
		elseif (isset($li['show']) && !$li['show'])
704
			unset($list_items[$key]);
705
	}
706
707
	// Now check if there are any items left
708
	if (empty($list_items))
709
		return;
710
711
	// Print the quickbuttons
712
	$output = '
713
		<ul class="quickbuttons' . (!empty($list_class) ? ' quickbuttons_' . $list_class : '') . '">';
714
715
	// This is used for a list item or a sublist item
716
	$list_item_format = function($li)
717
	{
718
		$html = '
719
			<li' . (!empty($li['class']) ? ' class="' . $li['class'] . '"' : '') . (!empty($li['id']) ? ' id="' . $li['id'] . '"' : '') . (!empty($li['custom']) ? ' ' . $li['custom'] : '') . '>';
720
721
		if (isset($li['content']))
722
			$html .= $li['content'];
723
		else
724
			$html .= '
725
				<a href="' . (!empty($li['href']) ? $li['href'] : 'javascript:void(0);') . '"' . (!empty($li['javascript']) ? ' ' . $li['javascript'] : '') . '>
726
					' . (!empty($li['icon']) ? '<span class="main_icons ' . $li['icon'] . '"></span>' : '') . (!empty($li['label']) ? $li['label'] : '') . '
727
				</a>';
728
729
		$html .= '
730
			</li>';
731
732
		return $html;
733
	};
734
735
	foreach ($list_items as $key => $li)
736
	{
737
		// Handle the sublist
738
		if ($key == 'more')
739
		{
740
			$output .= '
741
			<li class="post_options">
742
				<a href="javascript:void(0);">' . $txt['post_options'] . '</a>
743
				<ul>';
744
745
			foreach ($li as $subli)
746
				$output .= $list_item_format($subli);
747
748
			$output .= '
749
				</ul>
750
			</li>';
751
		}
752
		// Ordinary list item
753
		else
754
			$output .= $list_item_format($li);
755
	}
756
757
	$output .= '
758
		</ul><!-- .quickbuttons -->';
759
760
	// There are a few spots where the result needs to be returned
761
	if ($output_method == 'echo')
762
		echo $output;
763
	else
764
		return $output;
765
}
766
767
/**
768
 * The upper part of the maintenance warning box
769
 */
770
function template_maint_warning_above()
771
{
772
	global $txt, $context, $scripturl;
773
774
	echo '
775
	<div class="errorbox" id="errors">
776
		<dl>
777
			<dt>
778
				<strong id="error_serious">', $txt['forum_in_maintenance'], '</strong>
779
			</dt>
780
			<dd class="error" id="error_list">
781
				', sprintf($txt['maintenance_page'], $scripturl . '?action=admin;area=serversettings;' . $context['session_var'] . '=' . $context['session_id']), '
782
			</dd>
783
		</dl>
784
	</div>';
785
}
786
787
/**
788
 * The lower part of the maintenance warning box.
789
 */
790
function template_maint_warning_below()
791
{
792
793
}
794
795
?>