Issues (1014)

Themes/default/BoardIndex.template.php (3 issues)

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines https://www.simplemachines.org
7
 * @copyright 2022 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1.0
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;
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
			echo '
36
			<li>', $news, '</li>';
37
38
		echo '
39
		</ul>
40
		<script>
41
			jQuery("#smf_slider").slippry({
42
				pause: ', $settings['newsfader_time'], ',
43
				adaptiveHeight: 0,
44
				captions: 0,
45
				controls: 0,
46
			});
47
		</script>';
48
	}
49
}
50
51
/**
52
 * This actually displays the board index
53
 */
54
function template_main()
55
{
56
	global $context, $txt, $scripturl;
57
58
	echo '
59
	<div id="boardindex_table" class="boardindex_table">';
60
61
	/* Each category in categories is made up of:
62
	id, href, link, name, is_collapsed (is it collapsed?), can_collapse (is it okay if it is?),
63
	new (is it new?), collapse_href (href to collapse/expand), collapse_image (up/down image),
64
	and boards. (see below.) */
65
	foreach ($context['categories'] as $category)
66
	{
67
		// If theres no parent boards we can see, avoid showing an empty category (unless its collapsed)
68
		if (empty($category['boards']) && !$category['is_collapsed'])
69
			continue;
70
71
		echo '
72
		<div class="main_container">
73
			<div class="cat_bar ', $category['is_collapsed'] ? 'collapsed' : '', '" id="category_', $category['id'], '">
74
				<h3 class="catbg">';
75
76
		// If this category even can collapse, show a link to collapse it.
77
		if ($category['can_collapse'])
78
			echo '
79
					<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>';
80
81
		echo '
82
					', $category['link'], '
83
				</h3>', !empty($category['description']) ? '
84
				<div class="desc">' . $category['description'] . '</div>' : '', '
85
			</div>
86
			<div id="category_', $category['id'], '_boards" ', (!empty($category['css_class']) ? ('class="' . $category['css_class'] . '"') : ''), $category['is_collapsed'] ? ' style="display: none;"' : '', '>';
87
88
		/* Each board in each category's boards has:
89
		new (is it new?), id, name, description, moderators (see below), link_moderators (just a list.),
90
		children (see below.), link_children (easier to use.), children_new (are they new?),
91
		topics (# of), posts (# of), link, href, and last_post. (see below.) */
92
		foreach ($category['boards'] as $board)
93
		{
94
			echo '
95
				<div id="board_', $board['id'], '" class="up_contain ', (!empty($board['css_class']) ? $board['css_class'] : ''), '">
96
					<div class="board_icon">
97
						', function_exists('template_bi_' . $board['type'] . '_icon') ? call_user_func('template_bi_' . $board['type'] . '_icon', $board) : template_bi_board_icon($board), '
0 ignored issues
show
Are you sure the usage of template_bi_board_icon($board) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
98
					</div>
99
					<div class="info">
100
						', function_exists('template_bi_' . $board['type'] . '_info') ? call_user_func('template_bi_' . $board['type'] . '_info', $board) : template_bi_board_info($board), '
101
					</div><!-- .info -->';
102
103
			// Show some basic information about the number of posts, etc.
104
			echo '
105
					<div class="board_stats">
106
						', function_exists('template_bi_' . $board['type'] . '_stats') ? call_user_func('template_bi_' . $board['type'] . '_stats', $board) : template_bi_board_stats($board), '
0 ignored issues
show
Are you sure the usage of template_bi_board_stats($board) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
107
					</div>';
108
109
			// Show the last post if there is one.
110
			echo'
111
					<div class="lastpost">
112
						', function_exists('template_bi_' . $board['type'] . '_lastpost') ? call_user_func('template_bi_' . $board['type'] . '_lastpost', $board) : template_bi_board_lastpost($board), '
0 ignored issues
show
Are you sure the usage of template_bi_board_lastpost($board) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
113
					</div>';
114
115
			// Won't somebody think of the children!
116
			if (function_exists('template_bi_' . $board['type'] . '_children'))
117
				call_user_func('template_bi_' . $board['type'] . '_children', $board);
118
			else
119
				template_bi_board_children($board);
120
121
			echo '
122
				</div><!-- #board_[id] -->';
123
		}
124
125
		echo '
126
			</div><!-- #category_[id]_boards -->
127
		</div><!-- .main_container -->';
128
	}
129
130
	echo '
131
	</div><!-- #boardindex_table -->';
132
133
	// Show the mark all as read button?
134
	if ($context['user']['is_logged'] && !empty($context['categories']))
135
		echo '
136
	<div class="mark_read">
137
		', template_button_strip($context['mark_read_button'], 'right'), '
138
	</div>';
139
}
140
141
/**
142
 * Outputs the board icon for a standard board.
143
 *
144
 * @param array $board Current board information.
145
 */
146
function template_bi_board_icon($board)
147
{
148
	global $context, $scripturl;
149
150
	echo '
151
		<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>';
152
}
153
154
/**
155
 * Outputs the board icon for a redirect.
156
 *
157
 * @param array $board Current board information.
158
 */
159
function template_bi_redirect_icon($board)
160
{
161
	global $context, $scripturl;
162
163
	echo '
164
		<a href="', $board['href'], '" class="board_', $board['board_class'], '"', !empty($board['board_tooltip']) ? ' title="' . $board['board_tooltip'] . '"' : '', '></a>';
165
}
166
167
/**
168
 * Outputs the board info for a standard board or redirect.
169
 *
170
 * @param array $board Current board information.
171
 */
172
function template_bi_board_info($board)
173
{
174
	global $context, $scripturl, $txt;
175
176
	echo '
177
		<a class="subject mobile_subject" href="', $board['href'], '" id="b', $board['id'], '">
178
			', $board['name'], '
179
		</a>';
180
181
	// Has it outstanding posts for approval?
182
	if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
183
		echo '
184
		<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 amt">!</a>';
185
186
	echo '
187
		<div class="board_description">', $board['description'], '</div>';
188
189
	// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
190
	if (!empty($board['link_moderators']))
191
		echo '
192
		<p class="moderators">', count($board['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
193
}
194
195
/**
196
 * Outputs the board stats for a standard board.
197
 *
198
 * @param array $board Current board information.
199
 */
200
function template_bi_board_stats($board)
201
{
202
	global $txt;
203
204
	echo '
205
		<p>
206
			', $txt['posts'], ': ', comma_format($board['posts']), '<br>', $txt['board_topics'], ': ', comma_format($board['topics']), '
207
		</p>';
208
}
209
210
/**
211
 * Outputs the board stats for a redirect.
212
 *
213
 * @param array $board Current board information.
214
 */
215
function template_bi_redirect_stats($board)
216
{
217
	global $txt;
218
219
	echo '
220
		<p>
221
			', $txt['redirects'], ': ', comma_format($board['posts']), '
222
		</p>';
223
}
224
225
/**
226
 * Outputs the board lastposts for a standard board or a redirect.
227
 * When on a mobile device, this may be hidden if no last post exists.
228
 *
229
 * @param array $board Current board information.
230
 */
231
function template_bi_board_lastpost($board)
232
{
233
	if (!empty($board['last_post']['id']))
234
		echo '
235
			<p>', $board['last_post']['last_post_message'], '</p>';
236
}
237
238
/**
239
 * Outputs the board children for a standard board.
240
 *
241
 * @param array $board Current board information.
242
 */
243
function template_bi_board_children($board)
244
{
245
	global $txt, $scripturl, $context;
246
247
	// Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)
248
	if (!empty($board['children']))
249
	{
250
		// Sort the links into an array with new boards bold so it can be imploded.
251
		$children = array();
252
		/* Each child in each board's children has:
253
			id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
254
		foreach ($board['children'] as $child)
255
		{
256
			if (!$child['is_redirect'])
257
				$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']) . ')" class="new_posts">' . $txt['new'] . '</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>';
258
			else
259
				$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . ' - ' . $child['short_description'] . '">' . $child['name'] . '</a>';
260
261
			// Has it posts awaiting approval?
262
			if ($child['can_approve_posts'] && ($child['unapproved_posts'] || $child['unapproved_topics']))
263
				$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 amt">!</a>';
264
265
			$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
266
		}
267
268
		echo '
269
			<div id="board_', $board['id'], '_children" class="children">
270
				<p><strong id="child_list_', $board['id'], '">', $txt['sub_boards'], '</strong>', implode(' ', $children), '</p>
271
			</div>';
272
	}
273
}
274
275
/**
276
 * The lower part of the outer layer of the board index
277
 */
278
function template_boardindex_outer_below()
279
{
280
	template_info_center();
281
}
282
283
/**
284
 * Displays the info center
285
 */
286
function template_info_center()
287
{
288
	global $context, $options, $txt;
289
290
	if (empty($context['info_center']))
291
		return;
292
293
	// Here's where the "Info Center" starts...
294
	echo '
295
	<div class="roundframe" id="info_center">
296
		<div class="title_bar">
297
			<h3 class="titlebg">
298
				<span class="toggle_up floatright" id="upshrink_ic" title="', $txt['hide_infocenter'], '" style="display: none;"></span>
299
				<a href="#" id="upshrink_link">', sprintf($txt['info_center_title'], $context['forum_name_html_safe']), '</a>
300
			</h3>
301
		</div>
302
		<div id="upshrink_stats"', empty($options['collapse_header_ic']) ? '' : ' style="display: none;"', '>';
303
304
	foreach ($context['info_center'] as $block)
305
	{
306
		$func = 'template_ic_block_' . $block['tpl'];
307
		$func();
308
	}
309
310
	echo '
311
		</div><!-- #upshrink_stats -->
312
	</div><!-- #info_center -->';
313
314
	// Info center collapse object.
315
	echo '
316
	<script>
317
		var oInfoCenterToggle = new smc_Toggle({
318
			bToggleEnabled: true,
319
			bCurrentlyCollapsed: ', empty($options['collapse_header_ic']) ? 'false' : 'true', ',
320
			aSwappableContainers: [
321
				\'upshrink_stats\'
322
			],
323
			aSwapImages: [
324
				{
325
					sId: \'upshrink_ic\',
326
					altExpanded: ', JavaScriptEscape($txt['hide_infocenter']), ',
327
					altCollapsed: ', JavaScriptEscape($txt['show_infocenter']), '
328
				}
329
			],
330
			aSwapLinks: [
331
				{
332
					sId: \'upshrink_link\',
333
					msgExpanded: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), ',
334
					msgCollapsed: ', JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])), '
335
				}
336
			],
337
			oThemeOptions: {
338
				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
339
				sOptionName: \'collapse_header_ic\',
340
				sSessionId: smf_session_id,
341
				sSessionVar: smf_session_var,
342
			},
343
			oCookieOptions: {
344
				bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
345
				sCookieName: \'upshrinkIC\'
346
			}
347
		});
348
	</script>';
349
}
350
351
/**
352
 * The recent posts section of the info center
353
 */
354
function template_ic_block_recent()
355
{
356
	global $context, $scripturl, $settings, $txt;
357
358
	// This is the "Recent Posts" bar.
359
	echo '
360
			<div class="sub_bar">
361
				<h4 class="subbg">
362
					<a href="', $scripturl, '?action=recent"><span class="main_icons recent_posts"></span> ', $txt['recent_posts'], '</a>
363
				</h4>
364
			</div>
365
			<div id="recent_posts_content">';
366
367
	// Only show one post.
368
	if ($settings['number_recent_posts'] == 1)
369
	{
370
		// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
371
		echo '
372
				<p id="infocenter_onepost" class="inline">
373
					<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a> ', sprintf($txt['is_recent_updated'], '&quot;' . $context['latest_post']['link'] . '&quot;'), ' (', $context['latest_post']['time'], ')<br>
374
				</p>';
375
	}
376
	// Show lots of posts.
377
	elseif (!empty($context['latest_posts']))
378
	{
379
		echo '
380
				<table id="ic_recentposts">
381
					<tr class="windowbg">
382
						<th class="recentpost">', $txt['message'], '</th>
383
						<th class="recentposter">', $txt['author'], '</th>
384
						<th class="recentboard">', $txt['board'], '</th>
385
						<th class="recenttime">', $txt['date'], '</th>
386
					</tr>';
387
388
		/* Each post in latest_posts has:
389
			board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
390
			subject, short_subject (shortened with...), time, link, and href. */
391
		foreach ($context['latest_posts'] as $post)
392
			echo '
393
					<tr class="windowbg">
394
						<td class="recentpost"><strong>', $post['link'], '</strong></td>
395
						<td class="recentposter">', $post['poster']['link'], '</td>
396
						<td class="recentboard">', $post['board']['link'], '</td>
397
						<td class="recenttime">', $post['time'], '</td>
398
					</tr>';
399
		echo '
400
				</table>';
401
	}
402
	echo '
403
			</div><!-- #recent_posts_content -->';
404
}
405
406
/**
407
 * The calendar section of the info center
408
 */
409
function template_ic_block_calendar()
410
{
411
	global $context, $scripturl, $txt;
412
413
	// Show information about events, birthdays, and holidays on the calendar.
414
	echo '
415
			<div class="sub_bar">
416
				<h4 class="subbg">
417
					<a href="', $scripturl, '?action=calendar' . '"><span class="main_icons calendar"></span> ', $context['calendar_only_today'] ? $txt['calendar_today'] : $txt['calendar_upcoming'], '</a>
418
				</h4>
419
			</div>';
420
421
	// Holidays like "Christmas", "Chanukah", and "We Love [Unknown] Day" :P
422
	if (!empty($context['calendar_holidays']))
423
		echo '
424
			<p class="inline holiday">
425
				<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $context['calendar_holidays']), '
426
			</p>';
427
428
	// People's birthdays. Like mine. And yours, I guess. Kidding.
429
	if (!empty($context['calendar_birthdays']))
430
	{
431
		echo '
432
			<p class="inline">
433
				<span class="birthday">', $context['calendar_only_today'] ? $txt['birthdays'] : $txt['birthdays_upcoming'], '</span>';
434
435
		// 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?)
436
		foreach ($context['calendar_birthdays'] as $member)
437
			echo '
438
				<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'] ? '' : ', ';
439
440
		echo '
441
			</p>';
442
	}
443
444
	// Events like community get-togethers.
445
	if (!empty($context['calendar_events']))
446
	{
447
		echo '
448
			<p class="inline">
449
				<span class="event">', $context['calendar_only_today'] ? $txt['events'] : $txt['events_upcoming'], '</span> ';
450
451
		// Each event in calendar_events should have:
452
		//		title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
453
		foreach ($context['calendar_events'] as $event)
454
			echo '
455
				', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '"><span class="main_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>' : ', ';
456
		echo '
457
			</p>';
458
	}
459
}
460
461
/**
462
 * The stats section of the info center
463
 */
464
function template_ic_block_stats()
465
{
466
	global $scripturl, $txt, $context, $settings;
467
468
	// Show statistical style information...
469
	echo '
470
			<div class="sub_bar">
471
				<h4 class="subbg">
472
					<a href="', $scripturl, '?action=stats" title="', $txt['more_stats'], '"><span class="main_icons stats"></span> ', $txt['forum_stats'], '</a>
473
				</h4>
474
			</div>
475
			<p class="inline">
476
				', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - ' . $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', '<br>
477
				', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  (' . $context['latest_post']['time'] . ')<br>' : ''), '
478
				<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
479
			</p>';
480
}
481
482
/**
483
 * The who's online section of the info center
484
 */
485
function template_ic_block_online()
486
{
487
	global $context, $scripturl, $txt, $modSettings, $settings;
488
	// "Users online" - in order of activity.
489
	echo '
490
			<div class="sub_bar">
491
				<h4 class="subbg">
492
					', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', '<span class="main_icons people"></span> ', $txt['online_users'], '', $context['show_who'] ? '</a>' : '', '
493
				</h4>
494
			</div>
495
			<p class="inline">
496
				', $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'];
497
498
	// Handle hidden users and buddies.
499
	$bracketList = array();
500
501
	if ($context['show_buddies'])
502
		$bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
503
504
	if (!empty($context['num_spiders']))
505
		$bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
506
507
	if (!empty($context['num_users_hidden']))
508
		$bracketList[] = comma_format($context['num_users_hidden']) . ' ' . ($context['num_spiders'] == 1 ? $txt['hidden'] : $txt['hidden_s']);
509
510
	if (!empty($bracketList))
511
		echo ' (' . implode(', ', $bracketList) . ')';
512
513
	echo $context['show_who'] ? '</a>' : '', '
514
515
				&nbsp;-&nbsp;', $txt['most_online_today'], ': <strong>', comma_format($modSettings['mostOnlineToday']), '</strong>&nbsp;-&nbsp;
516
				', $txt['most_online_ever'], ': ', comma_format($modSettings['mostOnline']), ' (', timeformat($modSettings['mostDate']), ')<br>';
517
518
	// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
519
	if (!empty($context['users_online']))
520
	{
521
		echo '
522
				', sprintf($txt['users_active'], $modSettings['lastActive']), ': ', implode(', ', $context['list_users_online']);
523
524
		// Showing membergroups?
525
		if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
526
			echo '
527
				<span class="membergroups">' . implode(', ', $context['membergroups']) . '</span>';
528
	}
529
530
	echo '
531
			</p>';
532
}
533
534
?>