Completed
Pull Request — patch_1-1-4 (#3210)
by Emanuele
12:56
created

BoardIndex.template.php ➔ template_ic_recent_posts()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 53
rs 9.0254
c 0
b 0
f 0

How to fix   Long Method   

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
/**
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.4
13
 *
14
 */
15
16
/**
17
 * Loads the template used to display boards
18
 */
19
function template_BoardIndex_init()
20
{
21
	loadTemplate('GenericBoards');
22
}
23
24
/**
25
 * Main template for displaying the list of boards
26
 */
27
function template_boards_list()
28
{
29
	global $context, $txt;
30
31
	// Each category in categories is made up of:
32
	// id, href, link, name, is_collapsed (is it collapsed?), can_collapse (is it okay if it is?),
33
	// new (is it new?), collapse_href (href to collapse/expand), collapse_image (up/down image),
34
	// and boards. (see below.)
35
	foreach ($context['categories'] as $category)
36
	{
37
		// If there are no parent boards we can see, avoid showing an empty category (unless its collapsed).
38
		if (empty($category['boards']) && !$category['is_collapsed'])
39
			continue;
40
41
		// @todo - Invent nifty class name for boardindex header bars.
42
		echo '
43
		
44
		<header class="category_header">';
45
46
		// If this category even can collapse, show a link to collapse it.
47
		if ($category['can_collapse'])
48
			echo '
49
			<a class="chevricon i-chevron-', $category['is_collapsed'] ? 'down' : 'up', '" href="', $category['collapse_href'], '" title="', $category['is_collapsed'] ? $txt['show'] : $txt['hide'], '"></a>';
50
51
		// The "category link" is only a link for logged in members. Guests just get the name.
52
		echo '
53
				', $category['link'], '
54
		</header>
55
		<section class="forum_category" id="category_', $category['id'], '">';
56
57
		// Assuming the category hasn't been collapsed...
58
		if (!$category['is_collapsed'])
59
			template_list_boards($category['boards'], 'category_' . $category['id'] . '_boards');
60
61
		echo '
62
		</section>';
63
	}
64
}
65
66
/**
67
 * Show information above the boardindex, like the newsfader
68
 */
69
function template_boardindex_outer_above()
70
{
71
	global $context, $settings, $txt;
72
73
	// Show some statistics if info centre stats is off.
74
	if (!$settings['show_stats_index'])
75
	{
76
		echo '
77
		<div id="index_common_stats">
78
			', $txt['members'], ': ', $context['common_stats']['total_members'], ' &nbsp;&#8226;&nbsp; ', $txt['posts_made'], ': ', $context['common_stats']['total_posts'], ' &nbsp;&#8226;&nbsp; ', $txt['topics_made'], ': ', $context['common_stats']['total_topics'], '<br />
79
			', $settings['show_latest_member'] ? ' ' . sprintf($txt['welcome_newest_member'], ' <strong>' . $context['common_stats']['latest_member']['link'] . '</strong>') : '', '
80
		</div>';
81
	}
82
83
		echo '
84
		<main>';
85
}
86
87
/**
88
 * Show information below the boardindex, like stats, infocenter
89
 */
90
function template_boardindex_outer_below()
91
{
92
	global $context, $settings, $txt;
93
94
	// @todo - Just <div> for the parent, <p>'s for the icon stuffz, and the buttonlist <ul> for "Mark read".
95
	// Sort the floats in the CSS file, as other tricks will be needed as well (media queries, for instance).
96
	echo '
97
		</main>
98
		<aside id="posting_icons">';
99
100
	// Show the mark all as read button?
101
	if ($settings['show_mark_read'] && !$context['user']['is_guest'] && !empty($context['categories']))
102
		echo '
103
			', template_button_strip($context['mark_read_button'], 'right');
104
105
	if ($context['user']['is_logged'])
106
		echo '
107
			<p title="', $txt['new_posts'], '"><i class="icon i-board-new"></i>', $txt['new_posts'], '</p>';
108
109
	echo '
110
			<p title="', $txt['old_posts'], '"><i class="icon i-board-off"></i>', $txt['old_posts'], '</p>
111
			<p title="', $txt['redirect_board'], '"><i class="icon i-board-redirect"></i>', $txt['redirect_board'], '</p>
112
		</aside>';
113
}
114
115
/**
116
 * The infocenter ... stats, recent topics, other important information that never gets seen :P
117
 */
118
function template_info_center_below()
119
{
120
	global $context, $txt;
121
122
	if (empty($context['info_center_callbacks']))
123
	{
124
		return;
125
	}
126
127
	// Here's where the "Info Center" starts...
128
	echo '
129
	<aside id="info_center" class="forum_category">
130
		<h2 class="category_header panel_toggle">
131
				<i id="upshrink_ic" class="hide chevricon i-chevron-', empty($context['minmax_preferences']['info']) ? 'up' : 'down', '" title="', $txt['hide'], '"></i>
132
			<a href="#" id="upshrink_link">', sprintf($txt['info_center_title'], $context['forum_name_html_safe']), '</a>
133
		</h2>
134
		<ul id="upshrinkHeaderIC" class="category_boards', empty($context['minmax_preferences']['info']) ? '' : ' hide', '">';
135
136
	call_template_callbacks('ic', $context['info_center_callbacks']);
137
138
	echo '
139
		</ul>
140
	</aside>';
141
142
	// Info center collapse object.
143
	addInlineJavascript('
144
		var oInfoCenterToggle = new elk_Toggle({
145
			bToggleEnabled: true,
146
			bCurrentlyCollapsed: ' . (empty($context['minmax_preferences']['info']) ? 'false' : 'true') . ',
147
			aSwappableContainers: [
148
				\'upshrinkHeaderIC\'
149
			],
150
			aSwapClasses: [
151
				{
152
					sId: \'upshrink_ic\',
153
					classExpanded: \'chevricon i-chevron-up\',
154
					titleExpanded: ' . JavaScriptEscape($txt['hide']) . ',
155
					classCollapsed: \'chevricon i-chevron-down\',
156
					titleCollapsed: ' . JavaScriptEscape($txt['show']) . '
157
				}
158
			],
159
			aSwapLinks: [
160
				{
161
					sId: \'upshrink_link\',
162
					msgExpanded: ' . JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])) . ',
163
					msgCollapsed: ' . JavaScriptEscape(sprintf($txt['info_center_title'], $context['forum_name_html_safe'])) . '
164
				}
165
			],
166
			oThemeOptions: {
167
				bUseThemeSettings: ' . ($context['user']['is_guest'] ? 'false' : 'true') . ',
168
				sOptionName: \'minmax_preferences\',
169
				sSessionId: elk_session_id,
170
				sSessionVar: elk_session_var,
171
				sAdditionalVars: \';minmax_key=info\'
172
			},
173
			oCookieOptions: {
174
				bUseCookie: ' . ($context['user']['is_guest'] ? 'true' : 'false') . ',
175
				sCookieName: \'upshrinkIC\'
176
			}
177
		});
178
	', true);
179
}
180
181
/**
182
 * This is the "Recent Posts" bar.
183
 */
184
function template_ic_recent_posts()
185
{
186
	global $context, $txt, $scripturl, $settings;
187
188
	// Show the Recent Posts title
189
	// hslice class is a left over from webslice support.
190
	echo '
191
			<li class="board_row hslice" id="recent_posts_content">
192
				<h3 class="ic_section_header">
193
					<a href="', $scripturl, '?action=recent"><i class="icon i-post-text"></i>', $txt['recent_posts'], '</a>
194
				</h3>';
195
196
	// Only show one post.
197
	if ($settings['number_recent_posts'] == 1)
198
	{
199
		// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
200
		echo '
201
				<p id="infocenter_onepost" class="inline">
202
					<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>&nbsp;', sprintf($txt['is_recent_updated'], '&quot;' . $context['latest_post']['link'] . '&quot;'), ' (', $context['latest_post']['html_time'], ')
203
				</p>';
204
	}
205
	// Show lots of posts. @todo - Although data here is actually tabular, perhaps use faux table for greater responsiveness.
206
	elseif (!empty($context['latest_posts']))
207
	{
208
		echo '
209
				<table id="ic_recentposts">
210
					<tr>
211
						<th class="recentpost">', $txt['message'], '</th>
212
						<th class="recentposter">', $txt['author'], '</th>
213
						<th class="recentboard">', $txt['board'], '</th>
214
						<th class="recenttime">', $txt['date'], '</th>
215
					</tr>';
216
217
		// Each post in latest_posts has:
218
		// board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
219
		// subject, short_subject (shortened with...), time, link, and href.
220
		foreach ($context['latest_posts'] as $post)
221
		{
222
			echo '
223
					<tr>
224
						<td class="recentpost"><strong>', $post['link'], '</strong></td>
225
						<td class="recentposter">', $post['poster']['link'], '</td>
226
						<td class="recentboard">', $post['board']['link'], '</td>
227
						<td class="recenttime">', $post['html_time'], '</td>
228
					</tr>';
229
		}
230
231
		echo '
232
				</table>';
233
	}
234
	echo '
235
			</li>';
236
}
237
238
/**
239
 * Show information about events, birthdays, and holidays on the calendar in the info center
240
 */
241
function template_ic_show_events()
242
{
243
	global $context, $txt, $scripturl;
244
245
	echo '
246
			<li class="board_row">
247
				<h3 class="ic_section_header">
248
					<a href="', $scripturl, '?action=calendar">
249
						<i class="icon i-calendar"></i> ', $context['calendar_only_today'] ? $txt['calendar_today'] : $txt['calendar_upcoming'], '
250
					</a>
251
				</h3>';
252
253
	// Holidays like "Christmas", "Hanukkah", and "We Love [Unknown] Day" :P.
254
	if (!empty($context['calendar_holidays']))
255
		echo '
256
				<p class="inline holiday">', $txt['calendar_prompt'], ' ', implode(', ', $context['calendar_holidays']), '</p>';
257
258
	// People's birthdays. Like mine. And yours, I guess. Kidding.
259
	if (!empty($context['calendar_birthdays']))
260
	{
261
		echo '
262
				<p class="inline">
263
					<span class="birthday">', $context['calendar_only_today'] ? $txt['birthdays'] : $txt['birthdays_upcoming'], '</span>';
264
265
		// 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?)
266
		foreach ($context['calendar_birthdays'] as $member)
267
			echo '
268
					<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['is_today'] ? '<strong>' : '', $member['name'], $member['is_today'] ? '</strong>' : '', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
269
270
		echo '
271
				</p>';
272
	}
273
274
	// Events like community get-togethers.
275
	if (!empty($context['calendar_events']))
276
	{
277
		echo '
278
				<p class="inline">
279
					<span class="event">', $context['calendar_only_today'] ? $txt['events'] : $txt['events_upcoming'], '</span> ';
280
281
		// Each event in calendar_events should have:
282
		// title, href, is_last, can_edit (are they allowed?), modify_href, and is_today.
283
		foreach ($context['calendar_events'] as $event)
284
			echo '
285
					', $event['can_edit'] ? '<a href="' . $event['modify_href'] . '" title="' . $txt['calendar_edit'] . '" class="icon i-modify"></a> ' : '', $event['href'] == '' ? '' : '<a href="' . $event['href'] . '">', $event['is_today'] ? '<strong>' . $event['title'] . '</strong>' : $event['title'], $event['href'] == '' ? '' : '</a>', $event['is_last'] ? '<br />' : ', ';
286
287
		echo '
288
				</p>';
289
	}
290
291
	echo '
292
			</li>';
293
}
294
295
/**
296
 * Show statistical style information in the info center
297
 */
298
function template_ic_show_stats()
299
{
300
	global $txt, $scripturl, $context, $settings, $modSettings;
301
302
	echo '
303
			<li class="board_row">
304
				<h3 class="ic_section_header">
305
					', $context['show_stats'] ? '<a href="' . $scripturl . '?action=stats" title="' . $txt['more_stats'] . '"><i class="icon i-pie-chart"></i>' . $txt['forum_stats'] . '</a>' : $txt['forum_stats'], '
306
				</h3>
307
				<p class="inline">
308
					', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - ' . $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', ' - ', $txt['most_online_today'], ': ', comma_format($modSettings['mostOnlineToday']), '<br />
309
					', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  ( ' . $context['latest_post']['time'] . ' )' : ''), ' - <a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
310
				</p>
311
			</li>';
312
}
313
314
/**
315
 * Show the online users in the info center
316
 */
317
function template_ic_show_users()
318
{
319
	global $context, $txt, $scripturl, $settings, $modSettings;
320
321
	// "Users online" - in order of activity.
322
	echo '
323
			<li class="board_row">
324
				<h3 class="ic_section_header">
325
					', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', '<i class="icon i-users"></i>', $txt['online_now'], ':
326
					', comma_format($context['num_users_online']), ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'], ', ', comma_format($context['num_guests']), ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'];
327
328
	// Handle hidden users and buddies.
329
	$bracketList = array();
330 View Code Duplication
	if ($context['show_buddies'])
331
		$bracketList[] = comma_format($context['num_buddies']) . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
332
333 View Code Duplication
	if (!empty($context['num_spiders']))
334
		$bracketList[] = comma_format($context['num_spiders']) . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
335
336
	if (!empty($context['num_users_hidden']))
337
		$bracketList[] = comma_format($context['num_users_hidden']) . ' ' . ($context['num_users_hidden'] == 1 ? $txt['hidden'] : $txt['hidden_s']);
338
339
	if (!empty($bracketList))
340
		echo ' (' . implode(', ', $bracketList) . ')';
341
342
	echo $context['show_who'] ? '</a>' : '', '
343
				</h3>';
344
345
	// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
346
	if (!empty($context['users_online']))
347
	{
348
		echo '
349
				<p class="inline">', sprintf($txt['users_active'], $modSettings['lastActive']), ': ', implode(', ', $context['list_users_online']), '</p>';
350
351
		// Showing membergroups?
352 View Code Duplication
		if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
353
			echo '
354
				<p class="inline membergroups">[' . implode(',&nbsp;', $context['membergroups']) . ']</p>';
355
	}
356
	echo '
357
			</li>';
358
}
359