Issues (1061)

Sources/Subs-BoardIndex.php (1 issue)

1
<?php
2
3
/**
4
 * This file currently only contains one function to collect the data needed to
5
 * show a list of boards for the board index and the message index.
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines https://www.simplemachines.org
11
 * @copyright 2020 Simple Machines and individual contributors
12
 * @license https://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 RC2
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
/**
21
 * Fetches a list of boards and (optional) categories including
22
 * statistical information, child boards and moderators.
23
 * 	- Used by both the board index (main data) and the message index (child
24
 * boards).
25
 * 	- Depending on the include_categories setting returns an associative
26
 * array with categories->boards->child_boards or an associative array
27
 * with boards->child_boards.
28
 *
29
 * @param array $board_index_options An array of boardindex options
30
 * @return array An array of information for displaying the boardindex
31
 */
32
33
function getBoardIndex($board_index_options)
34
{
35
	global $smcFunc, $scripturl, $user_info, $modSettings, $txt;
36
	global $settings, $options, $context, $sourcedir;
37
38
	require_once($sourcedir . '/Subs-Boards.php');
39
40
	// For performance, track the latest post while going through the boards.
41
	if (!empty($board_index_options['set_latest_post']))
42
		$latest_post = array(
43
			'timestamp' => 0,
44
			'ref' => 0
45
		);
46
47
	// This setting is not allowed to be empty
48
	if (empty($modSettings['boardindex_max_depth']))
49
		$modSettings['boardindex_max_depth'] = 1;
50
51
	$board_index_selects = array(
52
		'b.id_board',
53
		'b.name AS board_name',
54
		'b.description',
55
		'CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect',
56
		'b.num_posts',
57
		'b.num_topics',
58
		'b.unapproved_posts',
59
		'b.unapproved_topics',
60
		'b.id_parent'
61
	);
62
63
	$board_index_parameters = array(
64
		'current_member' => $user_info['id'],
65
		'child_level' => $board_index_options['base_level'],
66
		'max_child_level' => $board_index_options['base_level'] + $modSettings['boardindex_max_depth'],
67
		'blank_string' => ''
68
	);
69
70
	call_integration_hook('integrate_pre_boardindex', array(&$board_index_selects, &$board_index_parameters));
71
72
	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
73
	if ($board_index_options['parent_id'] != 0 && $smcFunc['db_cte_support']())
74
		$result_boards = $smcFunc['db_query']('', '
75
			WITH RECURSIVE
76
				boards_cte (child_level, id_board, name, description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order)
77
			AS
78
			(
79
				SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order
80
				FROM {db_prefix}boards AS b
81
				WHERE {query_see_board} AND b.id_board = {int:id_parent}
82
					UNION ALL
83
				SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order
84
				FROM {db_prefix}boards AS b
85
					JOIN boards_cte AS bc ON (b.id_parent = bc.id_board)
86
				WHERE {query_see_board}
87
					AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level}
88
			)
89
			SELECT' . ($board_index_options['include_categories'] ? '
90
				c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
91
				' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ',
92
				COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name,
93
				m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name,
94
				' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
95
				(CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? '
96
				c.can_collapse,' : '')) . '
97
				COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ',  mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . '
98
			FROM boards_cte AS b' . ($board_index_options['include_categories'] ? '
99
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
100
				LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
101
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? '
102
				LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : '
103
				LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . '
104
			WHERE b.id_parent != 0
105
			ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC',
106
			array_merge($board_index_parameters, array(
107
				'id_parent' => $board_index_options['parent_id']
108
			))
109
		);
110
	else
111
		$result_boards = $smcFunc['db_query']('', '
112
			SELECT' . ($board_index_options['include_categories'] ? '
113
				c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
114
				' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ',
115
				COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name,
116
				m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name,
117
				' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
118
				(CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? '
119
				c.can_collapse,' : '')) . '
120
				COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ',  mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . '
121
			FROM {db_prefix}boards AS b' . ($board_index_options['include_categories'] ? '
122
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
123
				LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
124
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? '
125
				LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : '
126
				LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . '
127
			WHERE {query_see_board}
128
				AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level}
129
			ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC',
130
			$board_index_parameters
131
		);
132
133
	// Start with an empty array.
134
	if ($board_index_options['include_categories'])
135
		$categories = array();
136
	else
137
		$this_category = array();
138
139
	$boards = array();
140
141
	// Children can affect parents, so we need to gather all the boards first and then process them after.
142
	$row_boards = array();
143
144
	foreach ($smcFunc['db_fetch_all']($result_boards) as $row)
145
		$row_boards[$row['id_board']] = $row;
146
147
	$smcFunc['db_free_result']($result_boards);
148
149
	// Run through the categories and boards (or only boards)....
150
	for (reset($row_boards); key($row_boards) !== null; next($row_boards))
151
	{
152
		$row_board = current($row_boards);
153
154
		// Perhaps we are ignoring this board?
155
		$ignoreThisBoard = in_array($row_board['id_board'], $user_info['ignoreboards']);
156
		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
157
158
		// Add parent boards to the $boards list later used to fetch moderators
159
		if ($row_board['id_parent'] == $board_index_options['parent_id'])
160
			$boards[] = $row_board['id_board'];
161
162
		if ($board_index_options['include_categories'])
163
		{
164
			// Haven't set this category yet.
165
			if (empty($categories[$row_board['id_cat']]))
166
			{
167
				$name = parse_bbc($row_board['cat_name'], false, '', $context['description_allowed_tags']);
168
				$description = parse_bbc($row_board['cat_desc'], false, '', $context['description_allowed_tags']);
169
170
				$categories[$row_board['id_cat']] = array(
171
					'id' => $row_board['id_cat'],
172
					'name' => $name,
173
					'description' => $description,
174
					'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && !empty($options['collapse_category_' . $row_board['id_cat']]),
175
					'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1,
176
					'href' => $scripturl . '#c' . $row_board['id_cat'],
177
					'boards' => array(),
178
					'new' => false,
179
					'css_class' => ''
180
				);
181
182
				$categories[$row_board['id_cat']]['link'] = '' . (!$context['user']['is_guest'] ? '<a href="' . $scripturl . '?action=unread;c=' . $row_board['id_cat'] . '" title="' . sprintf($txt['new_posts_in_category'], $name) . '" id="c' . $row_board['id_cat'] . '">' . $name . '</a>' : '<span id="c' . $row_board['id_cat'] . '">' . $name . '</span>');
183
			}
184
185
			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
186
			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
187
				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
188
189
			// Avoid showing category unread link where it only has redirection boards.
190
			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
191
192
			// Let's save some typing.  Climbing the array might be slower, anyhow.
193
			$this_category = &$categories[$row_board['id_cat']]['boards'];
194
		}
195
196
		// This is a parent board.
197
		if ($row_board['id_parent'] == $board_index_options['parent_id'])
198
		{
199
			// Is this a new board, or just another moderator?
200
			if (!isset($this_category[$row_board['id_board']]['type']))
201
			{
202
				// Not a child.
203
				$isChild = false;
204
205
				// We might or might not have already added this board, so...
206
				if (!isset($this_category[$row_board['id_board']]))
207
					$this_category[$row_board['id_board']] = array();
208
209
				$board_name = parse_bbc($row_board['board_name'], false, '', $context['description_allowed_tags']);
210
				$board_description = parse_bbc($row_board['description'], false, '', $context['description_allowed_tags']);
211
212
				$this_category[$row_board['id_board']] += array(
213
					'new' => empty($row_board['is_read']),
214
					'id' => $row_board['id_board'],
215
					'type' => $row_board['is_redirect'] ? 'redirect' : 'board',
216
					'name' => $board_name,
217
					'description' => $board_description,
218
					'moderators' => array(),
219
					'moderator_groups' => array(),
220
					'link_moderators' => array(),
221
					'link_moderator_groups' => array(),
222
					'children' => array(),
223
					'link_children' => array(),
224
					'children_new' => false,
225
					'topics' => $row_board['num_topics'],
226
					'posts' => $row_board['num_posts'],
227
					'is_redirect' => $row_board['is_redirect'],
228
					'unapproved_topics' => $row_board['unapproved_topics'],
229
					'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'],
230
					'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])),
231
					'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0',
232
					'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $board_name . '</a>',
233
					'board_class' => 'off',
234
					'css_class' => ''
235
				);
236
237
				call_integration_hook('integrate_boardindex_board', array(&$this_category, $row_board));
238
239
				// We can do some of the figuring-out-what-icon now.
240
				// For certain types of thing we also set up what the tooltip is.
241
				if ($this_category[$row_board['id_board']]['is_redirect'])
242
				{
243
					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
244
					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
245
				}
246
				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
247
				{
248
					// If we're showing to guests, we want to give them the idea that something interesting is going on!
249
					$this_category[$row_board['id_board']]['board_class'] = 'on';
250
					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
251
				}
252
				else
253
				{
254
					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
255
				}
256
			}
257
		}
258
		// This is a child board.
259
		elseif (isset($row_boards[$row_board['id_parent']]['id_parent']) && $row_boards[$row_board['id_parent']]['id_parent'] == $board_index_options['parent_id'])
260
		{
261
			$isChild = true;
262
263
			// Ensure the parent has at least the most important info defined
264
			if (!isset($this_category[$row_board['id_parent']]))
265
				$this_category[$row_board['id_parent']] = array(
266
					'children' => array(),
267
					'children_new' => false,
268
					'board_class' => 'off'
269
				);
270
271
			$board_name = parse_bbc($row_board['board_name'], false, '', $context['description_allowed_tags']);
272
			$board_description = parse_bbc($row_board['description'], false, '', $context['description_allowed_tags']);
273
274
			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
275
				'id' => $row_board['id_board'],
276
				'name' => $board_name,
277
				'description' => $board_description,
278
				'short_description' => shorten_subject($board_description, 128),
279
				'new' => empty($row_board['is_read']),
280
				'topics' => $row_board['num_topics'],
281
				'posts' => $row_board['num_posts'],
282
				'is_redirect' => $row_board['is_redirect'],
283
				'unapproved_topics' => $row_board['unapproved_topics'],
284
				'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'],
285
				'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])),
286
				'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0',
287
				'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $board_name . '</a>'
288
			);
289
290
			// Counting child board posts in the parent's totals?
291
			if (!empty($board_index_options['countChildPosts']) && !$row_board['is_redirect'])
292
			{
293
				$row_boards[$row_board['id_parent']]['num_posts'] += $row_board['num_posts'];
294
				$row_boards[$row_board['id_parent']]['num_topics'] += $row_board['num_topics'];
295
			}
296
297
			// Does this board contain new boards?
298
			$this_category[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']);
299
300
			// Update the icon if appropriate
301
			if ($this_category[$row_board['id_parent']]['children_new'] && $this_category[$row_board['id_parent']]['board_class'] == 'off')
302
			{
303
				$this_category[$row_board['id_parent']]['board_class'] = 'on2';
304
				$this_category[$row_board['id_parent']]['board_tooltip'] = $txt['new_posts'];
305
			}
306
307
			// This is easier to use in many cases for the theme....
308
			$this_category[$row_board['id_parent']]['link_children'][] = &$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['link'];
309
		}
310
		// A further descendent (grandchild, great-grandchild, etc.)
311
		else
312
		{
313
			// Propagate some values to the parent board
314
			if (isset($row_boards[$row_board['id_parent']]))
315
			{
316
				if (empty($row_board['is_read']))
317
					$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
318
319
				if (!empty($board_index_options['countChildPosts']) && !$row_board['is_redirect'])
320
				{
321
					$row_boards[$row_board['id_parent']]['num_posts'] += $row_board['num_posts'];
322
					$row_boards[$row_board['id_parent']]['num_topics'] += $row_board['num_topics'];
323
				}
324
325
				if ($row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time'])
326
				{
327
					$row_boards[$row_board['id_parent']]['id_msg'] = $row_board['id_msg'];
328
					$row_boards[$row_board['id_parent']]['subject'] = $row_board['subject'];
329
					$row_boards[$row_board['id_parent']]['poster_time'] = $row_board['poster_time'];
330
					$row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : '');
331
					$row_boards[$row_board['id_parent']]['poster_name'] = $row_board['poster_name'];
332
					$row_boards[$row_board['id_parent']]['real_name'] = $row_board['real_name'];
333
					$row_boards[$row_board['id_parent']]['id_member'] = $row_board['id_member'];
334
					$row_boards[$row_board['id_parent']]['id_topic'] = $row_board['id_topic'];
335
					$row_boards[$row_board['id_parent']]['new_from'] = $row_board['new_from'];
336
337
					if (!empty($settings['avatars_on_boardIndex']))
338
					{
339
						$row_boards[$row_board['id_parent']]['avatar'] = $row_board['avatar'];
340
						$row_boards[$row_board['id_parent']]['email_address'] = $row_board['email_address'];
341
						$row_boards[$row_board['id_parent']]['member_filename'] = !empty($row_board['member_filename']) ? $row_board['member_filename'] : '';
342
					}
343
				}
344
			}
345
346
			continue;
347
		}
348
349
		// Prepare the subject, and make sure it's not too long.
350
		censorText($row_board['subject']);
351
		$row_board['short_subject'] = shorten_subject($row_board['subject'], 24);
352
		$this_last_post = array(
353
			'id' => $row_board['id_msg'],
354
			'time' => $row_board['poster_time'],
355
			'timestamp' => forum_time(true, $row_board['poster_time']),
356
			'subject' => $row_board['short_subject'],
357
			'member' => array(
358
				'id' => $row_board['id_member'],
359
				'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'],
360
				'name' => $row_board['real_name'],
361
				'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $scripturl . '?action=profile;u=' . $row_board['id_member'] : '',
362
				'link' => $row_board['poster_name'] != '' ? (!empty($row_board['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row_board['id_member'] . '">' . $row_board['real_name'] . '</a>' : $row_board['real_name']) : $txt['not_applicable'],
363
			),
364
			'start' => 'msg' . $row_board['new_from'],
365
			'topic' => $row_board['id_topic']
366
		);
367
368
		if (!empty($settings['avatars_on_boardIndex']))
369
			$this_last_post['member']['avatar'] = set_avatar_data(array(
370
				'avatar' => $row_board['avatar'],
371
				'email' => $row_board['email_address'],
372
				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : ''
373
			));
374
375
		// Provide the href and link.
376
		if ($row_board['subject'] != '')
377
		{
378
			$this_last_post['href'] = $scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($user_info['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new';
379
			$this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>';
380
		}
381
		else
382
		{
383
			$this_last_post['href'] = '';
384
			$this_last_post['link'] = $txt['not_applicable'];
385
			$this_last_post['last_post_message'] = '';
386
		}
387
388
		// Set the last post in the parent board.
389
		if ($isChild && !empty($row_board['poster_time'])
390
			&& $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time'])
391
			$this_category[$row_board['id_parent']]['last_post'] = $this_last_post;
392
393
		// Set the last post in the root board
394
		if (!$isChild && !empty($row_board['poster_time'])
395
			&& (empty($this_category[$row_board['id_board']]['last_post']['timestamp'])
396
				|| $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])
397
				)
398
			)
399
			$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
400
401
		// Just in the child...?
402
		if ($isChild)
403
			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
404
405
		// Determine a global most recent topic.
406
		if (!empty($board_index_options['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $latest_post does not seem to be defined for all execution paths leading up to this point.
Loading history...
407
			$latest_post = array(
408
				'timestamp' => $row_board['poster_time'],
409
				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post']
410
			);
411
	}
412
413
	/* The board's and children's 'last_post's have:
414
	time, timestamp (a number that represents the time.), id (of the post), topic (topic id.),
415
	link, href, subject, start (where they should go for the first unread post.),
416
	and member. (which has id, name, link, href, username in it.)
417
	timeformat is a pricy call do it only for thos how get shown */
418
	// Fetch the board's moderators and moderator groups
419
	$boards = array_unique($boards);
420
	$moderators = getBoardModerators($boards);
421
	$groups = getBoardModeratorGroups($boards);
422
	if ($board_index_options['include_categories'])
423
		foreach ($categories as &$category)
424
		{
425
			foreach ($category['boards'] as &$board)
426
			{
427
				if (!empty($moderators[$board['id']]))
428
				{
429
					$board['moderators'] = $moderators[$board['id']];
430
					foreach ($moderators[$board['id']] as $moderator)
431
						$board['link_moderators'][] = $moderator['link'];
432
				}
433
				if (!empty($groups[$board['id']]))
434
				{
435
					$board['moderator_groups'] = $groups[$board['id']];
436
					foreach ($groups[$board['id']] as $group)
437
					{
438
						$board['link_moderators'][] = $group['link'];
439
						$board['link_moderator_groups'][] = $group['link'];
440
					}
441
				}
442
				if (!empty($board['last_post']))
443
					$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
444
			}
445
		}
446
	else
447
		foreach ($this_category as &$board)
448
		{
449
			if (!empty($moderators[$board['id']]))
450
			{
451
				$board['moderators'] = $moderators[$board['id']];
452
				foreach ($moderators[$board['id']] as $moderator)
453
					$board['link_moderators'][] = $moderator['link'];
454
			}
455
			if (!empty($groups[$board['id']]))
456
			{
457
				$board['moderator_groups'] = $groups[$board['id']];
458
				foreach ($groups[$board['id']] as $group)
459
				{
460
					$board['link_moderators'][] = $group['link'];
461
					$board['link_moderator_groups'][] = $group['link'];
462
				}
463
			}
464
			if (!empty($board['last_post']))
465
				$board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']);
466
		}
467
468
	unset($category, $board);
469
470
	if ($board_index_options['include_categories'])
471
		sortCategories($categories);
472
	else
473
		sortBoards($this_category);
474
475
	// By now we should know the most recent post...if we wanna know it that is.
476
	if (!empty($board_index_options['set_latest_post']) && !empty($latest_post['ref']))
477
	{
478
		$latest_post['ref']['time'] = timeformat($latest_post['ref']['time']);
479
		$context['latest_post'] = $latest_post['ref'];
480
	}
481
482
	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
483
	if ($board_index_options['include_categories'])
484
		call_integration_hook('integrate_getboardtree', array($board_index_options, &$categories));
485
	else
486
		call_integration_hook('integrate_getboardtree', array($board_index_options, &$this_category));
487
488
	return $board_index_options['include_categories'] ? $categories : $this_category;
489
}
490
491
?>