Passed
Pull Request — release-2.1 (#7267)
by Jon
06:11
created

theme_linktree()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 50
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 23
c 1
b 0
f 0
nc 18
nop 1
dl 0
loc 50
rs 7.3166

How to fix   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>', $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="menu_icon mobile_user_menu"></a>
413
				<div id="main_menu">
414
					<div id="mobile_user_menu" class="popup_container">
415
						<div class="popup_window description">
416
							<div class="popup_heading">', $txt['mobile_user_menu'], '
417
								<a href="javascript:void(0);" class="main_icons hide_popup"></a>
418
							</div>
419
							', 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...
420
						</div>
421
					</div>
422
				</div>';
423
424
	theme_linktree();
425
426
	echo '
427
			</div><!-- #inner_section -->
428
		</div><!-- #upper_section -->';
429
430
	// The main content should go here.
431
	echo '
432
		<div id="content_section">
433
			<div id="main_content_section">';
434
}
435
436
/**
437
 * The stuff shown immediately below the main content, including the footer
438
 */
439
function template_body_below()
440
{
441
	global $context, $txt, $scripturl, $modSettings;
442
443
	echo '
444
			</div><!-- #main_content_section -->
445
		</div><!-- #content_section -->
446
	</div><!-- #wrapper -->
447
</div><!-- #footerfix -->';
448
449
	// Show the footer with copyright, terms and help links.
450
	echo '
451
	<div id="footer">
452
		<div class="inner_wrap">';
453
454
	// There is now a global "Go to top" link at the right.
455
	echo '
456
		<ul>
457
			<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>
458
			<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...
459
		</ul>';
460
461
	// Show the load time?
462
	if ($context['show_load_time'])
463
		echo '
464
		<p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
465
466
	echo '
467
		</div>
468
	</div><!-- #footer -->';
469
470
}
471
472
/**
473
 * This shows any deferred JavaScript and closes out the HTML
474
 */
475
function template_html_below()
476
{
477
	// Load in any javascipt that could be deferred to the end of the page
478
	template_javascript(true);
479
480
	echo '
481
</body>
482
</html>';
483
}
484
485
/**
486
 * Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
487
 *
488
 * @param bool $force_show Whether to force showing it even if settings say otherwise
489
 */
490
function theme_linktree($force_show = false)
491
{
492
	global $context, $shown_linktree, $scripturl, $txt;
493
494
	// If linktree is empty, just return - also allow an override.
495
	if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
496
		return;
497
498
	echo '
499
				<div class="navigate_section">
500
					<ul>';
501
502
	// Each tree item has a URL and name. Some may have extra_before and extra_after.
503
	foreach ($context['linktree'] as $link_num => $tree)
504
	{
505
		echo '
506
						<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
507
508
		// Don't show a separator for the first one.
509
		// Better here. Always points to the next level when the linktree breaks to a second line.
510
		// Picked a better looking HTML entity, and added support for RTL plus a span for styling.
511
		if ($link_num != 0)
512
			echo '
513
							<span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';
514
515
		// Show something before the link?
516
		if (isset($tree['extra_before']))
517
			echo $tree['extra_before'], ' ';
518
519
		// Show the link, including a URL if it should have one.
520
		if (isset($tree['url']))
521
			echo '
522
							<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>';
523
		else
524
			echo '
525
							<span>' . $tree['name'] . '</span>';
526
527
		// Show something after the link...?
528
		if (isset($tree['extra_after']))
529
			echo ' ', $tree['extra_after'];
530
531
		echo '
532
						</li>';
533
	}
534
535
	echo '
536
					</ul>
537
				</div><!-- .navigate_section -->';
538
539
	$shown_linktree = true;
540
}
541
542
/**
543
 * Show the menu up top. Something like [home] [help] [profile] [logout]...
544
 */
545
function template_menu()
546
{
547
	global $context;
548
549
	echo '
550
					<ul class="dropmenu menu_nav">';
551
552
	// Note: Menu markup has been cleaned up to remove unnecessary spans and classes.
553
	foreach ($context['menu_buttons'] as $act => $button)
554
	{
555
		echo '
556
						<li class="button_', $act, '', !empty($button['sub_buttons']) ? ' subsections"' : '"', '>
557
							<a', $button['active_button'] ? ' class="active"' : '', ' href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', isset($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : '', '>
558
								', $button['icon'], '<span class="textmenu">', $button['title'], !empty($button['amt']) ? ' <span class="amt">' . $button['amt'] . '</span>' : '', '</span>
559
							</a>';
560
561
		// 2nd level menus
562
		if (!empty($button['sub_buttons']))
563
		{
564
			echo '
565
							<ul>';
566
567
			foreach ($button['sub_buttons'] as $childbutton)
568
			{
569
				echo '
570
								<li', !empty($childbutton['sub_buttons']) ? ' class="subsections"' : '', '>
571
									<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', isset($childbutton['onclick']) ? ' onclick="' . $childbutton['onclick'] . '"' : '', '>
572
										', $childbutton['title'], !empty($childbutton['amt']) ? ' <span class="amt">' . $childbutton['amt'] . '</span>' : '', '
573
									</a>';
574
				// 3rd level menus :)
575
				if (!empty($childbutton['sub_buttons']))
576
				{
577
					echo '
578
									<ul>';
579
580
					foreach ($childbutton['sub_buttons'] as $grandchildbutton)
581
						echo '
582
										<li>
583
											<a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', isset($grandchildbutton['onclick']) ? ' onclick="' . $grandchildbutton['onclick'] . '"' : '', '>
584
												', $grandchildbutton['title'], !empty($grandchildbutton['amt']) ? ' <span class="amt">' . $grandchildbutton['amt'] . '</span>' : '', '
585
											</a>
586
										</li>';
587
588
					echo '
589
									</ul>';
590
				}
591
592
				echo '
593
								</li>';
594
			}
595
			echo '
596
							</ul>';
597
		}
598
		echo '
599
						</li>';
600
	}
601
602
	echo '
603
					</ul><!-- .menu_nav -->';
604
}
605
606
/**
607
 * Generate a strip of buttons.
608
 *
609
 * @param array $button_strip An array with info for displaying the strip
610
 * @param string $direction The direction
611
 * @param array $strip_options Options for the button strip
612
 */
613
function template_button_strip($button_strip, $direction = '', $strip_options = array())
614
{
615
	global $context, $txt;
616
617
	if (!is_array($strip_options))
0 ignored issues
show
introduced by
The condition is_array($strip_options) is always true.
Loading history...
618
		$strip_options = array();
619
620
	// Create the buttons...
621
	$buttons = array();
622
	foreach ($button_strip as $key => $value)
623
	{
624
		// 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!)
625
		if (!isset($value['test']) || !empty($context[$value['test']]))
626
		{
627
			if (!isset($value['id']))
628
				$value['id'] = $key;
629
630
			$button = '
631
				<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>';
632
633
			if (!empty($value['sub_buttons']))
634
			{
635
				$button .= '
636
					<div class="top_menu dropmenu ' . $key . '_dropdown">
637
						<div class="viewport">
638
							<div class="overview">';
639
				foreach ($value['sub_buttons'] as $element)
640
				{
641
					if (isset($element['test']) && empty($context[$element['test']]))
642
						continue;
643
644
					$button .= '
645
								<a href="' . $element['url'] . '"><strong>' . $txt[$element['text']] . '</strong>';
646
					if (isset($txt[$element['text'] . '_desc']))
647
						$button .= '<br><span>' . $txt[$element['text'] . '_desc'] . '</span>';
648
					$button .= '</a>';
649
				}
650
				$button .= '
651
							</div><!-- .overview -->
652
						</div><!-- .viewport -->
653
					</div><!-- .top_menu -->';
654
			}
655
656
			$buttons[] = $button;
657
		}
658
	}
659
660
	// No buttons? No button strip either.
661
	if (empty($buttons))
662
		return;
663
664
	echo '
665
		<div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"' : ''), '>
666
			', implode('', $buttons), '
667
		</div>';
668
}
669
670
/**
671
 * Generate a list of quickbuttons.
672
 *
673
 * @param array $list_items An array with info for displaying the strip
674
 * @param string $list_class Used for integration hooks and as a class name
675
 * @param string $output_method The output method. If 'echo', simply displays the buttons, otherwise returns the HTML for them
676
 * @return void|string Returns nothing unless output_method is something other than 'echo'
677
 */
678
function template_quickbuttons($list_items, $list_class = null, $output_method = 'echo')
679
{
680
	global $txt;
681
682
	// Enable manipulation with hooks
683
	if (!empty($list_class))
684
		call_integration_hook('integrate_' . $list_class . '_quickbuttons', array(&$list_items));
685
686
	// Make sure the list has at least one shown item
687
	foreach ($list_items as $key => $li)
688
	{
689
		// Is there a sublist, and does it have any shown items
690
		if ($key == 'more')
691
		{
692
			foreach ($li as $subkey => $subli)
693
				if (isset($subli['show']) && !$subli['show'])
694
					unset($list_items[$key][$subkey]);
695
696
			if (empty($list_items[$key]))
697
				unset($list_items[$key]);
698
		}
699
		// A normal list item
700
		elseif (isset($li['show']) && !$li['show'])
701
			unset($list_items[$key]);
702
	}
703
704
	// Now check if there are any items left
705
	if (empty($list_items))
706
		return;
707
708
	// Print the quickbuttons
709
	$output = '
710
		<ul class="quickbuttons' . (!empty($list_class) ? ' quickbuttons_' . $list_class : '') . '">';
711
712
	// This is used for a list item or a sublist item
713
	$list_item_format = function($li)
714
	{
715
		$html = '
716
			<li' . (!empty($li['class']) ? ' class="' . $li['class'] . '"' : '') . (!empty($li['id']) ? ' id="' . $li['id'] . '"' : '') . (!empty($li['custom']) ? ' ' . $li['custom'] : '') . '>';
717
718
		if (isset($li['content']))
719
			$html .= $li['content'];
720
		else
721
			$html .= '
722
				<a href="' . (!empty($li['href']) ? $li['href'] : 'javascript:void(0);') . '"' . (!empty($li['javascript']) ? ' ' . $li['javascript'] : '') . '>
723
					' . (!empty($li['icon']) ? '<span class="main_icons ' . $li['icon'] . '"></span>' : '') . (!empty($li['label']) ? $li['label'] : '') . '
724
				</a>';
725
726
		$html .= '
727
			</li>';
728
729
		return $html;
730
	};
731
732
	foreach ($list_items as $key => $li)
733
	{
734
		// Handle the sublist
735
		if ($key == 'more')
736
		{
737
			$output .= '
738
			<li class="post_options">
739
				<a href="javascript:void(0);">' . $txt['post_options'] . '</a>
740
				<ul>';
741
742
			foreach ($li as $subli)
743
				$output .= $list_item_format($subli);
744
745
			$output .= '
746
				</ul>
747
			</li>';
748
		}
749
		// Ordinary list item
750
		else
751
			$output .= $list_item_format($li);
752
	}
753
754
	$output .= '
755
		</ul><!-- .quickbuttons -->';
756
757
	// There are a few spots where the result needs to be returned
758
	if ($output_method == 'echo')
759
		echo $output;
760
	else
761
		return $output;
762
}
763
764
/**
765
 * The upper part of the maintenance warning box
766
 */
767
function template_maint_warning_above()
768
{
769
	global $txt, $context, $scripturl;
770
771
	echo '
772
	<div class="errorbox" id="errors">
773
		<dl>
774
			<dt>
775
				<strong id="error_serious">', $txt['forum_in_maintenance'], '</strong>
776
			</dt>
777
			<dd class="error" id="error_list">
778
				', sprintf($txt['maintenance_page'], $scripturl . '?action=admin;area=serversettings;' . $context['session_var'] . '=' . $context['session_id']), '
779
			</dd>
780
		</dl>
781
	</div>';
782
}
783
784
/**
785
 * The lower part of the maintenance warning box.
786
 */
787
function template_maint_warning_below()
788
{
789
790
}
791
792
?>