Completed
Pull Request — release-2.1 (#5018)
by Mathias
06:19
created
Sources/Subs-BoardIndex.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	$smcFunc['db_free_result']($result_boards);
135 135
 
136 136
 	// Run through the categories and boards (or only boards)....
137
-	for (reset($row_boards); key($row_boards)!==null; next($row_boards))
137
+	for (reset($row_boards); key($row_boards) !== null; next($row_boards))
138 138
 	{
139 139
 		$row_board = current($row_boards);
140 140
 
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 
353 353
 		// Set the last post in the root board 
354 354
 		if (!$isChild && !empty($row_board['poster_time'])
355
-			&& ( empty($this_category[$row_board['id_board']]['last_post']['poster_time'])
356
-				|| forum_time(true,$this_category[$row_board['id_board']]['last_post']['poster_time']) < forum_time(true, $row_board['poster_time'])
355
+			&& (empty($this_category[$row_board['id_board']]['last_post']['poster_time'])
356
+				|| forum_time(true, $this_category[$row_board['id_board']]['last_post']['poster_time']) < forum_time(true, $row_board['poster_time'])
357 357
 				)
358 358
 			)
359 359
 			$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
Please login to merge, or discard this patch.
Braces   +74 added lines, -57 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,19 +38,21 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// This setting is not allowed to be empty
47
-	if (empty($modSettings['boardindex_max_depth']))
48
-		$modSettings['boardindex_max_depth'] = 1;
49
+	if (empty($modSettings['boardindex_max_depth'])) {
50
+			$modSettings['boardindex_max_depth'] = 1;
51
+	}
49 52
 
50 53
 	// 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']('', '
54
+	if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) {
55
+			$result_boards = $smcFunc['db_query']('', '
53 56
 			WITH RECURSIVE 
54 57
 				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 58
 			as
@@ -90,8 +93,8 @@  discard block
 block discarded – undo
90 93
 				'id_parent' => $boardIndexOptions['parent_id'],
91 94
 			)
92 95
 		);
93
-	else
94
-		$result_boards = $smcFunc['db_query']('', '
96
+	} else {
97
+			$result_boards = $smcFunc['db_query']('', '
95 98
 			SELECT' . ($boardIndexOptions['include_categories'] ? '
96 99
 				c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
97 100
 				b.id_board, b.name AS board_name, b.description,
@@ -119,18 +122,21 @@  discard block
 block discarded – undo
119 122
 				'blank_string' => '',
120 123
 			)
121 124
 		);
125
+	}
122 126
 
123 127
 	// Start with an empty array.
124
-	if ($boardIndexOptions['include_categories'])
125
-		$categories = array();
126
-	else
127
-		$this_category = array();
128
+	if ($boardIndexOptions['include_categories']) {
129
+			$categories = array();
130
+	} else {
131
+			$this_category = array();
132
+	}
128 133
 	$boards = array();
129 134
 
130 135
 	// Children can affect parents, so we need to gather all the boards first and then process them after.
131 136
 	$row_boards = array();
132
-	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards))
133
-		$row_boards[$row_board['id_board']] = $row_board;
137
+	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) {
138
+			$row_boards[$row_board['id_board']] = $row_board;
139
+	}
134 140
 	$smcFunc['db_free_result']($result_boards);
135 141
 
136 142
 	// Run through the categories and boards (or only boards)....
@@ -143,8 +149,9 @@  discard block
 block discarded – undo
143 149
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
144 150
 
145 151
 		// Add parent boards to the $boards list later used to fetch moderators
146
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
147
-			$boards[] = $row_board['id_board'];
152
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
153
+					$boards[] = $row_board['id_board'];
154
+		}
148 155
 
149 156
 		if ($boardIndexOptions['include_categories'])
150 157
 		{
@@ -166,8 +173,9 @@  discard block
 block discarded – undo
166 173
 			}
167 174
 
168 175
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
169
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
170
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
176
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
177
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
178
+			}
171 179
 
172 180
 			// Avoid showing category unread link where it only has redirection boards.
173 181
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -186,8 +194,9 @@  discard block
 block discarded – undo
186 194
 				$isChild = false;
187 195
 
188 196
 				// We might or might not have already added this board, so...
189
-				if (!isset($this_category[$row_board['id_board']]))
190
-					$this_category[$row_board['id_board']] = array();
197
+				if (!isset($this_category[$row_board['id_board']])) {
198
+									$this_category[$row_board['id_board']] = array();
199
+				}
191 200
 
192 201
 				$this_category[$row_board['id_board']] += array(
193 202
 					'new' => empty($row_board['is_read']),
@@ -220,14 +229,12 @@  discard block
 block discarded – undo
220 229
 				{
221 230
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
222 231
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
223
-				}
224
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
232
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
225 233
 				{
226 234
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
227 235
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
228 236
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
229
-				}
230
-				else
237
+				} else
231 238
 				{
232 239
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
233 240
 				}
@@ -239,12 +246,13 @@  discard block
 block discarded – undo
239 246
 			$isChild = true;
240 247
 
241 248
 			// Ensure the parent has at least the most important info defined
242
-			if (!isset($this_category[$row_board['id_parent']]))
243
-				$this_category[$row_board['id_parent']] = array(
249
+			if (!isset($this_category[$row_board['id_parent']])) {
250
+							$this_category[$row_board['id_parent']] = array(
244 251
 					'children' => array(),
245 252
 					'children_new' => false,
246 253
 					'board_class' => 'off',
247 254
 				);
255
+			}
248 256
 
249 257
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
250 258
 				'id' => $row_board['id_board'],
@@ -288,8 +296,9 @@  discard block
 block discarded – undo
288 296
 			// Propagate some values to the parent board
289 297
 			if (isset($row_boards[$row_board['id_parent']]))
290 298
 			{
291
-				if (empty($row_board['is_read']))
292
-					$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
299
+				if (empty($row_board['is_read'])) {
300
+									$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
301
+				}
293 302
 
294 303
 				if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect'])
295 304
 				{
@@ -320,12 +329,13 @@  discard block
 block discarded – undo
320 329
 			'topic' => $row_board['id_topic']
321 330
 		);
322 331
 
323
-		if (!empty($settings['avatars_on_boardIndex']))
324
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
332
+		if (!empty($settings['avatars_on_boardIndex'])) {
333
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
325 334
 				'avatar' => $row_board['avatar'],
326 335
 				'email' => $row_board['email_address'],
327 336
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
328 337
 			));
338
+		}
329 339
 
330 340
 		// Provide the href and link.
331 341
 		if ($row_board['subject'] != '')
@@ -337,8 +347,7 @@  discard block
 block discarded – undo
337 347
 			link, href, subject, start (where they should go for the first unread post.),
338 348
 			and member. (which has id, name, link, href, username in it.) */
339 349
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
340
-		}
341
-		else
350
+		} else
342 351
 		{
343 352
 			$this_last_post['href'] = '';
344 353
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -347,27 +356,31 @@  discard block
 block discarded – undo
347 356
 
348 357
 		// Set the last post in the parent board.
349 358
 		if ($isChild && !empty($row_board['poster_time']) 
350
-				&& forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))
351
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
359
+				&& forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time'])) {
360
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
361
+		}
352 362
 
353 363
 		// Set the last post in the root board 
354 364
 		if (!$isChild && !empty($row_board['poster_time'])
355 365
 			&& ( empty($this_category[$row_board['id_board']]['last_post']['poster_time'])
356 366
 				|| forum_time(true,$this_category[$row_board['id_board']]['last_post']['poster_time']) < forum_time(true, $row_board['poster_time'])
357 367
 				)
358
-			)
359
-			$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
368
+			) {
369
+					$this_category[$row_board['id_board']]['last_post'] = $this_last_post;
370
+		}
360 371
 
361 372
 		// Just in the child...?
362
-		if ($isChild)
363
-			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
373
+		if ($isChild) {
374
+					$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
375
+		}
364 376
 
365 377
 		// Determine a global most recent topic.
366
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
367
-			$latest_post = array(
378
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
379
+					$latest_post = array(
368 380
 				'timestamp' => $row_board['poster_time'],
369 381
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
370 382
 			);
383
+		}
371 384
 	}
372 385
 
373 386
 	// Fetch the board's moderators and moderator groups
@@ -383,8 +396,9 @@  discard block
 block discarded – undo
383 396
 				if (!empty($moderators[$board['id']]))
384 397
 				{
385 398
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
386
-					foreach ($moderators[$board['id']] as $moderator)
387
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
399
+					foreach ($moderators[$board['id']] as $moderator) {
400
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
401
+					}
388 402
 				}
389 403
 				if (!empty($groups[$board['id']]))
390 404
 				{
@@ -397,16 +411,16 @@  discard block
 block discarded – undo
397 411
 				}
398 412
 			}
399 413
 		}
400
-	}
401
-	else
414
+	} else
402 415
 	{
403 416
 		foreach ($this_category as $k => $board)
404 417
 		{
405 418
 			if (!empty($moderators[$board['id']]))
406 419
 			{
407 420
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
408
-				foreach ($moderators[$board['id']] as $moderator)
409
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
421
+				foreach ($moderators[$board['id']] as $moderator) {
422
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
423
+				}
410 424
 			}
411 425
 			if (!empty($groups[$board['id']]))
412 426
 			{
@@ -420,20 +434,23 @@  discard block
 block discarded – undo
420 434
 		}
421 435
 	}
422 436
 
423
-	if ($boardIndexOptions['include_categories'])
424
-		sortCategories($categories);
425
-	else
426
-		sortBoards($this_category);
437
+	if ($boardIndexOptions['include_categories']) {
438
+			sortCategories($categories);
439
+	} else {
440
+			sortBoards($this_category);
441
+	}
427 442
 
428 443
 	// By now we should know the most recent post...if we wanna know it that is.
429
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
430
-		$context['latest_post'] = $latest_post['ref'];
444
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
445
+			$context['latest_post'] = $latest_post['ref'];
446
+	}
431 447
 
432 448
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
433
-	if ($boardIndexOptions['include_categories'])
434
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
435
-	else
436
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
449
+	if ($boardIndexOptions['include_categories']) {
450
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
451
+	} else {
452
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
453
+	}
437 454
 
438 455
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
439 456
 }
Please login to merge, or discard this patch.