Issues (1027)

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