Passed
Push — release-2.1 ( 59d839...229f76 )
by Mert
05:21
created

template_quickbuttons()   F

Complexity

Conditions 24
Paths 306

Size

Total Lines 83
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 24
eloc 41
nc 306
nop 3
dl 0
loc 83
rs 2.0083
c 2
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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