Completed
Pull Request — release-2.1 (#4156)
by 01
13:04 queued 03:20
created
Sources/Subs-Boards.php 1 patch
Braces   +247 added lines, -175 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
  * Mark a board or multiple boards read.
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 	global $user_info, $modSettings, $smcFunc;
29 30
 
30 31
 	// Force $boards to be an array.
31
-	if (!is_array($boards))
32
-		$boards = array($boards);
33
-	else
34
-		$boards = array_unique($boards);
32
+	if (!is_array($boards)) {
33
+			$boards = array($boards);
34
+	} else {
35
+			$boards = array_unique($boards);
36
+	}
35 37
 
36 38
 	// No boards, nothing to mark as read.
37
-	if (empty($boards))
38
-		return;
39
+	if (empty($boards)) {
40
+			return;
41
+	}
39 42
 
40 43
 	// Allow the user to mark a board as unread.
41 44
 	if ($unread)
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	else
66 69
 	{
67 70
 		$markRead = array();
68
-		foreach ($boards as $board)
69
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
71
+		foreach ($boards as $board) {
72
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
73
+		}
70 74
 
71 75
 		// Update log_mark_read and log_boards.
72 76
 		$smcFunc['db_insert']('replace',
@@ -99,8 +103,9 @@  discard block
 block discarded – undo
99 103
 	list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
100 104
 	$smcFunc['db_free_result']($result);
101 105
 
102
-	if (empty($lowest_topic))
103
-		return;
106
+	if (empty($lowest_topic)) {
107
+			return;
108
+	}
104 109
 
105 110
 	// @todo SLOW This query seems to eat it sometimes.
106 111
 	$result = $smcFunc['db_query']('', '
@@ -118,12 +123,13 @@  discard block
 block discarded – undo
118 123
 		)
119 124
 	);
120 125
 	$topics = array();
121
-	while ($row = $smcFunc['db_fetch_assoc']($result))
122
-		$topics[] = $row['id_topic'];
126
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
127
+			$topics[] = $row['id_topic'];
128
+	}
123 129
 	$smcFunc['db_free_result']($result);
124 130
 
125
-	if (!empty($topics))
126
-		$smcFunc['db_query']('', '
131
+	if (!empty($topics)) {
132
+			$smcFunc['db_query']('', '
127 133
 			DELETE FROM {db_prefix}log_topics
128 134
 			WHERE id_member = {int:current_member}
129 135
 				AND id_topic IN ({array_int:topic_list})',
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 				'topic_list' => $topics,
133 139
 			)
134 140
 		);
135
-}
141
+	}
142
+	}
136 143
 
137 144
 /**
138 145
  * Mark one or more boards as read.
@@ -157,23 +164,26 @@  discard block
 block discarded – undo
157 164
 			)
158 165
 		);
159 166
 		$boards = array();
160
-		while ($row = $smcFunc['db_fetch_assoc']($result))
161
-			$boards[] = $row['id_board'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
168
+					$boards[] = $row['id_board'];
169
+		}
162 170
 		$smcFunc['db_free_result']($result);
163 171
 
164
-		if (!empty($boards))
165
-			markBoardsRead($boards, isset($_REQUEST['unread']));
172
+		if (!empty($boards)) {
173
+					markBoardsRead($boards, isset($_REQUEST['unread']));
174
+		}
166 175
 
167 176
 		$_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
168
-		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
169
-			redirectexit('action=unread');
177
+		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) {
178
+					redirectexit('action=unread');
179
+		}
170 180
 
171
-		if (isset($_SESSION['topicseen_cache']))
172
-			$_SESSION['topicseen_cache'] = array();
181
+		if (isset($_SESSION['topicseen_cache'])) {
182
+					$_SESSION['topicseen_cache'] = array();
183
+		}
173 184
 
174 185
 		redirectexit();
175
-	}
176
-	elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
186
+	} elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
177 187
 	{
178 188
 		// Make sure all the topics are integers!
179 189
 		$topics = array_map('intval', explode('-', $_REQUEST['topics']));
@@ -189,13 +199,15 @@  discard block
 block discarded – undo
189 199
 			)
190 200
 		);
191 201
 		$logged_topics = array();
192
-		while ($row = $smcFunc['db_fetch_assoc']($request))
193
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
203
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
204
+		}
194 205
 		$smcFunc['db_free_result']($request);
195 206
 
196 207
 		$markRead = array();
197
-		foreach ($topics as $id_topic)
198
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
208
+		foreach ($topics as $id_topic) {
209
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
210
+		}
199 211
 
200 212
 		$smcFunc['db_insert']('replace',
201 213
 			'{db_prefix}log_topics',
@@ -204,8 +216,9 @@  discard block
 block discarded – undo
204 216
 			array('id_member', 'id_topic')
205 217
 		);
206 218
 
207
-		if (isset($_SESSION['topicseen_cache']))
208
-			$_SESSION['topicseen_cache'] = array();
219
+		if (isset($_SESSION['topicseen_cache'])) {
220
+					$_SESSION['topicseen_cache'] = array();
221
+		}
209 222
 
210 223
 		redirectexit('action=unreadreplies');
211 224
 	}
@@ -230,11 +243,13 @@  discard block
 block discarded – undo
230 243
 		if (!empty($_GET['t']))
231 244
 		{
232 245
 			// If they read the whole topic, go back to the beginning.
233
-			if ($_GET['t'] >= $topicinfo['id_last_msg'])
234
-				$earlyMsg = 0;
246
+			if ($_GET['t'] >= $topicinfo['id_last_msg']) {
247
+							$earlyMsg = 0;
248
+			}
235 249
 			// If they want to mark the whole thing read, same.
236
-			elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
237
-				$earlyMsg = 0;
250
+			elseif ($_GET['t'] <= $topicinfo['id_first_msg']) {
251
+							$earlyMsg = 0;
252
+			}
238 253
 			// Otherwise, get the latest message before the named one.
239 254
 			else
240 255
 			{
@@ -255,9 +270,9 @@  discard block
 block discarded – undo
255 270
 			}
256 271
 		}
257 272
 		// Marking read from first page?  That's the whole topic.
258
-		elseif ($_REQUEST['start'] == 0)
259
-			$earlyMsg = 0;
260
-		else
273
+		elseif ($_REQUEST['start'] == 0) {
274
+					$earlyMsg = 0;
275
+		} else
261 276
 		{
262 277
 			$result = $smcFunc['db_query']('', '
263 278
 				SELECT id_msg
@@ -285,8 +300,7 @@  discard block
 block discarded – undo
285 300
 		);
286 301
 
287 302
 		redirectexit('board=' . $board . '.0');
288
-	}
289
-	else
303
+	} else
290 304
 	{
291 305
 		$categories = array();
292 306
 		$boards = array();
@@ -294,17 +308,20 @@  discard block
 block discarded – undo
294 308
 		if (isset($_REQUEST['c']))
295 309
 		{
296 310
 			$_REQUEST['c'] = explode(',', $_REQUEST['c']);
297
-			foreach ($_REQUEST['c'] as $c)
298
-				$categories[] = (int) $c;
311
+			foreach ($_REQUEST['c'] as $c) {
312
+							$categories[] = (int) $c;
313
+			}
299 314
 		}
300 315
 		if (isset($_REQUEST['boards']))
301 316
 		{
302 317
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
303
-			foreach ($_REQUEST['boards'] as $b)
304
-				$boards[] = (int) $b;
318
+			foreach ($_REQUEST['boards'] as $b) {
319
+							$boards[] = (int) $b;
320
+			}
321
+		}
322
+		if (!empty($board)) {
323
+					$boards[] = (int) $board;
305 324
 		}
306
-		if (!empty($board))
307
-			$boards[] = (int) $board;
308 325
 
309 326
 		if (isset($_REQUEST['children']) && !empty($boards))
310 327
 		{
@@ -324,9 +341,10 @@  discard block
 block discarded – undo
324 341
 					'board_list' => $boards,
325 342
 				)
326 343
 			);
327
-			while ($row = $smcFunc['db_fetch_assoc']($request))
328
-				if (in_array($row['id_parent'], $boards))
344
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
345
+							if (in_array($row['id_parent'], $boards))
329 346
 					$boards[] = $row['id_board'];
347
+			}
330 348
 			$smcFunc['db_free_result']($request);
331 349
 		}
332 350
 
@@ -343,8 +361,9 @@  discard block
 block discarded – undo
343 361
 			$clauseParameters['board_list'] = $boards;
344 362
 		}
345 363
 
346
-		if (empty($clauses))
347
-			redirectexit();
364
+		if (empty($clauses)) {
365
+					redirectexit();
366
+		}
348 367
 
349 368
 		$request = $smcFunc['db_query']('', '
350 369
 			SELECT b.id_board
@@ -355,19 +374,22 @@  discard block
 block discarded – undo
355 374
 			))
356 375
 		);
357 376
 		$boards = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$boards[] = $row['id_board'];
377
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
378
+					$boards[] = $row['id_board'];
379
+		}
360 380
 		$smcFunc['db_free_result']($request);
361 381
 
362
-		if (empty($boards))
363
-			redirectexit();
382
+		if (empty($boards)) {
383
+					redirectexit();
384
+		}
364 385
 
365 386
 		markBoardsRead($boards, isset($_REQUEST['unread']));
366 387
 
367 388
 		foreach ($boards as $b)
368 389
 		{
369
-			if (isset($_SESSION['topicseen_cache'][$b]))
370
-				$_SESSION['topicseen_cache'][$b] = array();
390
+			if (isset($_SESSION['topicseen_cache'][$b])) {
391
+							$_SESSION['topicseen_cache'][$b] = array();
392
+			}
371 393
 		}
372 394
 
373 395
 		if (!isset($_REQUEST['unread']))
@@ -385,8 +407,9 @@  discard block
 block discarded – undo
385 407
 			if ($smcFunc['db_num_rows']($result) > 0)
386 408
 			{
387 409
 				$logBoardInserts = array();
388
-				while ($row = $smcFunc['db_fetch_assoc']($result))
389
-					$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
410
+				while ($row = $smcFunc['db_fetch_assoc']($result)) {
411
+									$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
412
+				}
390 413
 
391 414
 				$smcFunc['db_insert']('replace',
392 415
 					'{db_prefix}log_boards',
@@ -397,17 +420,18 @@  discard block
 block discarded – undo
397 420
 			}
398 421
 			$smcFunc['db_free_result']($result);
399 422
 
400
-			if (empty($board))
401
-				redirectexit();
402
-			else
403
-				redirectexit('board=' . $board . '.0');
404
-		}
405
-		else
423
+			if (empty($board)) {
424
+							redirectexit();
425
+			} else {
426
+							redirectexit('board=' . $board . '.0');
427
+			}
428
+		} else
406 429
 		{
407
-			if (empty($board_info['parent']))
408
-				redirectexit();
409
-			else
410
-				redirectexit('board=' . $board_info['parent'] . '.0');
430
+			if (empty($board_info['parent'])) {
431
+							redirectexit();
432
+			} else {
433
+							redirectexit('board=' . $board_info['parent'] . '.0');
434
+			}
411 435
 		}
412 436
 	}
413 437
 }
@@ -432,11 +456,13 @@  discard block
 block discarded – undo
432 456
 			'selected_message' => (int) $messageID,
433 457
 		)
434 458
 	);
435
-	if ($smcFunc['db_num_rows']($result) > 0)
436
-		list ($memberID) = $smcFunc['db_fetch_row']($result);
459
+	if ($smcFunc['db_num_rows']($result) > 0) {
460
+			list ($memberID) = $smcFunc['db_fetch_row']($result);
461
+	}
437 462
 	// The message doesn't even exist.
438
-	else
439
-		$memberID = 0;
463
+	else {
464
+			$memberID = 0;
465
+	}
440 466
 	$smcFunc['db_free_result']($result);
441 467
 
442 468
 	return (int) $memberID;
@@ -457,8 +483,9 @@  discard block
 block discarded – undo
457 483
 	getBoardTree();
458 484
 
459 485
 	// Make sure given boards and categories exist.
460
-	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
461
-		fatal_lang_error('no_board');
486
+	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) {
487
+			fatal_lang_error('no_board');
488
+	}
462 489
 
463 490
 	$id = $board_id;
464 491
 	call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
@@ -486,8 +513,9 @@  discard block
 block discarded – undo
486 513
 			$child_level = 0;
487 514
 			$id_parent = 0;
488 515
 			$after = 0;
489
-			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
490
-				$after = max($after, $boards[$id_board]['order']);
516
+			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) {
517
+							$after = max($after, $boards[$id_board]['order']);
518
+			}
491 519
 		}
492 520
 
493 521
 		// Make the board a child of a given board.
@@ -498,17 +526,19 @@  discard block
 block discarded – undo
498 526
 			$id_parent = $boardOptions['target_board'];
499 527
 
500 528
 			// People can be creative, in many ways...
501
-			if (isChildOf($id_parent, $board_id))
502
-				fatal_lang_error('mboards_parent_own_child_error', false);
503
-			elseif ($id_parent == $board_id)
504
-				fatal_lang_error('mboards_board_own_child_error', false);
529
+			if (isChildOf($id_parent, $board_id)) {
530
+							fatal_lang_error('mboards_parent_own_child_error', false);
531
+			} elseif ($id_parent == $board_id) {
532
+							fatal_lang_error('mboards_board_own_child_error', false);
533
+			}
505 534
 
506 535
 			$after = $boards[$boardOptions['target_board']]['order'];
507 536
 
508 537
 			// Check if there are already children and (if so) get the max board order.
509
-			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
510
-				foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
538
+			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) {
539
+							foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
511 540
 					$after = max($after, $boards[$childBoard_id]['order']);
541
+			}
512 542
 		}
513 543
 
514 544
 		// Place a board before or after another board, on the same child level.
@@ -521,8 +551,9 @@  discard block
 block discarded – undo
521 551
 		}
522 552
 
523 553
 		// Oops...?
524
-		else
525
-			trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
554
+		else {
555
+					trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
556
+		}
526 557
 
527 558
 		// Get a list of children of this board.
528 559
 		$childList = array();
@@ -531,14 +562,16 @@  discard block
 block discarded – undo
531 562
 		// See if there are changes that affect children.
532 563
 		$childUpdates = array();
533 564
 		$levelDiff = $child_level - $boards[$board_id]['level'];
534
-		if ($levelDiff != 0)
535
-			$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
536
-		if ($id_cat != $boards[$board_id]['category'])
537
-			$childUpdates[] = 'id_cat = {int:category}';
565
+		if ($levelDiff != 0) {
566
+					$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
567
+		}
568
+		if ($id_cat != $boards[$board_id]['category']) {
569
+					$childUpdates[] = 'id_cat = {int:category}';
570
+		}
538 571
 
539 572
 		// Fix the children of this board.
540
-		if (!empty($childList) && !empty($childUpdates))
541
-			$smcFunc['db_query']('', '
573
+		if (!empty($childList) && !empty($childUpdates)) {
574
+					$smcFunc['db_query']('', '
542 575
 				UPDATE {db_prefix}boards
543 576
 				SET ' . implode(',
544 577
 					', $childUpdates) . '
@@ -549,6 +582,7 @@  discard block
 block discarded – undo
549 582
 					'level_diff' => $levelDiff,
550 583
 				)
551 584
 			);
585
+		}
552 586
 
553 587
 		// Make some room for this spot.
554 588
 		$smcFunc['db_query']('', '
@@ -644,8 +678,8 @@  discard block
 block discarded – undo
644 678
 	call_integration_hook('integrate_modify_board', array($id, $boardOptions, &$boardUpdates, &$boardUpdateParameters));
645 679
 
646 680
 	// Do the updates (if any).
647
-	if (!empty($boardUpdates))
648
-		$smcFunc['db_query']('', '
681
+	if (!empty($boardUpdates)) {
682
+			$smcFunc['db_query']('', '
649 683
 			UPDATE {db_prefix}boards
650 684
 			SET
651 685
 				' . implode(',
@@ -655,6 +689,7 @@  discard block
 block discarded – undo
655 689
 				'selected_board' => $board_id,
656 690
 			))
657 691
 		);
692
+	}
658 693
 
659 694
 	// Set moderators of this board.
660 695
 	if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
@@ -679,13 +714,15 @@  discard block
 block discarded – undo
679 714
 			{
680 715
 				$moderators[$k] = trim($moderators[$k]);
681 716
 
682
-				if (strlen($moderators[$k]) == 0)
683
-					unset($moderators[$k]);
717
+				if (strlen($moderators[$k]) == 0) {
718
+									unset($moderators[$k]);
719
+				}
684 720
 			}
685 721
 
686 722
 			// Find all the id_member's for the member_name's in the list.
687
-			if (empty($boardOptions['moderators']))
688
-				$boardOptions['moderators'] = array();
723
+			if (empty($boardOptions['moderators'])) {
724
+							$boardOptions['moderators'] = array();
725
+			}
689 726
 			if (!empty($moderators))
690 727
 			{
691 728
 				$request = $smcFunc['db_query']('', '
@@ -698,8 +735,9 @@  discard block
 block discarded – undo
698 735
 						'limit' => count($moderators),
699 736
 					)
700 737
 				);
701
-				while ($row = $smcFunc['db_fetch_assoc']($request))
702
-					$boardOptions['moderators'][] = $row['id_member'];
738
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
739
+									$boardOptions['moderators'][] = $row['id_member'];
740
+				}
703 741
 				$smcFunc['db_free_result']($request);
704 742
 			}
705 743
 		}
@@ -708,8 +746,9 @@  discard block
 block discarded – undo
708 746
 		if (!empty($boardOptions['moderators']))
709 747
 		{
710 748
 			$inserts = array();
711
-			foreach ($boardOptions['moderators'] as $moderator)
712
-				$inserts[] = array($board_id, $moderator);
749
+			foreach ($boardOptions['moderators'] as $moderator) {
750
+							$inserts[] = array($board_id, $moderator);
751
+			}
713 752
 
714 753
 			$smcFunc['db_insert']('insert',
715 754
 				'{db_prefix}moderators',
@@ -739,14 +778,16 @@  discard block
 block discarded – undo
739 778
 			{
740 779
 				$moderator_groups[$k] = trim($moderator_groups[$k]);
741 780
 
742
-				if (strlen($moderator_groups[$k]) == 0)
743
-					unset($moderator_groups[$k]);
781
+				if (strlen($moderator_groups[$k]) == 0) {
782
+									unset($moderator_groups[$k]);
783
+				}
744 784
 			}
745 785
 
746 786
 			/* 	Find all the id_group's for all the group names in the list
747 787
 				But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
748
-			if (empty($boardOptions['moderator_groups']))
749
-				$boardOptions['moderator_groups'] = array();
788
+			if (empty($boardOptions['moderator_groups'])) {
789
+							$boardOptions['moderator_groups'] = array();
790
+			}
750 791
 			if (!empty($moderator_groups))
751 792
 			{
752 793
 				$request = $smcFunc['db_query']('', '
@@ -777,8 +818,9 @@  discard block
 block discarded – undo
777 818
 		if (!empty($boardOptions['moderator_groups']))
778 819
 		{
779 820
 			$inserts = array();
780
-			foreach ($boardOptions['moderator_groups'] as $moderator_group)
781
-				$inserts[] = array($board_id, $moderator_group);
821
+			foreach ($boardOptions['moderator_groups'] as $moderator_group) {
822
+							$inserts[] = array($board_id, $moderator_group);
823
+			}
782 824
 
783 825
 			$smcFunc['db_insert']('insert',
784 826
 				'{db_prefix}moderator_groups',
@@ -792,14 +834,16 @@  discard block
 block discarded – undo
792 834
 		updateSettings(array('settings_updated' => time()));
793 835
 	}
794 836
 
795
-	if (isset($boardOptions['move_to']))
796
-		reorderBoards();
837
+	if (isset($boardOptions['move_to'])) {
838
+			reorderBoards();
839
+	}
797 840
 
798 841
 	clean_cache('data');
799 842
 
800
-	if (empty($boardOptions['dont_log']))
801
-		logAction('edit_board', array('board' => $board_id), 'admin');
802
-}
843
+	if (empty($boardOptions['dont_log'])) {
844
+			logAction('edit_board', array('board' => $board_id), 'admin');
845
+	}
846
+	}
803 847
 
804 848
 /**
805 849
  * Create a new board and set its properties and position.
@@ -815,11 +859,13 @@  discard block
 block discarded – undo
815 859
 	global $boards, $smcFunc;
816 860
 
817 861
 	// Trigger an error if one of the required values is not set.
818
-	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
819
-		trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
862
+	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) {
863
+			trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
864
+	}
820 865
 
821
-	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
822
-		trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
866
+	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) {
867
+			trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
868
+	}
823 869
 
824 870
 	// Set every optional value to its default value.
825 871
 	$boardOptions += array(
@@ -853,8 +899,9 @@  discard block
 block discarded – undo
853 899
 		1
854 900
 	);
855 901
 
856
-	if (empty($board_id))
857
-		return 0;
902
+	if (empty($board_id)) {
903
+			return 0;
904
+	}
858 905
 
859 906
 	// Change the board according to the given specifications.
860 907
 	modifyBoard($board_id, $boardOptions);
@@ -917,8 +964,9 @@  discard block
 block discarded – undo
917 964
 	global $sourcedir, $boards, $smcFunc;
918 965
 
919 966
 	// No boards to delete? Return!
920
-	if (empty($boards_to_remove))
921
-		return;
967
+	if (empty($boards_to_remove)) {
968
+			return;
969
+	}
922 970
 
923 971
 	getBoardTree();
924 972
 
@@ -929,12 +977,14 @@  discard block
 block discarded – undo
929 977
 	{
930 978
 		// Get a list of the child boards that will also be removed.
931 979
 		$child_boards_to_remove = array();
932
-		foreach ($boards_to_remove as $board_to_remove)
933
-			recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
980
+		foreach ($boards_to_remove as $board_to_remove) {
981
+					recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
982
+		}
934 983
 
935 984
 		// Merge the children with their parents.
936
-		if (!empty($child_boards_to_remove))
937
-			$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
985
+		if (!empty($child_boards_to_remove)) {
986
+					$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
987
+		}
938 988
 	}
939 989
 	// Move the children to a safe home.
940 990
 	else
@@ -942,10 +992,11 @@  discard block
 block discarded – undo
942 992
 		foreach ($boards_to_remove as $id_board)
943 993
 		{
944 994
 			// @todo Separate category?
945
-			if ($moveChildrenTo === 0)
946
-				fixChildren($id_board, 0, 0);
947
-			else
948
-				fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
995
+			if ($moveChildrenTo === 0) {
996
+							fixChildren($id_board, 0, 0);
997
+			} else {
998
+							fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
999
+			}
949 1000
 		}
950 1001
 	}
951 1002
 
@@ -959,8 +1010,9 @@  discard block
 block discarded – undo
959 1010
 		)
960 1011
 	);
961 1012
 	$topics = array();
962
-	while ($row = $smcFunc['db_fetch_assoc']($request))
963
-		$topics[] = $row['id_topic'];
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$topics[] = $row['id_topic'];
1015
+	}
964 1016
 	$smcFunc['db_free_result']($request);
965 1017
 
966 1018
 	require_once($sourcedir . '/RemoveTopic.php');
@@ -1048,8 +1100,9 @@  discard block
 block discarded – undo
1048 1100
 	clean_cache('data');
1049 1101
 
1050 1102
 	// Let's do some serious logging.
1051
-	foreach ($boards_to_remove as $id_board)
1052
-		logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1103
+	foreach ($boards_to_remove as $id_board) {
1104
+			logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1105
+	}
1053 1106
 
1054 1107
 	reorderBoards();
1055 1108
 }
@@ -1068,8 +1121,8 @@  discard block
 block discarded – undo
1068 1121
 	$board_order = 0;
1069 1122
 	foreach ($cat_tree as $catID => $dummy)
1070 1123
 	{
1071
-		foreach ($boardList[$catID] as $boardID)
1072
-			if ($boards[$boardID]['order'] != ++$board_order)
1124
+		foreach ($boardList[$catID] as $boardID) {
1125
+					if ($boards[$boardID]['order'] != ++$board_order)
1073 1126
 				$smcFunc['db_query']('', '
1074 1127
 					UPDATE {db_prefix}boards
1075 1128
 					SET board_order = {int:new_order}
@@ -1079,6 +1132,7 @@  discard block
 block discarded – undo
1079 1132
 						'selected_board' => $boardID,
1080 1133
 					)
1081 1134
 				);
1135
+		}
1082 1136
 	}
1083 1137
 
1084 1138
 	// Empty the board order cache
@@ -1107,8 +1161,9 @@  discard block
 block discarded – undo
1107 1161
 		)
1108 1162
 	);
1109 1163
 	$children = array();
1110
-	while ($row = $smcFunc['db_fetch_assoc']($result))
1111
-		$children[] = $row['id_board'];
1164
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
1165
+			$children[] = $row['id_board'];
1166
+	}
1112 1167
 	$smcFunc['db_free_result']($result);
1113 1168
 
1114 1169
 	// ...and set it to a new parent and child_level.
@@ -1124,9 +1179,10 @@  discard block
 block discarded – undo
1124 1179
 	);
1125 1180
 
1126 1181
 	// Recursively fix the children of the children.
1127
-	foreach ($children as $child)
1128
-		fixChildren($child, $newLevel + 1, $child);
1129
-}
1182
+	foreach ($children as $child) {
1183
+			fixChildren($child, $newLevel + 1, $child);
1184
+	}
1185
+	}
1130 1186
 
1131 1187
 /**
1132 1188
  * Tries to load up the entire board order and category very very quickly
@@ -1143,8 +1199,9 @@  discard block
 block discarded – undo
1143 1199
 		'boards' => array(),
1144 1200
 	);
1145 1201
 
1146
-	if (!empty($tree_order['boards']))
1147
-		return $tree_order;
1202
+	if (!empty($tree_order['boards'])) {
1203
+			return $tree_order;
1204
+	}
1148 1205
 
1149 1206
 	if (($cached = cache_get_data('board_order', 86400)) !== null)
1150 1207
 	{
@@ -1160,8 +1217,9 @@  discard block
 block discarded – undo
1160 1217
 	);
1161 1218
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1219
 	{
1163
-		if (!in_array($row['id_cat'], $tree_order['cats']))
1164
-			$tree_order['cats'][] = $row['id_cat'];
1220
+		if (!in_array($row['id_cat'], $tree_order['cats'])) {
1221
+					$tree_order['cats'][] = $row['id_cat'];
1222
+		}
1165 1223
 		$tree_order['boards'][] = $row['id_board'];
1166 1224
 	}
1167 1225
 	$smcFunc['db_free_result']($request);
@@ -1181,16 +1239,19 @@  discard block
 block discarded – undo
1181 1239
 	$tree = getTreeOrder();
1182 1240
 
1183 1241
 	$ordered = array();
1184
-	foreach ($tree['boards'] as $board)
1185
-		if (!empty($boards[$board]))
1242
+	foreach ($tree['boards'] as $board) {
1243
+			if (!empty($boards[$board]))
1186 1244
 		{
1187 1245
 			$ordered[$board] = $boards[$board];
1246
+	}
1188 1247
 
1189
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards']))
1190
-				sortBoards($ordered[$board]['boards']);
1248
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) {
1249
+							sortBoards($ordered[$board]['boards']);
1250
+			}
1191 1251
 
1192
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['children']))
1193
-				sortBoards($ordered[$board]['children']);
1252
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) {
1253
+							sortBoards($ordered[$board]['children']);
1254
+			}
1194 1255
 		}
1195 1256
 
1196 1257
 	$boards = $ordered;
@@ -1206,12 +1267,14 @@  discard block
 block discarded – undo
1206 1267
 	$tree = getTreeOrder();
1207 1268
 
1208 1269
 	$ordered = array();
1209
-	foreach ($tree['cats'] as $cat)
1210
-		if (!empty($categories[$cat]))
1270
+	foreach ($tree['cats'] as $cat) {
1271
+			if (!empty($categories[$cat]))
1211 1272
 		{
1212 1273
 			$ordered[$cat] = $categories[$cat];
1213
-			if (!empty($ordered[$cat]['boards']))
1214
-				sortBoards($ordered[$cat]['boards']);
1274
+	}
1275
+			if (!empty($ordered[$cat]['boards'])) {
1276
+							sortBoards($ordered[$cat]['boards']);
1277
+			}
1215 1278
 		}
1216 1279
 
1217 1280
 	$categories = $ordered;
@@ -1227,8 +1290,9 @@  discard block
 block discarded – undo
1227 1290
 {
1228 1291
 	global $smcFunc, $scripturl, $txt;
1229 1292
 
1230
-	if (empty($boards))
1231
-		return array();
1293
+	if (empty($boards)) {
1294
+			return array();
1295
+	}
1232 1296
 
1233 1297
 	$request = $smcFunc['db_query']('', '
1234 1298
 		SELECT mem.id_member, mem.real_name, mo.id_board
@@ -1242,8 +1306,9 @@  discard block
 block discarded – undo
1242 1306
 	$moderators = array();
1243 1307
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1244 1308
 	{
1245
-		if (empty($moderators[$row['id_board']]))
1246
-			$moderators[$row['id_board']] = array();
1309
+		if (empty($moderators[$row['id_board']])) {
1310
+					$moderators[$row['id_board']] = array();
1311
+		}
1247 1312
 
1248 1313
 		$moderators[$row['id_board']][] = array(
1249 1314
 			'id' => $row['id_member'],
@@ -1267,8 +1332,9 @@  discard block
 block discarded – undo
1267 1332
 {
1268 1333
 	global $smcFunc, $scripturl, $txt;
1269 1334
 
1270
-	if (empty($boards))
1271
-		return array();
1335
+	if (empty($boards)) {
1336
+			return array();
1337
+	}
1272 1338
 
1273 1339
 	$request = $smcFunc['db_query']('', '
1274 1340
 		SELECT mg.id_group, mg.group_name, bg.id_board
@@ -1282,8 +1348,9 @@  discard block
 block discarded – undo
1282 1348
 	$groups = array();
1283 1349
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1284 1350
 	{
1285
-		if (empty($groups[$row['id_board']]))
1286
-			$groups[$row['id_board']] = array();
1351
+		if (empty($groups[$row['id_board']])) {
1352
+					$groups[$row['id_board']] = array();
1353
+		}
1287 1354
 
1288 1355
 		$groups[$row['id_board']][] = array(
1289 1356
 			'id' => $row['id_group'],
@@ -1358,8 +1425,9 @@  discard block
 block discarded – undo
1358 1425
 
1359 1426
 		if (!empty($row['id_board']))
1360 1427
 		{
1361
-			if ($row['child_level'] != $curLevel)
1362
-				$prevBoard = 0;
1428
+			if ($row['child_level'] != $curLevel) {
1429
+							$prevBoard = 0;
1430
+			}
1363 1431
 
1364 1432
 			$boards[$row['id_board']] = array(
1365 1433
 				'id' => $row['id_board'],
@@ -1391,16 +1459,16 @@  discard block
 block discarded – undo
1391 1459
 					'children' => array()
1392 1460
 				);
1393 1461
 				$boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
1394
-			}
1395
-			else
1462
+			} else
1396 1463
 			{
1397 1464
 				// Parent doesn't exist!
1398
-				if (!isset($boards[$row['id_parent']]['tree']))
1399
-					fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1465
+				if (!isset($boards[$row['id_parent']]['tree'])) {
1466
+									fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1467
+				}
1400 1468
 
1401 1469
 				// Wrong childlevel...we can silently fix this...
1402
-				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
1403
-					$smcFunc['db_query']('', '
1470
+				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) {
1471
+									$smcFunc['db_query']('', '
1404 1472
 						UPDATE {db_prefix}boards
1405 1473
 						SET child_level = {int:new_child_level}
1406 1474
 						WHERE id_board = {int:selected_board}',
@@ -1409,6 +1477,7 @@  discard block
 block discarded – undo
1409 1477
 							'selected_board' => $row['id_board'],
1410 1478
 						)
1411 1479
 					);
1480
+				}
1412 1481
 
1413 1482
 				$boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
1414 1483
 					'node' => &$boards[$row['id_board']],
@@ -1442,8 +1511,9 @@  discard block
 block discarded – undo
1442 1511
  */
1443 1512
 function recursiveBoards(&$_boardList, &$_tree)
1444 1513
 {
1445
-	if (empty($_tree['children']))
1446
-		return;
1514
+	if (empty($_tree['children'])) {
1515
+			return;
1516
+	}
1447 1517
 
1448 1518
 	foreach ($_tree['children'] as $id => $node)
1449 1519
 	{
@@ -1462,11 +1532,13 @@  discard block
 block discarded – undo
1462 1532
 {
1463 1533
 	global $boards;
1464 1534
 
1465
-	if (empty($boards[$child]['parent']))
1466
-		return false;
1535
+	if (empty($boards[$child]['parent'])) {
1536
+			return false;
1537
+	}
1467 1538
 
1468
-	if ($boards[$child]['parent'] == $parent)
1469
-		return true;
1539
+	if ($boards[$child]['parent'] == $parent) {
1540
+			return true;
1541
+	}
1470 1542
 
1471 1543
 	return isChildOf($boards[$child]['parent'], $parent);
1472 1544
 }
Please login to merge, or discard this patch.
Sources/Subs-Compat.php 1 patch
Braces   +27 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 4
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 
23 24
 /**
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 function sha1_smf($str)
29 30
 {
30 31
 	// If we have mhash loaded in, use it instead!
31
-	if (function_exists('mhash') && defined('MHASH_SHA1'))
32
-		return bin2hex(mhash(MHASH_SHA1, $str));
32
+	if (function_exists('mhash') && defined('MHASH_SHA1')) {
33
+			return bin2hex(mhash(MHASH_SHA1, $str));
34
+	}
33 35
 
34 36
 	$nblk = (strlen($str) + 8 >> 6) + 1;
35 37
 	$blks = array_pad(array(), $nblk * 16, 0);
36 38
 
37
-	for ($i = 0; $i < strlen($str); $i++)
38
-		$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
39
+	for ($i = 0; $i < strlen($str); $i++) {
40
+			$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
41
+	}
39 42
 
40 43
 	$blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
41 44
 
@@ -70,10 +73,11 @@  discard block
 block discarded – undo
70 73
 
71 74
 		for ($j = 0; $j < 80; $j++)
72 75
 		{
73
-			if ($j < 16)
74
-				$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
75
-			else
76
-				$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
76
+			if ($j < 16) {
77
+							$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
78
+			} else {
79
+							$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
80
+			}
77 81
 
78 82
 			$t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j);
79 83
 			$e = $d;
@@ -103,12 +107,15 @@  discard block
 block discarded – undo
103 107
  */
104 108
 function sha1_ft($t, $b, $c, $d)
105 109
 {
106
-	if ($t < 20)
107
-		return ($b & $c) | ((~$b) & $d);
108
-	if ($t < 40)
109
-		return $b ^ $c ^ $d;
110
-	if ($t < 60)
111
-		return ($b & $c) | ($b & $d) | ($c & $d);
110
+	if ($t < 20) {
111
+			return ($b & $c) | ((~$b) & $d);
112
+	}
113
+	if ($t < 40) {
114
+			return $b ^ $c ^ $d;
115
+	}
116
+	if ($t < 60) {
117
+			return ($b & $c) | ($b & $d) | ($c & $d);
118
+	}
112 119
 
113 120
 	return $b ^ $c ^ $d;
114 121
 }
@@ -132,10 +139,11 @@  discard block
 block discarded – undo
132 139
 function sha1_rol($num, $cnt)
133 140
 {
134 141
 	// Unfortunately, PHP uses unsigned 32-bit longs only.  So we have to kludge it a bit.
135
-	if ($num & 0x80000000)
136
-		$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
137
-	else
138
-		$a = $num >> (32 - $cnt);
142
+	if ($num & 0x80000000) {
143
+			$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
144
+	} else {
145
+			$a = $num >> (32 - $cnt);
146
+	}
139 147
 
140 148
 	return ($num << $cnt) | $a;
141 149
 }
Please login to merge, or discard this patch.
Sources/ManageErrors.php 1 patch
Braces   +49 added lines, -38 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
  * View the forum's error log.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 
36 38
 	// Check for the administrative permission to do this.
37 39
 	isAllowedTo('admin_forum');
@@ -85,8 +87,8 @@  discard block
 block discarded – undo
85 87
 	);
86 88
 
87 89
 	// Set up the filtering...
88
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
89
-		$filter = array(
90
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
91
+			$filter = array(
90 92
 			'variable' => $_GET['filter'],
91 93
 			'value' => array(
92 94
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -94,10 +96,12 @@  discard block
 block discarded – undo
94 96
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
95 97
 			'entity' => $filters[$_GET['filter']]['txt']
96 98
 		);
99
+	}
97 100
 
98 101
 	// Deleting, are we?
99
-	if (isset($_POST['delall']) || isset($_POST['delete']))
100
-		deleteErrors();
102
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
103
+			deleteErrors();
104
+	}
101 105
 
102 106
 	// Just how many errors are there?
103 107
 	$result = $smcFunc['db_query']('', '
@@ -112,12 +116,14 @@  discard block
 block discarded – undo
112 116
 	$smcFunc['db_free_result']($result);
113 117
 
114 118
 	// If this filter is empty...
115
-	if ($num_errors == 0 && isset($filter))
116
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
119
+	if ($num_errors == 0 && isset($filter)) {
120
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
121
+	}
117 122
 
118 123
 	// Clean up start.
119
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
120
-		$_GET['start'] = 0;
124
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
125
+			$_GET['start'] = 0;
126
+	}
121 127
 
122 128
 	// Do we want to reverse error listing?
123 129
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -127,9 +133,9 @@  discard block
 block discarded – undo
127 133
 	$context['start'] = $_GET['start'];
128 134
 
129 135
 	// Update the error count
130
-	if (!isset($filter))
131
-		$context['num_errors'] = $num_errors;
132
-	else
136
+	if (!isset($filter)) {
137
+			$context['num_errors'] = $num_errors;
138
+	} else
133 139
 	{
134 140
 		// We want all errors, not just the number of filtered messages...
135 141
 		$query = $smcFunc['db_query']('', '
@@ -161,8 +167,9 @@  discard block
 block discarded – undo
161 167
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
162 168
 	{
163 169
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
164
-		if ($search_message == $filter['value']['sql'])
165
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
170
+		if ($search_message == $filter['value']['sql']) {
171
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
172
+		}
166 173
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
167 174
 
168 175
 		$context['errors'][$row['id_error']] = array(
@@ -221,8 +228,9 @@  discard block
 block discarded – undo
221 228
 				'members' => count($members),
222 229
 			)
223 230
 		);
224
-		while ($row = $smcFunc['db_fetch_assoc']($request))
225
-			$members[$row['id_member']] = $row;
231
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
232
+					$members[$row['id_member']] = $row;
233
+		}
226 234
 		$smcFunc['db_free_result']($request);
227 235
 
228 236
 		// This is a guest...
@@ -254,20 +262,18 @@  discard block
 block discarded – undo
254 262
 			$id = $filter['value']['sql'];
255 263
 			loadMemberData($id, false, 'minimal');
256 264
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
257
-		}
258
-		elseif ($filter['variable'] == 'url')
259
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
260
-		elseif ($filter['variable'] == 'message')
265
+		} elseif ($filter['variable'] == 'url') {
266
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
267
+		} elseif ($filter['variable'] == 'message')
261 268
 		{
262 269
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
263 270
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
264
-		}
265
-		elseif ($filter['variable'] == 'error_type')
271
+		} elseif ($filter['variable'] == 'error_type')
266 272
 		{
267 273
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
274
+		} else {
275
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
268 276
 		}
269
-		else
270
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
271 277
 	}
272 278
 
273 279
 	$context['error_types'] = array();
@@ -308,10 +314,11 @@  discard block
 block discarded – undo
308 314
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
309 315
 
310 316
 	// Finally, work out what is the last tab!
311
-	if (isset($context['error_types'][$sum]))
312
-		$context['error_types'][$sum]['is_last'] = true;
313
-	else
314
-		$context['error_types']['all']['is_last'] = true;
317
+	if (isset($context['error_types'][$sum])) {
318
+			$context['error_types'][$sum]['is_last'] = true;
319
+	} else {
320
+			$context['error_types']['all']['is_last'] = true;
321
+	}
315 322
 
316 323
 	// And this is pretty basic ;).
317 324
 	$context['page_title'] = $txt['errlog'];
@@ -337,21 +344,23 @@  discard block
 block discarded – undo
337 344
 	validateToken('admin-el');
338 345
 
339 346
 	// Delete all or just some?
340
-	if (isset($_POST['delall']) && !isset($filter))
341
-		$smcFunc['db_query']('truncate_table', '
347
+	if (isset($_POST['delall']) && !isset($filter)) {
348
+			$smcFunc['db_query']('truncate_table', '
342 349
 			TRUNCATE {db_prefix}log_errors',
343 350
 			array(
344 351
 			)
345 352
 		);
353
+	}
346 354
 	// Deleting all with a filter?
347
-	elseif (isset($_POST['delall']) && isset($filter))
348
-		$smcFunc['db_query']('', '
355
+	elseif (isset($_POST['delall']) && isset($filter)) {
356
+			$smcFunc['db_query']('', '
349 357
 			DELETE FROM {db_prefix}log_errors
350 358
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
351 359
 			array(
352 360
 				'filter' => $filter['value']['sql'],
353 361
 			)
354 362
 		);
363
+	}
355 364
 	// Just specific errors?
356 365
 	elseif (!empty($_POST['delete']))
357 366
 	{
@@ -397,15 +406,17 @@  discard block
 block discarded – undo
397 406
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
398 407
 
399 408
 	// Make sure the file we are looking for is one they are allowed to look at
400
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
401
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
409
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
410
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
411
+	}
402 412
 
403 413
 	// get the min and max lines
404 414
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
405 415
 	$max = $line + 21; // One additional line to make everything work out correctly
406 416
 
407
-	if ($max <= 0 || $min >= $max)
408
-		fatal_lang_error('error_bad_line');
417
+	if ($max <= 0 || $min >= $max) {
418
+			fatal_lang_error('error_bad_line');
419
+	}
409 420
 
410 421
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
411 422
 
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +402 added lines, -303 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
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -381,8 +395,7 @@  discard block
 block discarded – undo
381 395
 
382 396
 			// Put the tags back into the body.
383 397
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
384
-		}
385
-		else
398
+		} else
386 399
 		{
387 400
 			// Just get rid of this evil tag.
388 401
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -395,8 +408,9 @@  discard block
 block discarded – undo
395 408
 		// Find the position of this again.
396 409
 		$start_pos = strpos($text, $matches[0]);
397 410
 		$end_pos = false;
398
-		if ($start_pos === false)
399
-			break;
411
+		if ($start_pos === false) {
412
+					break;
413
+		}
400 414
 
401 415
 		// This must have an end tag - and we must find the right one.
402 416
 		$lower_text = strtolower($text);
@@ -429,8 +443,9 @@  discard block
 block discarded – undo
429 443
 				break;
430 444
 			}
431 445
 		}
432
-		if ($end_pos === false)
433
-			break;
446
+		if ($end_pos === false) {
447
+					break;
448
+		}
434 449
 
435 450
 		// Now work out what the attributes are.
436 451
 		$attribs = fetchTagAttributes($matches[1]);
@@ -444,11 +459,11 @@  discard block
 block discarded – undo
444 459
 				$v = (int) trim($v);
445 460
 				$v = empty($v) ? 1 : $v;
446 461
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
462
+			} elseif ($s == 'face') {
463
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
464
+			} elseif ($s == 'color') {
465
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
447 466
 			}
448
-			elseif ($s == 'face')
449
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
450
-			elseif ($s == 'color')
451
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
452 467
 		}
453 468
 
454 469
 		// As before add in our tags.
@@ -456,8 +471,9 @@  discard block
 block discarded – undo
456 471
 		foreach ($tags as $tag)
457 472
 		{
458 473
 			$before .= $tag[0];
459
-			if (isset($tag[1]))
460
-				$after = $tag[1] . $after;
474
+			if (isset($tag[1])) {
475
+							$after = $tag[1] . $after;
476
+			}
461 477
 		}
462 478
 
463 479
 		// Remove the tag so it's never checked again.
@@ -468,8 +484,9 @@  discard block
 block discarded – undo
468 484
 	}
469 485
 
470 486
 	// Almost there, just a little more time.
471
-	if (connection_aborted() && $context['server']['is_apache'])
472
-		@apache_reset_timeout();
487
+	if (connection_aborted() && $context['server']['is_apache']) {
488
+			@apache_reset_timeout();
489
+	}
473 490
 
474 491
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
475 492
 	{
@@ -525,12 +542,13 @@  discard block
 block discarded – undo
525 542
 						{
526 543
 							$inList = true;
527 544
 
528
-							if ($tag === 'ol')
529
-								$listType = 'decimal';
530
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
531
-								$listType = $listTypeMapping[$match[1]];
532
-							else
533
-								$listType = null;
545
+							if ($tag === 'ol') {
546
+															$listType = 'decimal';
547
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
548
+															$listType = $listTypeMapping[$match[1]];
549
+							} else {
550
+															$listType = null;
551
+							}
534 552
 
535 553
 							$listDepth++;
536 554
 
@@ -594,9 +612,7 @@  discard block
 block discarded – undo
594 612
 							$parts[$i + 1] = '';
595 613
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
596 614
 							$parts[$i + 3] = '';
597
-						}
598
-
599
-						else
615
+						} else
600 616
 						{
601 617
 							// We're in a list item.
602 618
 							if ($listDepth > 0)
@@ -633,9 +649,7 @@  discard block
 block discarded – undo
633 649
 							$parts[$i + 1] = '';
634 650
 							$parts[$i + 2] = '';
635 651
 							$parts[$i + 3] = '';
636
-						}
637
-
638
-						else
652
+						} else
639 653
 						{
640 654
 							// Remove the trailing breaks from the list item.
641 655
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -673,8 +687,9 @@  discard block
 block discarded – undo
673 687
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
674 688
 		}
675 689
 
676
-		for ($i = $listDepth; $i > 0; $i--)
677
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
690
+		for ($i = $listDepth; $i > 0; $i--) {
691
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		}
678 693
 
679 694
 	}
680 695
 
@@ -683,8 +698,9 @@  discard block
 block discarded – undo
683 698
 	{
684 699
 		// Find the position of the image.
685 700
 		$start_pos = strpos($text, $matches[0]);
686
-		if ($start_pos === false)
687
-			break;
701
+		if ($start_pos === false) {
702
+					break;
703
+		}
688 704
 		$end_pos = $start_pos + strlen($matches[0]);
689 705
 
690 706
 		$params = '';
@@ -693,12 +709,13 @@  discard block
 block discarded – undo
693 709
 		$attrs = fetchTagAttributes($matches[1]);
694 710
 		foreach ($attrs as $attrib => $value)
695 711
 		{
696
-			if (in_array($attrib, array('width', 'height')))
697
-				$params .= ' ' . $attrib . '=' . (int) $value;
698
-			elseif ($attrib == 'alt' && trim($value) != '')
699
-				$params .= ' alt=' . trim($value);
700
-			elseif ($attrib == 'src')
701
-				$src = trim($value);
712
+			if (in_array($attrib, array('width', 'height'))) {
713
+							$params .= ' ' . $attrib . '=' . (int) $value;
714
+			} elseif ($attrib == 'alt' && trim($value) != '') {
715
+							$params .= ' alt=' . trim($value);
716
+			} elseif ($attrib == 'src') {
717
+							$src = trim($value);
718
+			}
702 719
 		}
703 720
 
704 721
 		$tag = '';
@@ -709,10 +726,11 @@  discard block
 block discarded – undo
709 726
 			{
710 727
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
711 728
 
712
-				if (substr($src, 0, 1) === '/')
713
-					$src = $baseURL . $src;
714
-				else
715
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				if (substr($src, 0, 1) === '/') {
730
+									$src = $baseURL . $src;
731
+				} else {
732
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
733
+				}
716 734
 			}
717 735
 
718 736
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -890,20 +908,23 @@  discard block
 block discarded – undo
890 908
 		},
891 909
 	);
892 910
 
893
-	foreach ($tags as $tag => $replace)
894
-		$text = preg_replace_callback($tag, $replace, $text);
911
+	foreach ($tags as $tag => $replace) {
912
+			$text = preg_replace_callback($tag, $replace, $text);
913
+	}
895 914
 
896 915
 	// Please give us just a little more time.
897
-	if (connection_aborted() && $context['server']['is_apache'])
898
-		@apache_reset_timeout();
916
+	if (connection_aborted() && $context['server']['is_apache']) {
917
+			@apache_reset_timeout();
918
+	}
899 919
 
900 920
 	// What about URL's - the pain in the ass of the tag world.
901 921
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
902 922
 	{
903 923
 		// Find the position of the URL.
904 924
 		$start_pos = strpos($text, $matches[0]);
905
-		if ($start_pos === false)
906
-			break;
925
+		if ($start_pos === false) {
926
+					break;
927
+		}
907 928
 		$end_pos = $start_pos + strlen($matches[0]);
908 929
 
909 930
 		$tag_type = 'url';
@@ -917,8 +938,9 @@  discard block
 block discarded – undo
917 938
 				$href = trim($value);
918 939
 
919 940
 				// Are we dealing with an FTP link?
920
-				if (preg_match('~^ftps?://~', $href) === 1)
921
-					$tag_type = 'ftp';
941
+				if (preg_match('~^ftps?://~', $href) === 1) {
942
+									$tag_type = 'ftp';
943
+				}
922 944
 
923 945
 				// Or is this a link to an email address?
924 946
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -932,28 +954,31 @@  discard block
 block discarded – undo
932 954
 				{
933 955
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
934 956
 
935
-					if (substr($href, 0, 1) === '/')
936
-						$href = $baseURL . $href;
937
-					else
938
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					if (substr($href, 0, 1) === '/') {
958
+											$href = $baseURL . $href;
959
+					} else {
960
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
961
+					}
939 962
 				}
940 963
 			}
941 964
 
942 965
 			// External URL?
943 966
 			if ($attrib == 'target' && $tag_type == 'url')
944 967
 			{
945
-				if (trim($value) == '_blank')
946
-					$tag_type == 'iurl';
968
+				if (trim($value) == '_blank') {
969
+									$tag_type == 'iurl';
970
+				}
947 971
 			}
948 972
 		}
949 973
 
950 974
 		$tag = '';
951 975
 		if ($href != '')
952 976
 		{
953
-			if ($matches[2] == $href)
954
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
955
-			else
956
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			if ($matches[2] == $href) {
978
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
979
+			} else {
980
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
981
+			}
957 982
 		}
958 983
 
959 984
 		// Replace the tag
@@ -992,17 +1017,18 @@  discard block
 block discarded – undo
992 1017
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
993 1018
 		if ($text[$i] == '=')
994 1019
 		{
995
-			if ($tag_state == 0)
996
-				$tag_state = 1;
997
-			elseif ($tag_state == 2)
998
-				$value .= '=';
1020
+			if ($tag_state == 0) {
1021
+							$tag_state = 1;
1022
+			} elseif ($tag_state == 2) {
1023
+							$value .= '=';
1024
+			}
999 1025
 		}
1000 1026
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1001 1027
 		elseif ($text[$i] == ' ')
1002 1028
 		{
1003
-			if ($tag_state == 2)
1004
-				$value .= ' ';
1005
-			elseif ($tag_state == 1)
1029
+			if ($tag_state == 2) {
1030
+							$value .= ' ';
1031
+			} elseif ($tag_state == 1)
1006 1032
 			{
1007 1033
 				$attribs[$key] = $value;
1008 1034
 				$key = $value = '';
@@ -1013,24 +1039,27 @@  discard block
 block discarded – undo
1013 1039
 		elseif ($text[$i] == '"')
1014 1040
 		{
1015 1041
 			// Must be either going into or out of a string.
1016
-			if ($tag_state == 1)
1017
-				$tag_state = 2;
1018
-			else
1019
-				$tag_state = 1;
1042
+			if ($tag_state == 1) {
1043
+							$tag_state = 2;
1044
+			} else {
1045
+							$tag_state = 1;
1046
+			}
1020 1047
 		}
1021 1048
 		// Otherwise it's fine.
1022 1049
 		else
1023 1050
 		{
1024
-			if ($tag_state == 0)
1025
-				$key .= $text[$i];
1026
-			else
1027
-				$value .= $text[$i];
1051
+			if ($tag_state == 0) {
1052
+							$key .= $text[$i];
1053
+			} else {
1054
+							$value .= $text[$i];
1055
+			}
1028 1056
 		}
1029 1057
 	}
1030 1058
 
1031 1059
 	// Anything left?
1032
-	if ($key != '' && $value != '')
1033
-		$attribs[$key] = $value;
1060
+	if ($key != '' && $value != '') {
1061
+			$attribs[$key] = $value;
1062
+	}
1034 1063
 
1035 1064
 	return $attribs;
1036 1065
 }
@@ -1046,15 +1075,17 @@  discard block
 block discarded – undo
1046 1075
 	global $modSettings;
1047 1076
 
1048 1077
 	// Don't care about the texts that are too short.
1049
-	if (strlen($text) < 3)
1050
-		return $text;
1078
+	if (strlen($text) < 3) {
1079
+			return $text;
1080
+	}
1051 1081
 
1052 1082
 	// A list of tags that's disabled by the admin.
1053 1083
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1054 1084
 
1055 1085
 	// Add flash if it's disabled as embedded tag.
1056
-	if (empty($modSettings['enableEmbeddedFlash']))
1057
-		$disabled['flash'] = true;
1086
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1087
+			$disabled['flash'] = true;
1088
+	}
1058 1089
 
1059 1090
 	// Get a list of all the tags that are not disabled.
1060 1091
 	$all_tags = parse_bbc(false);
@@ -1062,10 +1093,12 @@  discard block
 block discarded – undo
1062 1093
 	$self_closing_tags = array();
1063 1094
 	foreach ($all_tags as $tag)
1064 1095
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1096
+		if (!isset($disabled[$tag['tag']])) {
1097
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1098
+		}
1099
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1100
+					$self_closing_tags[] = $tag['tag'];
1101
+		}
1069 1102
 	}
1070 1103
 
1071 1104
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1125,19 @@  discard block
 block discarded – undo
1092 1125
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1126
 
1094 1127
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1128
+				if ($isClosingTag && $insideTag === $tagName) {
1129
+									$insideTag = null;
1130
+				}
1097 1131
 
1098 1132
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1133
+				elseif (!$isClosingTag && $insideTag === null) {
1134
+									$insideTag = $tagName;
1135
+				}
1101 1136
 
1102 1137
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1138
+				else {
1139
+									unset($matches[$i]);
1140
+				}
1105 1141
 			}
1106 1142
 
1107 1143
 			// The next one is gonna be the other one.
@@ -1109,8 +1145,9 @@  discard block
 block discarded – undo
1109 1145
 		}
1110 1146
 
1111 1147
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1148
+		if ($insideTag !== null) {
1149
+					$matches[] = '[/' . $insideTag . ']';
1150
+		}
1114 1151
 
1115 1152
 		// And a complete text string again.
1116 1153
 		$text = implode('', $matches);
@@ -1119,8 +1156,9 @@  discard block
 block discarded – undo
1119 1156
 	// Quickly remove any tags which are back to back.
1120 1157
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1158
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1159
+	while (strlen($text) !== $lastlen) {
1160
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1161
+	}
1124 1162
 
1125 1163
 	// Need to sort the tags my name length.
1126 1164
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1195,9 @@  discard block
 block discarded – undo
1157 1195
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1196
 
1159 1197
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1198
+			if ($tag === '') {
1199
+							continue;
1200
+			}
1162 1201
 
1163 1202
 			// Special case: inside [code] blocks any code is left untouched.
1164 1203
 			elseif ($tag === 'code')
@@ -1169,8 +1208,9 @@  discard block
 block discarded – undo
1169 1208
 					$inCode = false;
1170 1209
 
1171 1210
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1211
+					if (!empty($inlineElements)) {
1212
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1213
+					}
1174 1214
 				}
1175 1215
 
1176 1216
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1239,9 @@  discard block
 block discarded – undo
1199 1239
 					$inNoBbc = false;
1200 1240
 
1201 1241
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1242
+					if (!empty($inlineElements)) {
1243
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1244
+					}
1204 1245
 				}
1205 1246
 
1206 1247
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1261,9 @@  discard block
 block discarded – undo
1220 1261
 			}
1221 1262
 
1222 1263
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1264
+			elseif ($inCode || $inNoBbc) {
1265
+							continue;
1266
+			}
1225 1267
 
1226 1268
 			// We're dealing with an opening tag.
1227 1269
 			if ($isOpeningTag)
@@ -1262,8 +1304,9 @@  discard block
 block discarded – undo
1262 1304
 							if ($parts[$j + 3] === $tag)
1263 1305
 							{
1264 1306
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1307
+								if ($parts[$j + 2] === '') {
1308
+																	$curLevel++;
1309
+								}
1267 1310
 
1268 1311
 								// A closing tag, decrease the level.
1269 1312
 								else
@@ -1286,13 +1329,15 @@  discard block
 block discarded – undo
1286 1329
 					{
1287 1330
 						if ($isCompetingTag)
1288 1331
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1332
+							if (!isset($competingElements[$tag])) {
1333
+															$competingElements[$tag] = array();
1334
+							}
1291 1335
 
1292 1336
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1337
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1338
+							if (count($competingElements[$tag]) > 1) {
1339
+															$parts[$i] .= '[/' . $tag . ']';
1340
+							}
1296 1341
 						}
1297 1342
 
1298 1343
 						$inlineElements[$elementContent] = $tag;
@@ -1313,15 +1358,17 @@  discard block
 block discarded – undo
1313 1358
 						$addClosingTags = array();
1314 1359
 						while ($element = array_pop($blockElements))
1315 1360
 						{
1316
-							if ($element === $tag)
1317
-								break;
1361
+							if ($element === $tag) {
1362
+															break;
1363
+							}
1318 1364
 
1319 1365
 							// Still a block tag was open not equal to this tag.
1320 1366
 							$addClosingTags[] = $element['type'];
1321 1367
 						}
1322 1368
 
1323
-						if (!empty($addClosingTags))
1324
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						if (!empty($addClosingTags)) {
1370
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1371
+						}
1325 1372
 
1326 1373
 						// Apparently the closing tag was not found on the stack.
1327 1374
 						if (!is_string($element) || $element !== $tag)
@@ -1331,8 +1378,7 @@  discard block
 block discarded – undo
1331 1378
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1332 1379
 							continue;
1333 1380
 						}
1334
-					}
1335
-					else
1381
+					} else
1336 1382
 					{
1337 1383
 						// Get rid of this closing tag!
1338 1384
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1361,53 +1407,62 @@  discard block
 block discarded – undo
1361 1407
 							unset($inlineElements[$tagContentToBeClosed]);
1362 1408
 
1363 1409
 							// Was this the tag we were looking for?
1364
-							if ($tagToBeClosed === $tag)
1365
-								break;
1410
+							if ($tagToBeClosed === $tag) {
1411
+															break;
1412
+							}
1366 1413
 
1367 1414
 							// Nope, close it and look further!
1368
-							else
1369
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							else {
1416
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1417
+							}
1370 1418
 						}
1371 1419
 
1372 1420
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1373 1421
 						{
1374 1422
 							array_pop($competingElements[$tag]);
1375 1423
 
1376
-							if (count($competingElements[$tag]) > 0)
1377
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							if (count($competingElements[$tag]) > 0) {
1425
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1426
+							}
1378 1427
 						}
1379 1428
 					}
1380 1429
 
1381 1430
 					// Unexpected closing tag, ex-ter-mi-nate.
1382
-					else
1383
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					else {
1432
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1433
+					}
1384 1434
 				}
1385 1435
 			}
1386 1436
 		}
1387 1437
 
1388 1438
 		// Close the code tags.
1389
-		if ($inCode)
1390
-			$parts[$i] .= '[/code]';
1439
+		if ($inCode) {
1440
+					$parts[$i] .= '[/code]';
1441
+		}
1391 1442
 
1392 1443
 		// The same for nobbc tags.
1393
-		elseif ($inNoBbc)
1394
-			$parts[$i] .= '[/nobbc]';
1444
+		elseif ($inNoBbc) {
1445
+					$parts[$i] .= '[/nobbc]';
1446
+		}
1395 1447
 
1396 1448
 		// Still inline tags left unclosed? Close them now, better late than never.
1397
-		elseif (!empty($inlineElements))
1398
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		elseif (!empty($inlineElements)) {
1450
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1451
+		}
1399 1452
 
1400 1453
 		// Now close the block elements.
1401
-		if (!empty($blockElements))
1402
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		if (!empty($blockElements)) {
1455
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1456
+		}
1403 1457
 
1404 1458
 		$text = implode('', $parts);
1405 1459
 	}
1406 1460
 
1407 1461
 	// Final clean up of back to back tags.
1408 1462
 	$lastlen = 0;
1409
-	while (strlen($text) !== $lastlen)
1410
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	while (strlen($text) !== $lastlen) {
1464
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1465
+	}
1411 1466
 
1412 1467
 	return $text;
1413 1468
 }
@@ -1436,22 +1491,25 @@  discard block
 block discarded – undo
1436 1491
 	$context['template_layers'] = array();
1437 1492
 	// Lets make sure we aren't going to output anything nasty.
1438 1493
 	@ob_end_clean();
1439
-	if (!empty($modSettings['enableCompressedOutput']))
1440
-		@ob_start('ob_gzhandler');
1441
-	else
1442
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1443 1499
 
1444 1500
 	// If we don't have any locale better avoid broken js
1445
-	if (empty($txt['lang_locale']))
1446
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1447 1504
 
1448 1505
 	$file_data = '(function ($) {
1449 1506
 	\'use strict\';
1450 1507
 
1451 1508
 	$.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {';
1452
-	foreach ($editortxt as $key => $val)
1453
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1454 1511
 		' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ',';
1512
+	}
1455 1513
 
1456 1514
 	$file_data .= '
1457 1515
 		dateFormat: "day.month.year"
@@ -1519,8 +1577,9 @@  discard block
 block discarded – undo
1519 1577
 				)
1520 1578
 			);
1521 1579
 			$icon_data = array();
1522
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1523
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1524 1583
 			$smcFunc['db_free_result']($request);
1525 1584
 
1526 1585
 			$icons = array();
@@ -1535,9 +1594,9 @@  discard block
 block discarded – undo
1535 1594
 			}
1536 1595
 
1537 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1538 1599
 		}
1539
-		else
1540
-			$icons = $temp;
1541 1600
 	}
1542 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1543 1602
 
@@ -1578,8 +1637,9 @@  discard block
 block discarded – undo
1578 1637
 	{
1579 1638
 		// Some general stuff.
1580 1639
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1581
-		if (!empty($context['drafts_autosave']))
1582
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1640
+		if (!empty($context['drafts_autosave'])) {
1641
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1642
+		}
1583 1643
 
1584 1644
 		// This really has some WYSIWYG stuff.
1585 1645
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1595,8 +1655,9 @@  discard block
 block discarded – undo
1595 1655
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1596 1656
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1597 1657
 		// editor language file
1598
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1599
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1658
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1659
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1660
+		}
1600 1661
 
1601 1662
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1602 1663
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1605,11 +1666,12 @@  discard block
 block discarded – undo
1605 1666
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1606 1667
 
1607 1668
 			// Some hidden information is needed in order to make the spell checking work.
1608
-			if (!isset($_REQUEST['xml']))
1609
-				$context['insert_after_template'] .= '
1669
+			if (!isset($_REQUEST['xml'])) {
1670
+							$context['insert_after_template'] .= '
1610 1671
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1611 1672
 			<input type="hidden" name="spellstring" value="">
1612 1673
 		</form>';
1674
+			}
1613 1675
 		}
1614 1676
 	}
1615 1677
 
@@ -1775,10 +1837,12 @@  discard block
 block discarded – undo
1775 1837
 
1776 1838
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1777 1839
 		$disabled_tags = array();
1778
-		if (!empty($modSettings['disabledBBC']))
1779
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1780
-		if (empty($modSettings['enableEmbeddedFlash']))
1781
-			$disabled_tags[] = 'flash';
1840
+		if (!empty($modSettings['disabledBBC'])) {
1841
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1842
+		}
1843
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1844
+					$disabled_tags[] = 'flash';
1845
+		}
1782 1846
 
1783 1847
 		foreach ($disabled_tags as $tag)
1784 1848
 		{
@@ -1788,9 +1852,10 @@  discard block
 block discarded – undo
1788 1852
 				$context['disabled_tags']['orderedlist'] = true;
1789 1853
 			}
1790 1854
 
1791
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1792
-				if ($tag === $thisTag)
1855
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1856
+							if ($tag === $thisTag)
1793 1857
 					$context['disabled_tags'][$tagNameBBC] = true;
1858
+			}
1794 1859
 
1795 1860
 			$context['disabled_tags'][trim($tag)] = true;
1796 1861
 		}
@@ -1800,19 +1865,21 @@  discard block
 block discarded – undo
1800 1865
 		$context['bbc_toolbar'] = array();
1801 1866
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1802 1867
 		{
1803
-			if (!isset($context['bbc_toolbar'][$row]))
1804
-				$context['bbc_toolbar'][$row] = array();
1868
+			if (!isset($context['bbc_toolbar'][$row])) {
1869
+							$context['bbc_toolbar'][$row] = array();
1870
+			}
1805 1871
 			$tagsRow = array();
1806 1872
 			foreach ($tagRow as $tag)
1807 1873
 			{
1808 1874
 				if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']]))
1809 1875
 				{
1810 1876
 					$tagsRow[] = $tag['code'];
1811
-					if (isset($tag['image']))
1812
-						$bbcodes_styles .= '
1877
+					if (isset($tag['image'])) {
1878
+											$bbcodes_styles .= '
1813 1879
 			.sceditor-button-' . $tag['code'] . ' div {
1814 1880
 				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
1815 1881
 			}';
1882
+					}
1816 1883
 					if (isset($tag['before']))
1817 1884
 					{
1818 1885
 						$context['bbcodes_handlers'] .= '
@@ -1826,8 +1893,7 @@  discard block
 block discarded – undo
1826 1893
 				});';
1827 1894
 					}
1828 1895
 
1829
-				}
1830
-				else
1896
+				} else
1831 1897
 				{
1832 1898
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1833 1899
 					$tagsRow = array();
@@ -1838,14 +1904,16 @@  discard block
 block discarded – undo
1838 1904
 			{
1839 1905
 				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1840 1906
 				$tagsRow = array();
1841
-				if (!isset($context['disabled_tags']['font']))
1842
-					$tagsRow[] = 'font';
1843
-				if (!isset($context['disabled_tags']['size']))
1844
-					$tagsRow[] = 'size';
1845
-				if (!isset($context['disabled_tags']['color']))
1846
-					$tagsRow[] = 'color';
1847
-			}
1848
-			elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1907
+				if (!isset($context['disabled_tags']['font'])) {
1908
+									$tagsRow[] = 'font';
1909
+				}
1910
+				if (!isset($context['disabled_tags']['size'])) {
1911
+									$tagsRow[] = 'size';
1912
+				}
1913
+				if (!isset($context['disabled_tags']['color'])) {
1914
+									$tagsRow[] = 'color';
1915
+				}
1916
+			} elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1849 1917
 			{
1850 1918
 				$tmp = array();
1851 1919
 				$tagsRow[] = 'removeformat';
@@ -1856,13 +1924,15 @@  discard block
 block discarded – undo
1856 1924
 				}
1857 1925
 			}
1858 1926
 
1859
-			if (!empty($tagsRow))
1860
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1927
+			if (!empty($tagsRow)) {
1928
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1929
+			}
1861 1930
 		}
1862
-		if (!empty($bbcodes_styles))
1863
-			$context['html_headers'] .= '
1931
+		if (!empty($bbcodes_styles)) {
1932
+					$context['html_headers'] .= '
1864 1933
 		<style>' . $bbcodes_styles . '
1865 1934
 		</style>';
1935
+		}
1866 1936
 	}
1867 1937
 
1868 1938
 	// Initialize smiley array... if not loaded before.
@@ -1874,8 +1944,8 @@  discard block
 block discarded – undo
1874 1944
 		);
1875 1945
 
1876 1946
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1877
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1878
-			$context['smileys']['postform'][] = array(
1947
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1948
+					$context['smileys']['postform'][] = array(
1879 1949
 				'smileys' => array(
1880 1950
 					array(
1881 1951
 						'code' => ':)',
@@ -1961,7 +2031,7 @@  discard block
 block discarded – undo
1961 2031
 				),
1962 2032
 				'isLast' => true,
1963 2033
 			);
1964
-		elseif ($user_info['smiley_set'] != 'none')
2034
+		} elseif ($user_info['smiley_set'] != 'none')
1965 2035
 		{
1966 2036
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1967 2037
 			{
@@ -1984,17 +2054,19 @@  discard block
 block discarded – undo
1984 2054
 
1985 2055
 				foreach ($context['smileys'] as $section => $smileyRows)
1986 2056
 				{
1987
-					foreach ($smileyRows as $rowIndex => $smileys)
1988
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2057
+					foreach ($smileyRows as $rowIndex => $smileys) {
2058
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2059
+					}
1989 2060
 
1990
-					if (!empty($smileyRows))
1991
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2061
+					if (!empty($smileyRows)) {
2062
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2063
+					}
1992 2064
 				}
1993 2065
 
1994 2066
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2067
+			} else {
2068
+							$context['smileys'] = $temp;
1995 2069
 			}
1996
-			else
1997
-				$context['smileys'] = $temp;
1998 2070
 		}
1999 2071
 	}
2000 2072
 
@@ -2020,8 +2092,9 @@  discard block
 block discarded – undo
2020 2092
 		loadTemplate('GenericControls');
2021 2093
 
2022 2094
 		// Some javascript ma'am?
2023
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2024
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2095
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2096
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2097
+		}
2025 2098
 
2026 2099
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2027 2100
 
@@ -2034,8 +2107,8 @@  discard block
 block discarded – undo
2034 2107
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2035 2108
 
2036 2109
 	// Log this into our collection.
2037
-	if ($isNew)
2038
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2110
+	if ($isNew) {
2111
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2039 2112
 			'id' => $verificationOptions['id'],
2040 2113
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2041 2114
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2046,13 +2119,15 @@  discard block
 block discarded – undo
2046 2119
 			'questions' => array(),
2047 2120
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2048 2121
 		);
2122
+	}
2049 2123
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2050 2124
 
2051 2125
 	// Is there actually going to be anything?
2052
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2053
-		return false;
2054
-	elseif (!$isNew && !$do_test)
2055
-		return true;
2126
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2127
+			return false;
2128
+	} elseif (!$isNew && !$do_test) {
2129
+			return true;
2130
+	}
2056 2131
 
2057 2132
 	// Sanitize reCAPTCHA fields?
2058 2133
 	if ($thisVerification['can_recaptcha'])
@@ -2065,11 +2140,12 @@  discard block
 block discarded – undo
2065 2140
 	}
2066 2141
 
2067 2142
 	// Add javascript for the object.
2068
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2069
-		$context['insert_after_template'] .= '
2143
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2144
+			$context['insert_after_template'] .= '
2070 2145
 			<script>
2071 2146
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2072 2147
 			</script>';
2148
+	}
2073 2149
 
2074 2150
 	// If we want questions do we have a cache of all the IDs?
2075 2151
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2092,8 +2168,9 @@  discard block
 block discarded – undo
2092 2168
 				unset ($row['id_question']);
2093 2169
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2094 2170
 				$row['answers'] = smf_json_decode($row['answers'], true);
2095
-				foreach ($row['answers'] as $k => $v)
2096
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2171
+				foreach ($row['answers'] as $k => $v) {
2172
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2173
+				}
2097 2174
 
2098 2175
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2099 2176
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2104,35 +2181,42 @@  discard block
 block discarded – undo
2104 2181
 		}
2105 2182
 	}
2106 2183
 
2107
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2108
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2184
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2185
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2186
+	}
2109 2187
 
2110 2188
 	// Do we need to refresh the verification?
2111
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2112
-		$force_refresh = true;
2113
-	else
2114
-		$force_refresh = false;
2189
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2190
+			$force_refresh = true;
2191
+	} else {
2192
+			$force_refresh = false;
2193
+	}
2115 2194
 
2116 2195
 	// This can also force a fresh, although unlikely.
2117
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2118
-		$force_refresh = true;
2196
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2197
+			$force_refresh = true;
2198
+	}
2119 2199
 
2120 2200
 	$verification_errors = array();
2121 2201
 	// Start with any testing.
2122 2202
 	if ($do_test)
2123 2203
 	{
2124 2204
 		// This cannot happen!
2125
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2126
-			fatal_lang_error('no_access', false);
2205
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2206
+					fatal_lang_error('no_access', false);
2207
+		}
2127 2208
 		// ... nor this!
2128
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2129
-			fatal_lang_error('no_access', false);
2209
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2210
+					fatal_lang_error('no_access', false);
2211
+		}
2130 2212
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2131
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2132
-			fatal_lang_error('no_access', false);
2213
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2214
+					fatal_lang_error('no_access', false);
2215
+		}
2133 2216
 		// While we're here, did the user do something bad?
2134
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2135
-			$verification_errors[] = 'wrong_verification_answer';
2217
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2218
+					$verification_errors[] = 'wrong_verification_answer';
2219
+		}
2136 2220
 
2137 2221
 		if ($thisVerification['can_recaptcha'])
2138 2222
 		{
@@ -2143,22 +2227,25 @@  discard block
 block discarded – undo
2143 2227
 			{
2144 2228
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2145 2229
 
2146
-				if (!$resp->isSuccess())
2147
-					$verification_errors[] = 'wrong_verification_code';
2230
+				if (!$resp->isSuccess()) {
2231
+									$verification_errors[] = 'wrong_verification_code';
2232
+				}
2233
+			} else {
2234
+							$verification_errors[] = 'wrong_verification_code';
2148 2235
 			}
2149
-			else
2150
-				$verification_errors[] = 'wrong_verification_code';
2151 2236
 		}
2152
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2153
-			$verification_errors[] = 'wrong_verification_code';
2237
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2238
+					$verification_errors[] = 'wrong_verification_code';
2239
+		}
2154 2240
 		if ($thisVerification['number_questions'])
2155 2241
 		{
2156 2242
 			$incorrectQuestions = array();
2157 2243
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2158 2244
 			{
2159 2245
 				// We don't have this question any more, thus no answers.
2160
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2161
-					continue;
2246
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2247
+									continue;
2248
+				}
2162 2249
 				// This is quite complex. We have our question but it might have multiple answers.
2163 2250
 				// First, did they actually answer this question?
2164 2251
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2170,24 +2257,28 @@  discard block
 block discarded – undo
2170 2257
 				else
2171 2258
 				{
2172 2259
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2173
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2174
-						$incorrectQuestions[] = $q;
2260
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2261
+											$incorrectQuestions[] = $q;
2262
+					}
2175 2263
 				}
2176 2264
 			}
2177 2265
 
2178
-			if (!empty($incorrectQuestions))
2179
-				$verification_errors[] = 'wrong_verification_answer';
2266
+			if (!empty($incorrectQuestions)) {
2267
+							$verification_errors[] = 'wrong_verification_answer';
2268
+			}
2180 2269
 		}
2181 2270
 	}
2182 2271
 
2183 2272
 	// Any errors means we refresh potentially.
2184 2273
 	if (!empty($verification_errors))
2185 2274
 	{
2186
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2187
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2275
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2276
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2277
+		}
2188 2278
 		// Too many errors?
2189
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2190
-			$force_refresh = true;
2279
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2280
+					$force_refresh = true;
2281
+		}
2191 2282
 
2192 2283
 		// Keep a track of these.
2193 2284
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2220,8 +2311,9 @@  discard block
 block discarded – undo
2220 2311
 			// Are we overriding the range?
2221 2312
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2222 2313
 
2223
-			for ($i = 0; $i < 6; $i++)
2224
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2314
+			for ($i = 0; $i < 6; $i++) {
2315
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2316
+			}
2225 2317
 		}
2226 2318
 
2227 2319
 		// Getting some new questions?
@@ -2229,8 +2321,9 @@  discard block
 block discarded – undo
2229 2321
 		{
2230 2322
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2231 2323
 			$possible_langs = array();
2232
-			if (isset($_SESSION['language']))
2233
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2324
+			if (isset($_SESSION['language'])) {
2325
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2326
+			}
2234 2327
 			if (!empty($user_info['language']));
2235 2328
 			$possible_langs[] = $user_info['language'];
2236 2329
 			$possible_langs[] = $language;
@@ -2249,8 +2342,7 @@  discard block
 block discarded – undo
2249 2342
 				}
2250 2343
 			}
2251 2344
 		}
2252
-	}
2253
-	else
2345
+	} else
2254 2346
 	{
2255 2347
 		// Same questions as before.
2256 2348
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2260,8 +2352,9 @@  discard block
 block discarded – undo
2260 2352
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2261 2353
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2262 2354
 	{
2263
-		if (!isset($context['html_headers']))
2264
-			$context['html_headers'] = '';
2355
+		if (!isset($context['html_headers'])) {
2356
+					$context['html_headers'] = '';
2357
+		}
2265 2358
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2266 2359
 	}
2267 2360
 
@@ -2287,11 +2380,13 @@  discard block
 block discarded – undo
2287 2380
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2288 2381
 
2289 2382
 	// Return errors if we have them.
2290
-	if (!empty($verification_errors))
2291
-		return $verification_errors;
2383
+	if (!empty($verification_errors)) {
2384
+			return $verification_errors;
2385
+	}
2292 2386
 	// If we had a test that one, make a note.
2293
-	elseif ($do_test)
2294
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2387
+	elseif ($do_test) {
2388
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2389
+	}
2295 2390
 
2296 2391
 	// Say that everything went well chaps.
2297 2392
 	return true;
@@ -2316,8 +2411,9 @@  discard block
 block discarded – undo
2316 2411
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2317 2412
 
2318 2413
 	// If we're just checking the callback function is registered return true or false.
2319
-	if ($checkRegistered != null)
2320
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2414
+	if ($checkRegistered != null) {
2415
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2416
+	}
2321 2417
 
2322 2418
 	checkSession('get');
2323 2419
 	loadTemplate('Xml');
@@ -2468,24 +2564,27 @@  discard block
 block discarded – undo
2468 2564
 		foreach ($possible_versions as $ver)
2469 2565
 		{
2470 2566
 			$ver = trim($ver);
2471
-			if (strpos($ver, 'SMF') === 0)
2472
-				$versions[] = $ver;
2567
+			if (strpos($ver, 'SMF') === 0) {
2568
+							$versions[] = $ver;
2569
+			}
2473 2570
 		}
2474 2571
 	}
2475 2572
 	$smcFunc['db_free_result']($request);
2476 2573
 
2477 2574
 	// Just in case we don't have ANYthing.
2478
-	if (empty($versions))
2479
-		$versions = array('SMF 2.0');
2575
+	if (empty($versions)) {
2576
+			$versions = array('SMF 2.0');
2577
+	}
2480 2578
 
2481
-	foreach ($versions as $id => $version)
2482
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2579
+	foreach ($versions as $id => $version) {
2580
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2483 2581
 			$xml_data['items']['children'][] = array(
2484 2582
 				'attributes' => array(
2485 2583
 					'id' => $id,
2486 2584
 				),
2487 2585
 				'value' => $version,
2488 2586
 			);
2587
+	}
2489 2588
 
2490 2589
 	return $xml_data;
2491 2590
 }
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +164 added lines, -128 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
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = smf_json_decode($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -125,16 +130,18 @@  discard block
 block discarded – undo
125 130
 			$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
126 131
 
127 132
 			// If that didn't work, try unserialize instead...
128
-			if (is_null($tfadata))
129
-				$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
133
+			if (is_null($tfadata)) {
134
+							$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
135
+			}
130 136
 
131 137
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
132 138
 
133 139
 			// If we're preserving the cookie, reset it with updated salt
134
-			if ($preserve && time() < $exp)
135
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
136
-			else
137
-				setTFACookie(-3600, 0, '');
140
+			if ($preserve && time() < $exp) {
141
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
142
+			} else {
143
+							setTFACookie(-3600, 0, '');
144
+			}
138 145
 		}
139 146
 
140 147
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -145,20 +152,20 @@  discard block
 block discarded – undo
145 152
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
146 153
 	{
147 154
 		// Strike!  You're outta there!
148
-		if ($_GET['member'] != $user_info['id'])
149
-			fatal_lang_error('login_cookie_error', false);
155
+		if ($_GET['member'] != $user_info['id']) {
156
+					fatal_lang_error('login_cookie_error', false);
157
+		}
150 158
 
151 159
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
152 160
 
153 161
 		// Some whitelisting for login_url...
154
-		if (empty($_SESSION['login_url']))
155
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
162
+		if (empty($_SESSION['login_url'])) {
163
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
164
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157 165
 		{
158 166
 			unset ($_SESSION['login_url']);
159 167
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
160
-		}
161
-		else
168
+		} else
162 169
 		{
163 170
 			// Best not to clutter the session data too much...
164 171
 			$temp = $_SESSION['login_url'];
@@ -169,8 +176,9 @@  discard block
 block discarded – undo
169 176
 	}
170 177
 
171 178
 	// Beyond this point you are assumed to be a guest trying to login.
172
-	if (!$user_info['is_guest'])
173
-		redirectexit();
179
+	if (!$user_info['is_guest']) {
180
+			redirectexit();
181
+	}
174 182
 
175 183
 	// Are you guessing with a script?
176 184
 	checkSession();
@@ -178,18 +186,21 @@  discard block
 block discarded – undo
178 186
 	spamProtection('login');
179 187
 
180 188
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
181
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
182
-		$_SESSION['login_url'] = $_SESSION['old_url'];
189
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
190
+			$_SESSION['login_url'] = $_SESSION['old_url'];
191
+	}
183 192
 
184 193
 	// Been guessing a lot, haven't we?
185
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
186
-		fatal_lang_error('login_threshold_fail', 'critical');
194
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
195
+			fatal_lang_error('login_threshold_fail', 'critical');
196
+	}
187 197
 
188 198
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
189
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
190
-		$modSettings['cookieTime'] = 3153600;
191
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
192
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
199
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
200
+			$modSettings['cookieTime'] = 3153600;
201
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
202
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
203
+	}
193 204
 
194 205
 	loadLanguage('Login');
195 206
 	// Load the template stuff.
@@ -309,8 +320,9 @@  discard block
 block discarded – undo
309 320
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
310 321
 
311 322
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
312
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
313
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
323
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
324
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
325
+			}
314 326
 
315 327
 			// phpBB3 users new hashing.  We now support it as well ;).
316 328
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -330,27 +342,29 @@  discard block
 block discarded – undo
330 342
 			// Some common md5 ones.
331 343
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
332 344
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
333
-		}
334
-		elseif (strlen($user_settings['passwd']) == 40)
345
+		} elseif (strlen($user_settings['passwd']) == 40)
335 346
 		{
336 347
 			// Maybe they are using a hash from before the password fix.
337 348
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
338 349
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
339 350
 
340 351
 			// BurningBoard3 style of hashing.
341
-			if (!empty($modSettings['enable_password_conversion']))
342
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
352
+			if (!empty($modSettings['enable_password_conversion'])) {
353
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
354
+			}
343 355
 
344 356
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
345 357
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
346 358
 			{
347 359
 				// Try iconv first, for no particular reason.
348
-				if (function_exists('iconv'))
349
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
360
+				if (function_exists('iconv')) {
361
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
362
+				}
350 363
 
351 364
 				// Say it aint so, iconv failed!
352
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
353
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
365
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
366
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
367
+				}
354 368
 			}
355 369
 		}
356 370
 
@@ -380,8 +394,9 @@  discard block
 block discarded – undo
380 394
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
381 395
 
382 396
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
383
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
384
-				redirectexit('action=reminder');
397
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
398
+							redirectexit('action=reminder');
399
+			}
385 400
 			// We'll give you another chance...
386 401
 			else
387 402
 			{
@@ -392,8 +407,7 @@  discard block
 block discarded – undo
392 407
 				return;
393 408
 			}
394 409
 		}
395
-	}
396
-	elseif (!empty($user_settings['passwd_flood']))
410
+	} elseif (!empty($user_settings['passwd_flood']))
397 411
 	{
398 412
 		// Let's be sure they weren't a little hacker.
399 413
 		validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true);
@@ -410,8 +424,9 @@  discard block
 block discarded – undo
410 424
 	}
411 425
 
412 426
 	// Check their activation status.
413
-	if (!checkActivation())
414
-		return;
427
+	if (!checkActivation()) {
428
+			return;
429
+	}
415 430
 
416 431
 	DoLogin();
417 432
 }
@@ -423,8 +438,9 @@  discard block
 block discarded – undo
423 438
 {
424 439
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
425 440
 
426
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
427
-		fatal_lang_error('no_access', false);
441
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
442
+			fatal_lang_error('no_access', false);
443
+	}
428 444
 
429 445
 	loadLanguage('Profile');
430 446
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -432,8 +448,9 @@  discard block
 block discarded – undo
432 448
 	$member = $context['tfa_member'];
433 449
 
434 450
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
435
-	if (time() - $member['last_login'] < 120)
436
-		fatal_lang_error('tfa_wait', false);
451
+	if (time() - $member['last_login'] < 120) {
452
+			fatal_lang_error('tfa_wait', false);
453
+	}
437 454
 
438 455
 	$totp = new \TOTP\Auth($member['tfa_secret']);
439 456
 	$totp->setRange(1);
@@ -447,8 +464,9 @@  discard block
 block discarded – undo
447 464
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
448 465
 	{
449 466
 		// Check to ensure we're forcing SSL for authentication
450
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
451
-			fatal_lang_error('login_ssl_required');
467
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
468
+					fatal_lang_error('login_ssl_required');
469
+		}
452 470
 
453 471
 		$code = $_POST['tfa_code'];
454 472
 
@@ -458,20 +476,19 @@  discard block
 block discarded – undo
458 476
 
459 477
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
460 478
 			redirectexit();
461
-		}
462
-		else
479
+		} else
463 480
 		{
464 481
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
465 482
 
466 483
 			$context['tfa_error'] = true;
467 484
 			$context['tfa_value'] = $_POST['tfa_code'];
468 485
 		}
469
-	}
470
-	elseif (!empty($_POST['tfa_backup']))
486
+	} elseif (!empty($_POST['tfa_backup']))
471 487
 	{
472 488
 		// Check to ensure we're forcing SSL for authentication
473
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
474
-			fatal_lang_error('login_ssl_required');
489
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
490
+					fatal_lang_error('login_ssl_required');
491
+		}
475 492
 
476 493
 		$backup = $_POST['tfa_backup'];
477 494
 
@@ -485,8 +502,7 @@  discard block
 block discarded – undo
485 502
 			));
486 503
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
487 504
 			redirectexit('action=profile;area=tfasetup;backup');
488
-		}
489
-		else
505
+		} else
490 506
 		{
491 507
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
492 508
 
@@ -509,8 +525,9 @@  discard block
 block discarded – undo
509 525
 {
510 526
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
511 527
 
512
-	if (!isset($context['login_errors']))
513
-		$context['login_errors'] = array();
528
+	if (!isset($context['login_errors'])) {
529
+			$context['login_errors'] = array();
530
+	}
514 531
 
515 532
 	// What is the true activation status of this account?
516 533
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -522,8 +539,9 @@  discard block
 block discarded – undo
522 539
 		return false;
523 540
 	}
524 541
 	// Awaiting approval still?
525
-	elseif ($activation_status == 3)
526
-		fatal_lang_error('still_awaiting_approval', 'user');
542
+	elseif ($activation_status == 3) {
543
+			fatal_lang_error('still_awaiting_approval', 'user');
544
+	}
527 545
 	// Awaiting deletion, changed their mind?
528 546
 	elseif ($activation_status == 4)
529 547
 	{
@@ -531,8 +549,7 @@  discard block
 block discarded – undo
531 549
 		{
532 550
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
533 551
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
534
-		}
535
-		else
552
+		} else
536 553
 		{
537 554
 			$context['disable_login_hashing'] = true;
538 555
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -572,8 +589,9 @@  discard block
 block discarded – undo
572 589
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
573 590
 
574 591
 	// Reset the login threshold.
575
-	if (isset($_SESSION['failed_login']))
576
-		unset($_SESSION['failed_login']);
592
+	if (isset($_SESSION['failed_login'])) {
593
+			unset($_SESSION['failed_login']);
594
+	}
577 595
 
578 596
 	$user_info['is_guest'] = false;
579 597
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -595,16 +613,18 @@  discard block
 block discarded – undo
595 613
 			'id_member' => $user_info['id'],
596 614
 		)
597 615
 	);
598
-	if ($smcFunc['db_num_rows']($request) == 1)
599
-		$_SESSION['first_login'] = true;
600
-	else
601
-		unset($_SESSION['first_login']);
616
+	if ($smcFunc['db_num_rows']($request) == 1) {
617
+			$_SESSION['first_login'] = true;
618
+	} else {
619
+			unset($_SESSION['first_login']);
620
+	}
602 621
 	$smcFunc['db_free_result']($request);
603 622
 
604 623
 	// You've logged in, haven't you?
605 624
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
606
-	if (empty($user_settings['tfa_secret']))
607
-		$update['last_login'] = time();
625
+	if (empty($user_settings['tfa_secret'])) {
626
+			$update['last_login'] = time();
627
+	}
608 628
 	updateMemberData($user_info['id'], $update);
609 629
 
610 630
 	// Get rid of the online entry for that old guest....
@@ -618,8 +638,8 @@  discard block
 block discarded – undo
618 638
 	$_SESSION['log_time'] = 0;
619 639
 
620 640
 	// Log this entry, only if we have it enabled.
621
-	if (!empty($modSettings['loginHistoryDays']))
622
-		$smcFunc['db_insert']('insert',
641
+	if (!empty($modSettings['loginHistoryDays'])) {
642
+			$smcFunc['db_insert']('insert',
623 643
 			'{db_prefix}member_logins',
624 644
 			array(
625 645
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -631,13 +651,15 @@  discard block
 block discarded – undo
631 651
 				'id_member', 'time'
632 652
 			)
633 653
 		);
654
+	}
634 655
 
635 656
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
636
-	if (empty($maintenance) || allowedTo('admin_forum'))
637
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
638
-	else
639
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
640
-}
657
+	if (empty($maintenance) || allowedTo('admin_forum')) {
658
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
659
+	} else {
660
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
661
+	}
662
+	}
641 663
 
642 664
 /**
643 665
  * Logs the current user out of their account.
@@ -653,13 +675,15 @@  discard block
 block discarded – undo
653 675
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
654 676
 
655 677
 	// Make sure they aren't being auto-logged out.
656
-	if (!$internal)
657
-		checkSession('get');
678
+	if (!$internal) {
679
+			checkSession('get');
680
+	}
658 681
 
659 682
 	require_once($sourcedir . '/Subs-Auth.php');
660 683
 
661
-	if (isset($_SESSION['pack_ftp']))
662
-		$_SESSION['pack_ftp'] = null;
684
+	if (isset($_SESSION['pack_ftp'])) {
685
+			$_SESSION['pack_ftp'] = null;
686
+	}
663 687
 
664 688
 	// It won't be first login anymore.
665 689
 	unset($_SESSION['first_login']);
@@ -687,24 +711,27 @@  discard block
 block discarded – undo
687 711
 
688 712
 	// And some other housekeeping while we're at it.
689 713
 	$salt = substr(md5(mt_rand()), 0, 4);
690
-	if (!empty($user_info['id']))
691
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
714
+	if (!empty($user_info['id'])) {
715
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
716
+	}
692 717
 
693 718
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
694 719
 	{
695 720
 		$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
696 721
 
697 722
 		// If that failed, try the old method
698
-		if (is_null($tfadata))
699
-			$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
723
+		if (is_null($tfadata)) {
724
+					$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
725
+		}
700 726
 
701 727
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
702 728
 
703 729
 		// If we're preserving the cookie, reset it with updated salt
704
-		if ($preserve && time() < $exp)
705
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
706
-		else
707
-			setTFACookie(-3600, 0, '');
730
+		if ($preserve && time() < $exp) {
731
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
732
+		} else {
733
+					setTFACookie(-3600, 0, '');
734
+		}
708 735
 	}
709 736
 
710 737
 	session_destroy();
@@ -712,14 +739,13 @@  discard block
 block discarded – undo
712 739
 	// Off to the merry board index we go!
713 740
 	if ($redirect)
714 741
 	{
715
-		if (empty($_SESSION['logout_url']))
716
-			redirectexit('', $context['server']['needs_login_fix']);
717
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
742
+		if (empty($_SESSION['logout_url'])) {
743
+					redirectexit('', $context['server']['needs_login_fix']);
744
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
718 745
 		{
719 746
 			unset ($_SESSION['logout_url']);
720 747
 			redirectexit();
721
-		}
722
-		else
748
+		} else
723 749
 		{
724 750
 			$temp = $_SESSION['logout_url'];
725 751
 			unset($_SESSION['logout_url']);
@@ -752,8 +778,9 @@  discard block
 block discarded – undo
752 778
 function phpBB3_password_check($passwd, $passwd_hash)
753 779
 {
754 780
 	// Too long or too short?
755
-	if (strlen($passwd_hash) != 34)
756
-		return;
781
+	if (strlen($passwd_hash) != 34) {
782
+			return;
783
+	}
757 784
 
758 785
 	// Range of characters allowed.
759 786
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -764,8 +791,9 @@  discard block
 block discarded – undo
764 791
 	$salt = substr($passwd_hash, 4, 8);
765 792
 
766 793
 	$hash = md5($salt . $passwd, true);
767
-	for (; $count != 0; --$count)
768
-		$hash = md5($hash . $passwd, true);
794
+	for (; $count != 0; --$count) {
795
+			$hash = md5($hash . $passwd, true);
796
+	}
769 797
 
770 798
 	$output = substr($passwd_hash, 0, 12);
771 799
 	$i = 0;
@@ -774,21 +802,25 @@  discard block
 block discarded – undo
774 802
 		$value = ord($hash[$i++]);
775 803
 		$output .= $range[$value & 0x3f];
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 8;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 8;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 6) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785
-		if ($i < 16)
786
-			$value |= ord($hash[$i]) << 16;
815
+		if ($i < 16) {
816
+					$value |= ord($hash[$i]) << 16;
817
+		}
787 818
 
788 819
 		$output .= $range[($value >> 12) & 0x3f];
789 820
 
790
-		if ($i++ >= 16)
791
-			break;
821
+		if ($i++ >= 16) {
822
+					break;
823
+		}
792 824
 
793 825
 		$output .= $range[($value >> 18) & 0x3f];
794 826
 	}
@@ -819,8 +851,9 @@  discard block
 block discarded – undo
819 851
 		require_once($sourcedir . '/Subs-Auth.php');
820 852
 		setLoginCookie(-3600, 0);
821 853
 
822
-		if (isset($_SESSION['login_' . $cookiename]))
823
-			unset($_SESSION['login_' . $cookiename]);
854
+		if (isset($_SESSION['login_' . $cookiename])) {
855
+					unset($_SESSION['login_' . $cookiename]);
856
+		}
824 857
 	}
825 858
 
826 859
 	// We need a member!
@@ -834,8 +867,9 @@  discard block
 block discarded – undo
834 867
 	}
835 868
 
836 869
 	// Right, have we got a flood value?
837
-	if ($password_flood_value !== false)
838
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
870
+	if ($password_flood_value !== false) {
871
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
872
+	}
839 873
 
840 874
 	// Timestamp or number of tries invalid?
841 875
 	if (empty($number_tries) || empty($time_stamp))
@@ -851,15 +885,17 @@  discard block
 block discarded – undo
851 885
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
852 886
 
853 887
 		// They are trying too fast, make them wait longer
854
-		if ($time_stamp < time() - 10)
855
-			$time_stamp = time();
888
+		if ($time_stamp < time() - 10) {
889
+					$time_stamp = time();
890
+		}
856 891
 	}
857 892
 
858 893
 	$number_tries++;
859 894
 
860 895
 	// Broken the law?
861
-	if ($number_tries > 5)
862
-		fatal_lang_error('login_threshold_brute_fail', 'critical');
896
+	if ($number_tries > 5) {
897
+			fatal_lang_error('login_threshold_brute_fail', 'critical');
898
+	}
863 899
 
864 900
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
865 901
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 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,11 +38,12 @@  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
 	// 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.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -160,14 +165,12 @@  discard block
 block discarded – undo
160 165
 				{
161 166
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
162 167
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
163
-				}
164
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
168
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
165 169
 				{
166 170
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
167 171
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
168 172
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
169
-				}
170
-				else
173
+				} else
171 174
 				{
172 175
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
173 176
 				}
@@ -218,14 +221,16 @@  discard block
 block discarded – undo
218 221
 		// Child of a child... just add it on...
219 222
 		elseif (!empty($boardIndexOptions['countChildPosts']))
220 223
 		{
221
-			if (!isset($parent_map))
222
-				$parent_map = array();
224
+			if (!isset($parent_map)) {
225
+							$parent_map = array();
226
+			}
223 227
 
224
-			if (!isset($parent_map[$row_board['id_parent']]))
225
-				foreach ($this_category as $id => $board)
228
+			if (!isset($parent_map[$row_board['id_parent']])) {
229
+							foreach ($this_category as $id => $board)
226 230
 				{
227 231
 					if (!isset($board['children'][$row_board['id_parent']]))
228 232
 						continue;
233
+			}
229 234
 
230 235
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
231 236
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -246,8 +251,9 @@  discard block
 block discarded – undo
246 251
 			continue;
247 252
 		}
248 253
 		// Found a child of a child - skip.
249
-		else
250
-			continue;
254
+		else {
255
+					continue;
256
+		}
251 257
 
252 258
 		// Prepare the subject, and make sure it's not too long.
253 259
 		censorText($row_board['subject']);
@@ -268,12 +274,13 @@  discard block
 block discarded – undo
268 274
 			'topic' => $row_board['id_topic']
269 275
 		);
270 276
 
271
-		if (!empty($settings['avatars_on_boardIndex']))
272
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
277
+		if (!empty($settings['avatars_on_boardIndex'])) {
278
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
273 279
 				'avatar' => $row_board['avatar'],
274 280
 				'email' => $row_board['email_address'],
275 281
 				'filename' => !empty($row['member_filename']) ? $row_board['member_filename'] : '',
276 282
 			));
283
+		}
277 284
 
278 285
 		// Provide the href and link.
279 286
 		if ($row_board['subject'] != '')
@@ -285,8 +292,7 @@  discard block
 block discarded – undo
285 292
 			link, href, subject, start (where they should go for the first unread post.),
286 293
 			and member. (which has id, name, link, href, username in it.) */
287 294
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
288
-		}
289
-		else
295
+		} else
290 296
 		{
291 297
 			$this_last_post['href'] = '';
292 298
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -294,8 +300,9 @@  discard block
 block discarded – undo
294 300
 		}
295 301
 
296 302
 		// Set the last post in the parent board.
297
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
298
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
303
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
304
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
305
+		}
299 306
 		// Just in the child...?
300 307
 		if ($isChild)
301 308
 		{
@@ -305,15 +312,17 @@  discard block
 block discarded – undo
305 312
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
306 313
 		}
307 314
 		// No last post for this board?  It's not new then, is it..?
308
-		elseif ($row_board['poster_name'] == '')
309
-			$this_category[$row_board['id_board']]['new'] = false;
315
+		elseif ($row_board['poster_name'] == '') {
316
+					$this_category[$row_board['id_board']]['new'] = false;
317
+		}
310 318
 
311 319
 		// Determine a global most recent topic.
312
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
313
-			$latest_post = array(
320
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
321
+					$latest_post = array(
314 322
 				'timestamp' => $row_board['poster_time'],
315 323
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
316 324
 			);
325
+		}
317 326
 	}
318 327
 	$smcFunc['db_free_result']($result_boards);
319 328
 
@@ -330,8 +339,9 @@  discard block
 block discarded – undo
330 339
 				if (!empty($moderators[$board['id']]))
331 340
 				{
332 341
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
333
-					foreach ($moderators[$board['id']] as $moderator)
334
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
342
+					foreach ($moderators[$board['id']] as $moderator) {
343
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
344
+					}
335 345
 				}
336 346
 				if (!empty($groups[$board['id']]))
337 347
 				{
@@ -344,16 +354,16 @@  discard block
 block discarded – undo
344 354
 				}
345 355
 			}
346 356
 		}
347
-	}
348
-	else
357
+	} else
349 358
 	{
350 359
 		foreach ($this_category as $k => $board)
351 360
 		{
352 361
 			if (!empty($moderators[$board['id']]))
353 362
 			{
354 363
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
355
-				foreach ($moderators[$board['id']] as $moderator)
356
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
364
+				foreach ($moderators[$board['id']] as $moderator) {
365
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
366
+				}
357 367
 			}
358 368
 			if (!empty($groups[$board['id']]))
359 369
 			{
@@ -367,20 +377,23 @@  discard block
 block discarded – undo
367 377
 		}
368 378
 	}
369 379
 
370
-	if ($boardIndexOptions['include_categories'])
371
-		sortCategories($categories);
372
-	else
373
-		sortBoards($this_category);
380
+	if ($boardIndexOptions['include_categories']) {
381
+			sortCategories($categories);
382
+	} else {
383
+			sortBoards($this_category);
384
+	}
374 385
 
375 386
 	// By now we should know the most recent post...if we wanna know it that is.
376
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
377
-		$context['latest_post'] = $latest_post['ref'];
387
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
388
+			$context['latest_post'] = $latest_post['ref'];
389
+	}
378 390
 
379 391
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
380
-	if ($boardIndexOptions['include_categories'])
381
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
382
-	else
383
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
392
+	if ($boardIndexOptions['include_categories']) {
393
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
394
+	} else {
395
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
396
+	}
384 397
 
385 398
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
386 399
 }
Please login to merge, or discard this patch.
Sources/Likes.php 1 patch
Braces   +106 added lines, -77 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Class Likes
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 		$this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false;
109 110
 
110 111
 		// We do not want to output debug information here.
111
-		if ($this->_js)
112
-			$db_show_debug = false;
112
+		if ($this->_js) {
113
+					$db_show_debug = false;
114
+		}
113 115
 	}
114 116
 
115 117
 	/**
@@ -143,8 +145,9 @@  discard block
 block discarded – undo
143 145
 			$call = $this->_sa;
144 146
 
145 147
 			// Guest can only view likes.
146
-			if ($call != 'view')
147
-				is_not_guest();
148
+			if ($call != 'view') {
149
+							is_not_guest();
150
+			}
148 151
 
149 152
 			checkSession('get');
150 153
 
@@ -182,15 +185,17 @@  discard block
 block discarded – undo
182 185
 		global $smcFunc, $modSettings;
183 186
 
184 187
 		// This feature is currently disable.
185
-		if (empty($modSettings['enable_likes']))
186
-			return $this->_error = 'like_disable';
188
+		if (empty($modSettings['enable_likes'])) {
189
+					return $this->_error = 'like_disable';
190
+		}
187 191
 
188 192
 		// Zerothly, they did indicate some kind of content to like, right?
189 193
 		preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches);
190 194
 		$this->_type = isset($matches[1]) ? $matches[1] : '';
191 195
 
192
-		if ($this->_type == '' || $this->_content <= 0)
193
-			return $this->_error = 'cannot_';
196
+		if ($this->_type == '' || $this->_content <= 0) {
197
+					return $this->_error = 'cannot_';
198
+		}
194 199
 
195 200
 		// First we need to verify if the user can see the type of content or not. This is set up to be extensible,
196 201
 		// so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks.
@@ -209,12 +214,14 @@  discard block
 block discarded – undo
209 214
 					'msg' => $this->_content,
210 215
 				)
211 216
 			);
212
-			if ($smcFunc['db_num_rows']($request) == 1)
213
-				list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
217
+			if ($smcFunc['db_num_rows']($request) == 1) {
218
+							list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
219
+			}
214 220
 
215 221
 			$smcFunc['db_free_result']($request);
216
-			if (empty($this->_idTopic))
217
-				return $this->_error = 'cannot_';
222
+			if (empty($this->_idTopic)) {
223
+							return $this->_error = 'cannot_';
224
+			}
218 225
 
219 226
 			// So we know what topic it's in and more importantly we know the user can see it.
220 227
 			// If we're not viewing, we need some info set up.
@@ -224,9 +231,7 @@  discard block
 block discarded – undo
224 231
 			$this->_validLikes['can_see'] = allowedTo('likes_view') ? true : 'cannot_view_likes';
225 232
 
226 233
 			$this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content'));
227
-		}
228
-
229
-		else
234
+		} else
230 235
 		{
231 236
 			// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
232 237
 			// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
@@ -244,8 +249,9 @@  discard block
 block discarded – undo
244 249
 					if ($result !== false)
245 250
 					{
246 251
 						// Match the type with what we already have.
247
-						if (!isset($result['type']) || $result['type'] != $this->_type)
248
-							return $this->_error = 'not_valid_like_type';
252
+						if (!isset($result['type']) || $result['type'] != $this->_type) {
253
+													return $this->_error = 'not_valid_like_type';
254
+						}
249 255
 
250 256
 						// Fill out the rest.
251 257
 						$this->_type = $result['type'];
@@ -256,17 +262,20 @@  discard block
 block discarded – undo
256 262
 				}
257 263
 			}
258 264
 
259
-			if (!$found)
260
-				return $this->_error = 'cannot_';
265
+			if (!$found) {
266
+							return $this->_error = 'cannot_';
267
+			}
261 268
 		}
262 269
 
263 270
 		// Does the user can see this?
264
-		if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see']))
265
-			return $this->_error = $this->_validLikes['can_see'];
271
+		if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) {
272
+					return $this->_error = $this->_validLikes['can_see'];
273
+		}
266 274
 
267 275
 		// Does the user can like this? Viewing a list of likes doesn't require this permission.
268
-			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like']))
269
-				return $this->_error = $this->_validLikes['can_like'];
276
+			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) {
277
+							return $this->_error = $this->_validLikes['can_like'];
278
+			}
270 279
 	}
271 280
 
272 281
 	/**
@@ -291,8 +300,9 @@  discard block
 block discarded – undo
291 300
 		);
292 301
 
293 302
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
294
-		if ($this->_sa == __FUNCTION__)
295
-			$this->_data = __FUNCTION__;
303
+		if ($this->_sa == __FUNCTION__) {
304
+					$this->_data = __FUNCTION__;
305
+		}
296 306
 	}
297 307
 
298 308
 	/**
@@ -322,8 +332,8 @@  discard block
 block discarded – undo
322 332
 
323 333
 		// Add a background task to process sending alerts.
324 334
 		// Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this.
325
-		if ($this->_type == 'msg')
326
-			$smcFunc['db_insert']('insert',
335
+		if ($this->_type == 'msg') {
336
+					$smcFunc['db_insert']('insert',
327 337
 				'{db_prefix}background_tasks',
328 338
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
329 339
 				array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', json_encode(array(
@@ -335,10 +345,12 @@  discard block
 block discarded – undo
335 345
 				)), 0),
336 346
 				array('id_task')
337 347
 			);
348
+		}
338 349
 
339 350
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
340
-		if ($this->_sa == __FUNCTION__)
341
-			$this->_data = __FUNCTION__;
351
+		if ($this->_sa == __FUNCTION__) {
352
+					$this->_data = __FUNCTION__;
353
+		}
342 354
 	}
343 355
 
344 356
 	/**
@@ -364,8 +376,9 @@  discard block
 block discarded – undo
364 376
 		$smcFunc['db_free_result']($request);
365 377
 
366 378
 		// If you want to call this directly, fill out _data property too.
367
-		if ($this->_sa == __FUNCTION__)
368
-			$this->_data = $this->_numLikes;
379
+		if ($this->_sa == __FUNCTION__) {
380
+					$this->_data = $this->_numLikes;
381
+		}
369 382
 	}
370 383
 
371 384
 	/**
@@ -378,8 +391,9 @@  discard block
 block discarded – undo
378 391
 		global $smcFunc;
379 392
 
380 393
 		// Safety first!
381
-		if (empty($this->_type) || empty($this->_content))
382
-			return $this->_error = 'cannot_';
394
+		if (empty($this->_type) || empty($this->_content)) {
395
+					return $this->_error = 'cannot_';
396
+		}
383 397
 
384 398
 		// Do we already like this?
385 399
 		$request = $smcFunc['db_query']('', '
@@ -397,26 +411,28 @@  discard block
 block discarded – undo
397 411
 		$this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0;
398 412
 		$smcFunc['db_free_result']($request);
399 413
 
400
-		if ($this->_alreadyLiked)
401
-			$this->delete();
402
-
403
-		else
404
-			$this->insert();
414
+		if ($this->_alreadyLiked) {
415
+					$this->delete();
416
+		} else {
417
+					$this->insert();
418
+		}
405 419
 
406 420
 		// Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable.
407 421
 		$this->_count();
408 422
 
409 423
 		// Update the likes count for messages.
410
-		if ($this->_type == 'msg')
411
-			$this->msgIssueLike();
424
+		if ($this->_type == 'msg') {
425
+					$this->msgIssueLike();
426
+		}
412 427
 
413 428
 		// Any callbacks?
414 429
 		elseif (!empty($this->_validLikes['callback']))
415 430
 		{
416 431
 			$call = call_helper($this->_validLikes['callback'], true);
417 432
 
418
-			if (!empty($call))
419
-				call_user_func_array($call, array($this));
433
+			if (!empty($call)) {
434
+							call_user_func_array($call, array($this));
435
+			}
420 436
 		}
421 437
 
422 438
 		// Sometimes there might be other things that need updating after we do this like.
@@ -425,8 +441,9 @@  discard block
 block discarded – undo
425 441
 		// Now some clean up. This is provided here for any like handlers that want to do any cache flushing.
426 442
 		// This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so
427 443
 		// in integrate_valid_likes where it absolutely has to exist.
428
-		if (!empty($this->_validLikes['flush_cache']))
429
-			cache_put_data($this->_validLikes['flush_cache'], null);
444
+		if (!empty($this->_validLikes['flush_cache'])) {
445
+					cache_put_data($this->_validLikes['flush_cache'], null);
446
+		}
430 447
 
431 448
 		// All done, start building the data to pass as response.
432 449
 		$this->_data = array(
@@ -450,8 +467,9 @@  discard block
 block discarded – undo
450 467
 	{
451 468
 		global $smcFunc;
452 469
 
453
-		if ($this->_type !== 'msg')
454
-			return;
470
+		if ($this->_type !== 'msg') {
471
+					return;
472
+		}
455 473
 
456 474
 		$smcFunc['db_query']('', '
457 475
 			UPDATE {db_prefix}messages
@@ -492,8 +510,9 @@  discard block
 block discarded – undo
492 510
 				'like_type' => $this->_type,
493 511
 			)
494 512
 		);
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
513
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
514
+					$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
515
+		}
497 516
 
498 517
 		// Now to get member data, including avatars and so on.
499 518
 		$members = array_keys($context['likers']);
@@ -501,8 +520,9 @@  discard block
 block discarded – undo
501 520
 		if (count($loaded) != count($members))
502 521
 		{
503 522
 			$members = array_diff($members, $loaded);
504
-			foreach ($members as $not_loaded)
505
-				unset ($context['likers'][$not_loaded]);
523
+			foreach ($members as $not_loaded) {
524
+							unset ($context['likers'][$not_loaded]);
525
+			}
506 526
 		}
507 527
 
508 528
 		foreach ($context['likers'] as $liker => $dummy)
@@ -544,12 +564,14 @@  discard block
 block discarded – undo
544 564
 		global $context, $txt;
545 565
 
546 566
 		// Don't do anything if someone else has already take care of the response.
547
-		if (!$this->_setResponse)
548
-			return;
567
+		if (!$this->_setResponse) {
568
+					return;
569
+		}
549 570
 
550 571
 		// Want a json response huh?
551
-		if ($this->_validLikes['json'])
552
-			return $this->jsonResponse();
572
+		if ($this->_validLikes['json']) {
573
+					return $this->jsonResponse();
574
+		}
553 575
 
554 576
 		// Set everything up for display.
555 577
 		loadTemplate('Likes');
@@ -559,8 +581,9 @@  discard block
 block discarded – undo
559 581
 		if ($this->_error)
560 582
 		{
561 583
 			// If this is a generic error, set it up good.
562
-			if ($this->_error == 'cannot_')
563
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
584
+			if ($this->_error == 'cannot_') {
585
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
586
+			}
564 587
 
565 588
 			// Is this request coming from an ajax call?
566 589
 			if ($this->_js)
@@ -570,8 +593,9 @@  discard block
 block discarded – undo
570 593
 			}
571 594
 
572 595
 			// Nope?  then just do a redirect to whatever URL was provided.
573
-			else
574
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
596
+			else {
597
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
598
+			}
575 599
 
576 600
 			return;
577 601
 		}
@@ -580,8 +604,9 @@  discard block
 block discarded – undo
580 604
 		else
581 605
 		{
582 606
 			// Not an ajax request so send the user back to the previous location or the main page.
583
-			if (!$this->_js)
584
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
607
+			if (!$this->_js) {
608
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
609
+			}
585 610
 
586 611
 			// These fine gentlemen all share the same template.
587 612
 			$generic = array('delete', 'insert', '_count');
@@ -612,8 +637,9 @@  discard block
 block discarded – undo
612 637
 		// If there is an error, send it.
613 638
 		if ($this->_error)
614 639
 		{
615
-			if ($this->_error == 'cannot_')
616
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
640
+			if ($this->_error == 'cannot_') {
641
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
642
+			}
617 643
 
618 644
 			$print['error'] = $this->_error;
619 645
 		}
@@ -649,33 +675,36 @@  discard block
 block discarded – undo
649 675
 	<body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
650 676
 		<div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
651 677
 
652
-	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
653
-		$_GET['verse'] = '4:16';
678
+	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) {
679
+			$_GET['verse'] = '4:16';
680
+	}
654 681
 
655
-	if ($_GET['verse'] == '2:18')
656
-		echo '
682
+	if ($_GET['verse'] == '2:18') {
683
+			echo '
657 684
 			Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
658
-	elseif ($_GET['verse'] == '4:16')
659
-		echo '
685
+	} elseif ($_GET['verse'] == '4:16') {
686
+			echo '
660 687
 			And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
661
-	elseif ($_GET['verse'] == '22:1-2')
662
-		echo '
688
+	} elseif ($_GET['verse'] == '22:1-2') {
689
+			echo '
663 690
 			<p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer.&nbsp; Alas, it needed more than <em>only one</em>, but yet even thought otherwise.&nbsp; It became that the opposition <em>rumored</em> and lied, but still to no avail.&nbsp; Their match, though not <em>perfect</em>, had them outdone.</p>
664 691
 			<p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue.&nbsp; <em>The end</em>.</p>';
692
+	}
665 693
 
666 694
 	echo '
667 695
 		</div>
668 696
 		<div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
669 697
 
670
-	if ($_GET['verse'] == '2:18')
671
-		echo '
698
+	if ($_GET['verse'] == '2:18') {
699
+			echo '
672 700
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
673
-	elseif ($_GET['verse'] == '4:16')
674
-		echo '
701
+	} elseif ($_GET['verse'] == '4:16') {
702
+			echo '
675 703
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
676
-	elseif ($_GET['verse'] == '22:1-2')
677
-		echo '
704
+	} elseif ($_GET['verse'] == '22:1-2') {
705
+			echo '
678 706
 			from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
707
+	}
679 708
 
680 709
 	echo '
681 710
 		</div>
Please login to merge, or discard this patch.
Sources/ManageScheduledTasks.php 1 patch
Braces   +54 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -40,10 +41,11 @@  discard block
 block discarded – undo
40 41
 	);
41 42
 
42 43
 	// We need to find what's the action.
43
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
44
-		$context['sub_action'] = $_REQUEST['sa'];
45
-	else
46
-		$context['sub_action'] = 'tasks';
44
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
45
+			$context['sub_action'] = $_REQUEST['sa'];
46
+	} else {
47
+			$context['sub_action'] = 'tasks';
48
+	}
47 49
 
48 50
 	// Now for the lovely tabs. That we all love.
49 51
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -90,9 +92,10 @@  discard block
 block discarded – undo
90 92
 
91 93
 		// Enable and disable as required.
92 94
 		$enablers = array(0);
93
-		foreach ($_POST['enable_task'] as $id => $enabled)
94
-			if ($enabled)
95
+		foreach ($_POST['enable_task'] as $id => $enabled) {
96
+					if ($enabled)
95 97
 				$enablers[] = (int) $id;
98
+		}
96 99
 
97 100
 		// Do the update!
98 101
 		$smcFunc['db_query']('', '
@@ -130,8 +133,9 @@  discard block
 block discarded – undo
130 133
 
131 134
 		// Lets figure out which ones they want to run.
132 135
 		$tasks = array();
133
-		foreach ($_POST['run_task'] as $task => $dummy)
134
-			$tasks[] = (int) $task;
136
+		foreach ($_POST['run_task'] as $task => $dummy) {
137
+					$tasks[] = (int) $task;
138
+		}
135 139
 
136 140
 		// Load up the tasks.
137 141
 		$request = $smcFunc['db_query']('', '
@@ -151,36 +155,41 @@  discard block
 block discarded – undo
151 155
 		while ($row = $smcFunc['db_fetch_assoc']($request))
152 156
 		{
153 157
 			// What kind of task are we handling?
154
-			if (!empty($row['callable']))
155
-				$task_string = $row['callable'];
158
+			if (!empty($row['callable'])) {
159
+							$task_string = $row['callable'];
160
+			}
156 161
 
157 162
 			// Default SMF task or old mods?
158
-			elseif (function_exists('scheduled_' . $row['task']))
159
-				$task_string = 'scheduled_' . $row['task'];
163
+			elseif (function_exists('scheduled_' . $row['task'])) {
164
+							$task_string = 'scheduled_' . $row['task'];
165
+			}
160 166
 
161 167
 			// One last resource, the task name.
162
-			elseif (!empty($row['task']))
163
-				$task_string = $row['task'];
168
+			elseif (!empty($row['task'])) {
169
+							$task_string = $row['task'];
170
+			}
164 171
 
165 172
 			$start_time = microtime();
166 173
 			// The functions got to exist for us to use it.
167
-			if (empty($task_string))
168
-				continue;
174
+			if (empty($task_string)) {
175
+							continue;
176
+			}
169 177
 
170 178
 			// Try to stop a timeout, this would be bad...
171 179
 			@set_time_limit(300);
172
-			if (function_exists('apache_reset_timeout'))
173
-				@apache_reset_timeout();
180
+			if (function_exists('apache_reset_timeout')) {
181
+							@apache_reset_timeout();
182
+			}
174 183
 
175 184
 			// Get the callable.
176 185
 			$callable_task = call_helper($task_string, true);
177 186
 
178 187
 			// Perform the task.
179
-			if (!empty($callable_task))
180
-				$completed = call_user_func($callable_task);
181
-
182
-			else
183
-				$completed = false;
188
+			if (!empty($callable_task)) {
189
+							$completed = call_user_func($callable_task);
190
+			} else {
191
+							$completed = false;
192
+			}
184 193
 
185 194
 			// Log that we did it ;)
186 195
 			if ($completed)
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 		$smcFunc['db_free_result']($request);
198 207
 
199 208
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
200
-		if (!empty($context['scheduled_errors']))
201
-			$_SESSION['st_error'] = $context['scheduled_errors'];
209
+		if (!empty($context['scheduled_errors'])) {
210
+					$_SESSION['st_error'] = $context['scheduled_errors'];
211
+		}
202 212
 
203 213
 		redirectexit('action=admin;area=scheduledtasks;done');
204 214
 	}
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 	$context['server_time'] = timeformat(time(), false, 'server');
371 381
 
372 382
 	// Cleaning...
373
-	if (!isset($_GET['tid']))
374
-		fatal_lang_error('no_access', false);
383
+	if (!isset($_GET['tid'])) {
384
+			fatal_lang_error('no_access', false);
385
+	}
375 386
 	$_GET['tid'] = (int) $_GET['tid'];
376 387
 
377 388
 	// Saving?
@@ -387,10 +398,12 @@  discard block
 block discarded – undo
387 398
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
388 399
 
389 400
 		// If a half is empty then assume zero offset!
390
-		if (!isset($matches[2]) || $matches[2] > 59)
391
-			$matches[2] = 0;
392
-		if (!isset($matches[1]) || $matches[1] > 23)
393
-			$matches[1] = 0;
401
+		if (!isset($matches[2]) || $matches[2] > 59) {
402
+					$matches[2] = 0;
403
+		}
404
+		if (!isset($matches[1]) || $matches[1] > 23) {
405
+					$matches[1] = 0;
406
+		}
394 407
 
395 408
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
396 409
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -400,8 +413,9 @@  discard block
 block discarded – undo
400 413
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
401 414
 
402 415
 		// Don't allow one minute intervals.
403
-		if ($interval == 1 && $unit == 'm')
404
-			$interval = 2;
416
+		if ($interval == 1 && $unit == 'm') {
417
+					$interval = 2;
418
+		}
405 419
 
406 420
 		// Is it disabled?
407 421
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -439,8 +453,9 @@  discard block
 block discarded – undo
439 453
 	);
440 454
 
441 455
 	// Should never, ever, happen!
442
-	if ($smcFunc['db_num_rows']($request) == 0)
443
-		fatal_lang_error('no_access', false);
456
+	if ($smcFunc['db_num_rows']($request) == 0) {
457
+			fatal_lang_error('no_access', false);
458
+	}
444 459
 
445 460
 	while ($row = $smcFunc['db_fetch_assoc']($request))
446 461
 	{
@@ -598,13 +613,14 @@  discard block
 block discarded – undo
598 613
 		)
599 614
 	);
600 615
 	$log_entries = array();
601
-	while ($row = $smcFunc['db_fetch_assoc']($request))
602
-		$log_entries[] = array(
616
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
617
+			$log_entries[] = array(
603 618
 			'id' => $row['id_log'],
604 619
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
605 620
 			'time_run' => $row['time_run'],
606 621
 			'time_taken' => $row['time_taken'],
607 622
 		);
623
+	}
608 624
 	$smcFunc['db_free_result']($request);
609 625
 
610 626
 	return $log_entries;
Please login to merge, or discard this patch.
Sources/ReportToMod.php 1 patch
Braces   +71 added lines, -51 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 4
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * Report a post or profile to the moderator... ask for a comment.
@@ -35,10 +36,11 @@  discard block
 block discarded – undo
35 36
 
36 37
 	// You can't use this if it's off or you are not allowed to do it.
37 38
 	// If we don't have the ID of something to report, we'll die with a no_access error below
38
-	if (isset($_REQUEST['msg']))
39
-		isAllowedTo('report_any');
40
-	elseif (isset($_REQUEST['u']))
41
-		isAllowedTo('report_user');
39
+	if (isset($_REQUEST['msg'])) {
40
+			isAllowedTo('report_any');
41
+	} elseif (isset($_REQUEST['u'])) {
42
+			isAllowedTo('report_user');
43
+	}
42 44
 
43 45
 	// Previewing or modifying?
44 46
 	if (isset($_POST['preview']) && !isset($_POST['save']))
@@ -56,19 +58,23 @@  discard block
 block discarded – undo
56 58
 	}
57 59
 
58 60
 	// If they're posting, it should be processed by ReportToModerator2.
59
-	if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview']))
60
-		ReportToModerator2();
61
+	if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) {
62
+			ReportToModerator2();
63
+	}
61 64
 
62 65
 	// We need a message ID or user ID to check!
63
-	if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u']))
64
-		fatal_lang_error('no_access', false);
66
+	if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) {
67
+			fatal_lang_error('no_access', false);
68
+	}
65 69
 
66 70
 	// For compatibility, accept mid, but we should be using msg. (not the flavor kind!)
67
-	if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid']))
68
-		$_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
71
+	if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) {
72
+			$_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
73
+	}
69 74
 	// msg and mid empty - assume we're reporting a user
70
-	elseif (!empty($_REQUEST['u']))
71
-		$_REQUEST['u'] = (int) $_REQUEST['u'];
75
+	elseif (!empty($_REQUEST['u'])) {
76
+			$_REQUEST['u'] = (int) $_REQUEST['u'];
77
+	}
72 78
 
73 79
 	// Set up some form values
74 80
 	$context['report_type'] = isset($_REQUEST['msg']) ? 'msg' : 'u';
@@ -89,8 +95,9 @@  discard block
 block discarded – undo
89 95
 				'id_msg' => $_REQUEST['msg'],
90 96
 			)
91 97
 		);
92
-		if ($smcFunc['db_num_rows']($result) == 0)
93
-			fatal_lang_error('no_board', false);
98
+		if ($smcFunc['db_num_rows']($result) == 0) {
99
+					fatal_lang_error('no_board', false);
100
+		}
94 101
 		list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result);
95 102
 		$smcFunc['db_free_result']($result);
96 103
 
@@ -101,8 +108,7 @@  discard block
 block discarded – undo
101 108
 
102 109
 		// The submit URL is different for users than it is for posts
103 110
 		$context['submit_url'] = $scripturl . '?action=reporttm;msg=' . $_REQUEST['msg'] . ';topic=' . $topic;
104
-	}
105
-	else
111
+	} else
106 112
 	{
107 113
 		// Check the user's ID
108 114
 		$result = $smcFunc['db_query']('', '
@@ -114,8 +120,9 @@  discard block
 block discarded – undo
114 120
 			)
115 121
 		);
116 122
 
117
-		if ($smcFunc['db_num_rows']($result) == 0)
118
-			fatal_lang_error('no_user', false);
123
+		if ($smcFunc['db_num_rows']($result) == 0) {
124
+					fatal_lang_error('no_user', false);
125
+		}
119 126
 		list($_REQUEST['u'], $display_name, $username) = $smcFunc['db_fetch_row']($result);
120 127
 
121 128
 		$context['current_user'] = $_REQUEST['u'];
@@ -170,10 +177,11 @@  discard block
 block discarded – undo
170 177
 	is_not_guest();
171 178
 
172 179
 	// You must have the proper permissions!
173
-	if (isset($_REQUEST['msg']))
174
-		isAllowedTo('report_any');
175
-	else
176
-		isAllowedTo('report_user');
180
+	if (isset($_REQUEST['msg'])) {
181
+			isAllowedTo('report_any');
182
+	} else {
183
+			isAllowedTo('report_user');
184
+	}
177 185
 
178 186
 	// Make sure they aren't spamming.
179 187
 	spamProtection('reporttm');
@@ -187,17 +195,20 @@  discard block
 block discarded – undo
187 195
 	$post_errors = array();
188 196
 
189 197
 	// Check their session.
190
-	if (checkSession('post', '', false) != '')
191
-		$post_errors[] = 'session_timeout';
198
+	if (checkSession('post', '', false) != '') {
199
+			$post_errors[] = 'session_timeout';
200
+	}
192 201
 
193 202
 	// Make sure we have a comment and it's clean.
194
-	if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '')
195
-		$post_errors[] = 'no_comment';
203
+	if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') {
204
+			$post_errors[] = 'no_comment';
205
+	}
196 206
 
197 207
 	$poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => ''));
198 208
 
199
-	if ($smcFunc['strlen']($poster_comment) > 254)
200
-		$post_errors[] = 'post_too_long';
209
+	if ($smcFunc['strlen']($poster_comment) > 254) {
210
+			$post_errors[] = 'post_too_long';
211
+	}
201 212
 
202 213
 	// Any errors?
203 214
 	if (!empty($post_errors))
@@ -205,8 +216,9 @@  discard block
 block discarded – undo
205 216
 		loadLanguage('Errors');
206 217
 
207 218
 		$context['post_errors'] = array();
208
-		foreach ($post_errors as $post_error)
209
-			$context['post_errors'][$post_error] = $txt['error_' . $post_error];
219
+		foreach ($post_errors as $post_error) {
220
+					$context['post_errors'][$post_error] = $txt['error_' . $post_error];
221
+		}
210 222
 
211 223
 		return ReportToModerator();
212 224
 	}
@@ -215,8 +227,7 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		// Handle this elsewhere to keep things from getting too long
217 229
 		reportPost($_POST['msg'], $poster_comment);
218
-	}
219
-	else
230
+	} else
220 231
 	{
221 232
 		reportUser($_POST['u'], $poster_comment);
222 233
 	}
@@ -247,8 +258,9 @@  discard block
 block discarded – undo
247 258
 			'id_msg' => $_POST['msg'],
248 259
 		)
249 260
 	);
250
-	if ($smcFunc['db_num_rows']($request) == 0)
251
-		fatal_lang_error('no_board', false);
261
+	if ($smcFunc['db_num_rows']($request) == 0) {
262
+			fatal_lang_error('no_board', false);
263
+	}
252 264
 	$message = $smcFunc['db_fetch_assoc']($request);
253 265
 	$smcFunc['db_free_result']($request);
254 266
 
@@ -264,18 +276,20 @@  discard block
 block discarded – undo
264 276
 			'ignored' => 1,
265 277
 		)
266 278
 	);
267
-	if ($smcFunc['db_num_rows']($request) != 0)
268
-		list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
279
+	if ($smcFunc['db_num_rows']($request) != 0) {
280
+			list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
281
+	}
269 282
 
270 283
 	$smcFunc['db_free_result']($request);
271 284
 
272 285
 	// If we're just going to ignore these, then who gives a monkeys...
273
-	if (!empty($ignore))
274
-		redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
286
+	if (!empty($ignore)) {
287
+			redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
288
+	}
275 289
 
276 290
 	// Already reported? My god, we could be dealing with a real rogue here...
277
-	if (!empty($id_report))
278
-		$smcFunc['db_query']('', '
291
+	if (!empty($id_report)) {
292
+			$smcFunc['db_query']('', '
279 293
 			UPDATE {db_prefix}log_reported
280 294
 			SET num_reports = num_reports + 1, time_updated = {int:current_time}
281 295
 			WHERE id_report = {int:id_report}',
@@ -284,11 +298,13 @@  discard block
 block discarded – undo
284 298
 				'id_report' => $id_report,
285 299
 			)
286 300
 		);
301
+	}
287 302
 	// Otherwise, we shall make one!
288 303
 	else
289 304
 	{
290
-		if (empty($message['real_name']))
291
-			$message['real_name'] = $message['poster_name'];
305
+		if (empty($message['real_name'])) {
306
+					$message['real_name'] = $message['poster_name'];
307
+		}
292 308
 
293 309
 		$id_report = $smcFunc['db_insert']('',
294 310
 			'{db_prefix}log_reported',
@@ -367,8 +383,9 @@  discard block
 block discarded – undo
367 383
 			'id_member' => $_POST['u']
368 384
 		)
369 385
 	);
370
-	if ($smcFunc['db_num_rows']($request) == 0)
371
-		fatal_lang_error('no_user', false);
386
+	if ($smcFunc['db_num_rows']($request) == 0) {
387
+			fatal_lang_error('no_user', false);
388
+	}
372 389
 	$user = $smcFunc['db_fetch_assoc']($request);
373 390
 	$smcFunc['db_free_result']($request);
374 391
 
@@ -388,18 +405,20 @@  discard block
 block discarded – undo
388 405
 			'ignored' => 1,
389 406
 		)
390 407
 	);
391
-	if ($smcFunc['db_num_rows']($request) != 0)
392
-		list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
408
+	if ($smcFunc['db_num_rows']($request) != 0) {
409
+			list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
410
+	}
393 411
 
394 412
 	$smcFunc['db_free_result']($request);
395 413
 
396 414
 	// If we're just going to ignore these, then who gives a monkeys...
397
-	if (!empty($ignore))
398
-		redirectexit('action=profile;u=' . $_POST['u']);
415
+	if (!empty($ignore)) {
416
+			redirectexit('action=profile;u=' . $_POST['u']);
417
+	}
399 418
 
400 419
 	// Already reported? My god, we could be dealing with a real rogue here...
401
-	if (!empty($id_report))
402
-		$smcFunc['db_query']('', '
420
+	if (!empty($id_report)) {
421
+			$smcFunc['db_query']('', '
403 422
 			UPDATE {db_prefix}log_reported
404 423
 			SET num_reports = num_reports + 1, time_updated = {int:current_time}
405 424
 			WHERE id_report = {int:id_report}',
@@ -408,6 +427,7 @@  discard block
 block discarded – undo
408 427
 				'id_report' => $id_report,
409 428
 			)
410 429
 		);
430
+	}
411 431
 	// Otherwise, we shall make one!
412 432
 	else
413 433
 	{
Please login to merge, or discard this patch.