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