Completed
Push — release-2.1 ( 689ddb...2ad0d4 )
by Michael
07:40
created

BoardIndex.template.php ➔ template_bi_board_children()   C

Complexity

Conditions 12
Paths 56

Size

Total Lines 31
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 15
nc 56
nop 1
dl 0
loc 31
rs 5.1612
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2017 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 4
11
 */
12
13
/**
14
 * The top part of the outer layer of the boardindex
15
 */
16
function template_boardindex_outer_above()
17
{
18
	template_newsfader();
19
}
20
21
/**
22
 * This shows the newsfader
23
 */
24
function template_newsfader()
25
{
26
	global $context, $settings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
27
28
	// Show the news fader?  (assuming there are things to show...)
29
	if (!empty($settings['show_newsfader']) && !empty($context['news_lines']))
30
	{
31
		echo '
32
		<ul id="smf_slider" class="roundframe">';
33
34
		foreach ($context['news_lines'] as $news)
35
		{
36
			echo '
37
			<li>', $news, '</li>';
38
		}
39
40
		echo '
41
		</ul>
42
		<script>
43
			jQuery("#smf_slider").slippry({
44
				pause: ', $settings['newsfader_time'], ',
45
				adaptiveHeight: 0,
46
				captions: 0,
47
				controls: 0,
48
			});
49
		</script>';
50
	}
51
}
52
53
/**
54
 * This actually displays the board index
55
 */
56
function template_main()
57
{
58
	global $context, $txt, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
59
60
	echo '
61
	<div id="boardindex_table" class="boardindex_table">';
62
63
	/* Each category in categories is made up of:
64
	id, href, link, name, is_collapsed (is it collapsed?), can_collapse (is it okay if it is?),
65
	new (is it new?), collapse_href (href to collapse/expand), collapse_image (up/down image),
66
	and boards. (see below.) */
67
	foreach ($context['categories'] as $category)
68
	{
69
		// If theres no parent boards we can see, avoid showing an empty category (unless its collapsed)
70
		if (empty($category['boards']) && !$category['is_collapsed'])
71
			continue;
72
73
		echo '
74
		<div class="main_container">
75
			<div class="cat_bar ', $category['is_collapsed'] ? 'collapsed' : '','" id="category_', $category['id'], '">
76
				<h3 class="catbg">';
77
78
		// If this category even can collapse, show a link to collapse it.
79
		if ($category['can_collapse'])
80
			echo '
81
					<span id="category_', $category['id'], '_upshrink" class="', $category['is_collapsed'] ? 'toggle_down' : 'toggle_up', ' floatright" data-collapsed="', (int) $category['is_collapsed'], '" title="', !$category['is_collapsed'] ? $txt['hide_category'] : $txt['show_category'], '" style="display: none;"></span>';
82
83
		echo '
84
					', $category['link'], '
85
				</h3>', !empty($category['description']) ? '
86
				<div class="desc">' . $category['description'] . '</div>' : '', '
87
			</div>
88
			<div id="category_', $category['id'], '_boards" ', (!empty($category['css_class']) ? ('class="' . $category['css_class'] . '"') : ''), '>';
89
90
			/* Each board in each category's boards has:
91
			new (is it new?), id, name, description, moderators (see below), link_moderators (just a list.),
92
			children (see below.), link_children (easier to use.), children_new (are they new?),
93
			topics (# of), posts (# of), link, href, and last_post. (see below.) */
94
			foreach ($category['boards'] as $board)
95
			{
96
				echo '
97
				<div id="board_', $board['id'], '" class="up_contain ', (!empty($board['css_class']) ? $board['css_class'] : ''), '">
98
					<div class="board_icon">', function_exists('template_bi_' . $board['type'] . '_icon') ? call_user_func('template_bi_' . $board['type'] . '_icon', $board) : template_bi_board_icon($board), '
99
					</div>
100
					<div class="info">', function_exists('template_bi_' . $board['type'] . '_info') ? call_user_func('template_bi_' . $board['type'] . '_info', $board) : template_bi_board_info($board);
101
102
				// Show some basic information about the number of posts, etc.
103
					echo '
104
					</div>
105
					<div class="board_stats">', function_exists('template_bi_' . $board['type'] . '_stats') ? call_user_func('template_bi_' . $board['type'] . '_stats', $board) : template_bi_board_stats($board), '
106
					</div>
107
					<div class="lastpost ',!empty($board['last_post']['id']) ? 'lpr_border' : 'hidden', '">', function_exists('template_bi_' . $board['type'] . '_lastpost') ? call_user_func('template_bi_' . $board['type'] . '_lastpost', $board) : template_bi_board_lastpost($board), '
108
					</div>';
109
110
				// Won't somebody think of the children!
111
				if (function_exists('template_bi_' . $board['type'] . '_children'))
112
					call_user_func('template_bi_' . $board['type'] . '_children', $board);
113
				else
114
					template_bi_board_children($board);
115
116
				echo '
117
					</div>';
118
			}
119
120
		echo '
121
			</div>
122
		</div>';
123
	}
124
125
	echo '
126
	</div>';
127
128
	// Show the mark all as read button?
129
	if ($context['user']['is_logged'] && !empty($context['categories']))
130
		echo '
131
		<div class="mark_read">', template_button_strip($context['mark_read_button'], 'right'), '</div>';
132
}
133
134
/**
135
 * Outputs the board icon for a standard board.
136
 *
137
 * @param array $board Current board information.
138
 */
139
function template_bi_board_icon($board)
140
{
141
	global $context, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
142
143
	echo '
144
						<a href="', ($context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '" class="board_', $board['board_class'], '"', !empty($board['board_tooltip']) ? ' title="' . $board['board_tooltip'] . '"' : '', '></a>';
145
}
146
147
/**
148
 * Outputs the board icon for a redirect.
149
 *
150
 * @param array $board Current board information.
151
 */
152
function template_bi_redirect_icon($board)
153
{
154
	global $context, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
155
156
	echo '
157
						<a href="', $board['href'], '" class="board_', $board['board_class'], '"', !empty($board['board_tooltip']) ? ' title="' . $board['board_tooltip'] . '"' : '', '></a>';
158
}
159
160
/**
161
 * Outputs the board info for a standard board or redirect.
162
 *
163
 * @param array $board Current board information.
164
 */
165
function template_bi_board_info($board)
166
{
167
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
168
169
	echo '
170
						<a class="subject mobile_subject" href="', $board['href'], '" id="b', $board['id'], '">
171
							', $board['name'], '
172
							<p class="board_description mobile_display">', $board['description'], '</p>
173
						</a>';
174
175
	// Has it outstanding posts for approval?
176 View Code Duplication
	if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
177
		echo '
178
						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
179
180
	echo '
181
						<p class="board_description">', $board['description'], '</p>';
182
183
	// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
184 View Code Duplication
	if (!empty($board['link_moderators']))
185
		echo '
186
						<p class="moderators">', count($board['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
187
}
188
189
/**
190
 * Outputs the board stats for a standard board.
191
 *
192
 * @param array $board Current board information.
193
 */
194
function template_bi_board_stats($board)
195
{
196
	global $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
197
198
	echo '
199
						<p>', comma_format($board['posts']), ' ', $txt['posts'], '
200
						', '<br> ' . comma_format($board['topics']) . ' ' . $txt['board_topics'], '
201
						</p>';
202
}
203
204
/**
205
 * Outputs the board stats for a redirect.
206
 *
207
 * @param array $board Current board information.
208
 */
209
function template_bi_redirect_stats($board)
210
{
211
	global $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
212
213
	echo '
214
						<p>', comma_format($board['posts']), ' ', $txt['redirects'], '
215
						</p>';
216
}
217
218
/**
219
 * Outputs the board lastposts for a standard board or a redirect.
220
 * When on a mobile device, this may be hidden if no last post exists.
221
 *
222
 * @param array $board Current board information.
223
 */
224
function template_bi_board_lastpost($board)
225
{
226 View Code Duplication
	if (!empty($board['last_post']['id']))
227
		echo '
228
						<p>', $board['last_post']['last_post_message'], '</p>';
229
}
230
231
/**
232
 * Outputs the board children for a standard board.
233
 *
234
 * @param array $board Current board information.
235
 */
236
function template_bi_board_children($board)
237
{
238
	global $txt, $scripturl, $context;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
239
240
	// Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)
241
	if (!empty($board['children']))
242
	{
243
		// Sort the links into an array with new boards bold so it can be imploded.
244
		$children = array();
245
		/* Each child in each board's children has:
246
				id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
247
		foreach ($board['children'] as $child)
248
		{
249
			if (!$child['is_redirect'])
250
				$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
251
			else
252
				$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . ' - ' . $child['short_description'] . '">' . $child['name'] . '</a>';
253
254
			// Has it posts awaiting approval?
255
			if ($child['can_approve_posts'] && ($child['unapproved_posts'] || $child['unapproved_topics']))
256
				$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
257
258
			$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
259
		}
260
261
	echo '
262
					<div id="board_', $board['id'], '_children" class="children">
263
						<p><strong id="child_list_', $board['id'], '">', $txt['sub_boards'], '</strong>', implode($children), '</p>
264
					</div>';
265
	}
266
}
267
268
/**
269
 * The lower part of the outer layer of the board index
270
 */
271
function template_boardindex_outer_below()
272
{
273
	template_info_center();
274
}
275
276
/**
277
 * Displays the info center
278
 */
279
function template_info_center()
280
{
281
	global $context, $options, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
282
283
	if (empty($context['info_center']))
284
		return;
285
286
	// Here's where the "Info Center" starts...
287
	echo '
288
	<div class="roundframe" id="info_center">
289
		<div class="title_bar">
290
			<h3 class="titlebg">
291
				<span class="toggle_up floatright" id="upshrink_ic" title="', $txt['hide_infocenter'], '" style="display: none;"></span>
292
				<a href="#" id="upshrink_link">', sprintf($txt['info_center_title'], $context['forum_name_html_safe']), '</a>
293
			</h3>
294
		</div>
295
		<div id="upshrinkHeaderIC"', empty($options['collapse_header_ic']) ? '' : ' style="display: none;"', '>';
296
297
	foreach ($context['info_center'] as $block)
298
	{
299
		$func = 'template_ic_block_' . $block['tpl'];
300
		$func();
301
	}
302
303
	echo '
304
		</div>
305
	</div>';
306
307
	// Info center collapse object.
308
	echo '
309
	<script>
310
		var oInfoCenterToggle = new smc_Toggle({
311
			bToggleEnabled: true,
312
			bCurrentlyCollapsed: ', empty($options['collapse_header_ic']) ? 'false' : 'true', ',
313
			aSwappableContainers: [
314
				\'upshrinkHeaderIC\'
315
			],
316
			aSwapImages: [
317
				{
318
					sId: \'upshrink_ic\',
319
					altExpanded: ', JavaScriptEscape($txt['hide_infocenter']), ',
320
					altCollapsed: ', JavaScriptEscape($txt['show_infocenter']), '
321
				}
322
			],
323
			aSwapLinks: [
324
				{
325
					sId: \'upshrink_link\',
326
					msgExpanded: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), ',
327
					msgCollapsed: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), '
328
				}
329
			],
330
			oThemeOptions: {
331
				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
332
				sOptionName: \'collapse_header_ic\',
333
				sSessionId: smf_session_id,
334
				sSessionVar: smf_session_var,
335
			},
336
			oCookieOptions: {
337
				bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
338
				sCookieName: \'upshrinkIC\'
339
			}
340
		});
341
	</script>';
342
}
343
344
/**
345
 * The recent posts section of the info center
346
 */
347
function template_ic_block_recent()
348
{
349
	global $context, $scripturl, $settings, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
350
351
	// This is the "Recent Posts" bar.
352
	echo '
353
			<div class="sub_bar">
354
				<h4 class="subbg">
355
					<a href="', $scripturl, '?action=recent"><span class="xx"></span>', $txt['recent_posts'], '</a>
356
				</h4>
357
			</div>
358
			<div id="recent_posts_content">';
359
360
	// Only show one post.
361
	if ($settings['number_recent_posts'] == 1)
362
	{
363
		// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
364
		echo '
365
				<p id="infocenter_onepost" class="inline">
366
					<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>&nbsp;&quot;', sprintf($txt['is_recent_updated'], '&quot;' . $context['latest_post']['link'], '&quot;'), ' (', $context['latest_post']['time'], ')<br>
367
				</p>';
368
	}
369
	// Show lots of posts.
370
	elseif (!empty($context['latest_posts']))
371
	{
372
		echo '
373
				<table id="ic_recentposts">
374
					<tr class="windowbg">
375
						<th class="recentpost">', $txt['message'], '</th>
376
						<th class="recentposter">', $txt['author'], '</th>
377
						<th class="recentboard">', $txt['board'], '</th>
378
						<th class="recenttime">', $txt['date'], '</th>
379
					</tr>';
380
381
		/* Each post in latest_posts has:
382
				board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
383
				subject, short_subject (shortened with...), time, link, and href. */
384
		foreach ($context['latest_posts'] as $post)
385
			echo '
386
					<tr class="windowbg">
387
						<td class="recentpost"><strong>', $post['link'], '</strong></td>
388
						<td class="recentposter">', $post['poster']['link'], '</td>
389
						<td class="recentboard">', $post['board']['link'], '</td>
390
						<td class="recenttime">', $post['time'], '</td>
391
					</tr>';
392
		echo '
393
				</table>';
394
	}
395
	echo '
396
			</div>';
397
}
398
399
/**
400
 * The calendar section of the info center
401
 */
402
function template_ic_block_calendar()
403
{
404
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
405
406
	// Show information about events, birthdays, and holidays on the calendar.
407
	echo '
408
			<div class="sub_bar">
409
				<h4 class="subbg">
410
					<a href="', $scripturl, '?action=calendar' . '"><span class="generic_icons calendar"></span> ', $context['calendar_only_today'] ? $txt['calendar_today'] : $txt['calendar_upcoming'], '</a>
411
				</h4>
412
			</div>';
413
414
	// Holidays like "Christmas", "Chanukah", and "We Love [Unknown] Day" :P.
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
415
	if (!empty($context['calendar_holidays']))
416
		echo '
417
				<p class="inline holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $context['calendar_holidays']), '</p>';
418
419
	// People's birthdays. Like mine. And yours, I guess. Kidding.
420
	if (!empty($context['calendar_birthdays']))
421
	{
422
		echo '
423
				<p class="inline">
424
					<span class="birthday">', $context['calendar_only_today'] ? $txt['birthdays'] : $txt['birthdays_upcoming'], '</span>';
425
		// Each member in calendar_birthdays has: id, name (person), age (if they have one set?), is_last. (last in list?), and is_today (birthday is today?)
426
		foreach ($context['calendar_birthdays'] as $member)
427
			echo '
428
					<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['is_today'] ? '<strong class="fix_rtl_names">' : '', $member['name'], $member['is_today'] ? '</strong>' : '', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
429
		echo '
430
				</p>';
431
	}
432
433
	// Events like community get-togethers.
434
	if (!empty($context['calendar_events']))
435
	{
436
		echo '
437
				<p class="inline">
438
					<span class="event">', $context['calendar_only_today'] ? $txt['events'] : $txt['events_upcoming'], '</span> ';
439
440
		// Each event in calendar_events should have:
441
		//		title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
442
		foreach ($context['calendar_events'] as $event)
443
			echo '
444
					', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '"><span class="generic_icons calendar_modify"></span></a> ' : '', $event['href'] == '' ? '' : '<a href="' . $event['href'] . '">', $event['is_today'] ? '<strong>' . $event['title'] . '</strong>' : $event['title'], $event['href'] == '' ? '' : '</a>', $event['is_last'] ? '<br>' : ', ';
445
		echo '
446
				</p>';
447
	}
448
}
449
450
/**
451
 * The stats section of the info center
452
 */
453
function template_ic_block_stats()
454
{
455
	global $scripturl, $txt, $context, $settings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
456
457
	// Show statistical style information...
458
	echo '
459
			<div class="sub_bar">
460
				<h4 class="subbg">
461
					<a href="', $scripturl, '?action=stats" title="', $txt['more_stats'], '"><span class="generic_icons stats"></span> ', $txt['forum_stats'], '</a>
462
				</h4>
463
			</div>
464
			<p class="inline">
465
				', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - ' . $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', '<br>
466
				', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  (' . $context['latest_post']['time'] . ')<br>' : ''), '
467
				<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
468
			</p>';
469
}
470
471
/**
472
 * The who's online section of the admin center
473
 */
474
function template_ic_block_online()
475
{
476
	global $context, $scripturl, $txt, $modSettings, $settings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
477
	// "Users online" - in order of activity.
478
	echo '
479
			<div class="sub_bar">
480
				<h4 class="subbg">
481
					', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', '<span class="generic_icons people"></span> ', $txt['online_users'], '', $context['show_who'] ? '</a>' : '', '
482
				</h4>
483
			</div>
484
			<p class="inline">
485
				', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', '<strong>', $txt['online'], ': </strong>', comma_format($context['num_guests']), ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($context['num_users_online']), ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
486
487
	// Handle hidden users and buddies.
488
	$bracketList = array();
489 View Code Duplication
	if ($context['show_buddies'])
490
		$bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
491 View Code Duplication
	if (!empty($context['num_spiders']))
492
		$bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
493
	if (!empty($context['num_users_hidden']))
494
		$bracketList[] = comma_format($context['num_users_hidden']) . ' ' . ($context['num_spiders'] == 1 ? $txt['hidden'] : $txt['hidden_s']);
495
496
	if (!empty($bracketList))
497
		echo ' (' . implode(', ', $bracketList) . ')';
498
499
	echo $context['show_who'] ? '</a>' : '', '
500
501
				&nbsp;-&nbsp;', $txt['most_online_today'], ': <strong>', comma_format($modSettings['mostOnlineToday']), '</strong>&nbsp;-&nbsp;
502
				', $txt['most_online_ever'], ': ', comma_format($modSettings['mostOnline']), ' (', timeformat($modSettings['mostDate']), ')<br>';
503
504
	// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
505
	if (!empty($context['users_online']))
506
	{
507
		echo '
508
				', sprintf($txt['users_active'], $modSettings['lastActive']), ': ', implode(', ', $context['list_users_online']);
509
510
		// Showing membergroups?
511 View Code Duplication
		if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
512
			echo '
513
				<span class="membergroups">' . implode(',&nbsp;', $context['membergroups']) . '</span>';
514
	}
515
516
	echo '
517
			</p>';
518
}
519
520
?>