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