Completed
Pull Request — patch_1-1-4 (#3191)
by Emanuele
13:25
created

index.template.php ➔ template_uc_generic_infobox()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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