Passed
Push — release-2.1 ( 0c2197...207d2d )
by Jeremy
05:47
created

getBoardIndex()   F

Complexity

Conditions 106
Paths 5120

Size

Total Lines 430
Code Lines 252

Duplication

Lines 0
Ratio 0 %

Importance

Changes 12
Bugs 0 Features 2
Metric Value
cc 106
eloc 252
c 12
b 0
f 2
nop 1
dl 0
loc 430
rs 0
nc 5120

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