Completed
Pull Request — release-2.1 (#4184)
by Mert
10:16
created
Sources/ScheduledTasks.php 1 patch
Braces   +277 added lines, -201 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
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1548,8 +1616,9 @@  discard block
 block discarded – undo
1548 1616
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1549 1617
 
1550 1618
 		// Send the actual email.
1551
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1552
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1619
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1620
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1621
+		}
1553 1622
 
1554 1623
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1555 1624
 		{
@@ -1572,18 +1641,19 @@  discard block
 block discarded – undo
1572 1641
 	}
1573 1642
 
1574 1643
 	// Insert the alerts if any
1575
-	if (!empty($alert_rows))
1576
-		$smcFunc['db_insert']('',
1644
+	if (!empty($alert_rows)) {
1645
+			$smcFunc['db_insert']('',
1577 1646
 			'{db_prefix}user_alerts',
1578 1647
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1579 1648
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1580 1649
 			$alert_rows,
1581 1650
 			array()
1582 1651
 		);
1652
+	}
1583 1653
 
1584 1654
 	// Mark the reminder as sent.
1585
-	if (!empty($subs_reminded))
1586
-		$smcFunc['db_query']('', '
1655
+	if (!empty($subs_reminded)) {
1656
+			$smcFunc['db_query']('', '
1587 1657
 			UPDATE {db_prefix}log_subscribed
1588 1658
 			SET reminder_sent = {int:reminder_sent}
1589 1659
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1592,6 +1662,7 @@  discard block
 block discarded – undo
1592 1662
 				'reminder_sent' => 1,
1593 1663
 			)
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	return true;
1597 1668
 }
@@ -1607,13 +1678,13 @@  discard block
 block discarded – undo
1607 1678
 	// We need to know where this thing is going.
1608 1679
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1609 1680
 	{
1610
-		if (!is_array($modSettings['attachmentUploadDir']))
1611
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1681
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1682
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1683
+		}
1612 1684
 
1613 1685
 		// Just use the current path for temp files.
1614 1686
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1615
-	}
1616
-	else
1687
+	} else
1617 1688
 	{
1618 1689
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1619 1690
 	}
@@ -1632,14 +1703,16 @@  discard block
 block discarded – undo
1632 1703
 
1633 1704
 		while ($file = readdir($dir))
1634 1705
 		{
1635
-			if ($file == '.' || $file == '..')
1636
-				continue;
1706
+			if ($file == '.' || $file == '..') {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (strpos($file, 'post_tmp_') !== false)
1639 1711
 			{
1640 1712
 				// Temp file is more than 5 hours old!
1641
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1642
-					@unlink($attach_dir . '/' . $file);
1713
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1714
+									@unlink($attach_dir . '/' . $file);
1715
+				}
1643 1716
 			}
1644 1717
 		}
1645 1718
 		closedir($dir);
@@ -1672,8 +1745,9 @@  discard block
 block discarded – undo
1672 1745
 		)
1673 1746
 	);
1674 1747
 
1675
-	while ($row = $smcFunc['db_fetch_row']($request))
1676
-		$topics[] = $row[0];
1748
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1749
+			$topics[] = $row[0];
1750
+	}
1677 1751
 	$smcFunc['db_free_result']($request);
1678 1752
 
1679 1753
 	// Zap, your gone
@@ -1693,8 +1767,9 @@  discard block
 block discarded – undo
1693 1767
 {
1694 1768
 	global $smcFunc, $sourcedir, $modSettings;
1695 1769
 
1696
-	if (empty($modSettings['drafts_keep_days']))
1697
-		return true;
1770
+	if (empty($modSettings['drafts_keep_days'])) {
1771
+			return true;
1772
+	}
1698 1773
 
1699 1774
 	// init
1700 1775
 	$drafts = array();
@@ -1712,8 +1787,9 @@  discard block
 block discarded – undo
1712 1787
 		)
1713 1788
 	);
1714 1789
 
1715
-	while ($row = $smcFunc['db_fetch_row']($request))
1716
-		$drafts[] = (int) $row[0];
1790
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1791
+			$drafts[] = (int) $row[0];
1792
+	}
1717 1793
 	$smcFunc['db_free_result']($request);
1718 1794
 
1719 1795
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +215 added lines, -157 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
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -157,8 +159,9 @@  discard block
 block discarded – undo
157 159
 	while ($row = $smcFunc['db_fetch_assoc']($result))
158 160
 	{
159 161
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
160
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
161
-			continue;
162
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
163
+					continue;
164
+		}
162 165
 
163 166
 		// Force a censor of the title - as often these are used by others.
164 167
 		censorText($row['title'], $use_permissions ? false : true);
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
168 171
 
169 172
 		// Sanity check
170
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
171
-			continue;
173
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
174
+					continue;
175
+		}
172 176
 
173 177
 		// Get set up for the loop
174 178
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -232,8 +236,8 @@  discard block
 block discarded – undo
232 236
 			);
233 237
 
234 238
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
235
-			if ($use_permissions)
236
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
239
+			if ($use_permissions) {
240
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
237 241
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
238 242
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
239 243
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -241,9 +245,10 @@  discard block
 block discarded – undo
241 245
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
242 246
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
243 247
 				));
248
+			}
244 249
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
245
-			else
246
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
250
+			else {
251
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
247 252
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
248 253
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
249 254
 					'can_edit' => false,
@@ -253,6 +258,7 @@  discard block
 block discarded – undo
253 258
 					'poster' => $row['id_member'],
254 259
 					'allowed_groups' => explode(',', $row['member_groups']),
255 260
 				));
261
+			}
256 262
 
257 263
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
258 264
 		}
@@ -262,8 +268,9 @@  discard block
 block discarded – undo
262 268
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
263 269
 	if ($use_permissions)
264 270
 	{
265
-		foreach ($events as $mday => $array)
266
-			$events[$mday][count($array) - 1]['is_last'] = true;
271
+		foreach ($events as $mday => $array) {
272
+					$events[$mday][count($array) - 1]['is_last'] = true;
273
+		}
267 274
 	}
268 275
 
269 276
 	ksort($events);
@@ -283,11 +290,12 @@  discard block
 block discarded – undo
283 290
 	global $smcFunc;
284 291
 
285 292
 	// Get the lowest and highest dates for "all years".
286
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
287
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
293
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
294
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
288 295
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
289
-	else
290
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
296
+	} else {
297
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
298
+	}
291 299
 
292 300
 	// Find some holidays... ;).
293 301
 	$result = $smcFunc['db_query']('', '
@@ -307,10 +315,11 @@  discard block
 block discarded – undo
307 315
 	$holidays = array();
308 316
 	while ($row = $smcFunc['db_fetch_assoc']($result))
309 317
 	{
310
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
311
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
312
-		else
313
-			$event_year = substr($low_date, 0, 4);
318
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
319
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
320
+		} else {
321
+					$event_year = substr($low_date, 0, 4);
322
+		}
314 323
 
315 324
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
316 325
 	}
@@ -336,10 +345,12 @@  discard block
 block discarded – undo
336 345
 	isAllowedTo('calendar_post');
337 346
 
338 347
 	// No board?  No topic?!?
339
-	if (empty($board))
340
-		fatal_lang_error('missing_board_id', false);
341
-	if (empty($topic))
342
-		fatal_lang_error('missing_topic_id', false);
348
+	if (empty($board)) {
349
+			fatal_lang_error('missing_board_id', false);
350
+	}
351
+	if (empty($topic)) {
352
+			fatal_lang_error('missing_topic_id', false);
353
+	}
343 354
 
344 355
 	// Administrator, Moderator, or owner.  Period.
345 356
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -357,12 +368,14 @@  discard block
 block discarded – undo
357 368
 		if ($row = $smcFunc['db_fetch_assoc']($result))
358 369
 		{
359 370
 			// Not the owner of the topic.
360
-			if ($row['id_member_started'] != $user_info['id'])
361
-				fatal_lang_error('not_your_topic', 'user');
371
+			if ($row['id_member_started'] != $user_info['id']) {
372
+							fatal_lang_error('not_your_topic', 'user');
373
+			}
362 374
 		}
363 375
 		// Topic/Board doesn't exist.....
364
-		else
365
-			fatal_lang_error('calendar_no_topic', 'general');
376
+		else {
377
+					fatal_lang_error('calendar_no_topic', 'general');
378
+		}
366 379
 		$smcFunc['db_free_result']($result);
367 380
 	}
368 381
 }
@@ -450,14 +463,16 @@  discard block
 block discarded – undo
450 463
 	if (!empty($calendarOptions['start_day']))
451 464
 	{
452 465
 		$nShift -= $calendarOptions['start_day'];
453
-		if ($nShift < 0)
454
-			$nShift = 7 + $nShift;
466
+		if ($nShift < 0) {
467
+					$nShift = 7 + $nShift;
468
+		}
455 469
 	}
456 470
 
457 471
 	// Number of rows required to fit the month.
458 472
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
459
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
460
-		$nRows++;
473
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
474
+			$nRows++;
475
+	}
461 476
 
462 477
 	// Fetch the arrays for birthdays, posted events, and holidays.
463 478
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -470,8 +485,9 @@  discard block
 block discarded – undo
470 485
 	{
471 486
 		$calendarGrid['week_days'][] = $count;
472 487
 		$count++;
473
-		if ($count == 7)
474
-			$count = 0;
488
+		if ($count == 7) {
489
+					$count = 0;
490
+		}
475 491
 	}
476 492
 
477 493
 	// Iterate through each week.
@@ -488,8 +504,9 @@  discard block
 block discarded – undo
488 504
 		{
489 505
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
490 506
 
491
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
492
-				$nDay = 0;
507
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
508
+							$nDay = 0;
509
+			}
493 510
 
494 511
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
495 512
 
@@ -507,8 +524,9 @@  discard block
 block discarded – undo
507 524
 	}
508 525
 
509 526
 	// What is the last day of the month?
510
-	if ($is_previous === true)
511
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
527
+	if ($is_previous === true) {
528
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
529
+	}
512 530
 
513 531
 	// We'll use the shift in the template.
514 532
 	$calendarGrid['shift'] = $nShift;
@@ -542,8 +560,9 @@  discard block
 block discarded – undo
542 560
 	{
543 561
 		// Here we offset accordingly to get things to the real start of a week.
544 562
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
545
-		if ($date_diff < 0)
546
-			$date_diff += 7;
563
+		if ($date_diff < 0) {
564
+					$date_diff += 7;
565
+		}
547 566
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
548 567
 		$day = (int) strftime('%d', $new_timestamp);
549 568
 		$month = (int) strftime('%m', $new_timestamp);
@@ -673,18 +692,20 @@  discard block
 block discarded – undo
673 692
 	{
674 693
 		foreach ($date_events as $event_key => $event_val)
675 694
 		{
676
-			if (in_array($event_val['id'], $temp))
677
-				unset($calendarGrid['events'][$date][$event_key]);
678
-			else
679
-				$temp[] = $event_val['id'];
695
+			if (in_array($event_val['id'], $temp)) {
696
+							unset($calendarGrid['events'][$date][$event_key]);
697
+			} else {
698
+							$temp[] = $event_val['id'];
699
+			}
680 700
 		}
681 701
 	}
682 702
 
683 703
 	// Give birthdays and holidays a friendly format, without the year
684
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
685
-		$date_format = '%b %d';
686
-	else
687
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
704
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
705
+			$date_format = '%b %d';
706
+	} else {
707
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
708
+	}
688 709
 
689 710
 	foreach (array('birthdays', 'holidays') as $type)
690 711
 	{
@@ -779,8 +800,9 @@  discard block
 block discarded – undo
779 800
 	// Holidays between now and now + days.
780 801
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
781 802
 	{
782
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
783
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
803
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
804
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
805
+		}
784 806
 	}
785 807
 
786 808
 	// Happy Birthday, guys and gals!
@@ -789,8 +811,9 @@  discard block
 block discarded – undo
789 811
 		$loop_date = strftime('%Y-%m-%d', $i);
790 812
 		if (isset($cached_data['birthdays'][$loop_date]))
791 813
 		{
792
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
793
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
814
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
815
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
816
+			}
794 817
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
795 818
 		}
796 819
 	}
@@ -802,8 +825,9 @@  discard block
 block discarded – undo
802 825
 		$loop_date = strftime('%Y-%m-%d', $i);
803 826
 
804 827
 		// No events today? Check the next day.
805
-		if (empty($cached_data['events'][$loop_date]))
806
-			continue;
828
+		if (empty($cached_data['events'][$loop_date])) {
829
+					continue;
830
+		}
807 831
 
808 832
 		// Loop through all events to add a few last-minute values.
809 833
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -816,9 +840,9 @@  discard block
 block discarded – undo
816 840
 			{
817 841
 				unset($cached_data['events'][$loop_date][$ev]);
818 842
 				continue;
843
+			} else {
844
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
819 845
 			}
820
-			else
821
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
822 846
 
823 847
 			// Might be set to true afterwards, depending on the permissions.
824 848
 			$this_event['can_edit'] = false;
@@ -826,15 +850,18 @@  discard block
 block discarded – undo
826 850
 			$this_event['date'] = $loop_date;
827 851
 		}
828 852
 
829
-		if (!empty($cached_data['events'][$loop_date]))
830
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
853
+		if (!empty($cached_data['events'][$loop_date])) {
854
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
855
+		}
831 856
 	}
832 857
 
833 858
 	// Mark the last item so that a list separator can be used in the template.
834
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
835
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
836
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
837
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
859
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
860
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
861
+	}
862
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
863
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
864
+	}
838 865
 
839 866
 	return array(
840 867
 		'data' => $return_data,
@@ -882,37 +909,46 @@  discard block
 block discarded – undo
882 909
 		if (isset($_POST['start_date']))
883 910
 		{
884 911
 			$d = date_parse($_POST['start_date']);
885
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
886
-				fatal_lang_error('invalid_date', false);
887
-			if (empty($d['year']))
888
-				fatal_lang_error('event_year_missing', false);
889
-			if (empty($d['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-		}
892
-		elseif (isset($_POST['start_datetime']))
912
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
913
+							fatal_lang_error('invalid_date', false);
914
+			}
915
+			if (empty($d['year'])) {
916
+							fatal_lang_error('event_year_missing', false);
917
+			}
918
+			if (empty($d['month'])) {
919
+							fatal_lang_error('event_month_missing', false);
920
+			}
921
+		} elseif (isset($_POST['start_datetime']))
893 922
 		{
894 923
 			$d = date_parse($_POST['start_datetime']);
895
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
896
-				fatal_lang_error('invalid_date', false);
897
-			if (empty($d['year']))
898
-				fatal_lang_error('event_year_missing', false);
899
-			if (empty($d['month']))
900
-				fatal_lang_error('event_month_missing', false);
924
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
925
+							fatal_lang_error('invalid_date', false);
926
+			}
927
+			if (empty($d['year'])) {
928
+							fatal_lang_error('event_year_missing', false);
929
+			}
930
+			if (empty($d['month'])) {
931
+							fatal_lang_error('event_month_missing', false);
932
+			}
901 933
 		}
902 934
 		// The 2.0 way
903 935
 		else
904 936
 		{
905 937
 			// No month?  No year?
906
-			if (!isset($_POST['month']))
907
-				fatal_lang_error('event_month_missing', false);
908
-			if (!isset($_POST['year']))
909
-				fatal_lang_error('event_year_missing', false);
938
+			if (!isset($_POST['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+			if (!isset($_POST['year'])) {
942
+							fatal_lang_error('event_year_missing', false);
943
+			}
910 944
 
911 945
 			// Check the month and year...
912
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
913
-				fatal_lang_error('invalid_month', false);
914
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
915
-				fatal_lang_error('invalid_year', false);
946
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
947
+							fatal_lang_error('invalid_month', false);
948
+			}
949
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
950
+							fatal_lang_error('invalid_year', false);
951
+			}
916 952
 		}
917 953
 	}
918 954
 
@@ -922,8 +958,9 @@  discard block
 block discarded – undo
922 958
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
923 959
 	if (isset($_POST['span']))
924 960
 	{
925
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
926
-			fatal_lang_error('invalid_days_numb', false);
961
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
962
+					fatal_lang_error('invalid_days_numb', false);
963
+		}
927 964
 	}
928 965
 
929 966
 	// There is no need to validate the following values if we are just deleting the event.
@@ -933,24 +970,29 @@  discard block
 block discarded – undo
933 970
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
934 971
 		{
935 972
 			// No day?
936
-			if (!isset($_POST['day']))
937
-				fatal_lang_error('event_day_missing', false);
973
+			if (!isset($_POST['day'])) {
974
+							fatal_lang_error('event_day_missing', false);
975
+			}
938 976
 
939 977
 			// Bad day?
940
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
941
-				fatal_lang_error('invalid_date', false);
978
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
979
+							fatal_lang_error('invalid_date', false);
980
+			}
942 981
 		}
943 982
 
944
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
945
-			fatal_lang_error('event_title_missing', false);
946
-		elseif (!isset($_POST['evtitle']))
947
-			$_POST['evtitle'] = $_POST['subject'];
983
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
984
+					fatal_lang_error('event_title_missing', false);
985
+		} elseif (!isset($_POST['evtitle'])) {
986
+					$_POST['evtitle'] = $_POST['subject'];
987
+		}
948 988
 
949 989
 		// No title?
950
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
951
-			fatal_lang_error('no_event_title', false);
952
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
953
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
990
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
991
+					fatal_lang_error('no_event_title', false);
992
+		}
993
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
994
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
995
+		}
954 996
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
955 997
 	}
956 998
 }
@@ -977,8 +1019,9 @@  discard block
 block discarded – undo
977 1019
 	);
978 1020
 
979 1021
 	// No results, return false.
980
-	if ($smcFunc['db_num_rows'] === 0)
981
-		return false;
1022
+	if ($smcFunc['db_num_rows'] === 0) {
1023
+			return false;
1024
+	}
982 1025
 
983 1026
 	// Grab the results and return.
984 1027
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1112,8 +1155,9 @@  discard block
 block discarded – undo
1112 1155
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1113 1156
 
1114 1157
 	$column_clauses = array();
1115
-	foreach ($event_columns as $col => $crit)
1116
-		$column_clauses[] = $col . ' = ' . $crit;
1158
+	foreach ($event_columns as $col => $crit) {
1159
+			$column_clauses[] = $col . ' = ' . $crit;
1160
+	}
1117 1161
 
1118 1162
 	$smcFunc['db_query']('', '
1119 1163
 		UPDATE {db_prefix}calendar
@@ -1198,8 +1242,9 @@  discard block
 block discarded – undo
1198 1242
 	);
1199 1243
 
1200 1244
 	// If nothing returned, we are in poo, poo.
1201
-	if ($smcFunc['db_num_rows']($request) === 0)
1202
-		return false;
1245
+	if ($smcFunc['db_num_rows']($request) === 0) {
1246
+			return false;
1247
+	}
1203 1248
 
1204 1249
 	$row = $smcFunc['db_fetch_assoc']($request);
1205 1250
 	$smcFunc['db_free_result']($request);
@@ -1207,8 +1252,9 @@  discard block
 block discarded – undo
1207 1252
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1208 1253
 
1209 1254
 	// Sanity check
1210
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1211
-		return false;
1255
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1256
+			return false;
1257
+	}
1212 1258
 
1213 1259
 	$return_value = array(
1214 1260
 		'boards' => array(),
@@ -1345,24 +1391,27 @@  discard block
 block discarded – undo
1345 1391
 
1346 1392
 	// Set $span, in case we need it
1347 1393
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1348
-	if ($span > 0)
1349
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1394
+	if ($span > 0) {
1395
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1396
+	}
1350 1397
 
1351 1398
 	// Define the timezone for this event, falling back to the default if not provided
1352
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1353
-		$tz = $eventOptions['tz'];
1354
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1355
-		$tz = $_POST['tz'];
1356
-	else
1357
-		$tz = getUserTimezone();
1399
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1400
+			$tz = $eventOptions['tz'];
1401
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1402
+			$tz = $_POST['tz'];
1403
+	} else {
1404
+			$tz = getUserTimezone();
1405
+	}
1358 1406
 
1359 1407
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1360
-	if (isset($eventOptions['allday']))
1361
-		$allday = $eventOptions['allday'];
1362
-	elseif (empty($_POST['allday']))
1363
-		$allday = false;
1364
-	else
1365
-		$allday = true;
1408
+	if (isset($eventOptions['allday'])) {
1409
+			$allday = $eventOptions['allday'];
1410
+	} elseif (empty($_POST['allday'])) {
1411
+			$allday = false;
1412
+	} else {
1413
+			$allday = true;
1414
+	}
1366 1415
 
1367 1416
 	// Input might come as individual parameters...
1368 1417
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1389,10 +1438,12 @@  discard block
 block discarded – undo
1389 1438
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1390 1439
 
1391 1440
 	// If the date and time were given in separate strings, combine them
1392
-	if (empty($start_string) && isset($start_date_string))
1393
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1394
-	if (empty($end_string) && isset($end_date_string))
1395
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1441
+	if (empty($start_string) && isset($start_date_string)) {
1442
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1443
+	}
1444
+	if (empty($end_string) && isset($end_date_string)) {
1445
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1446
+	}
1396 1447
 
1397 1448
 	// If some form of string input was given, override individually defined options with it
1398 1449
 	if (isset($start_string))
@@ -1483,10 +1534,11 @@  discard block
 block discarded – undo
1483 1534
 	if ($start_object >= $end_object)
1484 1535
 	{
1485 1536
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1486
-		if ($span > 0)
1487
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1488
-		else
1489
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1537
+		if ($span > 0) {
1538
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1539
+		} else {
1540
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1541
+		}
1490 1542
 	}
1491 1543
 
1492 1544
 	// Is $end_object too late?
@@ -1499,9 +1551,9 @@  discard block
 block discarded – undo
1499 1551
 			{
1500 1552
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1501 1553
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1554
+			} else {
1555
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1502 1556
 			}
1503
-			else
1504
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1505 1557
 		}
1506 1558
 	}
1507 1559
 
@@ -1514,8 +1566,7 @@  discard block
 block discarded – undo
1514 1566
 		$start_time = null;
1515 1567
 		$end_time = null;
1516 1568
 		$tz = null;
1517
-	}
1518
-	else
1569
+	} else
1519 1570
 	{
1520 1571
 		$start_time = date_format($start_object, 'H:i:s');
1521 1572
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1536,16 +1587,18 @@  discard block
 block discarded – undo
1536 1587
 	require_once($sourcedir . '/Subs.php');
1537 1588
 
1538 1589
 	// First, try to create a better date format, ignoring the "time" elements.
1539
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1540
-		$date_format = '%F';
1541
-	else
1542
-		$date_format = $matches[0];
1590
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1591
+			$date_format = '%F';
1592
+	} else {
1593
+			$date_format = $matches[0];
1594
+	}
1543 1595
 
1544 1596
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1545
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1546
-		$time_format = '%k:%M';
1547
-	else
1548
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1597
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1598
+			$time_format = '%k:%M';
1599
+	} else {
1600
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1601
+	}
1549 1602
 
1550 1603
 	// Should this be an all day event?
1551 1604
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
@@ -1554,8 +1607,9 @@  discard block
 block discarded – undo
1554 1607
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1555 1608
 
1556 1609
 	// We need to have a defined timezone in the steps below
1557
-	if (empty($row['timezone']))
1558
-		$row['timezone'] = getUserTimezone();
1610
+	if (empty($row['timezone'])) {
1611
+			$row['timezone'] = getUserTimezone();
1612
+	}
1559 1613
 
1560 1614
 	// Get most of the standard date information for the start and end datetimes
1561 1615
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1607,8 +1661,9 @@  discard block
 block discarded – undo
1607 1661
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1608 1662
 	static $member_cache = array();
1609 1663
 
1610
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1611
-		$id_member = $context['user']['id'];
1664
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1665
+			$id_member = $context['user']['id'];
1666
+	}
1612 1667
 
1613 1668
 	//check if the cache got the data
1614 1669
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1637,11 +1692,13 @@  discard block
 block discarded – undo
1637 1692
 		$smcFunc['db_free_result']($request);
1638 1693
 	}
1639 1694
 
1640
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1641
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1695
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1696
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1697
+	}
1642 1698
 
1643
-	if (isset($id_member))
1644
-		$member_cache[$id_member] = $timezone;
1699
+	if (isset($id_member)) {
1700
+			$member_cache[$id_member] = $timezone;
1701
+	}
1645 1702
 
1646 1703
 	return $timezone;
1647 1704
 }
@@ -1670,8 +1727,9 @@  discard block
 block discarded – undo
1670 1727
 		)
1671 1728
 	);
1672 1729
 	$holidays = array();
1673
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-		$holidays[] = $row;
1730
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1731
+			$holidays[] = $row;
1732
+	}
1675 1733
 	$smcFunc['db_free_result']($request);
1676 1734
 
1677 1735
 	return $holidays;
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1321 added lines, -983 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,20 +572,25 @@  discard block
 block discarded – undo
555 572
 	$start = (int) $start;
556 573
 	$start_invalid = $start < 0;
557 574
 	
558
-	if (!empty($options['low_id']))
559
-		$low_id = $options['low_id'];
560
-	if (!empty($options['max_id']))
561
-		$max_id = $options['max_id'];
575
+	if (!empty($options['low_id'])) {
576
+			$low_id = $options['low_id'];
577
+	}
578
+	if (!empty($options['max_id'])) {
579
+			$max_id = $options['max_id'];
580
+	}
562 581
 
563 582
 	// Make sure $start is a proper variable - not less than 0.
564
-	if ($start_invalid)
565
-		$start = 0;
583
+	if ($start_invalid) {
584
+			$start = 0;
585
+	}
566 586
 	// Not greater than the upper bound.
567
-	elseif ($start >= $max_value)
568
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
587
+	elseif ($start >= $max_value) {
588
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
589
+	}
569 590
 	// And it has to be a multiple of $num_per_page!
570
-	else
571
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
591
+	else {
592
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
593
+	}
572 594
 
573 595
 	$context['current_page'] = $start / $num_per_page;
574 596
 
@@ -596,101 +618,115 @@  discard block
 block discarded – undo
596 618
 	if (empty($modSettings['compactTopicPagesEnable']))
597 619
 	{
598 620
 		// Show the left arrow.
599
-		if (empty($low_id))
600
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
601
-		else
602
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
621
+		if (empty($low_id)) {
622
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
623
+		} else {
624
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
625
+		}
603 626
 		
604 627
 		// Show all the pages.
605 628
 		$display_page = 1;
606
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
607
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
629
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
630
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		}
608 632
 
609 633
 		// Show the right arrow.
610 634
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
611 635
 		if ($start != $counter - $max_value && !$start_invalid){
612
-			if (empty($max_id))
613
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
614
-			else
615
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
636
+			if (empty($max_id)) {
637
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
638
+			} else {
639
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
640
+			}
616 641
 		}
617 642
 			
618
-	}
619
-	else
643
+	} else
620 644
 	{
621 645
 		// If they didn't enter an odd value, pretend they did.
622 646
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
623 647
 
624 648
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
625
-		if (!empty($start) && $show_prevnext)
626
-			if (empty($low_id))
649
+		if (!empty($start) && $show_prevnext) {
650
+					if (empty($low_id))
627 651
 				$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-			else
629
-				$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
630
-		else
631
-			$pageindex .= '';
652
+		} else {
653
+							$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
654
+			}
655
+		else {
656
+					$pageindex .= '';
657
+		}
632 658
 
633 659
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
634
-		if ($start > $num_per_page * $PageContiguous)
635
-			$pageindex .= sprintf($base_link, 0, '1');
660
+		if ($start > $num_per_page * $PageContiguous) {
661
+					$pageindex .= sprintf($base_link, 0, '1');
662
+		}
636 663
 
637 664
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
638
-		if ($start > $num_per_page * ($PageContiguous + 1))
639
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
665
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
666
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
640 667
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
641 668
 				'{FIRST_PAGE}' => $num_per_page,
642 669
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
643 670
 				'{PER_PAGE}' => $num_per_page,
644 671
 			));
672
+		}
645 673
 
646 674
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
647
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
648
-			if ($start >= $num_per_page * $nCont)
675
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
676
+					if ($start >= $num_per_page * $nCont)
649 677
 			{
650 678
 				$tmpStart = $start - $num_per_page * $nCont;
651
-				if($nCont != 1 || empty($low_id))
652
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
653
-				else
654
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
679
+		}
680
+				if($nCont != 1 || empty($low_id)) {
681
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
682
+				} else {
683
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
684
+				}
655 685
 			}
656 686
 
657 687
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
688
+		if (!$start_invalid) {
689
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
690
+		} else {
691
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
692
+		}
662 693
 
663 694
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 695
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
696
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
697
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 698
 			{
668 699
 				$tmpStart = $start + $num_per_page * $nCont;
669
-				if($nCont != 1 || empty($max_id))
670
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
671
-				else
672
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
700
+		}
701
+				if($nCont != 1 || empty($max_id)) {
702
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
703
+				} else {
704
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
705
+				}
673 706
 			}
674 707
 
675 708
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
676
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
677
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
709
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
710
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678 711
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
679 712
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
680 713
 				'{LAST_PAGE}' => $tmpMaxPages,
681 714
 				'{PER_PAGE}' => $num_per_page,
682 715
 			));
716
+		}
683 717
 
684 718
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
685
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
686
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
719
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
720
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
721
+		}
687 722
 
688 723
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
689
-		if ($start != $tmpMaxPages && $show_prevnext)
690
-			if (empty($max_id))
724
+		if ($start != $tmpMaxPages && $show_prevnext) {
725
+					if (empty($max_id))
691 726
 				$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
692
-			else
693
-				$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
727
+		} else {
728
+							$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
729
+			}
694 730
 	}
695 731
 	$pageindex .= $settings['page_index']['extra_after'];
696 732
 
@@ -716,8 +752,9 @@  discard block
 block discarded – undo
716 752
 	if ($decimal_separator === null)
717 753
 	{
718 754
 		// Not set for whatever reason?
719
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
720
-			return $number;
755
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
756
+					return $number;
757
+		}
721 758
 
722 759
 		// Cache these each load...
723 760
 		$thousands_separator = $matches[1];
@@ -751,17 +788,20 @@  discard block
 block discarded – undo
751 788
 	static $local_cache;
752 789
 
753 790
 	// Offset the time.
754
-	if (!$offset_type)
755
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
791
+	if (!$offset_type) {
792
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
793
+	}
756 794
 	// Just the forum offset?
757
-	elseif ($offset_type == 'forum')
758
-		$time = $log_time + $modSettings['time_offset'] * 3600;
759
-	else
760
-		$time = $log_time;
795
+	elseif ($offset_type == 'forum') {
796
+			$time = $log_time + $modSettings['time_offset'] * 3600;
797
+	} else {
798
+			$time = $log_time;
799
+	}
761 800
 
762 801
 	// We can't have a negative date (on Windows, at least.)
763
-	if ($log_time < 0)
764
-		$log_time = 0;
802
+	if ($log_time < 0) {
803
+			$log_time = 0;
804
+	}
765 805
 
766 806
 	// Today and Yesterday?
767 807
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -778,56 +818,65 @@  discard block
 block discarded – undo
778 818
 		{
779 819
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
780 820
 			$today_fmt = $h . ':%M' . $s . ' %p';
821
+		} else {
822
+					$today_fmt = '%H:%M' . $s;
781 823
 		}
782
-		else
783
-			$today_fmt = '%H:%M' . $s;
784 824
 
785 825
 		// Same day of the year, same year.... Today!
786
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
787
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
826
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
827
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
828
+		}
788 829
 
789 830
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
790
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
791
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
831
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
832
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
833
+		}
792 834
 	}
793 835
 
794 836
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
795 837
 
796
-	if (!isset($local_cache))
797
-		$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
838
+	if (!isset($local_cache)) {
839
+			$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
840
+	}
798 841
 
799 842
 	if ($local_cache !== false)
800 843
 	{
801 844
 		//check if other process change the local
802 845
 		if ($process_safe === true)
803 846
 		{
804
-			if (setlocale(LC_TIME, '0') != $local_cache)
805
-				setlocale(LC_TIME, $txt['lang_locale']);
847
+			if (setlocale(LC_TIME, '0') != $local_cache) {
848
+							setlocale(LC_TIME, $txt['lang_locale']);
849
+			}
806 850
 		}
807 851
 
808
-		if (!isset($non_twelve_hour))
809
-			$non_twelve_hour = trim(strftime('%p')) === '';
810
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
811
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
852
+		if (!isset($non_twelve_hour)) {
853
+					$non_twelve_hour = trim(strftime('%p')) === '';
854
+		}
855
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
856
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
857
+		}
812 858
 
813
-		foreach (array('%a', '%A', '%b', '%B') as $token)
814
-			if (strpos($str, $token) !== false)
859
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
860
+					if (strpos($str, $token) !== false)
815 861
 				$str = str_replace($token, strftime($token, $time), $str);
816
-	}
817
-	else
862
+		}
863
+	} else
818 864
 	{
819 865
 		// Do-it-yourself time localization.  Fun.
820
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
821
-			if (strpos($str, $token) !== false)
866
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
867
+					if (strpos($str, $token) !== false)
822 868
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
869
+		}
823 870
 
824
-		if (strpos($str, '%p') !== false)
825
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
871
+		if (strpos($str, '%p') !== false) {
872
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
873
+		}
826 874
 	}
827 875
 
828 876
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
829
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
830
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
877
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
878
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
879
+	}
831 880
 
832 881
 	// Format any other characters..
833 882
 	return strftime($str, $time);
@@ -849,16 +898,19 @@  discard block
 block discarded – undo
849 898
 	static $translation = array();
850 899
 
851 900
 	// Determine the character set... Default to UTF-8
852
-	if (empty($context['character_set']))
853
-		$charset = 'UTF-8';
901
+	if (empty($context['character_set'])) {
902
+			$charset = 'UTF-8';
903
+	}
854 904
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
855
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
856
-		$charset = 'ISO-8859-1';
857
-	else
858
-		$charset = $context['character_set'];
905
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
906
+			$charset = 'ISO-8859-1';
907
+	} else {
908
+			$charset = $context['character_set'];
909
+	}
859 910
 
860
-	if (empty($translation))
861
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
911
+	if (empty($translation)) {
912
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
913
+	}
862 914
 
863 915
 	return strtr($string, $translation);
864 916
 }
@@ -880,8 +932,9 @@  discard block
 block discarded – undo
880 932
 	global $smcFunc;
881 933
 
882 934
 	// It was already short enough!
883
-	if ($smcFunc['strlen']($subject) <= $len)
884
-		return $subject;
935
+	if ($smcFunc['strlen']($subject) <= $len) {
936
+			return $subject;
937
+	}
885 938
 
886 939
 	// Shorten it by the length it was too long, and strip off junk from the end.
887 940
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -900,10 +953,11 @@  discard block
 block discarded – undo
900 953
 {
901 954
 	global $user_info, $modSettings;
902 955
 
903
-	if ($timestamp === null)
904
-		$timestamp = time();
905
-	elseif ($timestamp == 0)
906
-		return 0;
956
+	if ($timestamp === null) {
957
+			$timestamp = time();
958
+	} elseif ($timestamp == 0) {
959
+			return 0;
960
+	}
907 961
 
908 962
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
909 963
 }
@@ -932,8 +986,9 @@  discard block
 block discarded – undo
932 986
 		$array[$i] = $array[$j];
933 987
 		$array[$j] = $temp;
934 988
 
935
-		for ($i = 1; $p[$i] == 0; $i++)
936
-			$p[$i] = 1;
989
+		for ($i = 1; $p[$i] == 0; $i++) {
990
+					$p[$i] = 1;
991
+		}
937 992
 
938 993
 		$orders[] = $array;
939 994
 	}
@@ -965,12 +1020,14 @@  discard block
 block discarded – undo
965 1020
 	static $disabled;
966 1021
 
967 1022
 	// Don't waste cycles
968
-	if ($message === '')
969
-		return '';
1023
+	if ($message === '') {
1024
+			return '';
1025
+	}
970 1026
 
971 1027
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
972
-	if (!isset($context['utf8']))
973
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1028
+	if (!isset($context['utf8'])) {
1029
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1030
+	}
974 1031
 
975 1032
 	// Clean up any cut/paste issues we may have
976 1033
 	$message = sanitizeMSCutPaste($message);
@@ -982,13 +1039,15 @@  discard block
 block discarded – undo
982 1039
 		return $message;
983 1040
 	}
984 1041
 
985
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
986
-		$smileys = (bool) $smileys;
1042
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1043
+			$smileys = (bool) $smileys;
1044
+	}
987 1045
 
988 1046
 	if (empty($modSettings['enableBBC']) && $message !== false)
989 1047
 	{
990
-		if ($smileys === true)
991
-			parsesmileys($message);
1048
+		if ($smileys === true) {
1049
+					parsesmileys($message);
1050
+		}
992 1051
 
993 1052
 		return $message;
994 1053
 	}
@@ -1001,8 +1060,9 @@  discard block
 block discarded – undo
1001 1060
 	}
1002 1061
 
1003 1062
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1004
-	if (!empty($modSettings['autoLinkUrls']))
1005
-		set_tld_regex();
1063
+	if (!empty($modSettings['autoLinkUrls'])) {
1064
+			set_tld_regex();
1065
+	}
1006 1066
 
1007 1067
 	// Allow mods access before entering the main parse_bbc loop
1008 1068
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1016,12 +1076,14 @@  discard block
 block discarded – undo
1016 1076
 
1017 1077
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1018 1078
 
1019
-			foreach ($temp as $tag)
1020
-				$disabled[trim($tag)] = true;
1079
+			foreach ($temp as $tag) {
1080
+							$disabled[trim($tag)] = true;
1081
+			}
1021 1082
 		}
1022 1083
 
1023
-		if (empty($modSettings['enableEmbeddedFlash']))
1024
-			$disabled['flash'] = true;
1084
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1085
+					$disabled['flash'] = true;
1086
+		}
1025 1087
 
1026 1088
 		/* The following bbc are formatted as an array, with keys as follows:
1027 1089
 
@@ -1142,8 +1204,9 @@  discard block
 block discarded – undo
1142 1204
 					$returnContext = '';
1143 1205
 
1144 1206
 					// BBC or the entire attachments feature is disabled
1145
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1146
-						return $data;
1207
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1208
+											return $data;
1209
+					}
1147 1210
 
1148 1211
 					// Save the attach ID.
1149 1212
 					$attachID = $data;
@@ -1154,8 +1217,9 @@  discard block
 block discarded – undo
1154 1217
 					$currentAttachment = parseAttachBBC($attachID);
1155 1218
 
1156 1219
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1157
-					if (is_string($currentAttachment))
1158
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1220
+					if (is_string($currentAttachment)) {
1221
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1222
+					}
1159 1223
 
1160 1224
 					if (!empty($currentAttachment['is_image']))
1161 1225
 					{
@@ -1171,15 +1235,17 @@  discard block
 block discarded – undo
1171 1235
 							$height = ' height="' . $currentAttachment['height'] . '"';
1172 1236
 						}
1173 1237
 
1174
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1175
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1176
-						else
1177
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1238
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1239
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1240
+						} else {
1241
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1242
+						}
1178 1243
 					}
1179 1244
 
1180 1245
 					// No image. Show a link.
1181
-					else
1182
-						$returnContext .= $currentAttachment['link'];
1246
+					else {
1247
+											$returnContext .= $currentAttachment['link'];
1248
+					}
1183 1249
 
1184 1250
 					// Gotta append what we just did.
1185 1251
 					$data = $returnContext;
@@ -1210,8 +1276,9 @@  discard block
 block discarded – undo
1210 1276
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1211 1277
 						{
1212 1278
 							// Do PHP code coloring?
1213
-							if ($php_parts[$php_i] != '&lt;?php')
1214
-								continue;
1279
+							if ($php_parts[$php_i] != '&lt;?php') {
1280
+															continue;
1281
+							}
1215 1282
 
1216 1283
 							$php_string = '';
1217 1284
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1227,8 +1294,9 @@  discard block
 block discarded – undo
1227 1294
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1228 1295
 
1229 1296
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1230
-						if ($context['browser']['is_opera'])
1231
-							$data .= '&nbsp;';
1297
+						if ($context['browser']['is_opera']) {
1298
+													$data .= '&nbsp;';
1299
+						}
1232 1300
 					}
1233 1301
 				},
1234 1302
 				'block_level' => true,
@@ -1247,8 +1315,9 @@  discard block
 block discarded – undo
1247 1315
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1248 1316
 						{
1249 1317
 							// Do PHP code coloring?
1250
-							if ($php_parts[$php_i] != '&lt;?php')
1251
-								continue;
1318
+							if ($php_parts[$php_i] != '&lt;?php') {
1319
+															continue;
1320
+							}
1252 1321
 
1253 1322
 							$php_string = '';
1254 1323
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1264,8 +1333,9 @@  discard block
 block discarded – undo
1264 1333
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1265 1334
 
1266 1335
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1267
-						if ($context['browser']['is_opera'])
1268
-							$data[0] .= '&nbsp;';
1336
+						if ($context['browser']['is_opera']) {
1337
+													$data[0] .= '&nbsp;';
1338
+						}
1269 1339
 					}
1270 1340
 				},
1271 1341
 				'block_level' => true,
@@ -1303,11 +1373,13 @@  discard block
 block discarded – undo
1303 1373
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1304 1374
 				'validate' => function (&$tag, &$data, $disabled)
1305 1375
 				{
1306
-					if (isset($disabled['url']))
1307
-						$tag['content'] = '$1';
1376
+					if (isset($disabled['url'])) {
1377
+											$tag['content'] = '$1';
1378
+					}
1308 1379
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1309
-					if (empty($scheme))
1310
-						$data[0] = '//' . ltrim($data[0], ':/');
1380
+					if (empty($scheme)) {
1381
+											$data[0] = '//' . ltrim($data[0], ':/');
1382
+					}
1311 1383
 				},
1312 1384
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1313 1385
 			),
@@ -1321,10 +1393,11 @@  discard block
 block discarded – undo
1321 1393
 				{
1322 1394
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1323 1395
 
1324
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1325
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1326
-					else
1327
-						$css = '';
1396
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1397
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1398
+					} else {
1399
+											$css = '';
1400
+					}
1328 1401
 
1329 1402
 					$data = $class . $css;
1330 1403
 				},
@@ -1374,14 +1447,16 @@  discard block
 block discarded – undo
1374 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1375 1448
 					if ($image_proxy_enabled)
1376 1449
 					{
1377
-						if (empty($scheme))
1378
-							$data = 'http://' . ltrim($data, ':/');
1450
+						if (empty($scheme)) {
1451
+													$data = 'http://' . ltrim($data, ':/');
1452
+						}
1379 1453
 
1380
-						if ($scheme != 'https')
1381
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1454
+						if ($scheme != 'https') {
1455
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1456
+						}
1457
+					} elseif (empty($scheme)) {
1458
+											$data = '//' . ltrim($data, ':/');
1382 1459
 					}
1383
-					elseif (empty($scheme))
1384
-						$data = '//' . ltrim($data, ':/');
1385 1460
 				},
1386 1461
 				'disabled_content' => '($1)',
1387 1462
 			),
@@ -1397,14 +1472,16 @@  discard block
 block discarded – undo
1397 1472
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1398 1473
 					if ($image_proxy_enabled)
1399 1474
 					{
1400
-						if (empty($scheme))
1401
-							$data = 'http://' . ltrim($data, ':/');
1475
+						if (empty($scheme)) {
1476
+													$data = 'http://' . ltrim($data, ':/');
1477
+						}
1402 1478
 
1403
-						if ($scheme != 'https')
1404
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1479
+						if ($scheme != 'https') {
1480
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1481
+						}
1482
+					} elseif (empty($scheme)) {
1483
+											$data = '//' . ltrim($data, ':/');
1405 1484
 					}
1406
-					elseif (empty($scheme))
1407
-						$data = '//' . ltrim($data, ':/');
1408 1485
 				},
1409 1486
 				'disabled_content' => '($1)',
1410 1487
 			),
@@ -1416,8 +1493,9 @@  discard block
 block discarded – undo
1416 1493
 				{
1417 1494
 					$data = strtr($data, array('<br>' => ''));
1418 1495
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1419
-					if (empty($scheme))
1420
-						$data = '//' . ltrim($data, ':/');
1496
+					if (empty($scheme)) {
1497
+											$data = '//' . ltrim($data, ':/');
1498
+					}
1421 1499
 				},
1422 1500
 			),
1423 1501
 			array(
@@ -1428,13 +1506,14 @@  discard block
 block discarded – undo
1428 1506
 				'after' => '</a>',
1429 1507
 				'validate' => function (&$tag, &$data, $disabled)
1430 1508
 				{
1431
-					if (substr($data, 0, 1) == '#')
1432
-						$data = '#post_' . substr($data, 1);
1433
-					else
1509
+					if (substr($data, 0, 1) == '#') {
1510
+											$data = '#post_' . substr($data, 1);
1511
+					} else
1434 1512
 					{
1435 1513
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1436
-						if (empty($scheme))
1437
-							$data = '//' . ltrim($data, ':/');
1514
+						if (empty($scheme)) {
1515
+													$data = '//' . ltrim($data, ':/');
1516
+						}
1438 1517
 					}
1439 1518
 				},
1440 1519
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1512,8 +1591,9 @@  discard block
 block discarded – undo
1512 1591
 					{
1513 1592
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1514 1593
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1515
-						if ($add_begin)
1516
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1594
+						if ($add_begin) {
1595
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1596
+						}
1517 1597
 					}
1518 1598
 				},
1519 1599
 				'block_level' => false,
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 				'content' => '$1',
1645 1725
 				'validate' => function (&$tag, &$data, $disabled)
1646 1726
 				{
1647
-					if (is_numeric($data))
1648
-						$data = timeformat($data);
1649
-					else
1650
-						$tag['content'] = '[time]$1[/time]';
1727
+					if (is_numeric($data)) {
1728
+											$data = timeformat($data);
1729
+					} else {
1730
+											$tag['content'] = '[time]$1[/time]';
1731
+					}
1651 1732
 				},
1652 1733
 			),
1653 1734
 			array(
@@ -1674,8 +1755,9 @@  discard block
 block discarded – undo
1674 1755
 				{
1675 1756
 					$data = strtr($data, array('<br>' => ''));
1676 1757
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1677
-					if (empty($scheme))
1678
-						$data = '//' . ltrim($data, ':/');
1758
+					if (empty($scheme)) {
1759
+											$data = '//' . ltrim($data, ':/');
1760
+					}
1679 1761
 				},
1680 1762
 			),
1681 1763
 			array(
@@ -1687,8 +1769,9 @@  discard block
 block discarded – undo
1687 1769
 				'validate' => function (&$tag, &$data, $disabled)
1688 1770
 				{
1689 1771
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1690
-					if (empty($scheme))
1691
-						$data = '//' . ltrim($data, ':/');
1772
+					if (empty($scheme)) {
1773
+											$data = '//' . ltrim($data, ':/');
1774
+					}
1692 1775
 				},
1693 1776
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1694 1777
 				'disabled_after' => ' ($1)',
@@ -1708,8 +1791,9 @@  discard block
 block discarded – undo
1708 1791
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1709 1792
 		if ($message === false)
1710 1793
 		{
1711
-			if (isset($temp_bbc))
1712
-				$bbc_codes = $temp_bbc;
1794
+			if (isset($temp_bbc)) {
1795
+							$bbc_codes = $temp_bbc;
1796
+			}
1713 1797
 			usort($codes, function ($a, $b) {
1714 1798
 				return strcmp($a['tag'], $b['tag']);
1715 1799
 			});
@@ -1729,8 +1813,9 @@  discard block
 block discarded – undo
1729 1813
 		);
1730 1814
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1731 1815
 		{
1732
-			foreach ($itemcodes as $c => $dummy)
1733
-				$bbc_codes[$c] = array();
1816
+			foreach ($itemcodes as $c => $dummy) {
1817
+							$bbc_codes[$c] = array();
1818
+			}
1734 1819
 		}
1735 1820
 
1736 1821
 		// Shhhh!
@@ -1751,12 +1836,14 @@  discard block
 block discarded – undo
1751 1836
 		foreach ($codes as $code)
1752 1837
 		{
1753 1838
 			// Make it easier to process parameters later
1754
-			if (!empty($code['parameters']))
1755
-				ksort($code['parameters'], SORT_STRING);
1839
+			if (!empty($code['parameters'])) {
1840
+							ksort($code['parameters'], SORT_STRING);
1841
+			}
1756 1842
 
1757 1843
 			// If we are not doing every tag only do ones we are interested in.
1758
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1759
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1844
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1845
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1846
+			}
1760 1847
 		}
1761 1848
 		$codes = null;
1762 1849
 	}
@@ -1767,8 +1854,9 @@  discard block
 block discarded – undo
1767 1854
 		// It's likely this will change if the message is modified.
1768 1855
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1769 1856
 
1770
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1771
-			return $temp;
1857
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1858
+					return $temp;
1859
+		}
1772 1860
 
1773 1861
 		$cache_t = microtime();
1774 1862
 	}
@@ -1800,8 +1888,9 @@  discard block
 block discarded – undo
1800 1888
 		$disabled['flash'] = true;
1801 1889
 
1802 1890
 		// @todo Change maybe?
1803
-		if (!isset($_GET['images']))
1804
-			$disabled['img'] = true;
1891
+		if (!isset($_GET['images'])) {
1892
+					$disabled['img'] = true;
1893
+		}
1805 1894
 
1806 1895
 		// @todo Interface/setting to add more?
1807 1896
 	}
@@ -1825,8 +1914,9 @@  discard block
 block discarded – undo
1825 1914
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1826 1915
 
1827 1916
 		// Failsafe.
1828
-		if ($pos === false || $last_pos > $pos)
1829
-			$pos = strlen($message) + 1;
1917
+		if ($pos === false || $last_pos > $pos) {
1918
+					$pos = strlen($message) + 1;
1919
+		}
1830 1920
 
1831 1921
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1832 1922
 		if ($last_pos < $pos - 1)
@@ -1845,8 +1935,9 @@  discard block
 block discarded – undo
1845 1935
 
1846 1936
 				// <br> should be empty.
1847 1937
 				$empty_tags = array('br', 'hr');
1848
-				foreach ($empty_tags as $tag)
1849
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1938
+				foreach ($empty_tags as $tag) {
1939
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1940
+				}
1850 1941
 
1851 1942
 				// b, u, i, s, pre... basic tags.
1852 1943
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1855,8 +1946,9 @@  discard block
 block discarded – undo
1855 1946
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1856 1947
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1857 1948
 
1858
-					if ($diff > 0)
1859
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1949
+					if ($diff > 0) {
1950
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1951
+					}
1860 1952
 				}
1861 1953
 
1862 1954
 				// Do <img ...> - with security... action= -> action-.
@@ -1869,8 +1961,9 @@  discard block
 block discarded – undo
1869 1961
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1870 1962
 
1871 1963
 						// Remove action= from the URL - no funny business, now.
1872
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1873
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1964
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1965
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1966
+						}
1874 1967
 
1875 1968
 						// Check if the image is larger than allowed.
1876 1969
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1891,9 +1984,9 @@  discard block
 block discarded – undo
1891 1984
 
1892 1985
 							// Set the new image tag.
1893 1986
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1987
+						} else {
1988
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1894 1989
 						}
1895
-						else
1896
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1897 1990
 					}
1898 1991
 
1899 1992
 					$data = strtr($data, $replaces);
@@ -1906,16 +1999,18 @@  discard block
 block discarded – undo
1906 1999
 				$no_autolink_area = false;
1907 2000
 				if (!empty($open_tags))
1908 2001
 				{
1909
-					foreach ($open_tags as $open_tag)
1910
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2002
+					foreach ($open_tags as $open_tag) {
2003
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1911 2004
 							$no_autolink_area = true;
2005
+					}
1912 2006
 				}
1913 2007
 
1914 2008
 				// Don't go backwards.
1915 2009
 				// @todo Don't think is the real solution....
1916 2010
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1917
-				if ($pos < $lastAutoPos)
1918
-					$no_autolink_area = true;
2011
+				if ($pos < $lastAutoPos) {
2012
+									$no_autolink_area = true;
2013
+				}
1919 2014
 				$lastAutoPos = $pos;
1920 2015
 
1921 2016
 				if (!$no_autolink_area)
@@ -2024,17 +2119,19 @@  discard block
 block discarded – undo
2024 2119
 							if ($scheme == 'mailto')
2025 2120
 							{
2026 2121
 								$email_address = str_replace('mailto:', '', $url);
2027
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2028
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2029
-								else
2030
-									return $url;
2122
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2123
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2124
+								} else {
2125
+																	return $url;
2126
+								}
2031 2127
 							}
2032 2128
 
2033 2129
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2034
-							if (empty($scheme))
2035
-								$fullUrl = '//' . ltrim($url, ':/');
2036
-							else
2037
-								$fullUrl = $url;
2130
+							if (empty($scheme)) {
2131
+															$fullUrl = '//' . ltrim($url, ':/');
2132
+							} else {
2133
+															$fullUrl = $url;
2134
+							}
2038 2135
 
2039 2136
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2040 2137
 						}, $data);
@@ -2083,16 +2180,18 @@  discard block
 block discarded – undo
2083 2180
 		}
2084 2181
 
2085 2182
 		// Are we there yet?  Are we there yet?
2086
-		if ($pos >= strlen($message) - 1)
2087
-			break;
2183
+		if ($pos >= strlen($message) - 1) {
2184
+					break;
2185
+		}
2088 2186
 
2089 2187
 		$tags = strtolower($message[$pos + 1]);
2090 2188
 
2091 2189
 		if ($tags == '/' && !empty($open_tags))
2092 2190
 		{
2093 2191
 			$pos2 = strpos($message, ']', $pos + 1);
2094
-			if ($pos2 == $pos + 2)
2095
-				continue;
2192
+			if ($pos2 == $pos + 2) {
2193
+							continue;
2194
+			}
2096 2195
 
2097 2196
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2098 2197
 
@@ -2102,8 +2201,9 @@  discard block
 block discarded – undo
2102 2201
 			do
2103 2202
 			{
2104 2203
 				$tag = array_pop($open_tags);
2105
-				if (!$tag)
2106
-					break;
2204
+				if (!$tag) {
2205
+									break;
2206
+				}
2107 2207
 
2108 2208
 				if (!empty($tag['block_level']))
2109 2209
 				{
@@ -2117,10 +2217,11 @@  discard block
 block discarded – undo
2117 2217
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2118 2218
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2119 2219
 					{
2120
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2121
-							if ($temp['tag'] == $look_for)
2220
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2221
+													if ($temp['tag'] == $look_for)
2122 2222
 							{
2123 2223
 								$block_level = !empty($temp['block_level']);
2224
+						}
2124 2225
 								break;
2125 2226
 							}
2126 2227
 					}
@@ -2142,15 +2243,15 @@  discard block
 block discarded – undo
2142 2243
 			{
2143 2244
 				$open_tags = $to_close;
2144 2245
 				continue;
2145
-			}
2146
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2246
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2147 2247
 			{
2148 2248
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2149 2249
 				{
2150
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2151
-						if ($temp['tag'] == $look_for)
2250
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2251
+											if ($temp['tag'] == $look_for)
2152 2252
 						{
2153 2253
 							$block_level = !empty($temp['block_level']);
2254
+					}
2154 2255
 							break;
2155 2256
 						}
2156 2257
 				}
@@ -2158,8 +2259,9 @@  discard block
 block discarded – undo
2158 2259
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2159 2260
 				if (!$block_level)
2160 2261
 				{
2161
-					foreach ($to_close as $tag)
2162
-						array_push($open_tags, $tag);
2262
+					foreach ($to_close as $tag) {
2263
+											array_push($open_tags, $tag);
2264
+					}
2163 2265
 					continue;
2164 2266
 				}
2165 2267
 			}
@@ -2172,14 +2274,17 @@  discard block
 block discarded – undo
2172 2274
 
2173 2275
 				// See the comment at the end of the big loop - just eating whitespace ;).
2174 2276
 				$whitespace_regex = '';
2175
-				if (!empty($tag['block_level']))
2176
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2277
+				if (!empty($tag['block_level'])) {
2278
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2279
+				}
2177 2280
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2178
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2179
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2281
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2282
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2283
+				}
2180 2284
 
2181
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2182
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2285
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2286
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2287
+				}
2183 2288
 			}
2184 2289
 
2185 2290
 			if (!empty($to_close))
@@ -2192,8 +2297,9 @@  discard block
 block discarded – undo
2192 2297
 		}
2193 2298
 
2194 2299
 		// No tags for this character, so just keep going (fastest possible course.)
2195
-		if (!isset($bbc_codes[$tags]))
2196
-			continue;
2300
+		if (!isset($bbc_codes[$tags])) {
2301
+					continue;
2302
+		}
2197 2303
 
2198 2304
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2199 2305
 		$tag = null;
@@ -2202,44 +2308,52 @@  discard block
 block discarded – undo
2202 2308
 			$pt_strlen = strlen($possible['tag']);
2203 2309
 
2204 2310
 			// Not a match?
2205
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2206
-				continue;
2311
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2312
+							continue;
2313
+			}
2207 2314
 
2208 2315
 			$next_c = $message[$pos + 1 + $pt_strlen];
2209 2316
 
2210 2317
 			// A test validation?
2211
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2212
-				continue;
2318
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2319
+							continue;
2320
+			}
2213 2321
 			// Do we want parameters?
2214 2322
 			elseif (!empty($possible['parameters']))
2215 2323
 			{
2216
-				if ($next_c != ' ')
2217
-					continue;
2218
-			}
2219
-			elseif (isset($possible['type']))
2324
+				if ($next_c != ' ') {
2325
+									continue;
2326
+				}
2327
+			} elseif (isset($possible['type']))
2220 2328
 			{
2221 2329
 				// Do we need an equal sign?
2222
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2223
-					continue;
2330
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2331
+									continue;
2332
+				}
2224 2333
 				// Maybe we just want a /...
2225
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2226
-					continue;
2334
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2335
+									continue;
2336
+				}
2227 2337
 				// An immediate ]?
2228
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2229
-					continue;
2338
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2339
+									continue;
2340
+				}
2230 2341
 			}
2231 2342
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2232
-			elseif ($next_c != ']')
2233
-				continue;
2343
+			elseif ($next_c != ']') {
2344
+							continue;
2345
+			}
2234 2346
 
2235 2347
 			// Check allowed tree?
2236
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2237
-				continue;
2238
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2239
-				continue;
2348
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2349
+							continue;
2350
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2351
+							continue;
2352
+			}
2240 2353
 			// If this is in the list of disallowed child tags, don't parse it.
2241
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2242
-				continue;
2354
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2355
+							continue;
2356
+			}
2243 2357
 
2244 2358
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2245 2359
 
@@ -2251,8 +2365,9 @@  discard block
 block discarded – undo
2251 2365
 				foreach ($open_tags as $open_quote)
2252 2366
 				{
2253 2367
 					// Every parent quote this quote has flips the styling
2254
-					if ($open_quote['tag'] == 'quote')
2255
-						$quote_alt = !$quote_alt;
2368
+					if ($open_quote['tag'] == 'quote') {
2369
+											$quote_alt = !$quote_alt;
2370
+					}
2256 2371
 				}
2257 2372
 				// Add a class to the quote to style alternating blockquotes
2258 2373
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2263,8 +2378,9 @@  discard block
 block discarded – undo
2263 2378
 			{
2264 2379
 				// Build a regular expression for each parameter for the current tag.
2265 2380
 				$preg = array();
2266
-				foreach ($possible['parameters'] as $p => $info)
2267
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2381
+				foreach ($possible['parameters'] as $p => $info) {
2382
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2383
+				}
2268 2384
 
2269 2385
 				// Extract the string that potentially holds our parameters.
2270 2386
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2284,24 +2400,27 @@  discard block
 block discarded – undo
2284 2400
 
2285 2401
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2286 2402
 
2287
-					if ($match)
2288
-						$blob_counter = count($blobs) + 1;
2403
+					if ($match) {
2404
+											$blob_counter = count($blobs) + 1;
2405
+					}
2289 2406
 				}
2290 2407
 
2291 2408
 				// Didn't match our parameter list, try the next possible.
2292
-				if (!$match)
2293
-					continue;
2409
+				if (!$match) {
2410
+									continue;
2411
+				}
2294 2412
 
2295 2413
 				$params = array();
2296 2414
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2297 2415
 				{
2298 2416
 					$key = strtok(ltrim($matches[$i]), '=');
2299
-					if (isset($possible['parameters'][$key]['value']))
2300
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2301
-					elseif (isset($possible['parameters'][$key]['validate']))
2302
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2303
-					else
2304
-						$params['{' . $key . '}'] = $matches[$i + 1];
2417
+					if (isset($possible['parameters'][$key]['value'])) {
2418
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2419
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2420
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2421
+					} else {
2422
+											$params['{' . $key . '}'] = $matches[$i + 1];
2423
+					}
2305 2424
 
2306 2425
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2307 2426
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2309,23 +2428,26 @@  discard block
 block discarded – undo
2309 2428
 
2310 2429
 				foreach ($possible['parameters'] as $p => $info)
2311 2430
 				{
2312
-					if (!isset($params['{' . $p . '}']))
2313
-						$params['{' . $p . '}'] = '';
2431
+					if (!isset($params['{' . $p . '}'])) {
2432
+											$params['{' . $p . '}'] = '';
2433
+					}
2314 2434
 				}
2315 2435
 
2316 2436
 				$tag = $possible;
2317 2437
 
2318 2438
 				// Put the parameters into the string.
2319
-				if (isset($tag['before']))
2320
-					$tag['before'] = strtr($tag['before'], $params);
2321
-				if (isset($tag['after']))
2322
-					$tag['after'] = strtr($tag['after'], $params);
2323
-				if (isset($tag['content']))
2324
-					$tag['content'] = strtr($tag['content'], $params);
2439
+				if (isset($tag['before'])) {
2440
+									$tag['before'] = strtr($tag['before'], $params);
2441
+				}
2442
+				if (isset($tag['after'])) {
2443
+									$tag['after'] = strtr($tag['after'], $params);
2444
+				}
2445
+				if (isset($tag['content'])) {
2446
+									$tag['content'] = strtr($tag['content'], $params);
2447
+				}
2325 2448
 
2326 2449
 				$pos1 += strlen($given_param_string);
2327
-			}
2328
-			else
2450
+			} else
2329 2451
 			{
2330 2452
 				$tag = $possible;
2331 2453
 				$params = array();
@@ -2336,8 +2458,9 @@  discard block
 block discarded – undo
2336 2458
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2337 2459
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2338 2460
 		{
2339
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2340
-				continue;
2461
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2462
+							continue;
2463
+			}
2341 2464
 
2342 2465
 			$tag = $itemcodes[$message[$pos + 1]];
2343 2466
 
@@ -2358,9 +2481,9 @@  discard block
 block discarded – undo
2358 2481
 			{
2359 2482
 				array_pop($open_tags);
2360 2483
 				$code = '</li>';
2484
+			} else {
2485
+							$code = '';
2361 2486
 			}
2362
-			else
2363
-				$code = '';
2364 2487
 
2365 2488
 			// Now we open a new tag.
2366 2489
 			$open_tags[] = array(
@@ -2407,12 +2530,14 @@  discard block
 block discarded – undo
2407 2530
 		}
2408 2531
 
2409 2532
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2410
-		if ($tag === null)
2411
-			continue;
2533
+		if ($tag === null) {
2534
+					continue;
2535
+		}
2412 2536
 
2413 2537
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2414
-		if (isset($inside['disallow_children']))
2415
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2538
+		if (isset($inside['disallow_children'])) {
2539
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2540
+		}
2416 2541
 
2417 2542
 		// Is this tag disabled?
2418 2543
 		if (isset($disabled[$tag['tag']]))
@@ -2422,14 +2547,13 @@  discard block
 block discarded – undo
2422 2547
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2423 2548
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2424 2549
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2425
-			}
2426
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2550
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2427 2551
 			{
2428 2552
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2429 2553
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2554
+			} else {
2555
+							$tag['content'] = $tag['disabled_content'];
2430 2556
 			}
2431
-			else
2432
-				$tag['content'] = $tag['disabled_content'];
2433 2557
 		}
2434 2558
 
2435 2559
 		// we use this a lot
@@ -2439,8 +2563,9 @@  discard block
 block discarded – undo
2439 2563
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2440 2564
 		{
2441 2565
 			$n = count($open_tags) - 1;
2442
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2443
-				$n--;
2566
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2567
+							$n--;
2568
+			}
2444 2569
 
2445 2570
 			// Close all the non block level tags so this tag isn't surrounded by them.
2446 2571
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2452,12 +2577,15 @@  discard block
 block discarded – undo
2452 2577
 
2453 2578
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2454 2579
 				$whitespace_regex = '';
2455
-				if (!empty($tag['block_level']))
2456
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2457
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2458
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2459
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2460
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2580
+				if (!empty($tag['block_level'])) {
2581
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2582
+				}
2583
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2584
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2585
+				}
2586
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2587
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2588
+				}
2461 2589
 
2462 2590
 				array_pop($open_tags);
2463 2591
 			}
@@ -2475,16 +2603,19 @@  discard block
 block discarded – undo
2475 2603
 		elseif ($tag['type'] == 'unparsed_content')
2476 2604
 		{
2477 2605
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2478
-			if ($pos2 === false)
2479
-				continue;
2606
+			if ($pos2 === false) {
2607
+							continue;
2608
+			}
2480 2609
 
2481 2610
 			$data = substr($message, $pos1, $pos2 - $pos1);
2482 2611
 
2483
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2484
-				$data = substr($data, 4);
2612
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2613
+							$data = substr($data, 4);
2614
+			}
2485 2615
 
2486
-			if (isset($tag['validate']))
2487
-				$tag['validate']($tag, $data, $disabled, $params);
2616
+			if (isset($tag['validate'])) {
2617
+							$tag['validate']($tag, $data, $disabled, $params);
2618
+			}
2488 2619
 
2489 2620
 			$code = strtr($tag['content'], array('$1' => $data));
2490 2621
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2500,34 +2631,40 @@  discard block
 block discarded – undo
2500 2631
 			if (isset($tag['quoted']))
2501 2632
 			{
2502 2633
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2503
-				if ($tag['quoted'] != 'optional' && !$quoted)
2504
-					continue;
2634
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2635
+									continue;
2636
+				}
2505 2637
 
2506
-				if ($quoted)
2507
-					$pos1 += 6;
2638
+				if ($quoted) {
2639
+									$pos1 += 6;
2640
+				}
2641
+			} else {
2642
+							$quoted = false;
2508 2643
 			}
2509
-			else
2510
-				$quoted = false;
2511 2644
 
2512 2645
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2513
-			if ($pos2 === false)
2514
-				continue;
2646
+			if ($pos2 === false) {
2647
+							continue;
2648
+			}
2515 2649
 
2516 2650
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2517
-			if ($pos3 === false)
2518
-				continue;
2651
+			if ($pos3 === false) {
2652
+							continue;
2653
+			}
2519 2654
 
2520 2655
 			$data = array(
2521 2656
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2522 2657
 				substr($message, $pos1, $pos2 - $pos1)
2523 2658
 			);
2524 2659
 
2525
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2526
-				$data[0] = substr($data[0], 4);
2660
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2661
+							$data[0] = substr($data[0], 4);
2662
+			}
2527 2663
 
2528 2664
 			// Validation for my parking, please!
2529
-			if (isset($tag['validate']))
2530
-				$tag['validate']($tag, $data, $disabled, $params);
2665
+			if (isset($tag['validate'])) {
2666
+							$tag['validate']($tag, $data, $disabled, $params);
2667
+			}
2531 2668
 
2532 2669
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2533 2670
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2544,23 +2681,27 @@  discard block
 block discarded – undo
2544 2681
 		elseif ($tag['type'] == 'unparsed_commas_content')
2545 2682
 		{
2546 2683
 			$pos2 = strpos($message, ']', $pos1);
2547
-			if ($pos2 === false)
2548
-				continue;
2684
+			if ($pos2 === false) {
2685
+							continue;
2686
+			}
2549 2687
 
2550 2688
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2551
-			if ($pos3 === false)
2552
-				continue;
2689
+			if ($pos3 === false) {
2690
+							continue;
2691
+			}
2553 2692
 
2554 2693
 			// We want $1 to be the content, and the rest to be csv.
2555 2694
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2556 2695
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2557 2696
 
2558
-			if (isset($tag['validate']))
2559
-				$tag['validate']($tag, $data, $disabled, $params);
2697
+			if (isset($tag['validate'])) {
2698
+							$tag['validate']($tag, $data, $disabled, $params);
2699
+			}
2560 2700
 
2561 2701
 			$code = $tag['content'];
2562
-			foreach ($data as $k => $d)
2563
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2702
+			foreach ($data as $k => $d) {
2703
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2704
+			}
2564 2705
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2565 2706
 			$pos += strlen($code) - 1 + 2;
2566 2707
 		}
@@ -2568,24 +2709,28 @@  discard block
 block discarded – undo
2568 2709
 		elseif ($tag['type'] == 'unparsed_commas')
2569 2710
 		{
2570 2711
 			$pos2 = strpos($message, ']', $pos1);
2571
-			if ($pos2 === false)
2572
-				continue;
2712
+			if ($pos2 === false) {
2713
+							continue;
2714
+			}
2573 2715
 
2574 2716
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2575 2717
 
2576
-			if (isset($tag['validate']))
2577
-				$tag['validate']($tag, $data, $disabled, $params);
2718
+			if (isset($tag['validate'])) {
2719
+							$tag['validate']($tag, $data, $disabled, $params);
2720
+			}
2578 2721
 
2579 2722
 			// Fix after, for disabled code mainly.
2580
-			foreach ($data as $k => $d)
2581
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2723
+			foreach ($data as $k => $d) {
2724
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2725
+			}
2582 2726
 
2583 2727
 			$open_tags[] = $tag;
2584 2728
 
2585 2729
 			// Replace them out, $1, $2, $3, $4, etc.
2586 2730
 			$code = $tag['before'];
2587
-			foreach ($data as $k => $d)
2588
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2731
+			foreach ($data as $k => $d) {
2732
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2733
+			}
2589 2734
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2590 2735
 			$pos += strlen($code) - 1 + 2;
2591 2736
 		}
@@ -2596,28 +2741,33 @@  discard block
 block discarded – undo
2596 2741
 			if (isset($tag['quoted']))
2597 2742
 			{
2598 2743
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2599
-				if ($tag['quoted'] != 'optional' && !$quoted)
2600
-					continue;
2744
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2745
+									continue;
2746
+				}
2601 2747
 
2602
-				if ($quoted)
2603
-					$pos1 += 6;
2748
+				if ($quoted) {
2749
+									$pos1 += 6;
2750
+				}
2751
+			} else {
2752
+							$quoted = false;
2604 2753
 			}
2605
-			else
2606
-				$quoted = false;
2607 2754
 
2608 2755
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2609
-			if ($pos2 === false)
2610
-				continue;
2756
+			if ($pos2 === false) {
2757
+							continue;
2758
+			}
2611 2759
 
2612 2760
 			$data = substr($message, $pos1, $pos2 - $pos1);
2613 2761
 
2614 2762
 			// Validation for my parking, please!
2615
-			if (isset($tag['validate']))
2616
-				$tag['validate']($tag, $data, $disabled, $params);
2763
+			if (isset($tag['validate'])) {
2764
+							$tag['validate']($tag, $data, $disabled, $params);
2765
+			}
2617 2766
 
2618 2767
 			// For parsed content, we must recurse to avoid security problems.
2619
-			if ($tag['type'] != 'unparsed_equals')
2620
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2768
+			if ($tag['type'] != 'unparsed_equals') {
2769
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2770
+			}
2621 2771
 
2622 2772
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2623 2773
 
@@ -2629,34 +2779,40 @@  discard block
 block discarded – undo
2629 2779
 		}
2630 2780
 
2631 2781
 		// If this is block level, eat any breaks after it.
2632
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2633
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2782
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2783
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2784
+		}
2634 2785
 
2635 2786
 		// Are we trimming outside this tag?
2636
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2637
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2787
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2788
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2789
+		}
2638 2790
 	}
2639 2791
 
2640 2792
 	// Close any remaining tags.
2641
-	while ($tag = array_pop($open_tags))
2642
-		$message .= "\n" . $tag['after'] . "\n";
2793
+	while ($tag = array_pop($open_tags)) {
2794
+			$message .= "\n" . $tag['after'] . "\n";
2795
+	}
2643 2796
 
2644 2797
 	// Parse the smileys within the parts where it can be done safely.
2645 2798
 	if ($smileys === true)
2646 2799
 	{
2647 2800
 		$message_parts = explode("\n", $message);
2648
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2649
-			parsesmileys($message_parts[$i]);
2801
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2802
+					parsesmileys($message_parts[$i]);
2803
+		}
2650 2804
 
2651 2805
 		$message = implode('', $message_parts);
2652 2806
 	}
2653 2807
 
2654 2808
 	// No smileys, just get rid of the markers.
2655
-	else
2656
-		$message = strtr($message, array("\n" => ''));
2809
+	else {
2810
+			$message = strtr($message, array("\n" => ''));
2811
+	}
2657 2812
 
2658
-	if ($message !== '' && $message[0] === ' ')
2659
-		$message = '&nbsp;' . substr($message, 1);
2813
+	if ($message !== '' && $message[0] === ' ') {
2814
+			$message = '&nbsp;' . substr($message, 1);
2815
+	}
2660 2816
 
2661 2817
 	// Cleanup whitespace.
2662 2818
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2665,15 +2821,16 @@  discard block
 block discarded – undo
2665 2821
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2666 2822
 
2667 2823
 	// Cache the output if it took some time...
2668
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2669
-		cache_put_data($cache_key, $message, 240);
2824
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2825
+			cache_put_data($cache_key, $message, 240);
2826
+	}
2670 2827
 
2671 2828
 	// If this was a force parse revert if needed.
2672 2829
 	if (!empty($parse_tags))
2673 2830
 	{
2674
-		if (empty($temp_bbc))
2675
-			$bbc_codes = array();
2676
-		else
2831
+		if (empty($temp_bbc)) {
2832
+					$bbc_codes = array();
2833
+		} else
2677 2834
 		{
2678 2835
 			$bbc_codes = $temp_bbc;
2679 2836
 			unset($temp_bbc);
@@ -2700,8 +2857,9 @@  discard block
 block discarded – undo
2700 2857
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2701 2858
 
2702 2859
 	// No smiley set at all?!
2703
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2704
-		return;
2860
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2861
+			return;
2862
+	}
2705 2863
 
2706 2864
 	// If smileyPregSearch hasn't been set, do it now.
2707 2865
 	if (empty($smileyPregSearch))
@@ -2712,8 +2870,7 @@  discard block
 block discarded – undo
2712 2870
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2713 2871
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2714 2872
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2715
-		}
2716
-		else
2873
+		} else
2717 2874
 		{
2718 2875
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2719 2876
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2737,9 +2894,9 @@  discard block
 block discarded – undo
2737 2894
 				$smcFunc['db_free_result']($result);
2738 2895
 
2739 2896
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2897
+			} else {
2898
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2740 2899
 			}
2741
-			else
2742
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2743 2900
 		}
2744 2901
 
2745 2902
 		// The non-breaking-space is a complex thing...
@@ -2816,35 +2973,41 @@  discard block
 block discarded – undo
2816 2973
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2817 2974
 
2818 2975
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2819
-	if (!empty($context['flush_mail']))
2820
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2976
+	if (!empty($context['flush_mail'])) {
2977
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2821 2978
 		AddMailQueue(true);
2979
+	}
2822 2980
 
2823 2981
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2824 2982
 
2825
-	if ($add)
2826
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2983
+	if ($add) {
2984
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2985
+	}
2827 2986
 
2828 2987
 	// Put the session ID in.
2829
-	if (defined('SID') && SID != '')
2830
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2988
+	if (defined('SID') && SID != '') {
2989
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2990
+	}
2831 2991
 	// Keep that debug in their for template debugging!
2832
-	elseif (isset($_GET['debug']))
2833
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2992
+	elseif (isset($_GET['debug'])) {
2993
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2994
+	}
2834 2995
 
2835 2996
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2836 2997
 	{
2837
-		if (defined('SID') && SID != '')
2838
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2998
+		if (defined('SID') && SID != '') {
2999
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2839 3000
 				function ($m) use ($scripturl)
2840 3001
 				{
2841 3002
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3003
+		}
2842 3004
 				}, $setLocation);
2843
-		else
2844
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3005
+		else {
3006
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2845 3007
 				function ($m) use ($scripturl)
2846 3008
 				{
2847 3009
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3010
+		}
2848 3011
 				}, $setLocation);
2849 3012
 	}
2850 3013
 
@@ -2855,8 +3018,9 @@  discard block
 block discarded – undo
2855 3018
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2856 3019
 
2857 3020
 	// Debugging.
2858
-	if (isset($db_show_debug) && $db_show_debug === true)
2859
-		$_SESSION['debug_redirect'] = $db_cache;
3021
+	if (isset($db_show_debug) && $db_show_debug === true) {
3022
+			$_SESSION['debug_redirect'] = $db_cache;
3023
+	}
2860 3024
 
2861 3025
 	obExit(false);
2862 3026
 }
@@ -2875,51 +3039,60 @@  discard block
 block discarded – undo
2875 3039
 
2876 3040
 	// Attempt to prevent a recursive loop.
2877 3041
 	++$level;
2878
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2879
-		exit;
2880
-	if ($from_fatal_error)
2881
-		$has_fatal_error = true;
3042
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3043
+			exit;
3044
+	}
3045
+	if ($from_fatal_error) {
3046
+			$has_fatal_error = true;
3047
+	}
2882 3048
 
2883 3049
 	// Clear out the stat cache.
2884 3050
 	trackStats();
2885 3051
 
2886 3052
 	// If we have mail to send, send it.
2887
-	if (!empty($context['flush_mail']))
2888
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3053
+	if (!empty($context['flush_mail'])) {
3054
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2889 3055
 		AddMailQueue(true);
3056
+	}
2890 3057
 
2891 3058
 	$do_header = $header === null ? !$header_done : $header;
2892
-	if ($do_footer === null)
2893
-		$do_footer = $do_header;
3059
+	if ($do_footer === null) {
3060
+			$do_footer = $do_header;
3061
+	}
2894 3062
 
2895 3063
 	// Has the template/header been done yet?
2896 3064
 	if ($do_header)
2897 3065
 	{
2898 3066
 		// Was the page title set last minute? Also update the HTML safe one.
2899
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2900
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3067
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3068
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3069
+		}
2901 3070
 
2902 3071
 		// Start up the session URL fixer.
2903 3072
 		ob_start('ob_sessrewrite');
2904 3073
 
2905
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2906
-			$buffers = explode(',', $settings['output_buffers']);
2907
-		elseif (!empty($settings['output_buffers']))
2908
-			$buffers = $settings['output_buffers'];
2909
-		else
2910
-			$buffers = array();
3074
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3075
+					$buffers = explode(',', $settings['output_buffers']);
3076
+		} elseif (!empty($settings['output_buffers'])) {
3077
+					$buffers = $settings['output_buffers'];
3078
+		} else {
3079
+					$buffers = array();
3080
+		}
2911 3081
 
2912
-		if (isset($modSettings['integrate_buffer']))
2913
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3082
+		if (isset($modSettings['integrate_buffer'])) {
3083
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3084
+		}
2914 3085
 
2915
-		if (!empty($buffers))
2916
-			foreach ($buffers as $function)
3086
+		if (!empty($buffers)) {
3087
+					foreach ($buffers as $function)
2917 3088
 			{
2918 3089
 				$call = call_helper($function, true);
3090
+		}
2919 3091
 
2920 3092
 				// Is it valid?
2921
-				if (!empty($call))
2922
-					ob_start($call);
3093
+				if (!empty($call)) {
3094
+									ob_start($call);
3095
+				}
2923 3096
 			}
2924 3097
 
2925 3098
 		// Display the screen in the logical order.
@@ -2931,8 +3104,9 @@  discard block
 block discarded – undo
2931 3104
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2932 3105
 
2933 3106
 		// Anything special to put out?
2934
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2935
-			echo $context['insert_after_template'];
3107
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3108
+					echo $context['insert_after_template'];
3109
+		}
2936 3110
 
2937 3111
 		// Just so we don't get caught in an endless loop of errors from the footer...
2938 3112
 		if (!$footer_done)
@@ -2941,14 +3115,16 @@  discard block
 block discarded – undo
2941 3115
 			template_footer();
2942 3116
 
2943 3117
 			// (since this is just debugging... it's okay that it's after </html>.)
2944
-			if (!isset($_REQUEST['xml']))
2945
-				displayDebug();
3118
+			if (!isset($_REQUEST['xml'])) {
3119
+							displayDebug();
3120
+			}
2946 3121
 		}
2947 3122
 	}
2948 3123
 
2949 3124
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2950
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2951
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3125
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3126
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3127
+	}
2952 3128
 
2953 3129
 	// For session check verification.... don't switch browsers...
2954 3130
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2957,9 +3133,10 @@  discard block
 block discarded – undo
2957 3133
 	call_integration_hook('integrate_exit', array($do_footer));
2958 3134
 
2959 3135
 	// Don't exit if we're coming from index.php; that will pass through normally.
2960
-	if (!$from_index)
2961
-		exit;
2962
-}
3136
+	if (!$from_index) {
3137
+			exit;
3138
+	}
3139
+	}
2963 3140
 
2964 3141
 /**
2965 3142
  * Get the size of a specified image with better error handling.
@@ -2978,8 +3155,9 @@  discard block
 block discarded – undo
2978 3155
 	$url = str_replace(' ', '%20', $url);
2979 3156
 
2980 3157
 	// Can we pull this from the cache... please please?
2981
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2982
-		return $temp;
3158
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3159
+			return $temp;
3160
+	}
2983 3161
 	$t = microtime();
2984 3162
 
2985 3163
 	// Get the host to pester...
@@ -2989,12 +3167,10 @@  discard block
 block discarded – undo
2989 3167
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2990 3168
 	{
2991 3169
 		return false;
2992
-	}
2993
-	elseif (!isset($match[1]))
3170
+	} elseif (!isset($match[1]))
2994 3171
 	{
2995 3172
 		$size = @getimagesize($url);
2996
-	}
2997
-	else
3173
+	} else
2998 3174
 	{
2999 3175
 		// Try to connect to the server... give it half a second.
3000 3176
 		$temp = 0;
@@ -3033,12 +3209,14 @@  discard block
 block discarded – undo
3033 3209
 	}
3034 3210
 
3035 3211
 	// If we didn't get it, we failed.
3036
-	if (!isset($size))
3037
-		$size = false;
3212
+	if (!isset($size)) {
3213
+			$size = false;
3214
+	}
3038 3215
 
3039 3216
 	// If this took a long time, we may never have to do it again, but then again we might...
3040
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3041
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3217
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3218
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3219
+	}
3042 3220
 
3043 3221
 	// Didn't work.
3044 3222
 	return $size;
@@ -3056,8 +3234,9 @@  discard block
 block discarded – undo
3056 3234
 
3057 3235
 	// Under SSI this function can be called more then once.  That can cause some problems.
3058 3236
 	//   So only run the function once unless we are forced to run it again.
3059
-	if ($loaded && !$forceload)
3060
-		return;
3237
+	if ($loaded && !$forceload) {
3238
+			return;
3239
+	}
3061 3240
 
3062 3241
 	$loaded = true;
3063 3242
 
@@ -3069,14 +3248,16 @@  discard block
 block discarded – undo
3069 3248
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3070 3249
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3071 3250
 	{
3072
-		if (trim($context['news_lines'][$i]) == '')
3073
-			continue;
3251
+		if (trim($context['news_lines'][$i]) == '') {
3252
+					continue;
3253
+		}
3074 3254
 
3075 3255
 		// Clean it up for presentation ;).
3076 3256
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3077 3257
 	}
3078
-	if (!empty($context['news_lines']))
3079
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3258
+	if (!empty($context['news_lines'])) {
3259
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3260
+	}
3080 3261
 
3081 3262
 	if (!$user_info['is_guest'])
3082 3263
 	{
@@ -3085,40 +3266,48 @@  discard block
 block discarded – undo
3085 3266
 		$context['user']['alerts'] = &$user_info['alerts'];
3086 3267
 
3087 3268
 		// Personal message popup...
3088
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3089
-			$context['user']['popup_messages'] = true;
3090
-		else
3091
-			$context['user']['popup_messages'] = false;
3269
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3270
+					$context['user']['popup_messages'] = true;
3271
+		} else {
3272
+					$context['user']['popup_messages'] = false;
3273
+		}
3092 3274
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3093 3275
 
3094
-		if (allowedTo('moderate_forum'))
3095
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3276
+		if (allowedTo('moderate_forum')) {
3277
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3278
+		}
3096 3279
 
3097 3280
 		$context['user']['avatar'] = array();
3098 3281
 
3099 3282
 		// Check for gravatar first since we might be forcing them...
3100 3283
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3101 3284
 		{
3102
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3103
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3104
-			else
3105
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3285
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3286
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3287
+			} else {
3288
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3289
+			}
3106 3290
 		}
3107 3291
 		// Uploaded?
3108
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3109
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3292
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3293
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3294
+		}
3110 3295
 		// Full URL?
3111
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3112
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3296
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3297
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3298
+		}
3113 3299
 		// Otherwise we assume it's server stored.
3114
-		elseif ($user_info['avatar']['url'] != '')
3115
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3300
+		elseif ($user_info['avatar']['url'] != '') {
3301
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3302
+		}
3116 3303
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3117
-		else
3118
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3304
+		else {
3305
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3306
+		}
3119 3307
 
3120
-		if (!empty($context['user']['avatar']))
3121
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3308
+		if (!empty($context['user']['avatar'])) {
3309
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3310
+		}
3122 3311
 
3123 3312
 		// Figure out how long they've been logged in.
3124 3313
 		$context['user']['total_time_logged_in'] = array(
@@ -3126,8 +3315,7 @@  discard block
 block discarded – undo
3126 3315
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3127 3316
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3128 3317
 		);
3129
-	}
3130
-	else
3318
+	} else
3131 3319
 	{
3132 3320
 		$context['user']['messages'] = 0;
3133 3321
 		$context['user']['unread_messages'] = 0;
@@ -3135,12 +3323,14 @@  discard block
 block discarded – undo
3135 3323
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3136 3324
 		$context['user']['popup_messages'] = false;
3137 3325
 
3138
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3139
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3326
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3327
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3328
+		}
3140 3329
 
3141 3330
 		// If we've upgraded recently, go easy on the passwords.
3142
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3143
-			$context['disable_login_hashing'] = true;
3331
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3332
+					$context['disable_login_hashing'] = true;
3333
+		}
3144 3334
 	}
3145 3335
 
3146 3336
 	// Setup the main menu items.
@@ -3153,8 +3343,8 @@  discard block
 block discarded – undo
3153 3343
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3154 3344
 
3155 3345
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3156
-	if ($context['show_pm_popup'])
3157
-		addInlineJavaScript('
3346
+	if ($context['show_pm_popup']) {
3347
+			addInlineJavaScript('
3158 3348
 		jQuery(document).ready(function($) {
3159 3349
 			new smc_Popup({
3160 3350
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3162,15 +3352,17 @@  discard block
 block discarded – undo
3162 3352
 				icon_class: \'generic_icons mail_new\'
3163 3353
 			});
3164 3354
 		});');
3355
+	}
3165 3356
 
3166 3357
 	// Add a generic "Are you sure?" confirmation message.
3167 3358
 	addInlineJavaScript('
3168 3359
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3169 3360
 
3170 3361
 	// Now add the capping code for avatars.
3171
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3172
-		addInlineCss('
3362
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3363
+			addInlineCss('
3173 3364
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3365
+	}
3174 3366
 
3175 3367
 	// This looks weird, but it's because BoardIndex.php references the variable.
3176 3368
 	$context['common_stats']['latest_member'] = array(
@@ -3187,11 +3379,13 @@  discard block
 block discarded – undo
3187 3379
 	);
3188 3380
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3189 3381
 
3190
-	if (empty($settings['theme_version']))
3191
-		addJavaScriptVar('smf_scripturl', $scripturl);
3382
+	if (empty($settings['theme_version'])) {
3383
+			addJavaScriptVar('smf_scripturl', $scripturl);
3384
+	}
3192 3385
 
3193
-	if (!isset($context['page_title']))
3194
-		$context['page_title'] = '';
3386
+	if (!isset($context['page_title'])) {
3387
+			$context['page_title'] = '';
3388
+	}
3195 3389
 
3196 3390
 	// Set some specific vars.
3197 3391
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3201,21 +3395,23 @@  discard block
 block discarded – undo
3201 3395
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3202 3396
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3203 3397
 
3204
-	if (!empty($context['meta_keywords']))
3205
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3398
+	if (!empty($context['meta_keywords'])) {
3399
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3400
+	}
3206 3401
 
3207
-	if (!empty($context['canonical_url']))
3208
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3402
+	if (!empty($context['canonical_url'])) {
3403
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3404
+	}
3209 3405
 
3210
-	if (!empty($settings['og_image']))
3211
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3406
+	if (!empty($settings['og_image'])) {
3407
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3408
+	}
3212 3409
 
3213 3410
 	if (!empty($context['meta_description']))
3214 3411
 	{
3215 3412
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3216 3413
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3217
-	}
3218
-	else
3414
+	} else
3219 3415
 	{
3220 3416
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3221 3417
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3240,8 +3436,9 @@  discard block
 block discarded – undo
3240 3436
 	$memory_needed = memoryReturnBytes($needed);
3241 3437
 
3242 3438
 	// should we account for how much is currently being used?
3243
-	if ($in_use)
3244
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3439
+	if ($in_use) {
3440
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3441
+	}
3245 3442
 
3246 3443
 	// if more is needed, request it
3247 3444
 	if ($memory_current < $memory_needed)
@@ -3264,8 +3461,9 @@  discard block
 block discarded – undo
3264 3461
  */
3265 3462
 function memoryReturnBytes($val)
3266 3463
 {
3267
-	if (is_integer($val))
3268
-		return $val;
3464
+	if (is_integer($val)) {
3465
+			return $val;
3466
+	}
3269 3467
 
3270 3468
 	// Separate the number from the designator
3271 3469
 	$val = trim($val);
@@ -3301,10 +3499,11 @@  discard block
 block discarded – undo
3301 3499
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3302 3500
 
3303 3501
 		// Are we debugging the template/html content?
3304
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3305
-			header('Content-Type: application/xhtml+xml');
3306
-		elseif (!isset($_REQUEST['xml']))
3307
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3502
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3503
+					header('Content-Type: application/xhtml+xml');
3504
+		} elseif (!isset($_REQUEST['xml'])) {
3505
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3506
+		}
3308 3507
 	}
3309 3508
 
3310 3509
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3313,8 +3512,9 @@  discard block
 block discarded – undo
3313 3512
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3314 3513
 	{
3315 3514
 		$position = array_search('body', $context['template_layers']);
3316
-		if ($position === false)
3317
-			$position = array_search('main', $context['template_layers']);
3515
+		if ($position === false) {
3516
+					$position = array_search('main', $context['template_layers']);
3517
+		}
3318 3518
 
3319 3519
 		if ($position !== false)
3320 3520
 		{
@@ -3342,23 +3542,25 @@  discard block
 block discarded – undo
3342 3542
 
3343 3543
 			foreach ($securityFiles as $i => $securityFile)
3344 3544
 			{
3345
-				if (!file_exists($boarddir . '/' . $securityFile))
3346
-					unset($securityFiles[$i]);
3545
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3546
+									unset($securityFiles[$i]);
3547
+				}
3347 3548
 			}
3348 3549
 
3349 3550
 			// We are already checking so many files...just few more doesn't make any difference! :P
3350
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3351
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3352
-
3353
-			else
3354
-				$path = $modSettings['attachmentUploadDir'];
3551
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3552
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3553
+			} else {
3554
+							$path = $modSettings['attachmentUploadDir'];
3555
+			}
3355 3556
 
3356 3557
 			secureDirectory($path, true);
3357 3558
 			secureDirectory($cachedir);
3358 3559
 
3359 3560
 			// If agreement is enabled, at least the english version shall exists
3360
-			if ($modSettings['requireAgreement'])
3361
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3561
+			if ($modSettings['requireAgreement']) {
3562
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3563
+			}
3362 3564
 
3363 3565
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3364 3566
 			{
@@ -3373,18 +3575,21 @@  discard block
 block discarded – undo
3373 3575
 					echo '
3374 3576
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3375 3577
 
3376
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3377
-						echo '
3578
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3579
+											echo '
3378 3580
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3581
+					}
3379 3582
 				}
3380 3583
 
3381
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3382
-					echo '
3584
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3585
+									echo '
3383 3586
 				<strong>', $txt['cache_writable'], '</strong><br>';
3587
+				}
3384 3588
 
3385
-				if (!empty($agreement))
3386
-					echo '
3589
+				if (!empty($agreement)) {
3590
+									echo '
3387 3591
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3592
+				}
3388 3593
 
3389 3594
 				echo '
3390 3595
 			</p>
@@ -3399,16 +3604,18 @@  discard block
 block discarded – undo
3399 3604
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3400 3605
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3401 3606
 
3402
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3403
-				echo '
3607
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3608
+							echo '
3404 3609
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3610
+			}
3405 3611
 
3406
-			if (!empty($_SESSION['ban']['expire_time']))
3407
-				echo '
3612
+			if (!empty($_SESSION['ban']['expire_time'])) {
3613
+							echo '
3408 3614
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3409
-			else
3410
-				echo '
3615
+			} else {
3616
+							echo '
3411 3617
 					<div>', $txt['your_ban_expires_never'], '</div>';
3618
+			}
3412 3619
 
3413 3620
 			echo '
3414 3621
 				</div>';
@@ -3424,8 +3631,9 @@  discard block
 block discarded – undo
3424 3631
 	global $forum_copyright, $software_year, $forum_version;
3425 3632
 
3426 3633
 	// Don't display copyright for things like SSI.
3427
-	if (!isset($forum_version) || !isset($software_year))
3428
-		return;
3634
+	if (!isset($forum_version) || !isset($software_year)) {
3635
+			return;
3636
+	}
3429 3637
 
3430 3638
 	// Put in the version...
3431 3639
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3443,9 +3651,10 @@  discard block
 block discarded – undo
3443 3651
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3444 3652
 	$context['load_queries'] = $db_count;
3445 3653
 
3446
-	foreach (array_reverse($context['template_layers']) as $layer)
3447
-		loadSubTemplate($layer . '_below', true);
3448
-}
3654
+	foreach (array_reverse($context['template_layers']) as $layer) {
3655
+			loadSubTemplate($layer . '_below', true);
3656
+	}
3657
+	}
3449 3658
 
3450 3659
 /**
3451 3660
  * Output the Javascript files
@@ -3476,8 +3685,7 @@  discard block
 block discarded – undo
3476 3685
 			{
3477 3686
 				echo '
3478 3687
 		var ', $key, ';';
3479
-			}
3480
-			else
3688
+			} else
3481 3689
 			{
3482 3690
 				echo '
3483 3691
 		var ', $key, ' = ', $value, ';';
@@ -3492,26 +3700,27 @@  discard block
 block discarded – undo
3492 3700
 	foreach ($context['javascript_files'] as $id => $js_file)
3493 3701
 	{
3494 3702
 		// Last minute call! allow theme authors to disable single files.
3495
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3496
-			continue;
3703
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3704
+					continue;
3705
+		}
3497 3706
 
3498 3707
 		// By default all files don't get minimized unless the file explicitly says so!
3499 3708
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3500 3709
 		{
3501
-			if ($do_deferred && !empty($js_file['options']['defer']))
3502
-				$toMinifyDefer[] = $js_file;
3503
-
3504
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3505
-				$toMinify[] = $js_file;
3710
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3711
+							$toMinifyDefer[] = $js_file;
3712
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3713
+							$toMinify[] = $js_file;
3714
+			}
3506 3715
 
3507 3716
 			// Grab a random seed.
3508
-			if (!isset($minSeed))
3509
-				$minSeed = $js_file['options']['seed'];
3510
-		}
3511
-
3512
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3513
-			echo '
3717
+			if (!isset($minSeed)) {
3718
+							$minSeed = $js_file['options']['seed'];
3719
+			}
3720
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3721
+					echo '
3514 3722
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3723
+		}
3515 3724
 	}
3516 3725
 
3517 3726
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3519,14 +3728,14 @@  discard block
 block discarded – undo
3519 3728
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3520 3729
 
3521 3730
 		// Minify process couldn't work, print each individual files.
3522
-		if (!empty($result) && is_array($result))
3523
-			foreach ($result as $minFailedFile)
3731
+		if (!empty($result) && is_array($result)) {
3732
+					foreach ($result as $minFailedFile)
3524 3733
 				echo '
3525 3734
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3526
-
3527
-		else
3528
-			echo '
3735
+		} else {
3736
+					echo '
3529 3737
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3738
+		}
3530 3739
 	}
3531 3740
 
3532 3741
 	// Inline JavaScript - Actually useful some times!
@@ -3537,8 +3746,9 @@  discard block
 block discarded – undo
3537 3746
 			echo '
3538 3747
 <script>';
3539 3748
 
3540
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3541
-				echo $js_code;
3749
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3750
+							echo $js_code;
3751
+			}
3542 3752
 
3543 3753
 			echo '
3544 3754
 </script>';
@@ -3549,8 +3759,9 @@  discard block
 block discarded – undo
3549 3759
 			echo '
3550 3760
 	<script>';
3551 3761
 
3552
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3553
-				echo $js_code;
3762
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3763
+							echo $js_code;
3764
+			}
3554 3765
 
3555 3766
 			echo '
3556 3767
 	</script>';
@@ -3575,8 +3786,9 @@  discard block
 block discarded – undo
3575 3786
 	foreach ($context['css_files'] as $id => $file)
3576 3787
 	{
3577 3788
 		// Last minute call! allow theme authors to disable single files.
3578
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3579
-			continue;
3789
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3790
+					continue;
3791
+		}
3580 3792
 
3581 3793
 		// By default all files don't get minimized unless the file explicitly says so!
3582 3794
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3584,12 +3796,12 @@  discard block
 block discarded – undo
3584 3796
 			$toMinify[] = $file;
3585 3797
 
3586 3798
 			// Grab a random seed.
3587
-			if (!isset($minSeed))
3588
-				$minSeed = $file['options']['seed'];
3799
+			if (!isset($minSeed)) {
3800
+							$minSeed = $file['options']['seed'];
3801
+			}
3802
+		} else {
3803
+					$normal[] = $file['fileUrl'];
3589 3804
 		}
3590
-
3591
-		else
3592
-			$normal[] = $file['fileUrl'];
3593 3805
 	}
3594 3806
 
3595 3807
 	if (!empty($toMinify))
@@ -3597,28 +3809,30 @@  discard block
 block discarded – undo
3597 3809
 		$result = custMinify($toMinify, 'css');
3598 3810
 
3599 3811
 		// Minify process couldn't work, print each individual files.
3600
-		if (!empty($result) && is_array($result))
3601
-			foreach ($result as $minFailedFile)
3812
+		if (!empty($result) && is_array($result)) {
3813
+					foreach ($result as $minFailedFile)
3602 3814
 				echo '
3603 3815
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3604
-
3605
-		else
3606
-			echo '
3816
+		} else {
3817
+					echo '
3607 3818
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3819
+		}
3608 3820
 	}
3609 3821
 
3610 3822
 	// Print the rest after the minified files.
3611
-	if (!empty($normal))
3612
-		foreach ($normal as $nf)
3823
+	if (!empty($normal)) {
3824
+			foreach ($normal as $nf)
3613 3825
 			echo '
3614 3826
 	<link rel="stylesheet" href="', $nf ,'">';
3827
+	}
3615 3828
 
3616 3829
 	if ($db_show_debug === true)
3617 3830
 	{
3618 3831
 		// Try to keep only what's useful.
3619 3832
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3620
-		foreach ($context['css_files'] as $file)
3621
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3833
+		foreach ($context['css_files'] as $file) {
3834
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3835
+		}
3622 3836
 	}
3623 3837
 
3624 3838
 	if (!empty($context['css_header']))
@@ -3626,9 +3840,10 @@  discard block
 block discarded – undo
3626 3840
 		echo '
3627 3841
 	<style>';
3628 3842
 
3629
-		foreach ($context['css_header'] as $css)
3630
-			echo $css .'
3843
+		foreach ($context['css_header'] as $css) {
3844
+					echo $css .'
3631 3845
 	';
3846
+		}
3632 3847
 
3633 3848
 		echo'
3634 3849
 	</style>';
@@ -3652,15 +3867,17 @@  discard block
 block discarded – undo
3652 3867
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3653 3868
 	$data = !empty($data) ? $data : false;
3654 3869
 
3655
-	if (empty($type) || empty($data))
3656
-		return false;
3870
+	if (empty($type) || empty($data)) {
3871
+			return false;
3872
+	}
3657 3873
 
3658 3874
 	// Did we already did this?
3659 3875
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3660 3876
 
3661 3877
 	// Already done?
3662
-	if (!empty($toCache))
3663
-		return true;
3878
+	if (!empty($toCache)) {
3879
+			return true;
3880
+	}
3664 3881
 
3665 3882
 	// No namespaces, sorry!
3666 3883
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3742,8 +3959,9 @@  discard block
 block discarded – undo
3742 3959
 	global $modSettings, $smcFunc;
3743 3960
 
3744 3961
 	// Just make up a nice hash...
3745
-	if ($new)
3746
-		return sha1(md5($filename . time()) . mt_rand());
3962
+	if ($new) {
3963
+			return sha1(md5($filename . time()) . mt_rand());
3964
+	}
3747 3965
 
3748 3966
 	// Just make sure that attachment id is only a int
3749 3967
 	$attachment_id = (int) $attachment_id;
@@ -3760,23 +3978,25 @@  discard block
 block discarded – undo
3760 3978
 				'id_attach' => $attachment_id,
3761 3979
 			));
3762 3980
 
3763
-		if ($smcFunc['db_num_rows']($request) === 0)
3764
-			return false;
3981
+		if ($smcFunc['db_num_rows']($request) === 0) {
3982
+					return false;
3983
+		}
3765 3984
 
3766 3985
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3767 3986
 		$smcFunc['db_free_result']($request);
3768 3987
 	}
3769 3988
 
3770 3989
 	// Still no hash? mmm...
3771
-	if (empty($file_hash))
3772
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3990
+	if (empty($file_hash)) {
3991
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3992
+	}
3773 3993
 
3774 3994
 	// Are we using multiple directories?
3775
-	if (is_array($modSettings['attachmentUploadDir']))
3776
-		$path = $modSettings['attachmentUploadDir'][$dir];
3777
-
3778
-	else
3779
-		$path = $modSettings['attachmentUploadDir'];
3995
+	if (is_array($modSettings['attachmentUploadDir'])) {
3996
+			$path = $modSettings['attachmentUploadDir'][$dir];
3997
+	} else {
3998
+			$path = $modSettings['attachmentUploadDir'];
3999
+	}
3780 4000
 
3781 4001
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3782 4002
 }
@@ -3791,8 +4011,9 @@  discard block
 block discarded – undo
3791 4011
 function ip2range($fullip)
3792 4012
 {
3793 4013
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3794
-	if ($fullip == 'unknown')
3795
-		$fullip = '255.255.255.255';
4014
+	if ($fullip == 'unknown') {
4015
+			$fullip = '255.255.255.255';
4016
+	}
3796 4017
 
3797 4018
 	$ip_parts = explode('-', $fullip);
3798 4019
 	$ip_array = array();
@@ -3816,10 +4037,11 @@  discard block
 block discarded – undo
3816 4037
 		$ip_array['low'] = $ip_parts[0];
3817 4038
 		$ip_array['high'] = $ip_parts[1];
3818 4039
 		return $ip_array;
3819
-	}
3820
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4040
+	} elseif (count($ip_parts) == 2) {
4041
+		// if ip 22.22.*-22.22.*
3821 4042
 	{
3822 4043
 		$valid_low = isValidIP($ip_parts[0]);
4044
+	}
3823 4045
 		$valid_high = isValidIP($ip_parts[1]);
3824 4046
 		$count = 0;
3825 4047
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3834,7 +4056,9 @@  discard block
 block discarded – undo
3834 4056
 				$ip_parts[0] .= $mode . $min;
3835 4057
 				$valid_low = isValidIP($ip_parts[0]);
3836 4058
 				$count++;
3837
-				if ($count > 9) break;
4059
+				if ($count > 9) {
4060
+					break;
4061
+				}
3838 4062
 			}
3839 4063
 		}
3840 4064
 
@@ -3848,7 +4072,9 @@  discard block
 block discarded – undo
3848 4072
 				$ip_parts[1] .= $mode . $max;
3849 4073
 				$valid_high = isValidIP($ip_parts[1]);
3850 4074
 				$count++;
3851
-				if ($count > 9) break;
4075
+				if ($count > 9) {
4076
+					break;
4077
+				}
3852 4078
 			}
3853 4079
 		}
3854 4080
 
@@ -3873,46 +4099,54 @@  discard block
 block discarded – undo
3873 4099
 {
3874 4100
 	global $modSettings;
3875 4101
 
3876
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3877
-		return $host;
4102
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4103
+			return $host;
4104
+	}
3878 4105
 	$t = microtime();
3879 4106
 
3880 4107
 	// Try the Linux host command, perhaps?
3881 4108
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3882 4109
 	{
3883
-		if (!isset($modSettings['host_to_dis']))
3884
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3885
-		else
3886
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4110
+		if (!isset($modSettings['host_to_dis'])) {
4111
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4112
+		} else {
4113
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4114
+		}
3887 4115
 
3888 4116
 		// Did host say it didn't find anything?
3889
-		if (strpos($test, 'not found') !== false)
3890
-			$host = '';
4117
+		if (strpos($test, 'not found') !== false) {
4118
+					$host = '';
4119
+		}
3891 4120
 		// Invalid server option?
3892
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3893
-			updateSettings(array('host_to_dis' => 1));
4121
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4122
+					updateSettings(array('host_to_dis' => 1));
4123
+		}
3894 4124
 		// Maybe it found something, after all?
3895
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3896
-			$host = $match[1];
4125
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4126
+					$host = $match[1];
4127
+		}
3897 4128
 	}
3898 4129
 
3899 4130
 	// This is nslookup; usually only Windows, but possibly some Unix?
3900 4131
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3901 4132
 	{
3902 4133
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3903
-		if (strpos($test, 'Non-existent domain') !== false)
3904
-			$host = '';
3905
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3906
-			$host = $match[1];
4134
+		if (strpos($test, 'Non-existent domain') !== false) {
4135
+					$host = '';
4136
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4137
+					$host = $match[1];
4138
+		}
3907 4139
 	}
3908 4140
 
3909 4141
 	// This is the last try :/.
3910
-	if (!isset($host) || $host === false)
3911
-		$host = @gethostbyaddr($ip);
4142
+	if (!isset($host) || $host === false) {
4143
+			$host = @gethostbyaddr($ip);
4144
+	}
3912 4145
 
3913 4146
 	// It took a long time, so let's cache it!
3914
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3915
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4147
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4148
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4149
+	}
3916 4150
 
3917 4151
 	return $host;
3918 4152
 }
@@ -3948,20 +4182,21 @@  discard block
 block discarded – undo
3948 4182
 			{
3949 4183
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3950 4184
 				$total = 0;
3951
-				for ($i = 0; $i < $max_chars; $i++)
3952
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4185
+				for ($i = 0; $i < $max_chars; $i++) {
4186
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4187
+				}
3953 4188
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3954 4189
 			}
3955 4190
 		}
3956 4191
 		return array_unique($returned_ints);
3957
-	}
3958
-	else
4192
+	} else
3959 4193
 	{
3960 4194
 		// Trim characters before and after and add slashes for database insertion.
3961 4195
 		$returned_words = array();
3962
-		foreach ($words as $word)
3963
-			if (($word = trim($word, '-_\'')) !== '')
4196
+		foreach ($words as $word) {
4197
+					if (($word = trim($word, '-_\'')) !== '')
3964 4198
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4199
+		}
3965 4200
 
3966 4201
 		// Filter out all words that occur more than once.
3967 4202
 		return array_unique($returned_words);
@@ -3983,16 +4218,18 @@  discard block
 block discarded – undo
3983 4218
 	global $settings, $txt;
3984 4219
 
3985 4220
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3986
-	if (function_exists('template_create_button') && !$force_use)
3987
-		return template_create_button($name, $alt, $label = '', $custom = '');
4221
+	if (function_exists('template_create_button') && !$force_use) {
4222
+			return template_create_button($name, $alt, $label = '', $custom = '');
4223
+	}
3988 4224
 
3989
-	if (!$settings['use_image_buttons'])
3990
-		return $txt[$alt];
3991
-	elseif (!empty($settings['use_buttons']))
3992
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3993
-	else
3994
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3995
-}
4225
+	if (!$settings['use_image_buttons']) {
4226
+			return $txt[$alt];
4227
+	} elseif (!empty($settings['use_buttons'])) {
4228
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4229
+	} else {
4230
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4231
+	}
4232
+	}
3996 4233
 
3997 4234
 /**
3998 4235
  * Sets up all of the top menu buttons
@@ -4035,9 +4272,10 @@  discard block
 block discarded – undo
4035 4272
 	var user_menus = new smc_PopupMenu();
4036 4273
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4037 4274
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4038
-		if ($context['allow_pm'])
4039
-			addInlineJavaScript('
4275
+		if ($context['allow_pm']) {
4276
+					addInlineJavaScript('
4040 4277
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4278
+		}
4041 4279
 
4042 4280
 		if (!empty($modSettings['enable_ajax_alerts']))
4043 4281
 		{
@@ -4197,88 +4435,96 @@  discard block
 block discarded – undo
4197 4435
 
4198 4436
 		// Now we put the buttons in the context so the theme can use them.
4199 4437
 		$menu_buttons = array();
4200
-		foreach ($buttons as $act => $button)
4201
-			if (!empty($button['show']))
4438
+		foreach ($buttons as $act => $button) {
4439
+					if (!empty($button['show']))
4202 4440
 			{
4203 4441
 				$button['active_button'] = false;
4442
+		}
4204 4443
 
4205 4444
 				// This button needs some action.
4206
-				if (isset($button['action_hook']))
4207
-					$needs_action_hook = true;
4445
+				if (isset($button['action_hook'])) {
4446
+									$needs_action_hook = true;
4447
+				}
4208 4448
 
4209 4449
 				// Make sure the last button truly is the last button.
4210 4450
 				if (!empty($button['is_last']))
4211 4451
 				{
4212
-					if (isset($last_button))
4213
-						unset($menu_buttons[$last_button]['is_last']);
4452
+					if (isset($last_button)) {
4453
+											unset($menu_buttons[$last_button]['is_last']);
4454
+					}
4214 4455
 					$last_button = $act;
4215 4456
 				}
4216 4457
 
4217 4458
 				// Go through the sub buttons if there are any.
4218
-				if (!empty($button['sub_buttons']))
4219
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4459
+				if (!empty($button['sub_buttons'])) {
4460
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4220 4461
 					{
4221 4462
 						if (empty($subbutton['show']))
4222 4463
 							unset($button['sub_buttons'][$key]);
4464
+				}
4223 4465
 
4224 4466
 						// 2nd level sub buttons next...
4225 4467
 						if (!empty($subbutton['sub_buttons']))
4226 4468
 						{
4227 4469
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4228 4470
 							{
4229
-								if (empty($sub_button2['show']))
4230
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4471
+								if (empty($sub_button2['show'])) {
4472
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4473
+								}
4231 4474
 							}
4232 4475
 						}
4233 4476
 					}
4234 4477
 
4235 4478
 				// Does this button have its own icon?
4236
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4237
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4238
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4239
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4240
-				elseif (isset($button['icon']))
4241
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4242
-				else
4243
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4479
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4480
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4481
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4482
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4483
+				} elseif (isset($button['icon'])) {
4484
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4485
+				} else {
4486
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4487
+				}
4244 4488
 
4245 4489
 				$menu_buttons[$act] = $button;
4246 4490
 			}
4247 4491
 
4248
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4249
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4493
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4494
+		}
4250 4495
 	}
4251 4496
 
4252 4497
 	$context['menu_buttons'] = $menu_buttons;
4253 4498
 
4254 4499
 	// Logging out requires the session id in the url.
4255
-	if (isset($context['menu_buttons']['logout']))
4256
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4500
+	if (isset($context['menu_buttons']['logout'])) {
4501
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4502
+	}
4257 4503
 
4258 4504
 	// Figure out which action we are doing so we can set the active tab.
4259 4505
 	// Default to home.
4260 4506
 	$current_action = 'home';
4261 4507
 
4262
-	if (isset($context['menu_buttons'][$context['current_action']]))
4263
-		$current_action = $context['current_action'];
4264
-	elseif ($context['current_action'] == 'search2')
4265
-		$current_action = 'search';
4266
-	elseif ($context['current_action'] == 'theme')
4267
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4268
-	elseif ($context['current_action'] == 'register2')
4269
-		$current_action = 'register';
4270
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4271
-		$current_action = 'login';
4272
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4273
-		$current_action = 'moderate';
4508
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4509
+			$current_action = $context['current_action'];
4510
+	} elseif ($context['current_action'] == 'search2') {
4511
+			$current_action = 'search';
4512
+	} elseif ($context['current_action'] == 'theme') {
4513
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4514
+	} elseif ($context['current_action'] == 'register2') {
4515
+			$current_action = 'register';
4516
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4517
+			$current_action = 'login';
4518
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4519
+			$current_action = 'moderate';
4520
+	}
4274 4521
 
4275 4522
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4276 4523
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4277 4524
 	{
4278 4525
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4279 4526
 		$context[$current_action] = true;
4280
-	}
4281
-	elseif ($context['current_action'] == 'pm')
4527
+	} elseif ($context['current_action'] == 'pm')
4282 4528
 	{
4283 4529
 		$current_action = 'self_pm';
4284 4530
 		$context['self_pm'] = true;
@@ -4321,12 +4567,14 @@  discard block
 block discarded – undo
4321 4567
 	}
4322 4568
 
4323 4569
 	// Not all actions are simple.
4324
-	if (!empty($needs_action_hook))
4325
-		call_integration_hook('integrate_current_action', array(&$current_action));
4570
+	if (!empty($needs_action_hook)) {
4571
+			call_integration_hook('integrate_current_action', array(&$current_action));
4572
+	}
4326 4573
 
4327
-	if (isset($context['menu_buttons'][$current_action]))
4328
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4329
-}
4574
+	if (isset($context['menu_buttons'][$current_action])) {
4575
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4576
+	}
4577
+	}
4330 4578
 
4331 4579
 /**
4332 4580
  * Generate a random seed and ensure it's stored in settings.
@@ -4350,30 +4598,35 @@  discard block
 block discarded – undo
4350 4598
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4351 4599
 	global $context, $txt;
4352 4600
 
4353
-	if ($db_show_debug === true)
4354
-		$context['debug']['hooks'][] = $hook;
4601
+	if ($db_show_debug === true) {
4602
+			$context['debug']['hooks'][] = $hook;
4603
+	}
4355 4604
 
4356 4605
 	// Need to have some control.
4357
-	if (!isset($context['instances']))
4358
-		$context['instances'] = array();
4606
+	if (!isset($context['instances'])) {
4607
+			$context['instances'] = array();
4608
+	}
4359 4609
 
4360 4610
 	$results = array();
4361
-	if (empty($modSettings[$hook]))
4362
-		return $results;
4611
+	if (empty($modSettings[$hook])) {
4612
+			return $results;
4613
+	}
4363 4614
 
4364 4615
 	$functions = explode(',', $modSettings[$hook]);
4365 4616
 	// Loop through each function.
4366 4617
 	foreach ($functions as $function)
4367 4618
 	{
4368 4619
 		// Hook has been marked as "disabled". Skip it!
4369
-		if (strpos($function, '!') !== false)
4370
-			continue;
4620
+		if (strpos($function, '!') !== false) {
4621
+					continue;
4622
+		}
4371 4623
 
4372 4624
 		$call = call_helper($function, true);
4373 4625
 
4374 4626
 		// Is it valid?
4375
-		if (!empty($call))
4376
-			$results[$function] = call_user_func_array($call, $parameters);
4627
+		if (!empty($call)) {
4628
+					$results[$function] = call_user_func_array($call, $parameters);
4629
+		}
4377 4630
 
4378 4631
 		// Whatever it was suppose to call, it failed :(
4379 4632
 		elseif (!empty($function))
@@ -4389,8 +4642,9 @@  discard block
 block discarded – undo
4389 4642
 			}
4390 4643
 
4391 4644
 			// "Assume" the file resides on $boarddir somewhere...
4392
-			else
4393
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4645
+			else {
4646
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4647
+			}
4394 4648
 		}
4395 4649
 	}
4396 4650
 
@@ -4412,12 +4666,14 @@  discard block
 block discarded – undo
4412 4666
 	global $smcFunc, $modSettings;
4413 4667
 
4414 4668
 	// Any objects?
4415
-	if ($object)
4416
-		$function = $function . '#';
4669
+	if ($object) {
4670
+			$function = $function . '#';
4671
+	}
4417 4672
 
4418 4673
 	// Any files  to load?
4419
-	if (!empty($file) && is_string($file))
4420
-		$function = $file . (!empty($function) ? '|' . $function : '');
4674
+	if (!empty($file) && is_string($file)) {
4675
+			$function = $file . (!empty($function) ? '|' . $function : '');
4676
+	}
4421 4677
 
4422 4678
 	// Get the correct string.
4423 4679
 	$integration_call = $function;
@@ -4439,13 +4695,14 @@  discard block
 block discarded – undo
4439 4695
 		if (!empty($current_functions))
4440 4696
 		{
4441 4697
 			$current_functions = explode(',', $current_functions);
4442
-			if (in_array($integration_call, $current_functions))
4443
-				return;
4698
+			if (in_array($integration_call, $current_functions)) {
4699
+							return;
4700
+			}
4444 4701
 
4445 4702
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4703
+		} else {
4704
+					$permanent_functions = array($integration_call);
4446 4705
 		}
4447
-		else
4448
-			$permanent_functions = array($integration_call);
4449 4706
 
4450 4707
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4451 4708
 	}
@@ -4454,8 +4711,9 @@  discard block
 block discarded – undo
4454 4711
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4455 4712
 
4456 4713
 	// Do nothing, if it's already there.
4457
-	if (in_array($integration_call, $functions))
4458
-		return;
4714
+	if (in_array($integration_call, $functions)) {
4715
+			return;
4716
+	}
4459 4717
 
4460 4718
 	$functions[] = $integration_call;
4461 4719
 	$modSettings[$hook] = implode(',', $functions);
@@ -4478,12 +4736,14 @@  discard block
 block discarded – undo
4478 4736
 	global $smcFunc, $modSettings;
4479 4737
 
4480 4738
 	// Any objects?
4481
-	if ($object)
4482
-		$function = $function . '#';
4739
+	if ($object) {
4740
+			$function = $function . '#';
4741
+	}
4483 4742
 
4484 4743
 	// Any files  to load?
4485
-	if (!empty($file) && is_string($file))
4486
-		$function = $file . '|' . $function;
4744
+	if (!empty($file) && is_string($file)) {
4745
+			$function = $file . '|' . $function;
4746
+	}
4487 4747
 
4488 4748
 	// Get the correct string.
4489 4749
 	$integration_call = $function;
@@ -4504,16 +4764,18 @@  discard block
 block discarded – undo
4504 4764
 	{
4505 4765
 		$current_functions = explode(',', $current_functions);
4506 4766
 
4507
-		if (in_array($integration_call, $current_functions))
4508
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4767
+		if (in_array($integration_call, $current_functions)) {
4768
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4769
+		}
4509 4770
 	}
4510 4771
 
4511 4772
 	// Turn the function list into something usable.
4512 4773
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4513 4774
 
4514 4775
 	// You can only remove it if it's available.
4515
-	if (!in_array($integration_call, $functions))
4516
-		return;
4776
+	if (!in_array($integration_call, $functions)) {
4777
+			return;
4778
+	}
4517 4779
 
4518 4780
 	$functions = array_diff($functions, array($integration_call));
4519 4781
 	$modSettings[$hook] = implode(',', $functions);
@@ -4534,17 +4796,20 @@  discard block
 block discarded – undo
4534 4796
 	global $context, $smcFunc, $txt, $db_show_debug;
4535 4797
 
4536 4798
 	// Really?
4537
-	if (empty($string))
4538
-		return false;
4799
+	if (empty($string)) {
4800
+			return false;
4801
+	}
4539 4802
 
4540 4803
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4541 4804
 	// A closure? should be a callable one.
4542
-	if (is_array($string) || $string instanceof Closure)
4543
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4805
+	if (is_array($string) || $string instanceof Closure) {
4806
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4807
+	}
4544 4808
 
4545 4809
 	// No full objects, sorry! pass a method or a property instead!
4546
-	if (is_object($string))
4547
-		return false;
4810
+	if (is_object($string)) {
4811
+			return false;
4812
+	}
4548 4813
 
4549 4814
 	// Stay vitaminized my friends...
4550 4815
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4553,8 +4818,9 @@  discard block
 block discarded – undo
4553 4818
 	$string = load_file($string);
4554 4819
 
4555 4820
 	// Loaded file failed
4556
-	if (empty($string))
4557
-		return false;
4821
+	if (empty($string)) {
4822
+			return false;
4823
+	}
4558 4824
 
4559 4825
 	// Found a method.
4560 4826
 	if (strpos($string, '::') !== false)
@@ -4575,8 +4841,9 @@  discard block
 block discarded – undo
4575 4841
 				// Add another one to the list.
4576 4842
 				if ($db_show_debug === true)
4577 4843
 				{
4578
-					if (!isset($context['debug']['instances']))
4579
-						$context['debug']['instances'] = array();
4844
+					if (!isset($context['debug']['instances'])) {
4845
+											$context['debug']['instances'] = array();
4846
+					}
4580 4847
 
4581 4848
 					$context['debug']['instances'][$class] = $class;
4582 4849
 				}
@@ -4586,13 +4853,15 @@  discard block
 block discarded – undo
4586 4853
 		}
4587 4854
 
4588 4855
 		// Right then. This is a call to a static method.
4589
-		else
4590
-			$func = array($class, $method);
4856
+		else {
4857
+					$func = array($class, $method);
4858
+		}
4591 4859
 	}
4592 4860
 
4593 4861
 	// Nope! just a plain regular function.
4594
-	else
4595
-		$func = $string;
4862
+	else {
4863
+			$func = $string;
4864
+	}
4596 4865
 
4597 4866
 	// Right, we got what we need, time to do some checks.
4598 4867
 	if (!is_callable($func, false, $callable_name))
@@ -4608,17 +4877,18 @@  discard block
 block discarded – undo
4608 4877
 	else
4609 4878
 	{
4610 4879
 		// What are we gonna do about it?
4611
-		if ($return)
4612
-			return $func;
4880
+		if ($return) {
4881
+					return $func;
4882
+		}
4613 4883
 
4614 4884
 		// If this is a plain function, avoid the heat of calling call_user_func().
4615 4885
 		else
4616 4886
 		{
4617
-			if (is_array($func))
4618
-				call_user_func($func);
4619
-
4620
-			else
4621
-				$func();
4887
+			if (is_array($func)) {
4888
+							call_user_func($func);
4889
+			} else {
4890
+							$func();
4891
+			}
4622 4892
 		}
4623 4893
 	}
4624 4894
 }
@@ -4635,31 +4905,34 @@  discard block
 block discarded – undo
4635 4905
 {
4636 4906
 	global $sourcedir, $txt, $boarddir, $settings;
4637 4907
 
4638
-	if (empty($string))
4639
-		return false;
4908
+	if (empty($string)) {
4909
+			return false;
4910
+	}
4640 4911
 
4641 4912
 	if (strpos($string, '|') !== false)
4642 4913
 	{
4643 4914
 		list ($file, $string) = explode('|', $string);
4644 4915
 
4645 4916
 		// Match the wildcards to their regular vars.
4646
-		if (empty($settings['theme_dir']))
4647
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4648
-
4649
-		else
4650
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4917
+		if (empty($settings['theme_dir'])) {
4918
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4919
+		} else {
4920
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4921
+		}
4651 4922
 
4652 4923
 		// Load the file if it can be loaded.
4653
-		if (file_exists($absPath))
4654
-			require_once($absPath);
4924
+		if (file_exists($absPath)) {
4925
+					require_once($absPath);
4926
+		}
4655 4927
 
4656 4928
 		// No? try a fallback to $sourcedir
4657 4929
 		else
4658 4930
 		{
4659 4931
 			$absPath = $sourcedir .'/'. $file;
4660 4932
 
4661
-			if (file_exists($absPath))
4662
-				require_once($absPath);
4933
+			if (file_exists($absPath)) {
4934
+							require_once($absPath);
4935
+			}
4663 4936
 
4664 4937
 			// Sorry, can't do much for you at this point.
4665 4938
 			else
@@ -4686,8 +4959,9 @@  discard block
 block discarded – undo
4686 4959
 	global $user_info, $smcFunc;
4687 4960
 
4688 4961
 	// Make sure we have something to work with.
4689
-	if (empty($topic))
4690
-		return array();
4962
+	if (empty($topic)) {
4963
+			return array();
4964
+	}
4691 4965
 
4692 4966
 
4693 4967
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4710,8 +4984,9 @@  discard block
 block discarded – undo
4710 4984
 				'topic' => $topic,
4711 4985
 			)
4712 4986
 		);
4713
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4714
-			$temp[] = (int) $row['content_id'];
4987
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4988
+					$temp[] = (int) $row['content_id'];
4989
+		}
4715 4990
 
4716 4991
 		cache_put_data($cache_key, $temp, $ttl);
4717 4992
 	}
@@ -4732,8 +5007,9 @@  discard block
 block discarded – undo
4732 5007
 {
4733 5008
 	global $context;
4734 5009
 
4735
-	if (empty($string))
4736
-		return $string;
5010
+	if (empty($string)) {
5011
+			return $string;
5012
+	}
4737 5013
 
4738 5014
 	// UTF-8 occurences of MS special characters
4739 5015
 	$findchars_utf8 = array(
@@ -4774,10 +5050,11 @@  discard block
 block discarded – undo
4774 5050
 		'--',	// &mdash;
4775 5051
 	);
4776 5052
 
4777
-	if ($context['utf8'])
4778
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4779
-	else
4780
-		$string = str_replace($findchars_iso, $replacechars, $string);
5053
+	if ($context['utf8']) {
5054
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5055
+	} else {
5056
+			$string = str_replace($findchars_iso, $replacechars, $string);
5057
+	}
4781 5058
 
4782 5059
 	return $string;
4783 5060
 }
@@ -4796,49 +5073,59 @@  discard block
 block discarded – undo
4796 5073
 {
4797 5074
 	global $context;
4798 5075
 
4799
-	if (!isset($matches[2]))
4800
-		return '';
5076
+	if (!isset($matches[2])) {
5077
+			return '';
5078
+	}
4801 5079
 
4802 5080
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4803 5081
 
4804 5082
 	// remove left to right / right to left overrides
4805
-	if ($num === 0x202D || $num === 0x202E)
4806
-		return '';
5083
+	if ($num === 0x202D || $num === 0x202E) {
5084
+			return '';
5085
+	}
4807 5086
 
4808 5087
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4809
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4810
-		return '&#' . $num . ';';
5088
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5089
+			return '&#' . $num . ';';
5090
+	}
4811 5091
 
4812 5092
 	if (empty($context['utf8']))
4813 5093
 	{
4814 5094
 		// no control characters
4815
-		if ($num < 0x20)
4816
-			return '';
5095
+		if ($num < 0x20) {
5096
+					return '';
5097
+		}
4817 5098
 		// text is text
4818
-		elseif ($num < 0x80)
4819
-			return chr($num);
5099
+		elseif ($num < 0x80) {
5100
+					return chr($num);
5101
+		}
4820 5102
 		// all others get html-ised
4821
-		else
4822
-			return '&#' . $matches[2] . ';';
4823
-	}
4824
-	else
5103
+		else {
5104
+					return '&#' . $matches[2] . ';';
5105
+		}
5106
+	} else
4825 5107
 	{
4826 5108
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4827 5109
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4828
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4829
-			return '';
5110
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5111
+					return '';
5112
+		}
4830 5113
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4831
-		elseif ($num < 0x80)
4832
-			return chr($num);
5114
+		elseif ($num < 0x80) {
5115
+					return chr($num);
5116
+		}
4833 5117
 		// <0x800 (2048)
4834
-		elseif ($num < 0x800)
4835
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5118
+		elseif ($num < 0x800) {
5119
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5120
+		}
4836 5121
 		// < 0x10000 (65536)
4837
-		elseif ($num < 0x10000)
4838
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+		elseif ($num < 0x10000) {
5123
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5124
+		}
4839 5125
 		// <= 0x10FFFF (1114111)
4840
-		else
4841
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5126
+		else {
5127
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5128
+		}
4842 5129
 	}
4843 5130
 }
4844 5131
 
@@ -4854,28 +5141,34 @@  discard block
 block discarded – undo
4854 5141
  */
4855 5142
 function fixchar__callback($matches)
4856 5143
 {
4857
-	if (!isset($matches[1]))
4858
-		return '';
5144
+	if (!isset($matches[1])) {
5145
+			return '';
5146
+	}
4859 5147
 
4860 5148
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4861 5149
 
4862 5150
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4863 5151
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4864
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4865
-		return '';
5152
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5153
+			return '';
5154
+	}
4866 5155
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4867
-	elseif ($num < 0x80)
4868
-		return chr($num);
5156
+	elseif ($num < 0x80) {
5157
+			return chr($num);
5158
+	}
4869 5159
 	// <0x800 (2048)
4870
-	elseif ($num < 0x800)
4871
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5160
+	elseif ($num < 0x800) {
5161
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5162
+	}
4872 5163
 	// < 0x10000 (65536)
4873
-	elseif ($num < 0x10000)
4874
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5164
+	elseif ($num < 0x10000) {
5165
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5166
+	}
4875 5167
 	// <= 0x10FFFF (1114111)
4876
-	else
4877
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4878
-}
5168
+	else {
5169
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5170
+	}
5171
+	}
4879 5172
 
4880 5173
 /**
4881 5174
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4888,17 +5181,19 @@  discard block
 block discarded – undo
4888 5181
  */
4889 5182
 function entity_fix__callback($matches)
4890 5183
 {
4891
-	if (!isset($matches[2]))
4892
-		return '';
5184
+	if (!isset($matches[2])) {
5185
+			return '';
5186
+	}
4893 5187
 
4894 5188
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4895 5189
 
4896 5190
 	// we don't allow control characters, characters out of range, byte markers, etc
4897
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4898
-		return '';
4899
-	else
4900
-		return '&#' . $num . ';';
4901
-}
5191
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5192
+			return '';
5193
+	} else {
5194
+			return '&#' . $num . ';';
5195
+	}
5196
+	}
4902 5197
 
4903 5198
 /**
4904 5199
  * Return a Gravatar URL based on
@@ -4922,18 +5217,23 @@  discard block
 block discarded – undo
4922 5217
 		$ratings = array('G', 'PG', 'R', 'X');
4923 5218
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4924 5219
 		$url_params = array();
4925
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4926
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4927
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4928
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4929
-		if (!empty($modSettings['avatar_max_width_external']))
4930
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4931
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4932
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5220
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5221
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5222
+		}
5223
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5224
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5225
+		}
5226
+		if (!empty($modSettings['avatar_max_width_external'])) {
5227
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5228
+		}
5229
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5230
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4933 5231
 				$size_string = $modSettings['avatar_max_height_external'];
5232
+		}
4934 5233
 
4935
-		if (!empty($size_string))
4936
-			$url_params[] = 's=' . $size_string;
5234
+		if (!empty($size_string)) {
5235
+					$url_params[] = 's=' . $size_string;
5236
+		}
4937 5237
 	}
4938 5238
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4939 5239
 
@@ -4952,22 +5252,26 @@  discard block
 block discarded – undo
4952 5252
 	static $timezones = null, $lastwhen = null;
4953 5253
 
4954 5254
 	// No point doing this over if we already did it once
4955
-	if (!empty($timezones) && $when == $lastwhen)
4956
-		return $timezones;
4957
-	else
4958
-		$lastwhen = $when;
5255
+	if (!empty($timezones) && $when == $lastwhen) {
5256
+			return $timezones;
5257
+	} else {
5258
+			$lastwhen = $when;
5259
+	}
4959 5260
 
4960 5261
 	// Parseable datetime string?
4961
-	if (is_int($timestamp = strtotime($when)))
4962
-		$when = $timestamp;
5262
+	if (is_int($timestamp = strtotime($when))) {
5263
+			$when = $timestamp;
5264
+	}
4963 5265
 
4964 5266
 	// A Unix timestamp?
4965
-	elseif (is_numeric($when))
4966
-		$when = intval($when);
5267
+	elseif (is_numeric($when)) {
5268
+			$when = intval($when);
5269
+	}
4967 5270
 
4968 5271
 	// Invalid value? Just get current Unix timestamp.
4969
-	else
4970
-		$when = time();
5272
+	else {
5273
+			$when = time();
5274
+	}
4971 5275
 
4972 5276
 	// We'll need these too
4973 5277
 	$date_when = date_create('@' . $when);
@@ -5031,8 +5335,9 @@  discard block
 block discarded – undo
5031 5335
 	foreach ($priority_countries as $country)
5032 5336
 	{
5033 5337
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5034
-		if (!empty($country_tzids))
5035
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5338
+		if (!empty($country_tzids)) {
5339
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5340
+		}
5036 5341
 	}
5037 5342
 
5038 5343
 	// Process the preferred timezones first, then the rest.
@@ -5042,8 +5347,9 @@  discard block
 block discarded – undo
5042 5347
 	foreach ($tzids as $tzid)
5043 5348
 	{
5044 5349
 		// We don't want UTC right now
5045
-		if ($tzid == 'UTC')
5046
-			continue;
5350
+		if ($tzid == 'UTC') {
5351
+					continue;
5352
+		}
5047 5353
 
5048 5354
 		$tz = timezone_open($tzid);
5049 5355
 
@@ -5058,12 +5364,14 @@  discard block
 block discarded – undo
5058 5364
 		$tzgeo = timezone_location_get($tz);
5059 5365
 
5060 5366
 		// Don't overwrite our preferred tzids
5061
-		if (empty($zones[$tzkey]['tzid']))
5062
-			$zones[$tzkey]['tzid'] = $tzid;
5367
+		if (empty($zones[$tzkey]['tzid'])) {
5368
+					$zones[$tzkey]['tzid'] = $tzid;
5369
+		}
5063 5370
 
5064 5371
 		// A time zone from a prioritized country?
5065
-		if (in_array($tzid, $priority_tzids))
5066
-			$priority_zones[$tzkey] = true;
5372
+		if (in_array($tzid, $priority_tzids)) {
5373
+					$priority_zones[$tzkey] = true;
5374
+		}
5067 5375
 
5068 5376
 		// Keep track of the location and offset for this tzid
5069 5377
 		$tzid_parts = explode('/', $tzid);
@@ -5084,15 +5392,17 @@  discard block
 block discarded – undo
5084 5392
 
5085 5393
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5086 5394
 
5087
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5088
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5089
-		else
5090
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5395
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5396
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5397
+		} else {
5398
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5399
+		}
5091 5400
 
5092
-		if (isset($priority_zones[$tzkey]))
5093
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5094
-		else
5095
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5401
+		if (isset($priority_zones[$tzkey])) {
5402
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5403
+		} else {
5404
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5405
+		}
5096 5406
 	}
5097 5407
 
5098 5408
 	$timezones = array_merge(
@@ -5146,9 +5456,9 @@  discard block
 block discarded – undo
5146 5456
 			'Indian/Kerguelen' => 'TFT',
5147 5457
 		);
5148 5458
 
5149
-		if (!empty($missing_tz_abbrs[$tzid]))
5150
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5151
-		else
5459
+		if (!empty($missing_tz_abbrs[$tzid])) {
5460
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5461
+		} else
5152 5462
 		{
5153 5463
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5154 5464
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5176,8 +5486,9 @@  discard block
 block discarded – undo
5176 5486
  */
5177 5487
 function inet_ptod($ip_address)
5178 5488
 {
5179
-	if (!isValidIP($ip_address))
5180
-		return $ip_address;
5489
+	if (!isValidIP($ip_address)) {
5490
+			return $ip_address;
5491
+	}
5181 5492
 
5182 5493
 	$bin = inet_pton($ip_address);
5183 5494
 	return $bin;
@@ -5189,13 +5500,15 @@  discard block
 block discarded – undo
5189 5500
  */
5190 5501
 function inet_dtop($bin)
5191 5502
 {
5192
-	if(empty($bin))
5193
-		return '';
5503
+	if(empty($bin)) {
5504
+			return '';
5505
+	}
5194 5506
 
5195 5507
 	global $db_type;
5196 5508
 
5197
-	if ($db_type == 'postgresql')
5198
-		return $bin;
5509
+	if ($db_type == 'postgresql') {
5510
+			return $bin;
5511
+	}
5199 5512
 
5200 5513
 	$ip_address = inet_ntop($bin);
5201 5514
 
@@ -5220,26 +5533,32 @@  discard block
 block discarded – undo
5220 5533
  */
5221 5534
 function _safe_serialize($value)
5222 5535
 {
5223
-	if(is_null($value))
5224
-		return 'N;';
5536
+	if(is_null($value)) {
5537
+			return 'N;';
5538
+	}
5225 5539
 
5226
-	if(is_bool($value))
5227
-		return 'b:'. (int) $value .';';
5540
+	if(is_bool($value)) {
5541
+			return 'b:'. (int) $value .';';
5542
+	}
5228 5543
 
5229
-	if(is_int($value))
5230
-		return 'i:'. $value .';';
5544
+	if(is_int($value)) {
5545
+			return 'i:'. $value .';';
5546
+	}
5231 5547
 
5232
-	if(is_float($value))
5233
-		return 'd:'. str_replace(',', '.', $value) .';';
5548
+	if(is_float($value)) {
5549
+			return 'd:'. str_replace(',', '.', $value) .';';
5550
+	}
5234 5551
 
5235
-	if(is_string($value))
5236
-		return 's:'. strlen($value) .':"'. $value .'";';
5552
+	if(is_string($value)) {
5553
+			return 's:'. strlen($value) .':"'. $value .'";';
5554
+	}
5237 5555
 
5238 5556
 	if(is_array($value))
5239 5557
 	{
5240 5558
 		$out = '';
5241
-		foreach($value as $k => $v)
5242
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5559
+		foreach($value as $k => $v) {
5560
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5561
+		}
5243 5562
 
5244 5563
 		return 'a:'. count($value) .':{'. $out .'}';
5245 5564
 	}
@@ -5265,8 +5584,9 @@  discard block
 block discarded – undo
5265 5584
 
5266 5585
 	$out = _safe_serialize($value);
5267 5586
 
5268
-	if (isset($mbIntEnc))
5269
-		mb_internal_encoding($mbIntEnc);
5587
+	if (isset($mbIntEnc)) {
5588
+			mb_internal_encoding($mbIntEnc);
5589
+	}
5270 5590
 
5271 5591
 	return $out;
5272 5592
 }
@@ -5283,8 +5603,9 @@  discard block
 block discarded – undo
5283 5603
 function _safe_unserialize($str)
5284 5604
 {
5285 5605
 	// Input  is not a string.
5286
-	if(empty($str) || !is_string($str))
5287
-		return false;
5606
+	if(empty($str) || !is_string($str)) {
5607
+			return false;
5608
+	}
5288 5609
 
5289 5610
 	$stack = array();
5290 5611
 	$expected = array();
@@ -5300,43 +5621,38 @@  discard block
 block discarded – undo
5300 5621
 	while($state != 1)
5301 5622
 	{
5302 5623
 		$type = isset($str[0]) ? $str[0] : '';
5303
-		if($type == '}')
5304
-			$str = substr($str, 1);
5305
-
5306
-		else if($type == 'N' && $str[1] == ';')
5624
+		if($type == '}') {
5625
+					$str = substr($str, 1);
5626
+		} else if($type == 'N' && $str[1] == ';')
5307 5627
 		{
5308 5628
 			$value = null;
5309 5629
 			$str = substr($str, 2);
5310
-		}
5311
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5630
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5312 5631
 		{
5313 5632
 			$value = $matches[1] == '1' ? true : false;
5314 5633
 			$str = substr($str, 4);
5315
-		}
5316
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5634
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5317 5635
 		{
5318 5636
 			$value = (int)$matches[1];
5319 5637
 			$str = $matches[2];
5320
-		}
5321
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5638
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5322 5639
 		{
5323 5640
 			$value = (float)$matches[1];
5324 5641
 			$str = $matches[3];
5325
-		}
5326
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5642
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5327 5643
 		{
5328 5644
 			$value = substr($matches[2], 0, (int)$matches[1]);
5329 5645
 			$str = substr($matches[2], (int)$matches[1] + 2);
5330
-		}
5331
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5646
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5332 5647
 		{
5333 5648
 			$expectedLength = (int)$matches[1];
5334 5649
 			$str = $matches[2];
5335 5650
 		}
5336 5651
 
5337 5652
 		// Object or unknown/malformed type.
5338
-		else
5339
-			return false;
5653
+		else {
5654
+					return false;
5655
+		}
5340 5656
 
5341 5657
 		switch($state)
5342 5658
 		{
@@ -5364,8 +5680,9 @@  discard block
 block discarded – undo
5364 5680
 				if($type == '}')
5365 5681
 				{
5366 5682
 					// Array size is less than expected.
5367
-					if(count($list) < end($expected))
5368
-						return false;
5683
+					if(count($list) < end($expected)) {
5684
+											return false;
5685
+					}
5369 5686
 
5370 5687
 					unset($list);
5371 5688
 					$list = &$stack[count($stack)-1];
@@ -5374,8 +5691,9 @@  discard block
 block discarded – undo
5374 5691
 					// Go to terminal state if we're at the end of the root array.
5375 5692
 					array_pop($expected);
5376 5693
 
5377
-					if(count($expected) == 0)
5378
-						$state = 1;
5694
+					if(count($expected) == 0) {
5695
+											$state = 1;
5696
+					}
5379 5697
 
5380 5698
 					break;
5381 5699
 				}
@@ -5383,8 +5701,9 @@  discard block
 block discarded – undo
5383 5701
 				if($type == 'i' || $type == 's')
5384 5702
 				{
5385 5703
 					// Array size exceeds expected length.
5386
-					if(count($list) >= end($expected))
5387
-						return false;
5704
+					if(count($list) >= end($expected)) {
5705
+											return false;
5706
+					}
5388 5707
 
5389 5708
 					$key = $value;
5390 5709
 					$state = 3;
@@ -5418,8 +5737,9 @@  discard block
 block discarded – undo
5418 5737
 	}
5419 5738
 
5420 5739
 	// Trailing data in input.
5421
-	if(!empty($str))
5422
-		return false;
5740
+	if(!empty($str)) {
5741
+			return false;
5742
+	}
5423 5743
 
5424 5744
 	return $data;
5425 5745
 }
@@ -5442,8 +5762,9 @@  discard block
 block discarded – undo
5442 5762
 
5443 5763
 	$out = _safe_unserialize($str);
5444 5764
 
5445
-	if (isset($mbIntEnc))
5446
-		mb_internal_encoding($mbIntEnc);
5765
+	if (isset($mbIntEnc)) {
5766
+			mb_internal_encoding($mbIntEnc);
5767
+	}
5447 5768
 
5448 5769
 	return $out;
5449 5770
 }
@@ -5458,12 +5779,14 @@  discard block
 block discarded – undo
5458 5779
 function smf_chmod($file, $value = 0)
5459 5780
 {
5460 5781
 	// No file? no checks!
5461
-	if (empty($file))
5462
-		return false;
5782
+	if (empty($file)) {
5783
+			return false;
5784
+	}
5463 5785
 
5464 5786
 	// Already writable?
5465
-	if (is_writable($file))
5466
-		return true;
5787
+	if (is_writable($file)) {
5788
+			return true;
5789
+	}
5467 5790
 
5468 5791
 	// Do we have a file or a dir?
5469 5792
 	$isDir = is_dir($file);
@@ -5479,10 +5802,9 @@  discard block
 block discarded – undo
5479 5802
 		{
5480 5803
 			$isWritable = true;
5481 5804
 			break;
5805
+		} else {
5806
+					@chmod($file, $val);
5482 5807
 		}
5483
-
5484
-		else
5485
-			@chmod($file, $val);
5486 5808
 	}
5487 5809
 
5488 5810
 	return $isWritable;
@@ -5501,8 +5823,9 @@  discard block
 block discarded – undo
5501 5823
 	global $txt;
5502 5824
 
5503 5825
 	// Come on...
5504
-	if (empty($json) || !is_string($json))
5505
-		return array();
5826
+	if (empty($json) || !is_string($json)) {
5827
+			return array();
5828
+	}
5506 5829
 
5507 5830
 	$returnArray = @json_decode($json, $returnAsArray);
5508 5831
 
@@ -5540,11 +5863,11 @@  discard block
 block discarded – undo
5540 5863
 		$jsonDebug = $jsonDebug[0];
5541 5864
 		loadLanguage('Errors');
5542 5865
 
5543
-		if (!empty($jsonDebug))
5544
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5545
-
5546
-		else
5547
-			log_error($txt['json_'. $jsonError], 'critical');
5866
+		if (!empty($jsonDebug)) {
5867
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5868
+		} else {
5869
+					log_error($txt['json_'. $jsonError], 'critical');
5870
+		}
5548 5871
 
5549 5872
 		// Everyone expects an array.
5550 5873
 		return array();
@@ -5574,8 +5897,9 @@  discard block
 block discarded – undo
5574 5897
 	global $db_show_debug, $modSettings;
5575 5898
 
5576 5899
 	// Defensive programming anyone?
5577
-	if (empty($data))
5578
-		return false;
5900
+	if (empty($data)) {
5901
+			return false;
5902
+	}
5579 5903
 
5580 5904
 	// Don't need extra stuff...
5581 5905
 	$db_show_debug = false;
@@ -5583,11 +5907,11 @@  discard block
 block discarded – undo
5583 5907
 	// Kill anything else.
5584 5908
 	ob_end_clean();
5585 5909
 
5586
-	if (!empty($modSettings['CompressedOutput']))
5587
-		@ob_start('ob_gzhandler');
5588
-
5589
-	else
5590
-		ob_start();
5910
+	if (!empty($modSettings['CompressedOutput'])) {
5911
+			@ob_start('ob_gzhandler');
5912
+	} else {
5913
+			ob_start();
5914
+	}
5591 5915
 
5592 5916
 	// Set the header.
5593 5917
 	header($type);
@@ -5619,8 +5943,9 @@  discard block
 block discarded – undo
5619 5943
 	static $done = false;
5620 5944
 
5621 5945
 	// If we don't need to do anything, don't
5622
-	if (!$update && $done)
5623
-		return;
5946
+	if (!$update && $done) {
5947
+			return;
5948
+	}
5624 5949
 
5625 5950
 	// Should we get a new copy of the official list of TLDs?
5626 5951
 	if ($update)
@@ -5641,10 +5966,11 @@  discard block
 block discarded – undo
5641 5966
 		// Clean $tlds and convert it to an array
5642 5967
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5643 5968
 			$line = trim($line);
5644
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5645
-				return false;
5646
-			else
5647
-				return true;
5969
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5970
+							return false;
5971
+			} else {
5972
+							return true;
5973
+			}
5648 5974
 		});
5649 5975
 
5650 5976
 		// Convert Punycode to Unicode
@@ -5698,8 +6024,9 @@  discard block
 block discarded – undo
5698 6024
 						$idx += $digit * $w;
5699 6025
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5700 6026
 
5701
-						if ($digit < $t)
5702
-							break;
6027
+						if ($digit < $t) {
6028
+													break;
6029
+						}
5703 6030
 
5704 6031
 						$w = (int) ($w * ($base - $t));
5705 6032
 					}
@@ -5708,8 +6035,9 @@  discard block
 block discarded – undo
5708 6035
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5709 6036
 					$delta += intval($delta / ($deco_len + 1));
5710 6037
 
5711
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5712
-						$delta = intval($delta / ($base - $tmin));
6038
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6039
+											$delta = intval($delta / ($base - $tmin));
6040
+					}
5713 6041
 
5714 6042
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5715 6043
 					$is_first = false;
@@ -5718,8 +6046,9 @@  discard block
 block discarded – undo
5718 6046
 
5719 6047
 					if ($deco_len > 0)
5720 6048
 					{
5721
-						for ($i = $deco_len; $i > $idx; $i--)
5722
-							$decoded[$i] = $decoded[($i - 1)];
6049
+						for ($i = $deco_len; $i > $idx; $i--) {
6050
+													$decoded[$i] = $decoded[($i - 1)];
6051
+						}
5723 6052
 					}
5724 6053
 					$decoded[$idx++] = $char;
5725 6054
 				}
@@ -5727,24 +6056,29 @@  discard block
 block discarded – undo
5727 6056
 				foreach ($decoded as $k => $v)
5728 6057
 				{
5729 6058
 					// 7bit are transferred literally
5730
-					if ($v < 128)
5731
-						$output .= chr($v);
6059
+					if ($v < 128) {
6060
+											$output .= chr($v);
6061
+					}
5732 6062
 
5733 6063
 					// 2 bytes
5734
-					elseif ($v < (1 << 11))
5735
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6064
+					elseif ($v < (1 << 11)) {
6065
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6066
+					}
5736 6067
 
5737 6068
 					// 3 bytes
5738
-					elseif ($v < (1 << 16))
5739
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6069
+					elseif ($v < (1 << 16)) {
6070
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6071
+					}
5740 6072
 
5741 6073
 					// 4 bytes
5742
-					elseif ($v < (1 << 21))
5743
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6074
+					elseif ($v < (1 << 21)) {
6075
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6076
+					}
5744 6077
 
5745 6078
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5746
-					else
5747
-						$output .= $safe_char;
6079
+					else {
6080
+											$output .= $safe_char;
6081
+					}
5748 6082
 				}
5749 6083
 
5750 6084
 				$output_parts[] = $output;
@@ -5839,8 +6173,7 @@  discard block
 block discarded – undo
5839 6173
 
5840 6174
 		$strlen = 'mb_strlen';
5841 6175
 		$substr = 'mb_substr';
5842
-	}
5843
-	else
6176
+	} else
5844 6177
 	{
5845 6178
 		$strlen = $smcFunc['strlen'];
5846 6179
 		$substr = $smcFunc['substr'];
@@ -5854,20 +6187,21 @@  discard block
 block discarded – undo
5854 6187
 
5855 6188
 		$first = $substr($string, 0, 1);
5856 6189
 
5857
-		if (empty($index[$first]))
5858
-			$index[$first] = array();
6190
+		if (empty($index[$first])) {
6191
+					$index[$first] = array();
6192
+		}
5859 6193
 
5860 6194
 		if ($strlen($string) > 1)
5861 6195
 		{
5862 6196
 			// Sanity check on recursion
5863
-			if ($depth > 99)
5864
-				$index[$first][$substr($string, 1)] = '';
5865
-
5866
-			else
5867
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6197
+			if ($depth > 99) {
6198
+							$index[$first][$substr($string, 1)] = '';
6199
+			} else {
6200
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6201
+			}
6202
+		} else {
6203
+					$index[$first][''] = '';
5868 6204
 		}
5869
-		else
5870
-			$index[$first][''] = '';
5871 6205
 
5872 6206
 		$depth--;
5873 6207
 		return $index;
@@ -5890,9 +6224,9 @@  discard block
 block discarded – undo
5890 6224
 			$key_regex = preg_quote($key, $delim);
5891 6225
 			$new_key = $key;
5892 6226
 
5893
-			if (empty($value))
5894
-				$sub_regex = '';
5895
-			else
6227
+			if (empty($value)) {
6228
+							$sub_regex = '';
6229
+			} else
5896 6230
 			{
5897 6231
 				$sub_regex = $index_to_regex($value, $delim);
5898 6232
 
@@ -5900,22 +6234,22 @@  discard block
 block discarded – undo
5900 6234
 				{
5901 6235
 					$new_key_array = explode('(?'.'>', $sub_regex);
5902 6236
 					$new_key .= $new_key_array[0];
6237
+				} else {
6238
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5903 6239
 				}
5904
-				else
5905
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5906 6240
 			}
5907 6241
 
5908
-			if ($depth > 1)
5909
-				$regex[$new_key] = $key_regex . $sub_regex;
5910
-			else
6242
+			if ($depth > 1) {
6243
+							$regex[$new_key] = $key_regex . $sub_regex;
6244
+			} else
5911 6245
 			{
5912 6246
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5913 6247
 				{
5914 6248
 					$regex[$new_key] = $key_regex . $sub_regex;
5915 6249
 					unset($index[$key]);
6250
+				} else {
6251
+									break;
5916 6252
 				}
5917
-				else
5918
-					break;
5919 6253
 			}
5920 6254
 		}
5921 6255
 
@@ -5924,10 +6258,11 @@  discard block
 block discarded – undo
5924 6258
 			$l1 = $strlen($k1);
5925 6259
 			$l2 = $strlen($k2);
5926 6260
 
5927
-			if ($l1 == $l2)
5928
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5929
-			else
5930
-				return $l1 > $l2 ? -1 : 1;
6261
+			if ($l1 == $l2) {
6262
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6263
+			} else {
6264
+							return $l1 > $l2 ? -1 : 1;
6265
+			}
5931 6266
 		});
5932 6267
 
5933 6268
 		$depth--;
@@ -5938,15 +6273,18 @@  discard block
 block discarded – undo
5938 6273
 	$index = array();
5939 6274
 	$regexes = array();
5940 6275
 
5941
-	foreach ($strings as $string)
5942
-		$index = $add_string_to_index($string, $index);
6276
+	foreach ($strings as $string) {
6277
+			$index = $add_string_to_index($string, $index);
6278
+	}
5943 6279
 
5944
-	while (!empty($index))
5945
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6280
+	while (!empty($index)) {
6281
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6282
+	}
5946 6283
 
5947 6284
 	// Restore PHP's internal character encoding to whatever it was originally
5948
-	if (!empty($current_encoding))
5949
-		mb_internal_encoding($current_encoding);
6285
+	if (!empty($current_encoding)) {
6286
+			mb_internal_encoding($current_encoding);
6287
+	}
5950 6288
 
5951 6289
 	return $regexes;
5952 6290
 }
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +171 added lines, -124 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -167,9 +178,10 @@  discard block
 block discarded – undo
167 178
 		$reg_fields = explode(',', $modSettings['registration_fields']);
168 179
 
169 180
 		// We might have had some submissions on this front - go check.
170
-		foreach ($reg_fields as $field)
171
-			if (isset($_POST[$field]))
181
+		foreach ($reg_fields as $field) {
182
+					if (isset($_POST[$field]))
172 183
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
184
+		}
173 185
 
174 186
 		// Load all the fields in question.
175 187
 		setupProfileContext($reg_fields);
@@ -186,8 +198,9 @@  discard block
 block discarded – undo
186 198
 		$context['visual_verification_id'] = $verificationOptions['id'];
187 199
 	}
188 200
 	// Otherwise we have nothing to show.
189
-	else
190
-		$context['visual_verification'] = false;
201
+	else {
202
+			$context['visual_verification'] = false;
203
+	}
191 204
 
192 205
 
193 206
 	$context += array(
@@ -198,8 +211,9 @@  discard block
 block discarded – undo
198 211
 
199 212
 	// Were there any errors?
200 213
 	$context['registration_errors'] = array();
201
-	if (!empty($reg_errors))
202
-		$context['registration_errors'] = $reg_errors;
214
+	if (!empty($reg_errors)) {
215
+			$context['registration_errors'] = $reg_errors;
216
+	}
203 217
 
204 218
 	createToken('register');
205 219
 }
@@ -216,27 +230,32 @@  discard block
 block discarded – undo
216 230
 	validateToken('register');
217 231
 
218 232
 	// Check to ensure we're forcing SSL for authentication
219
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
220
-		fatal_lang_error('register_ssl_required');
233
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
234
+			fatal_lang_error('register_ssl_required');
235
+	}
221 236
 
222 237
 	// Start collecting together any errors.
223 238
 	$reg_errors = array();
224 239
 
225 240
 	// You can't register if it's disabled.
226
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
227
-		fatal_lang_error('registration_disabled', false);
241
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
242
+			fatal_lang_error('registration_disabled', false);
243
+	}
228 244
 
229 245
 	// Well, if you don't agree, you can't register.
230
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
231
-		redirectexit();
246
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
247
+			redirectexit();
248
+	}
232 249
 
233 250
 	// Make sure they came from *somewhere*, have a session.
234
-	if (!isset($_SESSION['old_url']))
235
-		redirectexit('action=signup');
251
+	if (!isset($_SESSION['old_url'])) {
252
+			redirectexit('action=signup');
253
+	}
236 254
 
237 255
 	// If we don't require an agreement, we need a extra check for coppa.
238
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
239
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
256
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
257
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
258
+	}
240 259
 	// Are they under age, and under age users are banned?
241 260
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
242 261
 	{
@@ -245,8 +264,9 @@  discard block
 block discarded – undo
245 264
 	}
246 265
 
247 266
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
248
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
249
-		redirectexit('action=signup');
267
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
268
+			redirectexit('action=signup');
269
+	}
250 270
 	// Failing that, check the time on it.
251 271
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
252 272
 	{
@@ -266,15 +286,17 @@  discard block
 block discarded – undo
266 286
 		if (is_array($context['visual_verification']))
267 287
 		{
268 288
 			loadLanguage('Errors');
269
-			foreach ($context['visual_verification'] as $error)
270
-				$reg_errors[] = $txt['error_' . $error];
289
+			foreach ($context['visual_verification'] as $error) {
290
+							$reg_errors[] = $txt['error_' . $error];
291
+			}
271 292
 		}
272 293
 	}
273 294
 
274 295
 	foreach ($_POST as $key => $value)
275 296
 	{
276
-		if (!is_array($_POST[$key]))
277
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
297
+		if (!is_array($_POST[$key])) {
298
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
299
+		}
278 300
 	}
279 301
 
280 302
 	// Collect all extra registration fields someone might have filled in.
@@ -304,12 +326,14 @@  discard block
 block discarded – undo
304 326
 		$reg_fields = explode(',', $modSettings['registration_fields']);
305 327
 
306 328
 		// Website is a little different
307
-		if (in_array('website', $reg_fields))
308
-			$possible_strings += array('website_url', 'website_title');
329
+		if (in_array('website', $reg_fields)) {
330
+					$possible_strings += array('website_url', 'website_title');
331
+		}
309 332
 	}
310 333
 
311
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
312
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
334
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
335
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
336
+	}
313 337
 
314 338
 	// Needed for isReservedName() and registerMember().
315 339
 	require_once($sourcedir . '/Subs-Members.php');
@@ -318,8 +342,9 @@  discard block
 block discarded – undo
318 342
 	if (isset($_POST['real_name']))
319 343
 	{
320 344
 		// Are you already allowed to edit the displayed name?
321
-		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))
322
-			$canEditDisplayName = true;
345
+		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) {
346
+					$canEditDisplayName = true;
347
+		}
323 348
 
324 349
 		// If you are a guest, will you be allowed to once you register?
325 350
 		else
@@ -343,33 +368,38 @@  discard block
 block discarded – undo
343 368
 			$_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
344 369
 
345 370
 			// Only set it if we are sure it is good
346
-			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
347
-				$possible_strings[] = 'real_name';
371
+			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
372
+							$possible_strings[] = 'real_name';
373
+			}
348 374
 		}
349 375
 	}
350 376
 
351 377
 	// Handle a string as a birthdate...
352
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
353
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
378
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
379
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
380
+	}
354 381
 	// Or birthdate parts...
355
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
356
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
382
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
383
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
384
+	}
357 385
 
358 386
 	// Validate the passed language file.
359 387
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
360 388
 	{
361 389
 		// Do we have any languages?
362
-		if (empty($context['languages']))
363
-			getLanguages();
390
+		if (empty($context['languages'])) {
391
+					getLanguages();
392
+		}
364 393
 
365 394
 		// Did we find it?
366
-		if (isset($context['languages'][$_POST['lngfile']]))
367
-			$_SESSION['language'] = $_POST['lngfile'];
368
-		else
395
+		if (isset($context['languages'][$_POST['lngfile']])) {
396
+					$_SESSION['language'] = $_POST['lngfile'];
397
+		} else {
398
+					unset($_POST['lngfile']);
399
+		}
400
+	} else {
369 401
 			unset($_POST['lngfile']);
370 402
 	}
371
-	else
372
-		unset($_POST['lngfile']);
373 403
 
374 404
 	// Set the options needed for registration.
375 405
 	$regOptions = array(
@@ -389,22 +419,27 @@  discard block
 block discarded – undo
389 419
 	);
390 420
 
391 421
 	// Include the additional options that might have been filled in.
392
-	foreach ($possible_strings as $var)
393
-		if (isset($_POST[$var]))
422
+	foreach ($possible_strings as $var) {
423
+			if (isset($_POST[$var]))
394 424
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
395
-	foreach ($possible_ints as $var)
396
-		if (isset($_POST[$var]))
425
+	}
426
+	foreach ($possible_ints as $var) {
427
+			if (isset($_POST[$var]))
397 428
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
398
-	foreach ($possible_floats as $var)
399
-		if (isset($_POST[$var]))
429
+	}
430
+	foreach ($possible_floats as $var) {
431
+			if (isset($_POST[$var]))
400 432
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
401
-	foreach ($possible_bools as $var)
402
-		if (isset($_POST[$var]))
433
+	}
434
+	foreach ($possible_bools as $var) {
435
+			if (isset($_POST[$var]))
403 436
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
437
+	}
404 438
 
405 439
 	// Registration options are always default options...
406
-	if (isset($_POST['default_options']))
407
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
440
+	if (isset($_POST['default_options'])) {
441
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
442
+	}
408 443
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
409 444
 
410 445
 	// Make sure they are clean, dammit!
@@ -424,12 +459,14 @@  discard block
 block discarded – undo
424 459
 	while ($row = $smcFunc['db_fetch_assoc']($request))
425 460
 	{
426 461
 		// Don't allow overriding of the theme variables.
427
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
428
-			unset($regOptions['theme_vars'][$row['col_name']]);
462
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
463
+					unset($regOptions['theme_vars'][$row['col_name']]);
464
+		}
429 465
 
430 466
 		// Not actually showing it then?
431
-		if (!$row['show_reg'])
432
-			continue;
467
+		if (!$row['show_reg']) {
468
+					continue;
469
+		}
433 470
 
434 471
 		// Prepare the value!
435 472
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -438,24 +475,27 @@  discard block
 block discarded – undo
438 475
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
439 476
 		{
440 477
 			// Is it too long?
441
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
442
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
478
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
479
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
480
+			}
443 481
 
444 482
 			// Any masks to apply?
445 483
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
446 484
 			{
447
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
448
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
449
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
450
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
451
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
452
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
485
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
486
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
487
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
488
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
489
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
490
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
491
+				}
453 492
 			}
454 493
 		}
455 494
 
456 495
 		// Is this required but not there?
457
-		if (trim($value) == '' && $row['show_reg'] > 1)
458
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
496
+		if (trim($value) == '' && $row['show_reg'] > 1) {
497
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
498
+		}
459 499
 	}
460 500
 	$smcFunc['db_free_result']($request);
461 501
 
@@ -463,8 +503,9 @@  discard block
 block discarded – undo
463 503
 	if (!empty($custom_field_errors))
464 504
 	{
465 505
 		loadLanguage('Errors');
466
-		foreach ($custom_field_errors as $error)
467
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
506
+		foreach ($custom_field_errors as $error) {
507
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
508
+		}
468 509
 	}
469 510
 
470 511
 	// Lets check for other errors before trying to register the member.
@@ -509,8 +550,9 @@  discard block
 block discarded – undo
509 550
 	}
510 551
 
511 552
 	// If COPPA has been selected then things get complicated, setup the template.
512
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
513
-		redirectexit('action=coppa;member=' . $memberID);
553
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
554
+			redirectexit('action=coppa;member=' . $memberID);
555
+	}
514 556
 	// Basic template variable setup.
515 557
 	elseif (!empty($modSettings['registration_method']))
516 558
 	{
@@ -522,8 +564,7 @@  discard block
 block discarded – undo
522 564
 			'sub_template' => 'after',
523 565
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
524 566
 		);
525
-	}
526
-	else
567
+	} else
527 568
 	{
528 569
 		call_integration_hook('integrate_activate', array($regOptions['username']));
529 570
 
@@ -543,16 +584,18 @@  discard block
 block discarded – undo
543 584
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
544 585
 
545 586
 	// Logged in users should not bother to activate their accounts
546
-	if (!empty($user_info['id']))
547
-		redirectexit();
587
+	if (!empty($user_info['id'])) {
588
+			redirectexit();
589
+	}
548 590
 
549 591
 	loadLanguage('Login');
550 592
 	loadTemplate('Login');
551 593
 
552 594
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
553 595
 	{
554
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
555
-			fatal_lang_error('no_access', false);
596
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
597
+					fatal_lang_error('no_access', false);
598
+		}
556 599
 
557 600
 		$context['member_id'] = 0;
558 601
 		$context['sub_template'] = 'resend';
@@ -592,11 +635,13 @@  discard block
 block discarded – undo
592 635
 	// Change their email address? (they probably tried a fake one first :P.)
593 636
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
594 637
 	{
595
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
596
-			fatal_lang_error('no_access', false);
638
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
639
+					fatal_lang_error('no_access', false);
640
+		}
597 641
 
598
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
599
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
642
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
643
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
644
+		}
600 645
 
601 646
 		// Make sure their email isn't banned.
602 647
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -612,8 +657,9 @@  discard block
 block discarded – undo
612 657
 			)
613 658
 		);
614 659
 
615
-		if ($smcFunc['db_num_rows']($request) != 0)
616
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
660
+		if ($smcFunc['db_num_rows']($request) != 0) {
661
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
662
+		}
617 663
 		$smcFunc['db_free_result']($request);
618 664
 
619 665
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -651,9 +697,9 @@  discard block
 block discarded – undo
651 697
 	// Quit if this code is not right.
652 698
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
653 699
 	{
654
-		if (!empty($row['is_activated']))
655
-			fatal_lang_error('already_activated', false);
656
-		elseif ($row['validation_code'] == '')
700
+		if (!empty($row['is_activated'])) {
701
+					fatal_lang_error('already_activated', false);
702
+		} elseif ($row['validation_code'] == '')
657 703
 		{
658 704
 			loadLanguage('Profile');
659 705
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -703,8 +749,9 @@  discard block
 block discarded – undo
703 749
 	loadTemplate('Register');
704 750
 
705 751
 	// No User ID??
706
-	if (!isset($_GET['member']))
707
-		fatal_lang_error('no_access', false);
752
+	if (!isset($_GET['member'])) {
753
+			fatal_lang_error('no_access', false);
754
+	}
708 755
 
709 756
 	// Get the user details...
710 757
 	$request = $smcFunc['db_query']('', '
@@ -717,8 +764,9 @@  discard block
 block discarded – undo
717 764
 			'is_coppa' => 5,
718 765
 		)
719 766
 	);
720
-	if ($smcFunc['db_num_rows']($request) == 0)
721
-		fatal_lang_error('no_access', false);
767
+	if ($smcFunc['db_num_rows']($request) == 0) {
768
+			fatal_lang_error('no_access', false);
769
+	}
722 770
 	list ($username) = $smcFunc['db_fetch_row']($request);
723 771
 	$smcFunc['db_free_result']($request);
724 772
 
@@ -756,8 +804,7 @@  discard block
 block discarded – undo
756 804
 			echo $data;
757 805
 			obExit(false);
758 806
 		}
759
-	}
760
-	else
807
+	} else
761 808
 	{
762 809
 		$context += array(
763 810
 			'page_title' => $txt['coppa_title'],
@@ -810,8 +857,9 @@  discard block
 block discarded – undo
810 857
 	{
811 858
 		require_once($sourcedir . '/Subs-Graphics.php');
812 859
 
813
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
814
-			header('HTTP/1.1 400 Bad Request');
860
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
861
+					header('HTTP/1.1 400 Bad Request');
862
+		}
815 863
 
816 864
 		// Otherwise just show a pre-defined letter.
817 865
 		elseif (isset($_REQUEST['letter']))
@@ -829,14 +877,13 @@  discard block
 block discarded – undo
829 877
 			header('Content-Type: image/gif');
830 878
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
831 879
 		}
832
-	}
833
-
834
-	elseif ($_REQUEST['format'] === '.wav')
880
+	} elseif ($_REQUEST['format'] === '.wav')
835 881
 	{
836 882
 		require_once($sourcedir . '/Subs-Sound.php');
837 883
 
838
-		if (!createWaveFile($code))
839
-			header('HTTP/1.1 400 Bad Request');
884
+		if (!createWaveFile($code)) {
885
+					header('HTTP/1.1 400 Bad Request');
886
+		}
840 887
 	}
841 888
 
842 889
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 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
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.
Sources/QueryString.php 1 patch
Braces   +181 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
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,8 +201,9 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193 208
 		elseif (strpos($_REQUEST['topic'], '.') !== false)
194 209
 		{
@@ -199,19 +214,22 @@  discard block
 block discarded – undo
199 214
 
200 215
 		// Now make sure the online log gets the right number.
201 216
 		$_GET['topic'] = $topic;
217
+	} else {
218
+			$topic = 0;
202 219
 	}
203
-	else
204
-		$topic = 0;
205 220
 
206 221
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
207
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
208
-		$_REQUEST['start'] = 0;
222
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
223
+			$_REQUEST['start'] = 0;
224
+	}
209 225
 
210 226
 	// The action needs to be a string and not an array or anything else
211
-	if (isset($_REQUEST['action']))
212
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
213
-	if (isset($_GET['action']))
214
-		$_GET['action'] = (string) $_GET['action'];
227
+	if (isset($_REQUEST['action'])) {
228
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
229
+	}
230
+	if (isset($_GET['action'])) {
231
+			$_GET['action'] = (string) $_GET['action'];
232
+	}
215 233
 
216 234
 	// Some mail providers like to encode semicolons in activation URLs...
217 235
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -237,29 +255,33 @@  discard block
 block discarded – undo
237 255
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
238 256
 
239 257
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
240
-	if (!isset($modSettings['proxy_ip_header']))
241
-		$modSettings['proxy_ip_header'] = 'autodetect';
258
+	if (!isset($modSettings['proxy_ip_header'])) {
259
+			$modSettings['proxy_ip_header'] = 'autodetect';
260
+	}
242 261
 
243 262
 	// Which headers are we going to check for Reverse Proxy IP headers?
244
-	if ($modSettings['proxy_ip_header'] == 'disabled')
245
-		$reverseIPheaders = array();
246
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
247
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
248
-	else
249
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
263
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
264
+			$reverseIPheaders = array();
265
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
266
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
267
+	} else {
268
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
269
+	}
250 270
 
251 271
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
252 272
 	foreach ($reverseIPheaders as $proxyIPheader)
253 273
 	{
254 274
 		// Ignore if this is not set.
255
-		if (!isset($_SERVER[$proxyIPheader]))
256
-			continue;
275
+		if (!isset($_SERVER[$proxyIPheader])) {
276
+					continue;
277
+		}
257 278
 
258 279
 		if (!empty($modSettings['proxy_ip_servers']))
259 280
 		{
260
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
261
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
281
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
282
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
262 283
 					continue;
284
+			}
263 285
 		}
264 286
 
265 287
 		// If there are commas, get the last one.. probably.
@@ -279,8 +301,9 @@  discard block
 block discarded – undo
279 301
 
280 302
 						// Just incase we have a legacy IPv4 address.
281 303
 						// @ TODO: Convert to IPv6.
282
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
283
-							continue;
304
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
305
+													continue;
306
+						}
284 307
 					}
285 308
 
286 309
 					continue;
@@ -292,36 +315,40 @@  discard block
 block discarded – undo
292 315
 			}
293 316
 		}
294 317
 		// Otherwise just use the only one.
295
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
296
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
297
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
318
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
319
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
320
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
298 321
 		{
299 322
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
300 323
 
301 324
 			// Just incase we have a legacy IPv4 address.
302 325
 			// @ TODO: Convert to IPv6.
303
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
304
-				continue;
326
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
327
+							continue;
328
+			}
305 329
 		}
306 330
 	}
307 331
 
308 332
 	// Make sure we know the URL of the current request.
309
-	if (empty($_SERVER['REQUEST_URI']))
310
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
311
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
312
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
313
-	else
314
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
333
+	if (empty($_SERVER['REQUEST_URI'])) {
334
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
335
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
336
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
337
+	} else {
338
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
339
+	}
315 340
 
316 341
 	// And make sure HTTP_USER_AGENT is set.
317 342
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
318 343
 
319 344
 	// Some final checking.
320
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
321
-		$_SERVER['BAN_CHECK_IP'] = '';
322
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
323
-		$_SERVER['REMOTE_ADDR'] = '';
324
-}
345
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
346
+			$_SERVER['BAN_CHECK_IP'] = '';
347
+	}
348
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
349
+			$_SERVER['REMOTE_ADDR'] = '';
350
+	}
351
+	}
325 352
 
326 353
 /**
327 354
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -332,8 +359,9 @@  discard block
 block discarded – undo
332 359
 function isValidIPv6($ip)
333 360
 {
334 361
 	//looking for :
335
-	if (strpos($ip, ':') === false)
336
-		return false;
362
+	if (strpos($ip, ':') === false) {
363
+			return false;
364
+	}
337 365
 
338 366
 	//check valid address
339 367
 	return inet_pton($ip);
@@ -350,15 +378,17 @@  discard block
 block discarded – undo
350 378
 	static $expanded = array();
351 379
 
352 380
 	// Check if we have done this already.
353
-	if (isset($expanded[$ip]))
354
-		return $expanded[$ip];
381
+	if (isset($expanded[$ip])) {
382
+			return $expanded[$ip];
383
+	}
355 384
 
356 385
 	// Expand the IP out.
357 386
 	$expanded_ip = explode(':', expandIPv6($ip));
358 387
 
359 388
 	$new_ip = array();
360
-	foreach ($expanded_ip as $int)
361
-		$new_ip[] = hexdec($int);
389
+	foreach ($expanded_ip as $int) {
390
+			$new_ip[] = hexdec($int);
391
+	}
362 392
 
363 393
 	// Save this incase of repeated use.
364 394
 	$expanded[$ip] = $new_ip;
@@ -378,8 +408,9 @@  discard block
 block discarded – undo
378 408
 	static $converted = array();
379 409
 
380 410
 	// Check if we have done this already.
381
-	if (isset($converted[$addr]))
382
-		return $converted[$addr];
411
+	if (isset($converted[$addr])) {
412
+			return $converted[$addr];
413
+	}
383 414
 
384 415
 	// Check if there are segments missing, insert if necessary.
385 416
 	if (strpos($addr, '::') !== false)
@@ -389,18 +420,20 @@  discard block
 block discarded – undo
389 420
 		$part[1] = explode(':', $part[1]);
390 421
 		$missing = array();
391 422
 
392
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
393
-			array_push($missing, '0000');
423
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
424
+					array_push($missing, '0000');
425
+		}
394 426
 
395 427
 		$part = array_merge($part[0], $missing, $part[1]);
428
+	} else {
429
+			$part = explode(':', $addr);
396 430
 	}
397
-	else
398
-		$part = explode(':', $addr);
399 431
 
400 432
 	// Pad each segment until it has 4 digits.
401
-	foreach ($part as &$p)
402
-		while (strlen($p) < 4)
433
+	foreach ($part as &$p) {
434
+			while (strlen($p) < 4)
403 435
 			$p = '0' . $p;
436
+	}
404 437
 
405 438
 	unset($p);
406 439
 
@@ -411,11 +444,12 @@  discard block
 block discarded – undo
411 444
 	$converted[$addr] = $result;
412 445
 
413 446
 	// Quick check to make sure the length is as expected.
414
-	if (!$strict_check || strlen($result) == 39)
415
-		return $result;
416
-	else
417
-		return false;
418
-}
447
+	if (!$strict_check || strlen($result) == 39) {
448
+			return $result;
449
+	} else {
450
+			return false;
451
+	}
452
+	}
419 453
 
420 454
 
421 455
 /**
@@ -446,15 +480,17 @@  discard block
 block discarded – undo
446 480
 {
447 481
 	global $smcFunc;
448 482
 
449
-	if (!is_array($var))
450
-		return $smcFunc['db_escape_string']($var);
483
+	if (!is_array($var)) {
484
+			return $smcFunc['db_escape_string']($var);
485
+	}
451 486
 
452 487
 	// Reindex the array with slashes.
453 488
 	$new_var = array();
454 489
 
455 490
 	// Add slashes to every element, even the indexes!
456
-	foreach ($var as $k => $v)
457
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
491
+	foreach ($var as $k => $v) {
492
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
493
+	}
458 494
 
459 495
 	return $new_var;
460 496
 }
@@ -474,12 +510,14 @@  discard block
 block discarded – undo
474 510
 {
475 511
 	global $smcFunc;
476 512
 
477
-	if (!is_array($var))
478
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
513
+	if (!is_array($var)) {
514
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
515
+	}
479 516
 
480 517
 	// Add the htmlspecialchars to every element.
481
-	foreach ($var as $k => $v)
482
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
518
+	foreach ($var as $k => $v) {
519
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
520
+	}
483 521
 
484 522
 	return $var;
485 523
 }
@@ -497,15 +535,17 @@  discard block
 block discarded – undo
497 535
  */
498 536
 function urldecode__recursive($var, $level = 0)
499 537
 {
500
-	if (!is_array($var))
501
-		return urldecode($var);
538
+	if (!is_array($var)) {
539
+			return urldecode($var);
540
+	}
502 541
 
503 542
 	// Reindex the array...
504 543
 	$new_var = array();
505 544
 
506 545
 	// Add the htmlspecialchars to every element.
507
-	foreach ($var as $k => $v)
508
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
546
+	foreach ($var as $k => $v) {
547
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
548
+	}
509 549
 
510 550
 	return $new_var;
511 551
 }
@@ -523,15 +563,17 @@  discard block
 block discarded – undo
523 563
 {
524 564
 	global $smcFunc;
525 565
 
526
-	if (!is_array($var))
527
-		return $smcFunc['db_unescape_string']($var);
566
+	if (!is_array($var)) {
567
+			return $smcFunc['db_unescape_string']($var);
568
+	}
528 569
 
529 570
 	// Reindex the array without slashes, this time.
530 571
 	$new_var = array();
531 572
 
532 573
 	// Strip the slashes from every element.
533
-	foreach ($var as $k => $v)
534
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
574
+	foreach ($var as $k => $v) {
575
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
576
+	}
535 577
 
536 578
 	return $new_var;
537 579
 }
@@ -549,15 +591,17 @@  discard block
 block discarded – undo
549 591
  */
550 592
 function stripslashes__recursive($var, $level = 0)
551 593
 {
552
-	if (!is_array($var))
553
-		return stripslashes($var);
594
+	if (!is_array($var)) {
595
+			return stripslashes($var);
596
+	}
554 597
 
555 598
 	// Reindex the array without slashes, this time.
556 599
 	$new_var = array();
557 600
 
558 601
 	// Strip the slashes from every element.
559
-	foreach ($var as $k => $v)
560
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
602
+	foreach ($var as $k => $v) {
603
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
604
+	}
561 605
 
562 606
 	return $new_var;
563 607
 }
@@ -578,12 +622,14 @@  discard block
 block discarded – undo
578 622
 	global $smcFunc;
579 623
 
580 624
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
581
-	if (!is_array($var))
582
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
625
+	if (!is_array($var)) {
626
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
627
+	}
583 628
 
584 629
 	// Go through all the elements and remove the whitespace.
585
-	foreach ($var as $k => $v)
586
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
630
+	foreach ($var as $k => $v) {
631
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
632
+	}
587 633
 
588 634
 	return $var;
589 635
 }
@@ -648,30 +694,37 @@  discard block
 block discarded – undo
648 694
 	global $scripturl, $modSettings, $context;
649 695
 
650 696
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
651
-	if ($scripturl == '' || !defined('SID'))
652
-		return $buffer;
697
+	if ($scripturl == '' || !defined('SID')) {
698
+			return $buffer;
699
+	}
653 700
 
654 701
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
655 702
 	// @todo smflib
656
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
657
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
703
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
704
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
705
+	}
658 706
 	// Debugging templates, are we?
659
-	elseif (isset($_GET['debug']))
660
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
707
+	elseif (isset($_GET['debug'])) {
708
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
709
+	}
661 710
 
662 711
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
663 712
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
664 713
 	{
665 714
 		// Let's do something special for session ids!
666
-		if (defined('SID') && SID != '')
667
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
715
+		if (defined('SID') && SID != '') {
716
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
668 717
 			{
669
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
718
+				global $scripturl;
719
+		}
720
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
670 721
 			}, $buffer);
671
-		else
672
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
722
+		else {
723
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
673 724
 			{
674
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
725
+				global $scripturl;
726
+		}
727
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
675 728
 			}, $buffer);
676 729
 	}
677 730
 
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +219 added lines, -163 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
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -61,11 +62,13 @@  discard block
 block discarded – undo
61 62
 			'db_mb4' => true,
62 63
 			'db_ping' => 'pg_ping',
63 64
 		);
65
+	}
64 66
 
65
-	if (!empty($db_options['persist']))
66
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
-	else
68
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	if (!empty($db_options['persist'])) {
68
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	} else {
70
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
+	}
69 72
 
70 73
 	// Something's wrong, show an error if its fatal (which we assume it is)
71 74
 	if (!$connection)
@@ -73,8 +76,7 @@  discard block
 block discarded – undo
73 76
 		if (!empty($db_options['non_fatal']))
74 77
 		{
75 78
 			return null;
76
-		}
77
-		else
79
+		} else
78 80
 		{
79 81
 			display_db_error();
80 82
 		}
@@ -125,31 +127,38 @@  discard block
 block discarded – undo
125 127
 
126 128
 	list ($values, $connection) = $db_callback;
127 129
 
128
-	if ($matches[1] === 'db_prefix')
129
-		return $db_prefix;
130
+	if ($matches[1] === 'db_prefix') {
131
+			return $db_prefix;
132
+	}
130 133
 
131
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
132
-		return $user_info[$matches[1]];
134
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
135
+			return $user_info[$matches[1]];
136
+	}
133 137
 
134
-	if ($matches[1] === 'empty')
135
-		return '\'\'';
138
+	if ($matches[1] === 'empty') {
139
+			return '\'\'';
140
+	}
136 141
 
137
-	if (!isset($matches[2]))
138
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
142
+	if (!isset($matches[2])) {
143
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	}
139 145
 
140
-	if ($matches[1] === 'literal')
141
-		return '\'' . pg_escape_string($matches[2]) . '\'';
146
+	if ($matches[1] === 'literal') {
147
+			return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	}
142 149
 
143
-	if (!isset($values[$matches[2]]))
144
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
150
+	if (!isset($values[$matches[2]])) {
151
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	}
145 153
 
146 154
 	$replacement = $values[$matches[2]];
147 155
 
148 156
 	switch ($matches[1])
149 157
 	{
150 158
 		case 'int':
151
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
152
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
159
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
160
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			}
153 162
 			return (string) (int) $replacement;
154 163
 		break;
155 164
 
@@ -161,65 +170,73 @@  discard block
 block discarded – undo
161 170
 		case 'array_int':
162 171
 			if (is_array($replacement))
163 172
 			{
164
-				if (empty($replacement))
165
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
173
+				if (empty($replacement)) {
174
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				}
166 176
 
167 177
 				foreach ($replacement as $key => $value)
168 178
 				{
169
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
170
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
180
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					}
171 182
 
172 183
 					$replacement[$key] = (string) (int) $value;
173 184
 				}
174 185
 
175 186
 				return implode(', ', $replacement);
187
+			} else {
188
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176 189
 			}
177
-			else
178
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 190
 
180 191
 		break;
181 192
 
182 193
 		case 'array_string':
183 194
 			if (is_array($replacement))
184 195
 			{
185
-				if (empty($replacement))
186
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196
+				if (empty($replacement)) {
197
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				}
187 199
 
188
-				foreach ($replacement as $key => $value)
189
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
200
+				foreach ($replacement as $key => $value) {
201
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				}
190 203
 
191 204
 				return implode(', ', $replacement);
205
+			} else {
206
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
192 207
 			}
193
-			else
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 208
 		break;
196 209
 
197 210
 		case 'date':
198
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
199
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
200
-			else
201
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
212
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
213
+			} else {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
202 216
 		break;
203 217
 
204 218
 		case 'time':
205
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
206
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
207
-			else
208
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
220
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
221
+			} else {
222
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			}
209 224
 		break;
210 225
 
211 226
 		case 'datetime':
212
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
213
-				return 'to_timestamp('.
227
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
228
+							return 'to_timestamp('.
214 229
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
215 230
 					',\'YYYY-MM-DD HH24:MI:SS\')';
216
-			else
217
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			} else {
232
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			}
218 234
 		break;
219 235
 
220 236
 		case 'float':
221
-			if (!is_numeric($replacement))
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			if (!is_numeric($replacement)) {
238
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239
+			}
223 240
 			return (string) (float) $replacement;
224 241
 		break;
225 242
 
@@ -232,31 +249,36 @@  discard block
 block discarded – undo
232 249
 		break;
233 250
 
234 251
 		case 'inet':
235
-			if ($replacement == 'null' || $replacement == '')
236
-				return 'null';
237
-			if (inet_pton($replacement) === false)
238
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+			if ($replacement == 'null' || $replacement == '') {
253
+							return 'null';
254
+			}
255
+			if (inet_pton($replacement) === false) {
256
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+			}
239 258
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
240 259
 
241 260
 		case 'array_inet':
242 261
 			if (is_array($replacement))
243 262
 			{
244
-				if (empty($replacement))
245
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+				if (empty($replacement)) {
264
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+				}
246 266
 
247 267
 				foreach ($replacement as $key => $value)
248 268
 				{
249
-					if ($replacement == 'null' || $replacement == '')
250
-						$replacement[$key] = 'null';
251
-					if (!isValidIP($value))
252
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+					if ($replacement == 'null' || $replacement == '') {
270
+											$replacement[$key] = 'null';
271
+					}
272
+					if (!isValidIP($value)) {
273
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+					}
253 275
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
254 276
 				}
255 277
 
256 278
 				return implode(', ', $replacement);
279
+			} else {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257 281
 			}
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 282
 		break;
261 283
 
262 284
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -399,8 +424,9 @@  discard block
 block discarded – undo
399 424
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
400 425
 
401 426
 		// Initialize $db_cache if not already initialized.
402
-		if (!isset($db_cache))
403
-			$db_cache = array();
427
+		if (!isset($db_cache)) {
428
+					$db_cache = array();
429
+		}
404 430
 
405 431
 		if (!empty($_SESSION['debug_redirect']))
406 432
 		{
@@ -426,17 +452,18 @@  discard block
 block discarded – undo
426 452
 		while (true)
427 453
 		{
428 454
 			$pos = strpos($db_string, '\'', $pos + 1);
429
-			if ($pos === false)
430
-				break;
455
+			if ($pos === false) {
456
+							break;
457
+			}
431 458
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
432 459
 
433 460
 			while (true)
434 461
 			{
435 462
 				$pos1 = strpos($db_string, '\'', $pos + 1);
436 463
 				$pos2 = strpos($db_string, '\\', $pos + 1);
437
-				if ($pos1 === false)
438
-					break;
439
-				elseif ($pos2 === false || $pos2 > $pos1)
464
+				if ($pos1 === false) {
465
+									break;
466
+				} elseif ($pos2 === false || $pos2 > $pos1)
440 467
 				{
441 468
 					$pos = $pos1;
442 469
 					break;
@@ -452,16 +479,19 @@  discard block
 block discarded – undo
452 479
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
453 480
 
454 481
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
455
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
456
-			$fail = true;
482
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
483
+					$fail = true;
484
+		}
457 485
 		// Trying to change passwords, slow us down, or something?
458
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
459
-			$fail = true;
460
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
461
-			$fail = true;
486
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
487
+					$fail = true;
488
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
489
+					$fail = true;
490
+		}
462 491
 
463
-		if (!empty($fail) && function_exists('log_error'))
464
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
492
+		if (!empty($fail) && function_exists('log_error')) {
493
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
494
+		}
465 495
 	}
466 496
 
467 497
 	// Set optimize stuff
@@ -480,18 +510,21 @@  discard block
 block discarded – undo
480 510
 
481 511
 		$db_string = $query_hints_set . $db_string;
482 512
 		
483
-		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...')
484
-			$db_cache[$db_count]['q'] = "\t\t" . $db_string;
513
+		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') {
514
+					$db_cache[$db_count]['q'] = "\t\t" . $db_string;
515
+		}
485 516
 	}
486 517
 
487 518
 	$db_last_result = @pg_query($connection, $db_string);
488 519
 
489
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
490
-		$db_last_result = smf_db_error($db_string, $connection);
520
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
521
+			$db_last_result = smf_db_error($db_string, $connection);
522
+	}
491 523
 
492 524
 	// Debugging.
493
-	if (isset($db_show_debug) && $db_show_debug === true)
494
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
525
+	if (isset($db_show_debug) && $db_show_debug === true) {
526
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
527
+	}
495 528
 
496 529
 	return $db_last_result;
497 530
 }
@@ -504,10 +537,11 @@  discard block
 block discarded – undo
504 537
 {
505 538
 	global $db_last_result, $db_replace_result;
506 539
 
507
-	if ($db_replace_result)
508
-		return $db_replace_result;
509
-	elseif ($result === null && !$db_last_result)
510
-		return 0;
540
+	if ($db_replace_result) {
541
+			return $db_replace_result;
542
+	} elseif ($result === null && !$db_last_result) {
543
+			return 0;
544
+	}
511 545
 
512 546
 	return pg_affected_rows($result === null ? $db_last_result : $result);
513 547
 }
@@ -531,8 +565,9 @@  discard block
 block discarded – undo
531 565
 		array(
532 566
 		)
533 567
 	);
534
-	if (!$request)
535
-		return false;
568
+	if (!$request) {
569
+			return false;
570
+	}
536 571
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
537 572
 	$smcFunc['db_free_result']($request);
538 573
 
@@ -553,12 +588,13 @@  discard block
 block discarded – undo
553 588
 	// Decide which connection to use
554 589
 	$connection = $connection === null ? $db_connection : $connection;
555 590
 
556
-	if ($type == 'begin')
557
-		return @pg_query($connection, 'BEGIN');
558
-	elseif ($type == 'rollback')
559
-		return @pg_query($connection, 'ROLLBACK');
560
-	elseif ($type == 'commit')
561
-		return @pg_query($connection, 'COMMIT');
591
+	if ($type == 'begin') {
592
+			return @pg_query($connection, 'BEGIN');
593
+	} elseif ($type == 'rollback') {
594
+			return @pg_query($connection, 'ROLLBACK');
595
+	} elseif ($type == 'commit') {
596
+			return @pg_query($connection, 'COMMIT');
597
+	}
562 598
 
563 599
 	return false;
564 600
 }
@@ -586,19 +622,22 @@  discard block
 block discarded – undo
586 622
 	$query_error = @pg_last_error($connection);
587 623
 
588 624
 	// Log the error.
589
-	if (function_exists('log_error'))
590
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
625
+	if (function_exists('log_error')) {
626
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
627
+	}
591 628
 
592 629
 	// Nothing's defined yet... just die with it.
593
-	if (empty($context) || empty($txt))
594
-		die($query_error);
630
+	if (empty($context) || empty($txt)) {
631
+			die($query_error);
632
+	}
595 633
 
596 634
 	// Show an error message, if possible.
597 635
 	$context['error_title'] = $txt['database_error'];
598
-	if (allowedTo('admin_forum'))
599
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
600
-	else
601
-		$context['error_message'] = $txt['try_again'];
636
+	if (allowedTo('admin_forum')) {
637
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
638
+	} else {
639
+			$context['error_message'] = $txt['try_again'];
640
+	}
602 641
 
603 642
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
604 643
 	{
@@ -620,12 +659,14 @@  discard block
 block discarded – undo
620 659
 {
621 660
 	global $db_row_count;
622 661
 
623
-	if ($counter !== false)
624
-		return pg_fetch_row($request, $counter);
662
+	if ($counter !== false) {
663
+			return pg_fetch_row($request, $counter);
664
+	}
625 665
 
626 666
 	// Reset the row counter...
627
-	if (!isset($db_row_count[(int) $request]))
628
-		$db_row_count[(int) $request] = 0;
667
+	if (!isset($db_row_count[(int) $request])) {
668
+			$db_row_count[(int) $request] = 0;
669
+	}
629 670
 
630 671
 	// Return the right row.
631 672
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -642,12 +683,14 @@  discard block
 block discarded – undo
642 683
 {
643 684
 	global $db_row_count;
644 685
 
645
-	if ($counter !== false)
646
-		return pg_fetch_assoc($request, $counter);
686
+	if ($counter !== false) {
687
+			return pg_fetch_assoc($request, $counter);
688
+	}
647 689
 
648 690
 	// Reset the row counter...
649
-	if (!isset($db_row_count[(int) $request]))
650
-		$db_row_count[(int) $request] = 0;
691
+	if (!isset($db_row_count[(int) $request])) {
692
+			$db_row_count[(int) $request] = 0;
693
+	}
651 694
 
652 695
 	// Return the right row.
653 696
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -700,11 +743,13 @@  discard block
 block discarded – undo
700 743
 
701 744
 	$replace = '';
702 745
 
703
-	if (empty($data))
704
-		return;
746
+	if (empty($data)) {
747
+			return;
748
+	}
705 749
 
706
-	if (!is_array($data[array_rand($data)]))
707
-		$data = array($data);
750
+	if (!is_array($data[array_rand($data)])) {
751
+			$data = array($data);
752
+	}
708 753
 
709 754
 	// Replace the prefix holder with the actual prefix.
710 755
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -723,11 +768,13 @@  discard block
 block discarded – undo
723 768
 			//pg 9.5 got replace support
724 769
 			$pg_version = $smcFunc['db_get_version']();
725 770
 			// if we got a Beta Version
726
-			if (stripos($pg_version, 'beta') !== false)
727
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
771
+			if (stripos($pg_version, 'beta') !== false) {
772
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
773
+			}
728 774
 			// or RC
729
-			if (stripos($pg_version, 'rc') !== false)
730
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
775
+			if (stripos($pg_version, 'rc') !== false) {
776
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
777
+			}
731 778
 
732 779
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
733 780
 		}
@@ -746,8 +793,7 @@  discard block
 block discarded – undo
746 793
 					$key_str .= ($count_pk > 0 ? ',' : '');
747 794
 					$key_str .= $columnName;
748 795
 					$count_pk++;
749
-				}
750
-				else //normal field
796
+				} else //normal field
751 797
 				{
752 798
 					$col_str .= ($count > 0 ? ',' : '');
753 799
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -755,20 +801,21 @@  discard block
 block discarded – undo
755 801
 				}
756 802
 			}
757 803
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
758
-		}
759
-		else
804
+		} else
760 805
 		{
761 806
 			foreach ($columns as $columnName => $type)
762 807
 			{
763 808
 				// Are we restricting the length?
764
-				if (strpos($type, 'string-') !== false)
765
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
766
-				else
767
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
809
+				if (strpos($type, 'string-') !== false) {
810
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
811
+				} else {
812
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
813
+				}
768 814
 
769 815
 				// A key? That's what we were looking for.
770
-				if (in_array($columnName, $keys))
771
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
816
+				if (in_array($columnName, $keys)) {
817
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
818
+				}
772 819
 				$count++;
773 820
 			}
774 821
 
@@ -804,10 +851,11 @@  discard block
 block discarded – undo
804 851
 		foreach ($columns as $columnName => $type)
805 852
 		{
806 853
 			// Are we restricting the length?
807
-			if (strpos($type, 'string-') !== false)
808
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
809
-			else
810
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+			if (strpos($type, 'string-') !== false) {
855
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
856
+			} else {
857
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+			}
811 859
 		}
812 860
 		$insertData = substr($insertData, 0, -2) . ')';
813 861
 
@@ -816,8 +864,9 @@  discard block
 block discarded – undo
816 864
 
817 865
 		// Here's where the variables are injected to the query.
818 866
 		$insertRows = array();
819
-		foreach ($data as $dataRow)
820
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
867
+		foreach ($data as $dataRow) {
868
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+		}
821 870
 
822 871
 		// Do the insert.
823 872
 		$request = $smcFunc['db_query']('', '
@@ -834,19 +883,21 @@  discard block
 block discarded – undo
834 883
 
835 884
 		if ($with_returning && $request !== false)
836 885
 		{
837
-			if ($returnmode === 2)
838
-				$return_var = array();
886
+			if ($returnmode === 2) {
887
+							$return_var = array();
888
+			}
839 889
 
840 890
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
841 891
 			{
842
-				if (is_numeric($row[0])) // try to emulate mysql limitation
892
+				if (is_numeric($row[0])) {
893
+					// try to emulate mysql limitation
843 894
 				{
844 895
 					if ($returnmode === 1)
845 896
 						$return_var = $row[0];
846
-					elseif ($returnmode === 2)
847
-						$return_var[] = $row[0];
848
-				}
849
-				else
897
+				} elseif ($returnmode === 2) {
898
+											$return_var[] = $row[0];
899
+					}
900
+				} else
850 901
 				{
851 902
 					$with_returning = false;
852 903
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -855,9 +906,10 @@  discard block
 block discarded – undo
855 906
 		}
856 907
 	}
857 908
 
858
-	if ($with_returning && !empty($return_var))
859
-		return $return_var;
860
-}
909
+	if ($with_returning && !empty($return_var)) {
910
+			return $return_var;
911
+	}
912
+	}
861 913
 
862 914
 /**
863 915
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -894,8 +946,9 @@  discard block
 block discarded – undo
894 946
  */
895 947
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
896 948
 {
897
-	if (empty($log_message))
898
-		$log_message = $error_message;
949
+	if (empty($log_message)) {
950
+			$log_message = $error_message;
951
+	}
899 952
 
900 953
 	foreach (debug_backtrace() as $step)
901 954
 	{
@@ -914,12 +967,14 @@  discard block
 block discarded – undo
914 967
 	}
915 968
 
916 969
 	// A special case - we want the file and line numbers for debugging.
917
-	if ($error_type == 'return')
918
-		return array($file, $line);
970
+	if ($error_type == 'return') {
971
+			return array($file, $line);
972
+	}
919 973
 
920 974
 	// Is always a critical error.
921
-	if (function_exists('log_error'))
922
-		log_error($log_message, 'critical', $file, $line);
975
+	if (function_exists('log_error')) {
976
+			log_error($log_message, 'critical', $file, $line);
977
+	}
923 978
 
924 979
 	if (function_exists('fatal_error'))
925 980
 	{
@@ -927,12 +982,12 @@  discard block
 block discarded – undo
927 982
 
928 983
 		// Cannot continue...
929 984
 		exit;
985
+	} elseif ($error_type) {
986
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
987
+	} else {
988
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
989
+	}
930 990
 	}
931
-	elseif ($error_type)
932
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
933
-	else
934
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
935
-}
936 991
 
937 992
 /**
938 993
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -949,10 +1004,11 @@  discard block
 block discarded – undo
949 1004
 		'\\' => '\\\\',
950 1005
 	);
951 1006
 
952
-	if ($translate_human_wildcards)
953
-		$replacements += array(
1007
+	if ($translate_human_wildcards) {
1008
+			$replacements += array(
954 1009
 			'*' => '%',
955 1010
 		);
1011
+	}
956 1012
 
957 1013
 	return strtr($string, $replacements);
958 1014
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +251 added lines, -185 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,24 +74,27 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
94 100
 		array(),
@@ -164,34 +170,42 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
174
-		return $user_info[$matches[1]];
181
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
182
+			return $user_info[$matches[1]];
183
+	}
175 184
 
176
-	if ($matches[1] === 'empty')
177
-		return '\'\'';
185
+	if ($matches[1] === 'empty') {
186
+			return '\'\'';
187
+	}
178 188
 
179
-	if (!isset($matches[2]))
180
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
189
+	if (!isset($matches[2])) {
190
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	}
181 192
 
182
-	if ($matches[1] === 'literal')
183
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
193
+	if ($matches[1] === 'literal') {
194
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	}
184 196
 
185
-	if (!isset($values[$matches[2]]))
186
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
197
+	if (!isset($values[$matches[2]])) {
198
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	}
187 200
 
188 201
 	$replacement = $values[$matches[2]];
189 202
 
190 203
 	switch ($matches[1])
191 204
 	{
192 205
 		case 'int':
193
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
207
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			}
195 209
 			return (string) (int) $replacement;
196 210
 		break;
197 211
 
@@ -203,65 +217,73 @@  discard block
 block discarded – undo
203 217
 		case 'array_int':
204 218
 			if (is_array($replacement))
205 219
 			{
206
-				if (empty($replacement))
207
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				if (empty($replacement)) {
221
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				}
208 223
 
209 224
 				foreach ($replacement as $key => $value)
210 225
 				{
211
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
212
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
227
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					}
213 229
 
214 230
 					$replacement[$key] = (string) (int) $value;
215 231
 				}
216 232
 
217 233
 				return implode(', ', $replacement);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218 236
 			}
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 237
 
222 238
 		break;
223 239
 
224 240
 		case 'array_string':
225 241
 			if (is_array($replacement))
226 242
 			{
227
-				if (empty($replacement))
228
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+				if (empty($replacement)) {
244
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				}
229 246
 
230
-				foreach ($replacement as $key => $value)
231
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
247
+				foreach ($replacement as $key => $value) {
248
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				}
232 250
 
233 251
 				return implode(', ', $replacement);
252
+			} else {
253
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234 254
 			}
235
-			else
236
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 255
 		break;
238 256
 
239 257
 		case 'date':
240
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
241
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
242
-			else
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
259
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
260
+			} else {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
244 263
 		break;
245 264
 
246 265
 		case 'time':
247
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
248
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
249
-			else
250
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
267
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
268
+			} else {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
251 271
 		break;
252 272
 
253 273
 		case 'datetime':
254
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
255
-				return 'str_to_date('.
274
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
275
+							return 'str_to_date('.
256 276
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
257 277
 					',\'%Y-%m-%d %h:%i:%s\')';
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			} else {
279
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			}
260 281
 		break;
261 282
 
262 283
 		case 'float':
263
-			if (!is_numeric($replacement))
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			if (!is_numeric($replacement)) {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
265 287
 			return (string) (float) $replacement;
266 288
 		break;
267 289
 
@@ -275,32 +297,37 @@  discard block
 block discarded – undo
275 297
 		break;
276 298
 
277 299
 		case 'inet':
278
-			if ($replacement == 'null' || $replacement == '')
279
-				return 'null';
280
-			if (!isValidIP($replacement))
281
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			if ($replacement == 'null' || $replacement == '') {
301
+							return 'null';
302
+			}
303
+			if (!isValidIP($replacement)) {
304
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305
+			}
282 306
 			//we don't use the native support of mysql > 5.6.2
283 307
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
284 308
 
285 309
 		case 'array_inet':
286 310
 			if (is_array($replacement))
287 311
 			{
288
-				if (empty($replacement))
289
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+				if (empty($replacement)) {
313
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				}
290 315
 
291 316
 				foreach ($replacement as $key => $value)
292 317
 				{
293
-					if ($replacement == 'null' || $replacement == '')
294
-						$replacement[$key] = 'null';
295
-					if (!isValidIP($value))
296
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					if ($replacement == 'null' || $replacement == '') {
319
+											$replacement[$key] = 'null';
320
+					}
321
+					if (!isValidIP($value)) {
322
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+					}
297 324
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
298 325
 				}
299 326
 
300 327
 				return implode(', ', $replacement);
328
+			} else {
329
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301 330
 			}
302
-			else
303
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 331
 		break;
305 332
 
306 333
 		default:
@@ -376,22 +403,25 @@  discard block
 block discarded – undo
376 403
 		// Are we in SSI mode?  If so try that username and password first
377 404
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
378 405
 		{
379
-			if (empty($db_persist))
380
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
381
-			else
382
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
406
+			if (empty($db_persist)) {
407
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
408
+			} else {
409
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			}
383 411
 		}
384 412
 		// Fall back to the regular username and password if need be
385 413
 		if (!$db_connection)
386 414
 		{
387
-			if (empty($db_persist))
388
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
389
-			else
390
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
415
+			if (empty($db_persist)) {
416
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
417
+			} else {
418
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			}
391 420
 		}
392 421
 
393
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
394
-			$db_connection = false;
422
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
423
+					$db_connection = false;
424
+		}
395 425
 
396 426
 		$connection = $db_connection;
397 427
 	}
@@ -399,18 +429,20 @@  discard block
 block discarded – undo
399 429
 	// One more query....
400 430
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
401 431
 
402
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
403
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
432
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
433
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
434
+	}
404 435
 
405 436
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
406 437
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
407 438
 	{
408 439
 		// Add before LIMIT
409
-		if ($pos = strpos($db_string, 'LIMIT '))
410
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
411
-		else
412
-			// Append it.
440
+		if ($pos = strpos($db_string, 'LIMIT ')) {
441
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
442
+		} else {
443
+					// Append it.
413 444
 			$db_string .= "\n\t\t\tORDER BY null";
445
+		}
414 446
 	}
415 447
 
416 448
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -432,8 +464,9 @@  discard block
 block discarded – undo
432 464
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
433 465
 
434 466
 		// Initialize $db_cache if not already initialized.
435
-		if (!isset($db_cache))
436
-			$db_cache = array();
467
+		if (!isset($db_cache)) {
468
+					$db_cache = array();
469
+		}
437 470
 
438 471
 		if (!empty($_SESSION['debug_redirect']))
439 472
 		{
@@ -459,17 +492,18 @@  discard block
 block discarded – undo
459 492
 		while (true)
460 493
 		{
461 494
 			$pos = strpos($db_string, '\'', $pos + 1);
462
-			if ($pos === false)
463
-				break;
495
+			if ($pos === false) {
496
+							break;
497
+			}
464 498
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
465 499
 
466 500
 			while (true)
467 501
 			{
468 502
 				$pos1 = strpos($db_string, '\'', $pos + 1);
469 503
 				$pos2 = strpos($db_string, '\\', $pos + 1);
470
-				if ($pos1 === false)
471
-					break;
472
-				elseif ($pos2 === false || $pos2 > $pos1)
504
+				if ($pos1 === false) {
505
+									break;
506
+				} elseif ($pos2 === false || $pos2 > $pos1)
473 507
 				{
474 508
 					$pos = $pos1;
475 509
 					break;
@@ -485,29 +519,35 @@  discard block
 block discarded – undo
485 519
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
486 520
 
487 521
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
488
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
489
-			$fail = true;
522
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
523
+					$fail = true;
524
+		}
490 525
 		// Trying to change passwords, slow us down, or something?
491
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
492
-			$fail = true;
493
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
494
-			$fail = true;
526
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
527
+					$fail = true;
528
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
529
+					$fail = true;
530
+		}
495 531
 
496
-		if (!empty($fail) && function_exists('log_error'))
497
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
532
+		if (!empty($fail) && function_exists('log_error')) {
533
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
534
+		}
498 535
 	}
499 536
 
500
-	if (empty($db_unbuffered))
501
-		$ret = @mysqli_query($connection, $db_string);
502
-	else
503
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
537
+	if (empty($db_unbuffered)) {
538
+			$ret = @mysqli_query($connection, $db_string);
539
+	} else {
540
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
541
+	}
504 542
 
505
-	if ($ret === false && empty($db_values['db_error_skip']))
506
-		$ret = smf_db_error($db_string, $connection);
543
+	if ($ret === false && empty($db_values['db_error_skip'])) {
544
+			$ret = smf_db_error($db_string, $connection);
545
+	}
507 546
 
508 547
 	// Debugging.
509
-	if (isset($db_show_debug) && $db_show_debug === true)
510
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
548
+	if (isset($db_show_debug) && $db_show_debug === true) {
549
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
550
+	}
511 551
 
512 552
 	return $ret;
513 553
 }
@@ -554,12 +594,13 @@  discard block
 block discarded – undo
554 594
 	// Decide which connection to use
555 595
 	$connection = $connection === null ? $db_connection : $connection;
556 596
 
557
-	if ($type == 'begin')
558
-		return @mysqli_query($connection, 'BEGIN');
559
-	elseif ($type == 'rollback')
560
-		return @mysqli_query($connection, 'ROLLBACK');
561
-	elseif ($type == 'commit')
562
-		return @mysqli_query($connection, 'COMMIT');
597
+	if ($type == 'begin') {
598
+			return @mysqli_query($connection, 'BEGIN');
599
+	} elseif ($type == 'rollback') {
600
+			return @mysqli_query($connection, 'ROLLBACK');
601
+	} elseif ($type == 'commit') {
602
+			return @mysqli_query($connection, 'COMMIT');
603
+	}
563 604
 
564 605
 	return false;
565 606
 }
@@ -599,8 +640,9 @@  discard block
 block discarded – undo
599 640
 	//    2013: Lost connection to server during query.
600 641
 
601 642
 	// Log the error.
602
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
603
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
643
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
644
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
645
+	}
604 646
 
605 647
 	// Database error auto fixing ;).
606 648
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -609,8 +651,9 @@  discard block
 block discarded – undo
609 651
 		$old_cache = @$modSettings['cache_enable'];
610 652
 		$modSettings['cache_enable'] = '1';
611 653
 
612
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
613
-			$db_last_error = max(@$db_last_error, $temp);
654
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
655
+					$db_last_error = max(@$db_last_error, $temp);
656
+		}
614 657
 
615 658
 		if (@$db_last_error < time() - 3600 * 24 * 3)
616 659
 		{
@@ -626,8 +669,9 @@  discard block
 block discarded – undo
626 669
 					foreach ($tables as $table)
627 670
 					{
628 671
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
629
-						if (trim($table) != '')
630
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
672
+						if (trim($table) != '') {
673
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
674
+						}
631 675
 					}
632 676
 				}
633 677
 
@@ -636,8 +680,9 @@  discard block
 block discarded – undo
636 680
 			// Table crashed.  Let's try to fix it.
637 681
 			elseif ($query_errno == 1016)
638 682
 			{
639
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
640
-					$fix_tables = array('`' . $match[1] . '`');
683
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
684
+									$fix_tables = array('`' . $match[1] . '`');
685
+				}
641 686
 			}
642 687
 			// Indexes crashed.  Should be easy to fix!
643 688
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -656,13 +701,15 @@  discard block
 block discarded – undo
656 701
 
657 702
 			// Make a note of the REPAIR...
658 703
 			cache_put_data('db_last_error', time(), 600);
659
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
660
-				updateSettingsFile(array('db_last_error' => time()));
704
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
705
+							updateSettingsFile(array('db_last_error' => time()));
706
+			}
661 707
 
662 708
 			// Attempt to find and repair the broken table.
663
-			foreach ($fix_tables as $table)
664
-				$smcFunc['db_query']('', "
709
+			foreach ($fix_tables as $table) {
710
+							$smcFunc['db_query']('', "
665 711
 					REPAIR TABLE $table", false, false);
712
+			}
666 713
 
667 714
 			// And send off an email!
668 715
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -671,11 +718,12 @@  discard block
 block discarded – undo
671 718
 
672 719
 			// Try the query again...?
673 720
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
674
-			if ($ret !== false)
675
-				return $ret;
721
+			if ($ret !== false) {
722
+							return $ret;
723
+			}
724
+		} else {
725
+					$modSettings['cache_enable'] = $old_cache;
676 726
 		}
677
-		else
678
-			$modSettings['cache_enable'] = $old_cache;
679 727
 
680 728
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
681 729
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -685,22 +733,25 @@  discard block
 block discarded – undo
685 733
 				// Are we in SSI mode?  If so try that username and password first
686 734
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
687 735
 				{
688
-					if (empty($db_persist))
689
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
690
-					else
691
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
736
+					if (empty($db_persist)) {
737
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
738
+					} else {
739
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
740
+					}
692 741
 				}
693 742
 				// Fall back to the regular username and password if need be
694 743
 				if (!$db_connection)
695 744
 				{
696
-					if (empty($db_persist))
697
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
698
-					else
699
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
745
+					if (empty($db_persist)) {
746
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
747
+					} else {
748
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
749
+					}
700 750
 				}
701 751
 
702
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
703
-					$db_connection = false;
752
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
753
+									$db_connection = false;
754
+				}
704 755
 			}
705 756
 
706 757
 			if ($db_connection)
@@ -711,24 +762,27 @@  discard block
 block discarded – undo
711 762
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
712 763
 
713 764
 					$new_errno = mysqli_errno($db_connection);
714
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
715
-						break;
765
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
766
+											break;
767
+					}
716 768
 				}
717 769
 
718 770
 				// If it failed again, shucks to be you... we're not trying it over and over.
719
-				if ($ret !== false)
720
-					return $ret;
771
+				if ($ret !== false) {
772
+									return $ret;
773
+				}
721 774
 			}
722 775
 		}
723 776
 		// Are they out of space, perhaps?
724 777
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
725 778
 		{
726
-			if (!isset($txt))
727
-				$query_error .= ' - check database storage space.';
728
-			else
779
+			if (!isset($txt)) {
780
+							$query_error .= ' - check database storage space.';
781
+			} else
729 782
 			{
730
-				if (!isset($txt['mysql_error_space']))
731
-					loadLanguage('Errors');
783
+				if (!isset($txt['mysql_error_space'])) {
784
+									loadLanguage('Errors');
785
+				}
732 786
 
733 787
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
734 788
 			}
@@ -736,15 +790,17 @@  discard block
 block discarded – undo
736 790
 	}
737 791
 
738 792
 	// Nothing's defined yet... just die with it.
739
-	if (empty($context) || empty($txt))
740
-		die($query_error);
793
+	if (empty($context) || empty($txt)) {
794
+			die($query_error);
795
+	}
741 796
 
742 797
 	// Show an error message, if possible.
743 798
 	$context['error_title'] = $txt['database_error'];
744
-	if (allowedTo('admin_forum'))
745
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
746
-	else
747
-		$context['error_message'] = $txt['try_again'];
799
+	if (allowedTo('admin_forum')) {
800
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
801
+	} else {
802
+			$context['error_message'] = $txt['try_again'];
803
+	}
748 804
 
749 805
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
750 806
 	{
@@ -774,25 +830,28 @@  discard block
 block discarded – undo
774 830
 	$connection = $connection === null ? $db_connection : $connection;
775 831
 
776 832
 	// With nothing to insert, simply return.
777
-	if (empty($data))
778
-		return;
833
+	if (empty($data)) {
834
+			return;
835
+	}
779 836
 
780 837
 	// Replace the prefix holder with the actual prefix.
781 838
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
782 839
 
783 840
 	// Inserting data as a single row can be done as a single array.
784
-	if (!is_array($data[array_rand($data)]))
785
-		$data = array($data);
841
+	if (!is_array($data[array_rand($data)])) {
842
+			$data = array($data);
843
+	}
786 844
 
787 845
 	// Create the mold for a single row insert.
788 846
 	$insertData = '(';
789 847
 	foreach ($columns as $columnName => $type)
790 848
 	{
791 849
 		// Are we restricting the length?
792
-		if (strpos($type, 'string-') !== false)
793
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
794
-		else
795
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		if (strpos($type, 'string-') !== false) {
851
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
852
+		} else {
853
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+		}
796 855
 	}
797 856
 	$insertData = substr($insertData, 0, -2) . ')';
798 857
 
@@ -801,8 +860,9 @@  discard block
 block discarded – undo
801 860
 
802 861
 	// Here's where the variables are injected to the query.
803 862
 	$insertRows = array();
804
-	foreach ($data as $dataRow)
805
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
863
+	foreach ($data as $dataRow) {
864
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
865
+	}
806 866
 
807 867
 	// Determine the method of insertion.
808 868
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -822,15 +882,16 @@  discard block
 block discarded – undo
822 882
 
823 883
 	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
824 884
 	{
825
-		if ($returnmode == 1)
826
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
827
-		else if ($returnmode == 2)
885
+		if ($returnmode == 1) {
886
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
887
+		} else if ($returnmode == 2)
828 888
 		{
829 889
 			$return_var = array();
830 890
 			$count = count($insertRows);
831 891
 			$start = smf_db_insert_id($table, $keys[0]);
832
-			for ($i = 0; $i < $count; $i++ )
833
-				$return_var[] = $start + $i;
892
+			for ($i = 0; $i < $count; $i++ ) {
893
+							$return_var[] = $start + $i;
894
+			}
834 895
 		}
835 896
 		return $return_var;
836 897
 	}
@@ -848,8 +909,9 @@  discard block
 block discarded – undo
848 909
  */
849 910
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
850 911
 {
851
-	if (empty($log_message))
852
-		$log_message = $error_message;
912
+	if (empty($log_message)) {
913
+			$log_message = $error_message;
914
+	}
853 915
 
854 916
 	foreach (debug_backtrace() as $step)
855 917
 	{
@@ -868,12 +930,14 @@  discard block
 block discarded – undo
868 930
 	}
869 931
 
870 932
 	// A special case - we want the file and line numbers for debugging.
871
-	if ($error_type == 'return')
872
-		return array($file, $line);
933
+	if ($error_type == 'return') {
934
+			return array($file, $line);
935
+	}
873 936
 
874 937
 	// Is always a critical error.
875
-	if (function_exists('log_error'))
876
-		log_error($log_message, 'critical', $file, $line);
938
+	if (function_exists('log_error')) {
939
+			log_error($log_message, 'critical', $file, $line);
940
+	}
877 941
 
878 942
 	if (function_exists('fatal_error'))
879 943
 	{
@@ -881,12 +945,12 @@  discard block
 block discarded – undo
881 945
 
882 946
 		// Cannot continue...
883 947
 		exit;
948
+	} elseif ($error_type) {
949
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
950
+	} else {
951
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
952
+	}
884 953
 	}
885
-	elseif ($error_type)
886
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
887
-	else
888
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
889
-}
890 954
 
891 955
 /**
892 956
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -903,10 +967,11 @@  discard block
 block discarded – undo
903 967
 		'\\' => '\\\\',
904 968
 	);
905 969
 
906
-	if ($translate_human_wildcards)
907
-		$replacements += array(
970
+	if ($translate_human_wildcards) {
971
+			$replacements += array(
908 972
 			'*' => '%',
909 973
 		);
974
+	}
910 975
 
911 976
 	return strtr($string, $replacements);
912 977
 }
@@ -920,8 +985,9 @@  discard block
 block discarded – undo
920 985
  */
921 986
 function smf_is_resource($result)
922 987
 {
923
-	if ($result instanceof mysqli_result)
924
-		return true;
988
+	if ($result instanceof mysqli_result) {
989
+			return true;
990
+	}
925 991
 
926 992
 	return false;
927 993
 }
Please login to merge, or discard this patch.
Sources/Profile-View.php 1 patch
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -582,10 +612,11 @@  discard block
 block discarded – undo
582 612
 
583 613
 	$range_limit = '';
584 614
 
585
-	if ($context['is_topics'])
586
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
587
-	else
588
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
615
+	if ($context['is_topics']) {
616
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
617
+	} else {
618
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
619
+	}
589 620
 
590 621
 	$maxIndex = $maxPerPage;
591 622
 
@@ -611,9 +642,9 @@  discard block
 block discarded – undo
611 642
 		{
612 643
 			$margin *= 5;
613 644
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
645
+		} else {
646
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
614 647
 		}
615
-		else
616
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
617 648
 	}
618 649
 
619 650
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 					'max' => $maxIndex,
646 677
 				)
647 678
 			);
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			$request = $smcFunc['db_query']('', '
652 682
 				SELECT
@@ -675,8 +705,9 @@  discard block
 block discarded – undo
675 705
 		}
676 706
 
677 707
 		// Make sure we quit this loop.
678
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
679
-			break;
708
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
709
+					break;
710
+		}
680 711
 		$looped = true;
681 712
 		$range_limit = '';
682 713
 	}
@@ -720,19 +751,21 @@  discard block
 block discarded – undo
720 751
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
721 752
 		);
722 753
 
723
-		if ($user_info['id'] == $row['id_member_started'])
724
-			$board_ids['own'][$row['id_board']][] = $counter;
754
+		if ($user_info['id'] == $row['id_member_started']) {
755
+					$board_ids['own'][$row['id_board']][] = $counter;
756
+		}
725 757
 		$board_ids['any'][$row['id_board']][] = $counter;
726 758
 	}
727 759
 	$smcFunc['db_free_result']($request);
728 760
 
729 761
 	// All posts were retrieved in reverse order, get them right again.
730
-	if ($reverse)
731
-		$context['posts'] = array_reverse($context['posts'], true);
762
+	if ($reverse) {
763
+			$context['posts'] = array_reverse($context['posts'], true);
764
+	}
732 765
 
733 766
 	// These are all the permissions that are different from board to board..
734
-	if ($context['is_topics'])
735
-		$permissions = array(
767
+	if ($context['is_topics']) {
768
+			$permissions = array(
736 769
 			'own' => array(
737 770
 				'post_reply_own' => 'can_reply',
738 771
 			),
@@ -740,8 +773,8 @@  discard block
 block discarded – undo
740 773
 				'post_reply_any' => 'can_reply',
741 774
 			)
742 775
 		);
743
-	else
744
-		$permissions = array(
776
+	} else {
777
+			$permissions = array(
745 778
 			'own' => array(
746 779
 				'post_reply_own' => 'can_reply',
747 780
 				'delete_own' => 'can_delete',
@@ -751,6 +784,7 @@  discard block
 block discarded – undo
751 784
 				'delete_any' => 'can_delete',
752 785
 			)
753 786
 		);
787
+	}
754 788
 
755 789
 	// For every permission in the own/any lists...
756 790
 	foreach ($permissions as $type => $list)
@@ -761,19 +795,22 @@  discard block
 block discarded – undo
761 795
 			$boards = boardsAllowedTo($permission);
762 796
 
763 797
 			// Hmm, they can do it on all boards, can they?
764
-			if (!empty($boards) && $boards[0] == 0)
765
-				$boards = array_keys($board_ids[$type]);
798
+			if (!empty($boards) && $boards[0] == 0) {
799
+							$boards = array_keys($board_ids[$type]);
800
+			}
766 801
 
767 802
 			// Now go through each board they can do the permission on.
768 803
 			foreach ($boards as $board_id)
769 804
 			{
770 805
 				// There aren't any posts displayed from this board.
771
-				if (!isset($board_ids[$type][$board_id]))
772
-					continue;
806
+				if (!isset($board_ids[$type][$board_id])) {
807
+									continue;
808
+				}
773 809
 
774 810
 				// Set the permission to true ;).
775
-				foreach ($board_ids[$type][$board_id] as $counter)
776
-					$context['posts'][$counter][$allowed] = true;
811
+				foreach ($board_ids[$type][$board_id] as $counter) {
812
+									$context['posts'][$counter][$allowed] = true;
813
+				}
777 814
 			}
778 815
 		}
779 816
 	}
@@ -804,8 +841,9 @@  discard block
 block discarded – undo
804 841
 	$boardsAllowed = boardsAllowedTo('view_attachments');
805 842
 
806 843
 	// Make sure we can't actually see anything...
807
-	if (empty($boardsAllowed))
808
-		$boardsAllowed = array(-1);
844
+	if (empty($boardsAllowed)) {
845
+			$boardsAllowed = array(-1);
846
+	}
809 847
 
810 848
 	require_once($sourcedir . '/Subs-List.php');
811 849
 
@@ -956,8 +994,8 @@  discard block
 block discarded – undo
956 994
 		)
957 995
 	);
958 996
 	$attachments = array();
959
-	while ($row = $smcFunc['db_fetch_assoc']($request))
960
-		$attachments[] = array(
997
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
998
+			$attachments[] = array(
961 999
 			'id' => $row['id_attach'],
962 1000
 			'filename' => $row['filename'],
963 1001
 			'downloads' => $row['downloads'],
@@ -969,6 +1007,7 @@  discard block
 block discarded – undo
969 1007
 			'board_name' => $row['name'],
970 1008
 			'approved' => $row['approved'],
971 1009
 		);
1010
+	}
972 1011
 
973 1012
 	$smcFunc['db_free_result']($request);
974 1013
 
@@ -1023,8 +1062,9 @@  discard block
 block discarded – undo
1023 1062
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1024 1063
 
1025 1064
 	// Only the owner can see the list (if the function is enabled of course)
1026
-	if ($user_info['id'] != $memID)
1027
-		return;
1065
+	if ($user_info['id'] != $memID) {
1066
+			return;
1067
+	}
1028 1068
 
1029 1069
 	require_once($sourcedir . '/Subs-List.php');
1030 1070
 
@@ -1170,8 +1210,9 @@  discard block
 block discarded – undo
1170 1210
 	);
1171 1211
 
1172 1212
 	$topics = array();
1173
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1174
-		$topics[] = $row['id_topic'];
1213
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1214
+			$topics[] = $row['id_topic'];
1215
+	}
1175 1216
 
1176 1217
 	$smcFunc['db_free_result']($request);
1177 1218
 
@@ -1191,8 +1232,9 @@  discard block
 block discarded – undo
1191 1232
 				'topics' => $topics,
1192 1233
 			)
1193 1234
 		);
1194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1195
-			$topicsInfo[] = $row;
1235
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1236
+					$topicsInfo[] = $row;
1237
+		}
1196 1238
 		$smcFunc['db_free_result']($request);
1197 1239
 	}
1198 1240
 
@@ -1240,8 +1282,9 @@  discard block
 block discarded – undo
1240 1282
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1241 1283
 
1242 1284
 	// Is the load average too high to allow searching just now?
1243
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1244
-		fatal_lang_error('loadavg_userstats_disabled', false);
1285
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1286
+			fatal_lang_error('loadavg_userstats_disabled', false);
1287
+	}
1245 1288
 
1246 1289
 	// General user statistics.
1247 1290
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1399,11 +1442,13 @@  discard block
 block discarded – undo
1399 1442
 	}
1400 1443
 	$smcFunc['db_free_result']($result);
1401 1444
 
1402
-	if ($maxPosts > 0)
1403
-		for ($hour = 0; $hour < 24; $hour++)
1445
+	if ($maxPosts > 0) {
1446
+			for ($hour = 0;
1447
+	}
1448
+	$hour < 24; $hour++)
1404 1449
 		{
1405
-			if (!isset($context['posts_by_time'][$hour]))
1406
-				$context['posts_by_time'][$hour] = array(
1450
+			if (!isset($context['posts_by_time'][$hour])) {
1451
+							$context['posts_by_time'][$hour] = array(
1407 1452
 					'hour' => $hour,
1408 1453
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1409 1454
 					'posts' => 0,
@@ -1411,7 +1456,7 @@  discard block
 block discarded – undo
1411 1456
 					'relative_percent' => 0,
1412 1457
 					'is_last' => $hour == 23,
1413 1458
 				);
1414
-			else
1459
+			} else
1415 1460
 			{
1416 1461
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1417 1462
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1444,8 +1489,9 @@  discard block
 block discarded – undo
1444 1489
 
1445 1490
 	foreach ($subActions as $sa => $action)
1446 1491
 	{
1447
-		if (!allowedTo($action[2]))
1448
-			unset($subActions[$sa]);
1492
+		if (!allowedTo($action[2])) {
1493
+					unset($subActions[$sa]);
1494
+		}
1449 1495
 	}
1450 1496
 
1451 1497
 	// Create the tabs for the template.
@@ -1463,15 +1509,18 @@  discard block
 block discarded – undo
1463 1509
 	);
1464 1510
 
1465 1511
 	// Moderation must be on to track edits.
1466
-	if (empty($modSettings['userlog_enabled']))
1467
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1512
+	if (empty($modSettings['userlog_enabled'])) {
1513
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1514
+	}
1468 1515
 
1469 1516
 	// Group requests must be active to show it...
1470
-	if (empty($modSettings['show_group_membership']))
1471
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1517
+	if (empty($modSettings['show_group_membership'])) {
1518
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1519
+	}
1472 1520
 
1473
-	if (empty($subActions))
1474
-		fatal_lang_error('no_access', false);
1521
+	if (empty($subActions)) {
1522
+			fatal_lang_error('no_access', false);
1523
+	}
1475 1524
 
1476 1525
 	$keys = array_keys($subActions);
1477 1526
 	$default = array_shift($keys);
@@ -1484,9 +1533,10 @@  discard block
 block discarded – undo
1484 1533
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1485 1534
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1486 1535
 
1487
-	if (!empty($call))
1488
-		call_user_func($call, $memID);
1489
-}
1536
+	if (!empty($call)) {
1537
+			call_user_func($call, $memID);
1538
+	}
1539
+	}
1490 1540
 
1491 1541
 /**
1492 1542
  * Handles tracking a user's activity
@@ -1502,8 +1552,9 @@  discard block
 block discarded – undo
1502 1552
 	isAllowedTo('moderate_forum');
1503 1553
 
1504 1554
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1505
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1506
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1555
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1556
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1557
+	}
1507 1558
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1508 1559
 
1509 1560
 	// Set the options for the list component.
@@ -1669,8 +1720,9 @@  discard block
 block discarded – undo
1669 1720
 			)
1670 1721
 		);
1671 1722
 		$message_members = array();
1672
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1673
-			$message_members[] = $row['id_member'];
1723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+					$message_members[] = $row['id_member'];
1725
+		}
1674 1726
 		$smcFunc['db_free_result']($request);
1675 1727
 
1676 1728
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1685,8 +1737,9 @@  discard block
 block discarded – undo
1685 1737
 					'ip_list' => $ips,
1686 1738
 				)
1687 1739
 			);
1688
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1689
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1740
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1741
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1742
+			}
1690 1743
 			$smcFunc['db_free_result']($request);
1691 1744
 		}
1692 1745
 
@@ -1700,8 +1753,9 @@  discard block
 block discarded – undo
1700 1753
 				'ip_list' => $ips,
1701 1754
 			)
1702 1755
 		);
1703
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1704
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1756
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1757
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1758
+		}
1705 1759
 		$smcFunc['db_free_result']($request);
1706 1760
 	}
1707 1761
 }
@@ -1761,8 +1815,8 @@  discard block
 block discarded – undo
1761 1815
 		))
1762 1816
 	);
1763 1817
 	$error_messages = array();
1764
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1765
-		$error_messages[] = array(
1818
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1819
+			$error_messages[] = array(
1766 1820
 			'ip' => inet_dtop($row['ip']),
1767 1821
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1768 1822
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1770,6 +1824,7 @@  discard block
 block discarded – undo
1770 1824
 			'time' => timeformat($row['log_time']),
1771 1825
 			'timestamp' => forum_time(true, $row['log_time']),
1772 1826
 		);
1827
+	}
1773 1828
 	$smcFunc['db_free_result']($request);
1774 1829
 
1775 1830
 	return $error_messages;
@@ -1832,8 +1887,8 @@  discard block
 block discarded – undo
1832 1887
 		))
1833 1888
 	);
1834 1889
 	$messages = array();
1835
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1836
-		$messages[] = array(
1890
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1891
+			$messages[] = array(
1837 1892
 			'ip' => inet_dtop($row['poster_ip']),
1838 1893
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1839 1894
 			'board' => array(
@@ -1846,6 +1901,7 @@  discard block
 block discarded – undo
1846 1901
 			'time' => timeformat($row['poster_time']),
1847 1902
 			'timestamp' => forum_time(true, $row['poster_time'])
1848 1903
 		);
1904
+	}
1849 1905
 	$smcFunc['db_free_result']($request);
1850 1906
 
1851 1907
 	return $messages;
@@ -1872,19 +1928,20 @@  discard block
 block discarded – undo
1872 1928
 		$context['sub_template'] = 'trackIP';
1873 1929
 		$context['page_title'] = $txt['profile'];
1874 1930
 		$context['base_url'] = $scripturl . '?action=trackip';
1875
-	}
1876
-	else
1931
+	} else
1877 1932
 	{
1878 1933
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1879 1934
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1880 1935
 	}
1881 1936
 
1882 1937
 	// Searching?
1883
-	if (isset($_REQUEST['searchip']))
1884
-		$context['ip'] = trim($_REQUEST['searchip']);
1938
+	if (isset($_REQUEST['searchip'])) {
1939
+			$context['ip'] = trim($_REQUEST['searchip']);
1940
+	}
1885 1941
 
1886
-	if (isValidIP($context['ip']) === false)
1887
-		fatal_lang_error('invalid_tracking_ip', false);
1942
+	if (isValidIP($context['ip']) === false) {
1943
+			fatal_lang_error('invalid_tracking_ip', false);
1944
+	}
1888 1945
 
1889 1946
 	//mysql didn't support like search with varbinary
1890 1947
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1892,8 +1949,9 @@  discard block
 block discarded – undo
1892 1949
 	$ip_var = $context['ip'];
1893 1950
 	$ip_string = '= {inet:ip_address}';
1894 1951
 
1895
-	if (empty($context['tracking_area']))
1896
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1952
+	if (empty($context['tracking_area'])) {
1953
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1954
+	}
1897 1955
 
1898 1956
 	$request = $smcFunc['db_query']('', '
1899 1957
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1904,8 +1962,9 @@  discard block
 block discarded – undo
1904 1962
 		)
1905 1963
 	);
1906 1964
 	$context['ips'] = array();
1907
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1908
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1965
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1966
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1967
+	}
1909 1968
 	$smcFunc['db_free_result']($request);
1910 1969
 
1911 1970
 	ksort($context['ips']);
@@ -2134,8 +2193,9 @@  discard block
 block discarded – undo
2134 2193
 		foreach ($context['whois_servers'] as $whois)
2135 2194
 		{
2136 2195
 			// Strip off the "decimal point" and anything following...
2137
-			if (in_array((int) $context['ip'], $whois['range']))
2138
-				$context['auto_whois_server'] = $whois;
2196
+			if (in_array((int) $context['ip'], $whois['range'])) {
2197
+							$context['auto_whois_server'] = $whois;
2198
+			}
2139 2199
 		}
2140 2200
 	}
2141 2201
 }
@@ -2152,10 +2212,11 @@  discard block
 block discarded – undo
2152 2212
 	// Gonna want this for the list.
2153 2213
 	require_once($sourcedir . '/Subs-List.php');
2154 2214
 
2155
-	if ($memID == 0)
2156
-		$context['base_url'] = $scripturl . '?action=trackip';
2157
-	else
2158
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2215
+	if ($memID == 0) {
2216
+			$context['base_url'] = $scripturl . '?action=trackip';
2217
+	} else {
2218
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2219
+	}
2159 2220
 
2160 2221
 	// Start with the user messages.
2161 2222
 	$listOptions = array(
@@ -2265,12 +2326,13 @@  discard block
 block discarded – undo
2265 2326
 		)
2266 2327
 	);
2267 2328
 	$logins = array();
2268
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2269
-		$logins[] = array(
2329
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2330
+			$logins[] = array(
2270 2331
 			'time' => timeformat($row['time']),
2271 2332
 			'ip' => inet_dtop($row['ip']),
2272 2333
 			'ip2' => inet_dtop($row['ip2']),
2273 2334
 		);
2335
+	}
2274 2336
 	$smcFunc['db_free_result']($request);
2275 2337
 
2276 2338
 	return $logins;
@@ -2295,11 +2357,12 @@  discard block
 block discarded – undo
2295 2357
 		)
2296 2358
 	);
2297 2359
 	$context['custom_field_titles'] = array();
2298
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2299
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2360
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2361
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2300 2362
 			'title' => $row['field_name'],
2301 2363
 			'parse_bbc' => $row['bbc'],
2302 2364
 		);
2365
+	}
2303 2366
 	$smcFunc['db_free_result']($request);
2304 2367
 
2305 2368
 	// Set the options for the error lists.
@@ -2438,19 +2501,22 @@  discard block
 block discarded – undo
2438 2501
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2439 2502
 	{
2440 2503
 		$extra = smf_json_decode($row['extra'], true);
2441
-		if (!empty($extra['applicator']))
2442
-			$members[] = $extra['applicator'];
2504
+		if (!empty($extra['applicator'])) {
2505
+					$members[] = $extra['applicator'];
2506
+		}
2443 2507
 
2444 2508
 		// Work out what the name of the action is.
2445
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2446
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2447
-		elseif (isset($txt[$row['action']]))
2448
-			$action_text = $txt[$row['action']];
2509
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2510
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2511
+		} elseif (isset($txt[$row['action']])) {
2512
+					$action_text = $txt[$row['action']];
2513
+		}
2449 2514
 		// Custom field?
2450
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2451
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2452
-		else
2453
-			$action_text = $row['action'];
2515
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2516
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2517
+		} else {
2518
+					$action_text = $row['action'];
2519
+		}
2454 2520
 
2455 2521
 		// Parse BBC?
2456 2522
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2482,13 +2548,15 @@  discard block
 block discarded – undo
2482 2548
 			)
2483 2549
 		);
2484 2550
 		$members = array();
2485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2486
-			$members[$row['id_member']] = $row['real_name'];
2551
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2552
+					$members[$row['id_member']] = $row['real_name'];
2553
+		}
2487 2554
 		$smcFunc['db_free_result']($request);
2488 2555
 
2489
-		foreach ($edits as $key => $value)
2490
-			if (isset($members[$value['id_member']]))
2556
+		foreach ($edits as $key => $value) {
2557
+					if (isset($members[$value['id_member']]))
2491 2558
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2559
+		}
2492 2560
 	}
2493 2561
 
2494 2562
 	return $edits;
@@ -2689,10 +2757,11 @@  discard block
 block discarded – undo
2689 2757
 	$context['board'] = $board;
2690 2758
 
2691 2759
 	// Determine which groups this user is in.
2692
-	if (empty($user_profile[$memID]['additional_groups']))
2693
-		$curGroups = array();
2694
-	else
2695
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2760
+	if (empty($user_profile[$memID]['additional_groups'])) {
2761
+			$curGroups = array();
2762
+	} else {
2763
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2764
+	}
2696 2765
 	$curGroups[] = $user_profile[$memID]['id_group'];
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2698 2767
 
@@ -2712,28 +2781,30 @@  discard block
 block discarded – undo
2712 2781
 	$context['no_access_boards'] = array();
2713 2782
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2714 2783
 	{
2715
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2716
-			$context['no_access_boards'][] = array(
2784
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2785
+					$context['no_access_boards'][] = array(
2717 2786
 				'id' => $row['id_board'],
2718 2787
 				'name' => $row['name'],
2719 2788
 				'is_last' => false,
2720 2789
 			);
2721
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2722
-			$context['boards'][$row['id_board']] = array(
2790
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2791
+					$context['boards'][$row['id_board']] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'selected' => $board == $row['id_board'],
2726 2795
 				'profile' => $row['id_profile'],
2727 2796
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2728 2797
 			);
2798
+		}
2729 2799
 	}
2730 2800
 	$smcFunc['db_free_result']($request);
2731 2801
 
2732 2802
 	require_once($sourcedir . '/Subs-Boards.php');
2733 2803
 	sortBoards($context['boards']);
2734 2804
 
2735
-	if (!empty($context['no_access_boards']))
2736
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2805
+	if (!empty($context['no_access_boards'])) {
2806
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2807
+	}
2737 2808
 
2738 2809
 	$context['member']['permissions'] = array(
2739 2810
 		'general' => array(),
@@ -2742,8 +2813,9 @@  discard block
 block discarded – undo
2742 2813
 
2743 2814
 	// If you're an admin we know you can do everything, we might as well leave.
2744 2815
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2745
-	if ($context['member']['has_all_permissions'])
2746
-		return;
2816
+	if ($context['member']['has_all_permissions']) {
2817
+			return;
2818
+	}
2747 2819
 
2748 2820
 	$denied = array();
2749 2821
 
@@ -2762,21 +2834,24 @@  discard block
 block discarded – undo
2762 2834
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2763 2835
 	{
2764 2836
 		// We don't know about this permission, it doesn't exist :P.
2765
-		if (!isset($txt['permissionname_' . $row['permission']]))
2766
-			continue;
2837
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2838
+					continue;
2839
+		}
2767 2840
 
2768
-		if (empty($row['add_deny']))
2769
-			$denied[] = $row['permission'];
2841
+		if (empty($row['add_deny'])) {
2842
+					$denied[] = $row['permission'];
2843
+		}
2770 2844
 
2771 2845
 		// Permissions that end with _own or _any consist of two parts.
2772
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2773
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2774
-		else
2775
-			$name = $txt['permissionname_' . $row['permission']];
2846
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2847
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2848
+		} else {
2849
+					$name = $txt['permissionname_' . $row['permission']];
2850
+		}
2776 2851
 
2777 2852
 		// Add this permission if it doesn't exist yet.
2778
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2779
-			$context['member']['permissions']['general'][$row['permission']] = array(
2853
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2854
+					$context['member']['permissions']['general'][$row['permission']] = array(
2780 2855
 				'id' => $row['permission'],
2781 2856
 				'groups' => array(
2782 2857
 					'allowed' => array(),
@@ -2786,6 +2861,7 @@  discard block
 block discarded – undo
2786 2861
 				'is_denied' => false,
2787 2862
 				'is_global' => true,
2788 2863
 			);
2864
+		}
2789 2865
 
2790 2866
 		// Add the membergroup to either the denied or the allowed groups.
2791 2867
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2819,18 +2895,20 @@  discard block
 block discarded – undo
2819 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2820 2896
 	{
2821 2897
 		// We don't know about this permission, it doesn't exist :P.
2822
-		if (!isset($txt['permissionname_' . $row['permission']]))
2823
-			continue;
2898
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2899
+					continue;
2900
+		}
2824 2901
 
2825 2902
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2826
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2827
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2828
-		else
2829
-			$name = $txt['permissionname_' . $row['permission']];
2903
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2904
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2905
+		} else {
2906
+					$name = $txt['permissionname_' . $row['permission']];
2907
+		}
2830 2908
 
2831 2909
 		// Create the structure for this permission.
2832
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2833
-			$context['member']['permissions']['board'][$row['permission']] = array(
2910
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2911
+					$context['member']['permissions']['board'][$row['permission']] = array(
2834 2912
 				'id' => $row['permission'],
2835 2913
 				'groups' => array(
2836 2914
 					'allowed' => array(),
@@ -2840,6 +2918,7 @@  discard block
 block discarded – undo
2840 2918
 				'is_denied' => false,
2841 2919
 				'is_global' => empty($board),
2842 2920
 			);
2921
+		}
2843 2922
 
2844 2923
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2845 2924
 
@@ -2858,8 +2937,9 @@  discard block
 block discarded – undo
2858 2937
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2859 2938
 
2860 2939
 	// Firstly, can we actually even be here?
2861
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2862
-		fatal_lang_error('no_access', false);
2940
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2941
+			fatal_lang_error('no_access', false);
2942
+	}
2863 2943
 
2864 2944
 	// Make sure things which are disabled stay disabled.
2865 2945
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2946,9 +3026,10 @@  discard block
 block discarded – undo
2946 3026
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2947 3027
 	);
2948 3028
 	$context['current_level'] = 0;
2949
-	foreach ($context['level_effects'] as $limit => $dummy)
2950
-		if ($context['member']['warning'] >= $limit)
3029
+	foreach ($context['level_effects'] as $limit => $dummy) {
3030
+			if ($context['member']['warning'] >= $limit)
2951 3031
 			$context['current_level'] = $limit;
2952
-}
3032
+	}
3033
+	}
2953 3034
 
2954 3035
 ?>
2955 3036
\ No newline at end of file
Please login to merge, or discard this patch.