Completed
Pull Request — patch_1-0-10 (#2898)
by Emanuele
06:09
created

index.template.php ➔ theme_linktree()   C

Complexity

Conditions 8
Paths 6

Size

Total Lines 40
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 14
nc 6
nop 1
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @name      ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
7
 *
8
 * This software is a derived product, based on:
9
 *
10
 * Simple Machines Forum (SMF)
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
13
 *
14
 * @version 1.0.10
15
 *
16
 */
17
18
 /**
19
 * This template is, perhaps, the most important template in the theme. It
20
 * contains the main template layer that displays the header and footer of
21
 * the forum, namely with body_above and body_below. It also contains the
22
 * menu sub template, which appropriately displays the menu; the init sub
23
 * template, which is there to set the theme up; (init can be missing.) and
24
 * the linktree sub template, which sorts out the link tree.
25
 *
26
 * The init sub template should load any data and set any hardcoded options.
27
 *
28
 * The body_above sub template is what is shown above the main content, and
29
 * should contain anything that should be shown up there.
30
 *
31
 * The body_below sub template, conversely, is shown after the main content.
32
 * It should probably contain the copyright statement and some other things.
33
 *
34
 * The linktree sub template should display the link tree, using the data
35
 * in the $context['linktree'] variable.
36
 *
37
 * The menu sub template should display all the relevant buttons the user
38
 * wants and or needs.
39
 */
40
41
/**
42
 * Initialize the template... mainly little settings.
43
 * load any data and set any hardcoded options.
44
 */
45
function template_init()
46
{
47
	return array(
48
		/* Use images from default theme when using templates from the default theme?
49
		  if this is 'always', images from the default theme will be used.
50
		  if this is 'defaults', images from the default theme will only be used with default templates.
51
		  if this is 'never' or isn't set at all, images from the default theme will not be used. */
52
		'use_default_images' => 'never',
53
54
		// The version this template/theme is for. This should probably be the version of the forum it was created for.
55
		'theme_version' => '1.0',
56
57
		// Set the following variable to true if this theme requires the optional theme strings file to be loaded.
58
		'require_theme_strings' => false,
59
60
		// This is used for the color variants.
61
		'theme_variants' => array('light', 'besocial'),
62
63
		// If the following variable is set to true, the avatar of the last poster will be displayed on the boardindex and message index.
64
		'avatars_on_indexes' => true,
65
66
		// This is used in the main menus to create a number next to the title of the menu to indicate the number of unread messages,
67
		// moderation reports, etc. You can style each menu level indicator as desired.
68
		'menu_numeric_notice' => array(
69
			// Top level menu entries
70
			0 => ' <span class="pm_indicator">%1$s</span>',
71
			// First dropdown
72
			1 => ' <span>[<strong>%1$s</strong>]</span>',
73
			// Second level dropdown
74
			2 => ' <span>[<strong>%1$s</strong>]</span>',
75
		),
76
77
		// This slightly more complex array, instead, will deal with page indexes as frequently requested by Ant :P
78
		// Oh no you don't. :D This slightly less complex array now has cleaner markup. :P
79
		// @todo - God it's still ugly though. Can't we just have links where we need them, without all those spans?
80
		// How do we get anchors only, where they will work? Spans and strong only where necessary?
81
		'page_index_template' => array(
82
			'base_link' => '<li class="linavPages"><a class="navPages" href="{base_link}" role="menuitem">%2$s</a></li>',
83
			'previous_page' => '<span class="previous_page" role="menuitem">{prev_txt}</span>',
84
			'current_page' => '<li class="linavPages"><strong class="current_page" role="menuitem">%1$s</strong></li>',
85
			'next_page' => '<span class="next_page" role="menuitem">{next_txt}</span>',
86
			'expand_pages' => '<li class="linavPages expand_pages" role="menuitem" {custom}> <a href="#">...</a> </li>',
87
			'all' => '<span class="linavPages all_pages" role="menuitem">{all_txt}</span>',
88
		),
89
90
		// @todo find a better place if we are going to create a notifications template
91
		'mentions' => array('mentioner_template' => '<a href="{mem_url}" class="mentionavatar">{avatar_img}{mem_name}</a>')
92
	);
93
}
94
95
/**
96
 * Simplify the use of callbacks in the templates.
97
 * @param string $id - A prefix for the template functions the final name
98
 *                     should look like:
99
 *                     template_{$id}_{$array[n]}
100
 * @param string[] $array - The array of function suffixes
101
 */
102
function call_template_callbacks($id, $array)
103
{
104
	if (empty($array))
105
		return;
106
107
	foreach ($array as $callback)
108
	{
109
		$func = 'template_' . $id . '_' . $callback;
110
		if (function_exists($func))
111
			$func();
112
	}
113
}
114
115
/**
116
 * The main sub template above the content.
117
 */
118
function template_html_above()
119
{
120
	global $context, $settings, $scripturl, $txt, $modSettings;
121
122
	// Show right to left and the character set for ease of translating.
123
	echo '<!DOCTYPE html>
124
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
125
<head>
126
	<title>', $context['page_title_html_safe'], '</title>';
127
128
	// Tell IE to render the page in standards not compatibility mode. really for ie >= 8
129
	// Note if this is not in the first 4k, its ignored, that's why its here
130
	if (isBrowser('ie'))
131
		echo '
132
	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />';
133
134
	// load in any css from addons or themes so they can overwrite if wanted
135
	template_css();
136
137
	// Save some database hits, if a width for multiple wrappers is set in admin.
138
	if (!empty($settings['forum_width']))
139
		echo '
140
	<style>
141
		.wrapper {width: ', $settings['forum_width'], ';}
142
	</style>';
143
144
	echo '
145
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
146
	<meta name="viewport" content="width=device-width" />
147
	<meta name="mobile-web-app-capable" content="yes" />
148
	<meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
149
	<meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '';
150
151
	// OpenID enabled? Advertise the location of our endpoint using YADIS protocol.
152
	if (!empty($modSettings['enableOpenID']))
153
		echo '
154
	<meta http-equiv="x-xrds-location" content="' . $scripturl . '?action=xrds" />';
155
156
	// Please don't index these Mr Robot.
157
	if (!empty($context['robot_no_index']))
158
		echo '
159
	<meta name="robots" content="noindex" />';
160
161
	// Present a canonical url for search engines to prevent duplicate content in their indices.
162
	if (!empty($context['canonical_url']))
163
		echo '
164
	<link rel="canonical" href="', $context['canonical_url'], '" />';
165
166
	// Show all the relative links, such as help, search, contents, and the like.
167
	echo '
168
	<link rel="shortcut icon" sizes="196x196" href="' . $settings['images_url'] . '/mobile.png" />
169
	<link rel="help" href="', $scripturl, '?action=help" />
170
	<link rel="contents" href="', $scripturl, '" />', ($context['allow_search'] ? '
171
	<link rel="search" href="' . $scripturl . '?action=search" />' : '');
172
173
	// If RSS feeds are enabled, advertise the presence of one.
174
	if (!empty($context['newsfeed_urls']))
175
		echo '
176
	<link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $context['newsfeed_urls']['rss'], '" />
177
	<link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['atom'], '" href="', $context['newsfeed_urls']['atom'], '" />';
178
179
	// If we're viewing a topic, these should be the previous and next topics, respectively.
180
	if (!empty($context['links']['next']))
181
		echo '<link rel="next" href="', $context['links']['next'], '" />';
182
	elseif (!empty($context['current_topic']))
183
		echo '<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
184
185
	if (!empty($context['links']['prev']))
186
		echo '<link rel="prev" href="', $context['links']['prev'], '" />';
187
	elseif (!empty($context['current_topic']))
188
		echo '<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />';
189
190
	// If we're in a board, or a topic for that matter, the index will be the board's index.
191
	if (!empty($context['current_board']))
192
		echo '
193
	<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';
194
195
	// load in any javascript files from addons and themes
196
	template_javascript();
197
198
	// Output any remaining HTML headers. (from addons, maybe?)
199
	echo $context['html_headers'];
200
201
	// A little help for our friends
202
	echo '
203
	<!--[if lt IE 9]>
204
		<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
205
	<![endif]-->';
206
207
	echo '
208
</head>
209
<body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? htmlspecialchars($context['current_action'], ENT_COMPAT, 'UTF-8') : (!empty($context['current_board']) ?
210
					'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . htmlspecialchars($context['current_board'], ENT_COMPAT, 'UTF-8') : '', '">';
211
}
212
213
/**
214
 * Section above the main contents of the page, after opening the body tag
215
 */
216
function template_body_above()
217
{
218
	global $context, $settings, $scripturl, $txt, $modSettings;
219
220
	// Go to top/bottom of page links and skipnav link for a11y.
221
	echo '
222
	<a id="top" href="#skipnav">', $txt['skip_nav'], '</a>
223
	<a href="#top" id="gotop" title="', $txt['go_up'], '">&#8593;</a>
224
	<a href="#bot" id="gobottom" title="', $txt['go_down'], '">&#8595;</a>';
225
226
	// Skip nav link.
227
	echo '
228
	<div id="top_section">
229
		<div class="wrapper">';
230
231
	call_template_callbacks('th', $context['theme_header_callbacks']);
232
233
	echo '
234
		</div>
235
		<div id="header" class="wrapper', !empty($settings['header_layout']) ? ($settings['header_layout'] == 1 ? ' centerheader' : ' rightheader') : '', '"', empty($context['minmax_preferences']['upshrink']) ? '' : ' style="display: none;" aria-hidden="true"', '>
236
			<h1 id="forumtitle">
237
				<a class="forumlink" href="', $scripturl, '">', $context['forum_name'], '</a>';
238
239
	echo '
240
				<span id="logobox">
241
					<img id="logo" src="', $context['header_logo_url_html_safe'], '" alt="', $context['forum_name_html_safe'], '" title="', $context['forum_name_html_safe'], '" />', empty($settings['site_slogan']) ? '' : '
242
					<span id="siteslogan">' . $settings['site_slogan'] . '</span>', '
243
				</span>
244
			</h1>';
245
246
	// Show the menu here, according to the menu sub template.
247
	echo '
248
		</div>';
249
250
	// WAI-ARIA a11y tweaks have been applied here.
251
	echo '
252
		<div id="menu_nav" role="navigation">
253
			', template_menu(), '
254
		</div>
255
	</div>
256
	<div id="wrapper" class="wrapper">
257
		<div id="upper_section"', empty($context['minmax_preferences']['upshrink']) ? '' : ' style="display: none;" aria-hidden="true"', '>';
258
259
	call_template_callbacks('uc', $context['upper_content_callbacks']);
260
261
	echo '
262
		</div>';
263
264
	// Show the navigation tree.
265
	theme_linktree();
266
267
	// The main content should go here. @todo - Skip nav link.
268
	echo '
269
		<div id="main_content_section"><a id="skipnav"></a>';
270
}
271
272
/**
273
 If the user is logged in, display the time, or a maintenance warning for admins.
274
 @todo - TBH I always intended the time/date to be more or less a place holder for more important things.
275
 The maintenance mode warning for admins is an obvious one, but this could also be used for moderation notifications.
276
 I also assumed this would be an obvious place for sites to put a string of icons to link to their FB, Twitter, etc.
277
 This could still be done via conditional, so that administration and moderation notices were still active when applicable.
278
 */
279
function template_th_login_bar()
280
{
281
	global $context, $modSettings, $txt, $scripturl, $settings;
282
283
		echo '
284
			<div id="top_section_notice" class="user">
285
				<form action="', $scripturl, '?action=login2;quicklogin" method="post" accept-charset="UTF-8" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
286
					<div id="password_login">
287
						<input type="text" name="user" size="10" class="input_text" placeholder="', $txt['username'], '" />
288
						<input type="password" name="passwrd" size="10" class="input_password" placeholder="', $txt['password'], '" />
289
						<select name="cookielength">
290
							<option value="60">', $txt['one_hour'], '</option>
291
							<option value="1440">', $txt['one_day'], '</option>
292
							<option value="10080">', $txt['one_week'], '</option>
293
							<option value="43200">', $txt['one_month'], '</option>
294
							<option value="-1" selected="selected">', $txt['forever'], '</option>
295
						</select>
296
						<input type="submit" value="', $txt['login'], '" class="button_submit" />
297
					</div>
298
					<input type="hidden" name="hash_passwrd" value="" />
299
					<input type="hidden" name="old_hash_passwrd" value="" />
300
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
301
					<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />';
302
303
		if (!empty($modSettings['enableOpenID']))
304
			echo '
305
					<a class="button_submit top_button" href="', $scripturl, '?action=login;openid"><img src="' . $settings['images_url'] . '/openid.png" title="' . $txt['openid'] . '" alt="' . $txt['openid'] . '" /></a>';
306
		echo '
307
				</form>
308
			</div>';
309
}
310
311
/**
312
 * A simple search bar (used in the header)
313
 */
314
function template_th_search_bar()
315
{
316
	global $context, $modSettings, $txt, $scripturl;
317
318
	echo '
319
			<form id="search_form" action="', $scripturl, '?action=search;sa=results" method="post" accept-charset="UTF-8">
320
				<label for="quicksearch">
321
					<input type="text" name="search" id="quicksearch" value="" class="input_text" placeholder="', $txt['search'], '" />
322
				</label>';
323
324
	// Using the quick search dropdown?
325
	if (!empty($modSettings['search_dropdown']))
326
	{
327
		$selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
328
329
		echo '
330
				<label for="search_selection">
331
				<select name="search_selection" id="search_selection">
332
					<option value="all"', ($selected == 'all' ? ' selected="selected"' : ''), '>', $txt['search_entireforum'], ' </option>';
333
334
		// Can't limit it to a specific topic if we are not in one
335
		if (!empty($context['current_topic']))
336
			echo '
337
					<option value="topic"', ($selected == 'current_topic' ? ' selected="selected"' : ''), '>', $txt['search_thistopic'], '</option>';
338
339
		// Can't limit it to a specific board if we are not in one
340
		if (!empty($context['current_board']))
341
			echo '
342
					<option value="board"', ($selected == 'current_board' ? ' selected="selected"' : ''), '>', $txt['search_thisbrd'], '</option>';
343
344
		if (!empty($context['additional_dropdown_search']))
345
			foreach ($context['additional_dropdown_search'] as $name => $engine)
346
				echo '
347
					<option value="', $name, '">', $engine['name'], '</option>';
348
349
		echo '
350
					<option value="members"', ($selected == 'members' ? ' selected="selected"' : ''), '>', $txt['search_members'], ' </option>
351
				</select>
352
				</label>';
353
	}
354
355
	// Search within current topic?
356
	if (!empty($context['current_topic']))
357
		echo '
358
				<input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_topic' : 'topic'), '" value="', $context['current_topic'], '" />';
359
	// If we're on a certain board, limit it to this board ;).
360
	elseif (!empty($context['current_board']))
361
		echo '
362
				<input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_brd[' : 'brd['), $context['current_board'], ']"', ' value="', $context['current_board'], '" />';
363
364
	echo '
365
				<input type="submit" name="search;sa=results" value="', $txt['search'], '" class="button_submit', (!empty($modSettings['search_dropdown'])) ? ' with_select' : '', '" />
366
				<input type="hidden" name="advanced" value="0" />
367
			</form>';
368
}
369
370
/**
371
 * The news fader wrapped in a div and with "news" text
372
 */
373
function template_uc_news_fader()
374
{
375
	global $settings, $context, $txt;
376
377
	// Display either news fader and random news lines (not both). These now run most of the same mark up and CSS. Less complication = happier n00bz. :)
378
	if (!empty($settings['enable_news']) && !empty($context['random_news_line']))
379
	{
380
		echo '
381
			<div id="news">
382
				<h2>', $txt['news'], '</h2>
383
				', template_news_fader(), '
384
			</div>';
385
	}
386
}
387
388
/**
389
 * Section down the page, before closing body
390
 */
391
function template_body_below()
392
{
393
	global $context, $txt;
394
395
	echo '
396
		</div>
397
	</div>';
398
399
	// Show RSS link, as well as the copyright.
400
	// Footer is full-width. Wrapper inside automatically matches admin width setting.
401
	echo '
402
	<div id="footer_section"><a id="bot"></a>
403
		<div class="wrapper">
404
			<ul>
405
				<li class="copyright">',
406
					theme_copyright(), '
407
				</li>',
408
				!empty($context['newsfeed_urls']['rss']) ? '<li>
409
					<a id="button_rss" href="' . $context['newsfeed_urls']['rss'] . '" class="rssfeeds new_win"><i class="largetext fa fa-rss"></i></a>
410
				</li>' : '',
411
			'</ul>';
412
413
	// Show the load time?
414
	if ($context['show_load_time'])
415
		echo '
416
			<p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
417
}
418
419
/**
420
 * Section down the page, at closing html tag
421
 */
422
function template_html_below()
423
{
424
	global $context;
425
426
	echo '
427
		</div>
428
	</div>';
429
430
	// load in any javascript that could be deferred to the end of the page
431
	template_javascript(true);
432
433
	// Anything special to put out?
434
	if (!empty($context['insert_after_template']))
435
		echo $context['insert_after_template'];
436
437
	echo '
438
</body>
439
</html>';
440
}
441
442
/**
443
 * Show a linktree. This is that thing that shows
444
 * "My Community | General Category | General Discussion"..
445
 * @param string $default a string representing the index in $context where
446
 *               the linktree is stored (default value is 'linktree')
447
 */
448
function theme_linktree($default = 'linktree')
449
{
450
	global $context, $settings;
451
452
	// If linktree is empty, just return - also allow an override.
453
	if (empty($context[$default]))
454
		return;
455
456
	// @todo - Look at changing markup here slightly. Need to incorporate relevant aria roles.
457
	echo '
458
				<ul class="navigate_section">';
459
460
	// Each tree item has a URL and name. Some may have extra_before and extra_after.
461
	// Added a linktree class to make targeting dividers easy.
462
	foreach ($context[$default] as $pos => $tree)
463
	{
464
		echo '
465
					<li class="linktree">
466
						<span>';
467
468
		// Dividers moved to pseudo-elements in CSS.
469
		// Show something before the link?
470
		if (isset($tree['extra_before']))
471
			echo $tree['extra_before'];
472
473
		// Show the link, including a URL if it should have one.
474
		echo $settings['linktree_link'] && isset($tree['url']) ? '<a href="' . $tree['url'] . '">' . ($pos == 0 ? '<i class="fa fa-home fa-lg"></i>' : $tree['name']) . '</a>' : $tree['name'];
475
476
		// Show something after the link...?
477
		if (isset($tree['extra_after']))
478
			echo $tree['extra_after'];
479
480
		echo '
481
						</span>
482
					</li>';
483
	}
484
485
	echo '
486
				</ul>';
487
}
488
489
/**
490
 * Show the menu up top. Something like [home] [help] [profile] [logout]...
491
 */
492
function template_menu()
493
{
494
	global $context, $txt;
495
496
	// WAI-ARIA a11y tweaks have been applied here.
497
	echo '
498
					<ul id="main_menu" class="wrapper" role="menubar">';
499
500
	// The upshrink image, right-floated.
501
	echo '
502
						<li id="collapse_button" class="listlevel1">
503
							<a class="linklevel1">
504
								<span id="upshrink_header">&nbsp;
505
									<span id="upshrink" class="collapse" style="display: none;" title="', $txt['upshrink_description'], '"></span>
506
								</span>
507
							</a>
508
						</li>';
509
510
	foreach ($context['menu_buttons'] as $act => $button)
511
	{
512
		echo '
513
						<li id="button_', $act, '" class="listlevel1', !empty($button['sub_buttons']) ? ' subsections" aria-haspopup="true"' : '"', ' role="menuitem">
514
							<a ', (!empty($button['data-icon']) ? 'data-icon="' . $button['data-icon'] . '" ' : ''), 'class="linklevel1', !empty($button['active_button']) ? ' active' : '', (!empty($button['indicator']) ? ' indicator' : '' ), '" href="', $button['href'], '" ', isset($button['target']) ? 'target="' . $button['target'] . '"' : '', '><span class="button_title">', $button['title'], '</span></a>';
515
516
		// Any 2nd level menus?
517
		if (!empty($button['sub_buttons']))
518
		{
519
			echo '
520
							<ul class="menulevel2" role="menu">';
521
522
			foreach ($button['sub_buttons'] as $childact => $childbutton)
523
			{
524
				echo '
525
								<li id="button_', $childact, '" class="listlevel2', !empty($childbutton['sub_buttons']) ? ' subsections" aria-haspopup="true"' : '"', ' role="menuitem">
526
									<a class="linklevel2" href="', $childbutton['href'], '" ', isset($childbutton['target']) ? 'target="' . $childbutton['target'] . '"' : '', '>', $childbutton['title'], '</a>';
527
528
				// 3rd level menus :)
529
				if (!empty($childbutton['sub_buttons']))
530
				{
531
					echo '
532
									<ul class="menulevel3" role="menu">';
533
534
					foreach ($childbutton['sub_buttons'] as $grandchildact => $grandchildbutton)
535
						echo '
536
										<li id="button_', $grandchildact, '" class="listlevel3" role="menuitem">
537
											<a class="linklevel3" href="', $grandchildbutton['href'], '" ', isset($grandchildbutton['target']) ? 'target="' . $grandchildbutton['target'] . '"' : '', '>', $grandchildbutton['title'], '</a>
538
										</li>';
539
540
					echo '
541
									</ul>';
542
				}
543
544
				echo '
545
								</li>';
546
			}
547
548
			echo '
549
							</ul>';
550
		}
551
552
		echo '
553
						</li>';
554
	}
555
556
	echo '
557
					</ul>';
558
559
	// Define the upper_section toggle in javascript.
560
	echo '
561
				<script><!-- // --><![CDATA[
562
					var oMainHeaderToggle = new elk_Toggle({
563
						bToggleEnabled: true,
564
						bCurrentlyCollapsed: ', empty($context['minmax_preferences']['upshrink']) ? 'false' : 'true', ',
565
						aSwappableContainers: [
566
							\'upper_section\',\'header\'
567
						],
568
						aSwapClasses: [
569
							{
570
								sId: \'upshrink\',
571
								classExpanded: \'collapse\',
572
								titleExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
573
								classCollapsed: \'expand\',
574
								titleCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
575
							}
576
						],
577
						oThemeOptions: {
578
							bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
579
							sOptionName: \'minmax_preferences\',
580
							sSessionId: elk_session_id,
581
							sSessionVar: elk_session_var,
582
							sAdditionalVars: \';minmax_key=upshrink\'
583
						},
584
						oCookieOptions: {
585
							bUseCookie: elk_member_id == 0 ? true : false,
586
							sCookieName: \'upshrink\'
587
						}
588
					});
589
				// ]]></script>';
590
}
591
592
/**
593
 * Generate a strip of buttons.
594
 *
595
 * @param mixed[] $button_strip
596
 * @param string $direction = ''
597
 * @param string[] $strip_options = array()
598
 */
599
function template_button_strip($button_strip, $direction = '', $strip_options = array())
600
{
601
	global $context, $txt;
602
603
	// Not sure if this can happen, but people can misuse functions very efficiently
604
	if (empty($button_strip))
605
		return;
606
607
	if (!is_array($strip_options))
608
		$strip_options = array();
609
610
	// List the buttons in reverse order for RTL languages.
611
	if ($context['right_to_left'])
612
		$button_strip = array_reverse($button_strip, true);
613
614
	// Create the buttons... now with cleaner markup (yay!).
615
	$buttons = array();
616
	foreach ($button_strip as $key => $value)
617
	{
618
		if (!isset($value['test']) || !empty($context[$value['test']]))
619
			$buttons[] = '
620
								<li role="menuitem"><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="linklevel1 button_strip_' . $key . (!empty($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '>' . $txt[$value['text']] . '</a></li>';
621
	}
622
623
	// No buttons? No button strip either.
624
	if (empty($buttons))
625
		return;
626
627
	echo '
628
							<ul role="menubar" class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"' : ''), '>
629
								', implode('', $buttons), '
630
							</ul>';
631
}
632
633
/**
634
 * Generate a strip of "quick" buttons (those present next to each message)
635
 *
636
 * What it does:
637
 * - Create a quick button, pass an array of the button name with key values
638
 * - array('somename' => array(href => text => custom => test =>))
639
 *		- href => link to call when button is pressed
640
 *		- text => text to display in the button
641
 *		- custom => custom action to perform, generally used to add 'onclick' events (optional)
642
 *		- test => key to check in the $tests array before showing the button (optional)
643
 *	- checkboxes can be shown as well as buttons, use array('check' => array(checkbox => (true | always), name => value =>)
644
 *		- if true follows show moderation as checkbox setting, always will always show
645
 *		- name => name of the checkbox array, like delete, will have [] added for the form
646
 *		- value => value for the checkbox to return in the post
647
 *
648
 * @param string $strip - the $context index where the strip is stored
649
 * @param bool[] $tests - an array of tests to determine if the button should
650
 * be displayed or not
651
 */
652
function template_quickbutton_strip($strip, $tests = array())
653
{
654
	global $options;
655
656
	$buttons = array();
657
658
	foreach ($strip as $key => $value)
659
	{
660
		if (isset($value['checkbox']))
661
		{
662
			if (!empty($value['checkbox']) && ((!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) || $value['checkbox'] === 'always'))
663
				$buttons[] = '
664
						<li class="listlevel1 ' . $key . '">
665
							<input class="input_check ' . $key . '_check" type="checkbox" name="' . $value['name'] . '[]" value="' . $value['value'] . '" />
666
						</li>';
667
		}
668
		elseif (!isset($value['test']) || !empty($tests[$value['test']]))
669
			$buttons[] = '
670
						<li class="listlevel1">
671
							<a href="' . $value['href'] . '" class="linklevel1 ' . $key . '_button"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '>' . $value['text'] . '</a>
672
						</li>';
673
	}
674
675
	// No buttons? No button strip either.
676
	if (empty($buttons))
677
		return;
678
679
	echo '
680
					<ul class="quickbuttons">', implode('
681
						', $buttons), '
682
					</ul>';
683
}
684
685
/**
686
 * Very simple and basic template to display a legend explaining the meaning
687
 * of some icons used in the messages listing (locked, sticky, etc.)
688
 */
689
function template_basicicons_legend()
690
{
691
	global $context, $modSettings, $txt;
692
693
	echo '
694
		<p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? '
695
			<span class="topicicon img_profile"></span>' . $txt['participation_caption'] : '<span class="topicicon img_normal"> </span>' . $txt['normal_topic'], '<br />
696
			' . (!empty($modSettings['pollMode']) ? '<span class="topicicon img_poll"> </span>' . $txt['poll'] : '') . '
697
		</p>
698
		<p>
699
			<span class="topicicon img_locked"> </span>' . $txt['locked_topic'] . '<br />' . (!empty($modSettings['enableStickyTopics']) ? '
700
			<span class="topicicon img_sticky"> </span>' . $txt['sticky_topic'] . '<br />' : '') . '
701
		</p>';
702
}
703
704
/**
705
 * Show a box with a message, mostly used to show errors, but can be used to show
706
 * sucess as well
707
 *
708
 * Looks for the display infomration in the $context[$error_id] array
709
 * Keys of array are 'type'
710
 *  - empty or success for successbox
711
 *  - serious for error box
712
 *  - warning for warning box
713
 * 'title' - optional value to place above list
714
 * 'errors' - array of text strings to display in the box
715
 *
716
 * @param string $error_id
717
 */
718
function template_show_error($error_id)
719
{
720
	global $context;
721
722
	if (empty($error_id))
723
		return;
724
725
	$error = isset($context[$error_id]) ? $context[$error_id] : array();
726
727
	echo '
728
					<div id="', $error_id, '" class="', (isset($error['type']) ? ($error['type'] === 'serious' ? 'errorbox' : 'warningbox') : 'successbox'), '" ', empty($error['errors']) ? ' style="display: none"' : '', '>';
729
730
	// Optional title for our results
731
	if (!empty($error['title']))
732
		echo '
733
						<dl>
734
							<dt>
735
								<strong id="', $error_id, '_title">', $error['title'], '</strong>
736
							</dt>
737
							<dd>';
738
739
	// Everything that went wrong, or correctly :)
740
	if (!empty($error['errors']))
741
	{
742
		echo '
743
								<ul', (isset($error['type']) ? ' class="error"' : ''), ' id="', $error_id, '_list">';
744
745
		foreach ($error['errors'] as $key => $err)
746
			echo '
747
									<li id="', $error_id, '_', $key, '">', $err, '</li>';
748
		echo '
749
								</ul>';
750
	}
751
752
	// All done
753
	if (!empty($error['title']))
754
		echo '
755
							</dd>
756
						</dl>';
757
758
	echo '
759
					</div>';
760
}
761
762
/**
763
 * Another used and abused piece of template that can be found everywhere
764
 *
765
 * @param string $button_strip index of $context to create the button strip
766
 * @param string $strip_direction direction of the button strip (see template_button_strip for details)
767
 * @param array $options array of optional values, possible values:
768
 *                - 'page_index' (string) index of $context where is located the pages index generated by constructPageIndex
769
 *                - 'page_index_markup' (string) markup for the page index, overrides 'page_index' and can be used if
770
 *                   the page index code is not in the first level of $context
771
 *                - 'extra' (string) used to add html markup at the end of the template
772
 */
773
function template_pagesection($button_strip = false, $strip_direction = '', $options = array())
774
{
775
	global $context;
776
777
	// Hmmm. I'm a tad wary of having floatleft here but anyway............
778
	// @todo - Try using table-cell display here. Should do auto rtl support. Less markup, less css. :)
779
	if (!empty($options['page_index_markup']))
780
		$pages = '<ul ' . (isset($options['page_index_id']) ? 'id="' . $options['page_index_id'] . '" ' : '') . 'class="pagelinks floatleft" role="menubar">' . $options['page_index_markup'] . '</ul>';
781
	else
782
	{
783
		if (!isset($options['page_index']))
784
			$options['page_index'] = 'page_index';
785
		$pages = empty($context[$options['page_index']]) ? '' : '<ul ' . (isset($options['page_index_id']) ? 'id="' . $options['page_index_id'] . '" ' : '') . 'class="pagelinks floatleft" role="menubar">' . $context[$options['page_index']] . '</ul>';
786
	}
787
788
	if (!isset($options['extra']))
789
		$options['extra'] = '';
790
791
	echo '
792
			<div class="pagesection" role="application">
793
				', $pages, '
794
				', !empty($button_strip) && !empty($context[$button_strip]) ? template_button_strip($context[$button_strip], $strip_direction) : '',
795
	$options['extra'], '
796
			</div>';
797
}
798
799
/**
800
 * This is the newsfader
801
 */
802
function template_news_fader()
803
{
804
	global $settings, $context;
805
806
	echo '
807
		<ul id="elkFadeScroller">
808
			<li>
809
				', $settings['enable_news'] == 2 ? implode('</li><li>', $context['news_lines']) : $context['random_news_line'], '
810
			</li>
811
		</ul>';
812
813
	addInlineJavascript('
814
		$(\'#elkFadeScroller\').Elk_NewsFader(' . (empy($settings['newsfader_time']) : '' : '{\'iFadeDelay\': ' . $settings['newsfader_time'] . '}') . ');', true);
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ':'
Loading history...
815
}
816