Completed
Pull Request — release-2.1 (#4089)
by Sebastiaan
08:14
created
Sources/Subs-Graphics.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@
 block discarded – undo
170 170
  *
171 171
  * @param string $fileName The path to the file
172 172
  * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp
173
- * @return boolean Whether the reencoding was successful
173
+ * @return false|null Whether the reencoding was successful
174 174
  */
175 175
 function reencodeImage($fileName, $preferred_format = 0)
176 176
 {
Please login to merge, or discard this patch.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -523,7 +523,6 @@  discard block
 block discarded – undo
523 523
 /**
524 524
  * Copy image.
525 525
  * Used when imagecopyresample() is not available.
526
-
527 526
  * @param resource $dst_img The destination image - a GD image resource
528 527
  * @param resource $src_img The source image - a GD image resource
529 528
  * @param int $dst_x The "x" coordinate of the destination image
@@ -754,7 +753,6 @@  discard block
 block discarded – undo
754 753
 
755 754
 /**
756 755
  * Writes a gif file to disk as a png file.
757
-
758 756
  * @param resource $gif A gif image resource
759 757
  * @param string $lpszFileName The name of the file
760 758
  * @param int $background_color The background color
Please login to merge, or discard this patch.
Braces   +240 added lines, -195 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 3
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -218,8 +225,7 @@  discard block
 block discarded – undo
218 225
 				fclose($fp);
219 226
 				return false;
220 227
 			}
221
-		}
222
-		else
228
+		} else
223 229
 		{
224 230
 			// Check for potential infection - focus on clues for inline php & flash.
225 231
 			// Will result in significantly fewer false positives than the paranoid check.
@@ -247,8 +253,9 @@  discard block
 block discarded – undo
247 253
 	global $gd2;
248 254
 
249 255
 	// Check to see if GD is installed and what version.
250
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
251
-		return false;
256
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
257
+			return false;
258
+	}
252 259
 
253 260
 	// Also determine if GD2 is installed and store it in a global.
254 261
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -320,8 +327,9 @@  discard block
 block discarded – undo
320 327
 	global $sourcedir;
321 328
 
322 329
 	// Nothing to do without GD or IM/MW
323
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
324
-		return false;
330
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
331
+			return false;
332
+	}
325 333
 
326 334
 	static $default_formats = array(
327 335
 		'1' => 'gif',
@@ -343,38 +351,39 @@  discard block
 block discarded – undo
343 351
 		fclose($fp_destination);
344 352
 
345 353
 		$sizes = @getimagesize($destination);
346
-	}
347
-	elseif ($fp_destination)
354
+	} elseif ($fp_destination)
348 355
 	{
349 356
 		$sizes = @getimagesize($source);
350 357
 
351 358
 		$fp_source = fopen($source, 'rb');
352 359
 		if ($fp_source !== false)
353 360
 		{
354
-			while (!feof($fp_source))
355
-				fwrite($fp_destination, fread($fp_source, 8192));
361
+			while (!feof($fp_source)) {
362
+							fwrite($fp_destination, fread($fp_source, 8192));
363
+			}
356 364
 			fclose($fp_source);
365
+		} else {
366
+					$sizes = array(-1, -1, -1);
357 367
 		}
358
-		else
359
-			$sizes = array(-1, -1, -1);
360 368
 		fclose($fp_destination);
361 369
 	}
362 370
 	// We can't get to the file.
363
-	else
364
-		$sizes = array(-1, -1, -1);
371
+	else {
372
+			$sizes = array(-1, -1, -1);
373
+	}
365 374
 
366 375
 	// See if we have -or- can get the needed memory for this operation
367 376
 	// ImageMagick isn't subject to PHP's memory limits :)
368
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
369
-		return false;
377
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
378
+			return false;
379
+	}
370 380
 
371 381
 	// A known and supported format?
372 382
 	// @todo test PSD and gif.
373 383
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
374 384
 	{
375 385
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
376
-	}
377
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
386
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
378 387
 	{
379 388
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
380 389
 		if ($src_img = @$imagecreatefrom($destination))
@@ -427,14 +436,14 @@  discard block
 block discarded – undo
427 436
 			$dest_width = empty($max_width) ? $src_width : $max_width;
428 437
 			$dest_height = empty($max_height) ? $src_height : $max_height;
429 438
 
430
-			if ($default_formats[$preferred_format] == 'jpeg')
431
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			if ($default_formats[$preferred_format] == 'jpeg') {
440
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
441
+			}
432 442
 
433 443
 			$imagick->setImageFormat($default_formats[$preferred_format]);
434 444
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
435 445
 			$success = $imagick->writeImage($destName);
436
-		}
437
-		else
446
+		} else
438 447
 		{
439 448
 			$magick_wand = newMagickWand();
440 449
 			MagickReadImage($magick_wand, $destName);
@@ -443,8 +452,9 @@  discard block
 block discarded – undo
443 452
 			$dest_width = empty($max_width) ? $src_width : $max_width;
444 453
 			$dest_height = empty($max_height) ? $src_height : $max_height;
445 454
 
446
-			if ($default_formats[$preferred_format] == 'jpeg')
447
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			if ($default_formats[$preferred_format] == 'jpeg') {
456
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
457
+			}
448 458
 
449 459
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
450 460
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -452,8 +462,7 @@  discard block
 block discarded – undo
452 462
 		}
453 463
 
454 464
 		return !empty($success);
455
-	}
456
-	elseif (checkGD())
465
+	} elseif (checkGD())
457 466
 	{
458 467
 		$success = false;
459 468
 
@@ -464,8 +473,7 @@  discard block
 block discarded – undo
464 473
 			{
465 474
 				$dst_width = $max_width;
466 475
 				$dst_height = round($src_height * $max_width / $src_width);
467
-			}
468
-			elseif (!empty($max_height))
476
+			} elseif (!empty($max_height))
469 477
 			{
470 478
 				$dst_width = round($src_width * $max_height / $src_height);
471 479
 				$dst_height = $max_height;
@@ -483,44 +491,48 @@  discard block
 block discarded – undo
483 491
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
484 492
 					{
485 493
 						imagealphablending($dst_img, false);
486
-						if (function_exists('imagesavealpha'))
487
-							imagesavealpha($dst_img, true);
494
+						if (function_exists('imagesavealpha')) {
495
+													imagesavealpha($dst_img, true);
496
+						}
488 497
 					}
498
+				} else {
499
+									$dst_img = imagecreate($dst_width, $dst_height);
489 500
 				}
490
-				else
491
-					$dst_img = imagecreate($dst_width, $dst_height);
492 501
 
493 502
 				// Resize it!
494
-				if ($gd2)
495
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
496
-				else
497
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				if ($gd2) {
504
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				} else {
506
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
507
+				}
508
+			} else {
509
+							$dst_img = $src_img;
498 510
 			}
499
-			else
500
-				$dst_img = $src_img;
511
+		} else {
512
+					$dst_img = $src_img;
501 513
 		}
502
-		else
503
-			$dst_img = $src_img;
504 514
 
505 515
 		// Save the image as ...
506
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
507
-			$success = imagepng($dst_img, $destName);
508
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
509
-			$success = imagegif($dst_img, $destName);
510
-		elseif (function_exists('imagejpeg'))
511
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
516
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
517
+					$success = imagepng($dst_img, $destName);
518
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
519
+					$success = imagegif($dst_img, $destName);
520
+		} elseif (function_exists('imagejpeg')) {
521
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
522
+		}
512 523
 
513 524
 		// Free the memory.
514 525
 		imagedestroy($src_img);
515
-		if ($dst_img != $src_img)
516
-			imagedestroy($dst_img);
526
+		if ($dst_img != $src_img) {
527
+					imagedestroy($dst_img);
528
+		}
517 529
 
518 530
 		return $success;
519
-	}
520
-	else
521
-		// Without GD, no image resizing at all.
531
+	} else {
532
+			// Without GD, no image resizing at all.
522 533
 		return false;
523
-}
534
+	}
535
+	}
524 536
 
525 537
 /**
526 538
  * Copy image.
@@ -574,8 +586,9 @@  discard block
 block discarded – undo
574 586
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
575 587
 			if ($color == -1)
576 588
 			{
577
-				if ($palsize++ < 256)
578
-					imagecolorallocate($dst_img, $red, $green, $blue);
589
+				if ($palsize++ < 256) {
590
+									imagecolorallocate($dst_img, $red, $green, $blue);
591
+				}
579 592
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
580 593
 			}
581 594
 
@@ -605,13 +618,15 @@  discard block
 block discarded – undo
605 618
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
606 619
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
607 620
 
608
-		if ($header['type'] != 0x4D42)
609
-			return false;
621
+		if ($header['type'] != 0x4D42) {
622
+					return false;
623
+		}
610 624
 
611
-		if ($gd2)
612
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
613
-		else
614
-			$dst_img = imagecreate($info['width'], $info['height']);
625
+		if ($gd2) {
626
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
627
+		} else {
628
+					$dst_img = imagecreate($info['width'], $info['height']);
629
+		}
615 630
 
616 631
 		$palette_size = $header['offset'] - 54;
617 632
 		$info['ncolor'] = $palette_size / 4;
@@ -637,8 +652,9 @@  discard block
 block discarded – undo
637 652
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
638 653
 			$scan_line = fread($fp, $scan_line_size);
639 654
 
640
-			if (strlen($scan_line) < $scan_line_size)
641
-				continue;
655
+			if (strlen($scan_line) < $scan_line_size) {
656
+							continue;
657
+			}
642 658
 
643 659
 			if ($info['bits'] == 32)
644 660
 			{
@@ -656,14 +672,14 @@  discard block
 block discarded – undo
656 672
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
657 673
 
658 674
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
659
-						if ($color == -1)
660
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						if ($color == -1) {
676
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
677
+						}
661 678
 					}
662 679
 
663 680
 					imagesetpixel($dst_img, $x, $y, $color);
664 681
 				}
665
-			}
666
-			elseif ($info['bits'] == 24)
682
+			} elseif ($info['bits'] == 24)
667 683
 			{
668 684
 				$x = 0;
669 685
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -678,14 +694,14 @@  discard block
 block discarded – undo
678 694
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
679 695
 
680 696
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
681
-						if ($color == -1)
682
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						if ($color == -1) {
698
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
699
+						}
683 700
 					}
684 701
 
685 702
 					imagesetpixel($dst_img, $x, $y, $color);
686 703
 				}
687
-			}
688
-			elseif ($info['bits'] == 16)
704
+			} elseif ($info['bits'] == 16)
689 705
 			{
690 706
 				$x = 0;
691 707
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -706,20 +722,20 @@  discard block
 block discarded – undo
706 722
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
707 723
 
708 724
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
709
-						if ($color == -1)
710
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						if ($color == -1) {
726
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
727
+						}
711 728
 					}
712 729
 
713 730
 					imagesetpixel($dst_img, $x, $y, $color);
714 731
 				}
715
-			}
716
-			elseif ($info['bits'] == 8)
732
+			} elseif ($info['bits'] == 8)
717 733
 			{
718 734
 				$x = 0;
719
-				for ($j = 0; $j < $scan_line_size; $x++)
720
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
721
-			}
722
-			elseif ($info['bits'] == 4)
735
+				for ($j = 0; $j < $scan_line_size; $x++) {
736
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
737
+				}
738
+			} elseif ($info['bits'] == 4)
723 739
 			{
724 740
 				$x = 0;
725 741
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -727,11 +743,11 @@  discard block
 block discarded – undo
727 743
 					$byte = ord($scan_line{$j++});
728 744
 
729 745
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
730
-					if (++$x < $info['width'])
731
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
746
+					if (++$x < $info['width']) {
747
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
748
+					}
732 749
 				}
733
-			}
734
-			elseif ($info['bits'] == 1)
750
+			} elseif ($info['bits'] == 1)
735 751
 			{
736 752
 				$x = 0;
737 753
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -740,7 +756,9 @@  discard block
 block discarded – undo
740 756
 
741 757
 					imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]);
742 758
 					for ($shift = 1; $shift < 8; $shift++) {
743
-						if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
759
+						if (++$x < $info['width']) {
760
+							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
761
+						}
744 762
 					}
745 763
 				}
746 764
 			}
@@ -764,15 +782,18 @@  discard block
 block discarded – undo
764 782
  */
765 783
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
766 784
 {
767
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
768
-		return false;
785
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
786
+			return false;
787
+	}
769 788
 
770 789
 	$fd = $gif->get_png_data($background_color);
771
-	if (strlen($fd) <= 0)
772
-		return false;
790
+	if (strlen($fd) <= 0) {
791
+			return false;
792
+	}
773 793
 
774
-	if (!($fh = @fopen($lpszFileName, 'wb')))
775
-		return false;
794
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
795
+			return false;
796
+	}
776 797
 
777 798
 	@fwrite($fh, $fd, strlen($fd));
778 799
 	@fflush($fh);
@@ -799,8 +820,9 @@  discard block
 block discarded – undo
799 820
 	// What type are we going to be doing?
800 821
 	$imageType = $modSettings['visual_verification_type'];
801 822
 	// Special case to allow the admin center to show samples.
802
-	if ($user_info['is_admin'] && isset($_GET['type']))
803
-		$imageType = (int) $_GET['type'];
823
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
824
+			$imageType = (int) $_GET['type'];
825
+	}
804 826
 
805 827
 	// Some quick references for what we do.
806 828
 	// Do we show no, low or high noise?
@@ -834,25 +856,28 @@  discard block
 block discarded – undo
834 856
 	$character_spacing = 1;
835 857
 
836 858
 	// What color is the background - generally white unless we're on "hard".
837
-	if ($simpleBGColor)
838
-		$background_color = array(255, 255, 255);
839
-	else
840
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
859
+	if ($simpleBGColor) {
860
+			$background_color = array(255, 255, 255);
861
+	} else {
862
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
863
+	}
841 864
 
842 865
 	// The color of the characters shown (red, green, blue).
843
-	if ($simpleFGColor)
844
-		$foreground_color = array(0, 0, 0);
845
-	else
866
+	if ($simpleFGColor) {
867
+			$foreground_color = array(0, 0, 0);
868
+	} else
846 869
 	{
847 870
 		$foreground_color = array(64, 101, 136);
848 871
 
849 872
 		// Has the theme author requested a custom color?
850
-		if (isset($settings['verification_foreground']))
851
-			$foreground_color = $settings['verification_foreground'];
873
+		if (isset($settings['verification_foreground'])) {
874
+					$foreground_color = $settings['verification_foreground'];
875
+		}
852 876
 	}
853 877
 
854
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
855
-		return false;
878
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
879
+			return false;
880
+	}
856 881
 
857 882
 	// Get a list of the available fonts.
858 883
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -863,25 +888,28 @@  discard block
 block discarded – undo
863 888
 	{
864 889
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
865 890
 		{
866
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
867
-				$font_list[] = $entry;
891
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
892
+							$font_list[] = $entry;
893
+			}
894
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
895
+					$ttfont_list[] = $entry;
868 896
 		}
869
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
870
-			$ttfont_list[] = $entry;
871 897
 	}
872 898
 
873
-	if (empty($font_list))
874
-		return false;
899
+	if (empty($font_list)) {
900
+			return false;
901
+	}
875 902
 
876 903
 	// For non-hard things don't even change fonts.
877 904
 	if (!$varyFonts)
878 905
 	{
879 906
 		$font_list = array($font_list[0]);
880 907
 		// Try use Screenge if we can - it looks good!
881
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
882
-			$ttfont_list = array('AnonymousPro.ttf');
883
-		else
884
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
908
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
909
+					$ttfont_list = array('AnonymousPro.ttf');
910
+		} else {
911
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
912
+		}
885 913
 
886 914
 	}
887 915
 
@@ -899,14 +927,16 @@  discard block
 block discarded – undo
899 927
 	}
900 928
 
901 929
 	// Load all fonts and determine the maximum font height.
902
-	foreach ($loaded_fonts as $font_index => $dummy)
903
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	foreach ($loaded_fonts as $font_index => $dummy) {
931
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
932
+	}
904 933
 
905 934
 	// Determine the dimensions of each character.
906
-	if ($imageType == 4 || $imageType == 5)
907
-		$extra = 80;
908
-	else
909
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
910 940
 
911 941
 	$total_width = $character_spacing * strlen($code) + $extra;
912 942
 	$max_height = 0;
@@ -927,13 +957,15 @@  discard block
 block discarded – undo
927 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
928 958
 
929 959
 	// Randomize the foreground color a little.
930
-	for ($i = 0; $i < 3; $i++)
931
-		$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	for ($i = 0; $i < 3; $i++) {
961
+			$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
962
+	}
932 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
933 964
 
934 965
 	// Color for the dots.
935
-	for ($i = 0; $i < 3; $i++)
936
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
966
+	for ($i = 0; $i < 3; $i++) {
967
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
968
+	}
937 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
938 970
 
939 971
 	// Some squares/rectanges for new extreme level
@@ -959,10 +991,11 @@  discard block
 block discarded – undo
959 991
 			$can_do_ttf = function_exists('imagettftext');
960 992
 
961 993
 			// How much rotation will we give?
962
-			if ($rotationType == 'none')
963
-				$angle = 0;
964
-			else
965
-				$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
994
+			if ($rotationType == 'none') {
995
+							$angle = 0;
996
+			} else {
997
+							$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
998
+			}
966 999
 
967 1000
 			// What color shall we do it?
968 1001
 			if ($fontColorType == 'cyclic')
@@ -976,51 +1009,56 @@  discard block
 block discarded – undo
976 1009
 					array(0, 0, 0),
977 1010
 					array(143, 39, 31),
978 1011
 				);
979
-				if (!isset($last_index))
980
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
981 1015
 				$new_index = $last_index;
982
-				while ($last_index == $new_index)
983
-					$new_index = mt_rand(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = mt_rand(0, count($colors) - 1);
1018
+				}
984 1019
 				$char_fg_color = $colors[$new_index];
985 1020
 				$last_index = $new_index;
1021
+			} elseif ($fontColorType == 'random') {
1022
+							$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1023
+			} else {
1024
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
986 1025
 			}
987
-			elseif ($fontColorType == 'random')
988
-				$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
989
-			else
990
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
991 1026
 
992 1027
 			if (!empty($can_do_ttf))
993 1028
 			{
994 1029
 				// GD2 handles font size differently.
995
-				if ($fontSizeRandom)
996
-					$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
997
-				else
998
-					$font_size = $gd2 ? 18 : 24;
1030
+				if ($fontSizeRandom) {
1031
+									$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
1032
+				} else {
1033
+									$font_size = $gd2 ? 18 : 24;
1034
+				}
999 1035
 
1000 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1001 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1002 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5));
1003 1039
 
1004 1040
 				// What font face?
1005
-				if (!empty($ttfont_list))
1006
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1041
+				if (!empty($ttfont_list)) {
1042
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1043
+				}
1007 1044
 
1008 1045
 				// What color are we to do it in?
1009 1046
 				$is_reverse = $showReverseChars ? mt_rand(0, 1) : false;
1010 1047
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1011 1048
 
1012 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1013
-				if (empty($fontcord))
1014
-					$can_do_ttf = false;
1015
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1016 1053
 				{
1017 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1018 1055
 					// Put the character back!
1019 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1020 1057
 				}
1021 1058
 
1022
-				if ($can_do_ttf)
1023
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				if ($can_do_ttf) {
1060
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1061
+				}
1024 1062
 			}
1025 1063
 
1026 1064
 			if (!$can_do_ttf)
@@ -1039,8 +1077,9 @@  discard block
 block discarded – undo
1039 1077
 				}
1040 1078
 
1041 1079
 				// Sorry, no rotation available.
1042
-				else
1043
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				else {
1081
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1082
+				}
1044 1083
 				$cur_x += $character['width'] + $character_spacing;
1045 1084
 			}
1046 1085
 		}
@@ -1053,17 +1092,22 @@  discard block
 block discarded – undo
1053 1092
 	}
1054 1093
 
1055 1094
 	// Make the background color transparent on the hard image.
1056
-	if (!$simpleBGColor)
1057
-		imagecolortransparent($code_image, $bg_color);
1058
-	if ($hasBorder)
1059
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1095
+	if (!$simpleBGColor) {
1096
+			imagecolortransparent($code_image, $bg_color);
1097
+	}
1098
+	if ($hasBorder) {
1099
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1100
+	}
1060 1101
 
1061 1102
 	// Add some noise to the background?
1062 1103
 	if ($noiseType != 'none')
1063 1104
 	{
1064
-		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2))
1065
-			for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10))
1066
-				imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1105
+		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) {
1106
+					for ($j = mt_rand(0, 10);
1107
+		}
1108
+		$j < $total_width; $j += mt_rand(1, 10)) {
1109
+							imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1110
+			}
1067 1111
 
1068 1112
 		// Put in some lines too?
1069 1113
 		if ($noiseType != 'extreme')
@@ -1076,8 +1120,7 @@  discard block
 block discarded – undo
1076 1120
 					$x1 = mt_rand(0, $total_width);
1077 1121
 					$x2 = mt_rand(0, $total_width);
1078 1122
 					$y1 = 0; $y2 = $max_height;
1079
-				}
1080
-				else
1123
+				} else
1081 1124
 				{
1082 1125
 					$y1 = mt_rand(0, $max_height);
1083 1126
 					$y2 = mt_rand(0, $max_height);
@@ -1086,8 +1129,7 @@  discard block
 block discarded – undo
1086 1129
 				imagesetthickness($code_image, mt_rand(1, 2));
1087 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color);
1088 1131
 			}
1089
-		}
1090
-		else
1132
+		} else
1091 1133
 		{
1092 1134
 			// Put in some ellipse
1093 1135
 			$num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6);
@@ -1107,8 +1149,7 @@  discard block
 block discarded – undo
1107 1149
 	{
1108 1150
 		header('Content-type: image/gif');
1109 1151
 		imagegif($code_image);
1110
-	}
1111
-	else
1152
+	} else
1112 1153
 	{
1113 1154
 		header('Content-type: image/png');
1114 1155
 		imagepng($code_image);
@@ -1131,25 +1172,29 @@  discard block
 block discarded – undo
1131 1172
 {
1132 1173
 	global $settings;
1133 1174
 
1134
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1135
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1136 1178
 
1137 1179
 	// Get a list of the available font directories.
1138 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1139 1181
 	$font_list = array();
1140
-	while ($entry = $font_dir->read())
1141
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1182
+	while ($entry = $font_dir->read()) {
1183
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1142 1184
 			$font_list[] = $entry;
1185
+	}
1143 1186
 
1144
-	if (empty($font_list))
1145
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1146 1190
 
1147 1191
 	// Pick a random font.
1148 1192
 	$random_font = $font_list[array_rand($font_list)];
1149 1193
 
1150 1194
 	// Check if the given letter exists.
1151
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1152
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1153 1198
 
1154 1199
 	// Include it!
1155 1200
 	header('Content-type: image/png');
Please login to merge, or discard this patch.
Sources/Subs-Membergroups.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -243,6 +243,7 @@
 block discarded – undo
243 243
  * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups.
244 244
  * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function
245 245
  * @param bool $ignoreProtected Whether to ignore protected groups
246
+ * @param integer $groups
246 247
  * @return bool Whether the operation was successful
247 248
  */
248 249
 function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false)
Please login to merge, or discard this patch.
Braces   +149 added lines, -112 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Delete one of more membergroups.
@@ -31,15 +32,16 @@  discard block
 block discarded – undo
31 32
 	global $smcFunc, $modSettings, $txt;
32 33
 
33 34
 	// Make sure it's an array.
34
-	if (!is_array($groups))
35
-		$groups = array((int) $groups);
36
-	else
35
+	if (!is_array($groups)) {
36
+			$groups = array((int) $groups);
37
+	} else
37 38
 	{
38 39
 		$groups = array_unique($groups);
39 40
 
40 41
 		// Make sure all groups are integer.
41
-		foreach ($groups as $key => $value)
42
-			$groups[$key] = (int) $value;
42
+		foreach ($groups as $key => $value) {
43
+					$groups[$key] = (int) $value;
44
+		}
43 45
 	}
44 46
 
45 47
 	// Some groups are protected (guests, administrators, moderators, newbies).
@@ -56,15 +58,17 @@  discard block
 block discarded – undo
56 58
 				'is_protected' => 1,
57 59
 			)
58 60
 		);
59
-		while ($row = $smcFunc['db_fetch_assoc']($request))
60
-			$protected_groups[] = $row['id_group'];
61
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
62
+					$protected_groups[] = $row['id_group'];
63
+		}
61 64
 		$smcFunc['db_free_result']($request);
62 65
 	}
63 66
 
64 67
 	// Make sure they don't delete protected groups!
65 68
 	$groups = array_diff($groups, array_unique($protected_groups));
66
-	if (empty($groups))
67
-		return 'no_group_found';
69
+	if (empty($groups)) {
70
+			return 'no_group_found';
71
+	}
68 72
 
69 73
 	// Make sure they don't try to delete a group attached to a paid subscription.
70 74
 	$subscriptions = array();
@@ -74,13 +78,14 @@  discard block
 block discarded – undo
74 78
 		ORDER BY name');
75 79
 	while ($row = $smcFunc['db_fetch_assoc']($request))
76 80
 	{
77
-		if (in_array($row['id_group'], $groups))
78
-			$subscriptions[] = $row['name'];
79
-		else
81
+		if (in_array($row['id_group'], $groups)) {
82
+					$subscriptions[] = $row['name'];
83
+		} else
80 84
 		{
81 85
 			$add_groups = explode(',', $row['add_groups']);
82
-			if (count(array_intersect($add_groups, $groups)) != 0)
83
-				$subscriptions[] = $row['name'];
86
+			if (count(array_intersect($add_groups, $groups)) != 0) {
87
+							$subscriptions[] = $row['name'];
88
+			}
84 89
 		}
85 90
 	}
86 91
 	$smcFunc['db_free_result']($request);
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 			'group_list' => $groups,
102 107
 		)
103 108
 	);
104
-	while ($row = $smcFunc['db_fetch_assoc']($request))
105
-		logAction('delete_group', array('group' => $row['group_name']), 'admin');
109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
110
+			logAction('delete_group', array('group' => $row['group_name']), 'admin');
111
+	}
106 112
 	$smcFunc['db_free_result']($request);
107 113
 
108 114
 	call_integration_hook('integrate_delete_membergroups', array($groups));
@@ -187,12 +193,14 @@  discard block
 block discarded – undo
187 193
 		)
188 194
 	);
189 195
 	$updates = array();
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$updates[$row['additional_groups']][] = $row['id_member'];
196
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
197
+			$updates[$row['additional_groups']][] = $row['id_member'];
198
+	}
192 199
 	$smcFunc['db_free_result']($request);
193 200
 
194
-	foreach ($updates as $additional_groups => $memberArray)
195
-		updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
201
+	foreach ($updates as $additional_groups => $memberArray) {
202
+			updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
203
+	}
196 204
 
197 205
 	// No boards can provide access to these membergroups anymore.
198 206
 	$request = $smcFunc['db_query']('', '
@@ -204,12 +212,13 @@  discard block
 block discarded – undo
204 212
 		)
205 213
 	);
206 214
 	$updates = array();
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$updates[$row['member_groups']][] = $row['id_board'];
215
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
216
+			$updates[$row['member_groups']][] = $row['id_board'];
217
+	}
209 218
 	$smcFunc['db_free_result']($request);
210 219
 
211
-	foreach ($updates as $member_groups => $boardArray)
212
-		$smcFunc['db_query']('', '
220
+	foreach ($updates as $member_groups => $boardArray) {
221
+			$smcFunc['db_query']('', '
213 222
 			UPDATE {db_prefix}boards
214 223
 			SET member_groups = {string:member_groups}
215 224
 			WHERE id_board IN ({array_int:board_lists})',
@@ -218,6 +227,7 @@  discard block
 block discarded – undo
218 227
 				'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
219 228
 			)
220 229
 		);
230
+	}
221 231
 
222 232
 	// Recalculate the post groups, as they likely changed.
223 233
 	updateStats('postgroups');
@@ -225,8 +235,9 @@  discard block
 block discarded – undo
225 235
 	// Make a note of the fact that the cache may be wrong.
226 236
 	$settings_update = array('settings_updated' => time());
227 237
 	// Have we deleted the spider group?
228
-	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
229
-		$settings_update['spider_group'] = 0;
238
+	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) {
239
+			$settings_update['spider_group'] = 0;
240
+	}
230 241
 
231 242
 	updateSettings($settings_update);
232 243
 
@@ -250,22 +261,24 @@  discard block
 block discarded – undo
250 261
 	global $smcFunc, $modSettings, $sourcedir;
251 262
 
252 263
 	// You're getting nowhere without this permission, unless of course you are the group's moderator.
253
-	if (!$permissionCheckDone)
254
-		isAllowedTo('manage_membergroups');
264
+	if (!$permissionCheckDone) {
265
+			isAllowedTo('manage_membergroups');
266
+	}
255 267
 
256 268
 	// Assume something will happen.
257 269
 	updateSettings(array('settings_updated' => time()));
258 270
 
259 271
 	// Cleaning the input.
260
-	if (!is_array($members))
261
-		$members = array((int) $members);
262
-	else
272
+	if (!is_array($members)) {
273
+			$members = array((int) $members);
274
+	} else
263 275
 	{
264 276
 		$members = array_unique($members);
265 277
 
266 278
 		// Cast the members to integer.
267
-		foreach ($members as $key => $value)
268
-			$members[$key] = (int) $value;
279
+		foreach ($members as $key => $value) {
280
+					$members[$key] = (int) $value;
281
+		}
269 282
 	}
270 283
 
271 284
 	// Before we get started, let's check we won't leave the admin group empty!
@@ -277,14 +290,15 @@  discard block
 block discarded – undo
277 290
 		// Remove any admins if there are too many.
278 291
 		$non_changing_admins = array_diff(array_keys($admins), $members);
279 292
 
280
-		if (empty($non_changing_admins))
281
-			$members = array_diff($members, array_keys($admins));
293
+		if (empty($non_changing_admins)) {
294
+					$members = array_diff($members, array_keys($admins));
295
+		}
282 296
 	}
283 297
 
284 298
 	// Just in case.
285
-	if (empty($members))
286
-		return false;
287
-	elseif ($groups === null)
299
+	if (empty($members)) {
300
+			return false;
301
+	} elseif ($groups === null)
288 302
 	{
289 303
 		// Wanna remove all groups from these members? That's easy.
290 304
 		$smcFunc['db_query']('', '
@@ -306,20 +320,21 @@  discard block
 block discarded – undo
306 320
 		updateStats('postgroups', $members);
307 321
 
308 322
 		// Log what just happened.
309
-		foreach ($members as $member)
310
-			logAction('removed_all_groups', array('member' => $member), 'admin');
323
+		foreach ($members as $member) {
324
+					logAction('removed_all_groups', array('member' => $member), 'admin');
325
+		}
311 326
 
312 327
 		return true;
313
-	}
314
-	elseif (!is_array($groups))
315
-		$groups = array((int) $groups);
316
-	else
328
+	} elseif (!is_array($groups)) {
329
+			$groups = array((int) $groups);
330
+	} else
317 331
 	{
318 332
 		$groups = array_unique($groups);
319 333
 
320 334
 		// Make sure all groups are integer.
321
-		foreach ($groups as $key => $value)
322
-			$groups[$key] = (int) $value;
335
+		foreach ($groups as $key => $value) {
336
+					$groups[$key] = (int) $value;
337
+		}
323 338
 	}
324 339
 
325 340
 	// Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want.
@@ -335,10 +350,11 @@  discard block
 block discarded – undo
335 350
 	$group_names = array();
336 351
 	while ($row = $smcFunc['db_fetch_assoc']($request))
337 352
 	{
338
-		if ($row['min_posts'] != -1)
339
-			$implicitGroups[] = $row['id_group'];
340
-		else
341
-			$group_names[$row['id_group']] = $row['group_name'];
353
+		if ($row['min_posts'] != -1) {
354
+					$implicitGroups[] = $row['id_group'];
355
+		} else {
356
+					$group_names[$row['id_group']] = $row['group_name'];
357
+		}
342 358
 	}
343 359
 	$smcFunc['db_free_result']($request);
344 360
 
@@ -357,8 +373,9 @@  discard block
 block discarded – undo
357 373
 			)
358 374
 		);
359 375
 		$protected_groups = array(1);
360
-		while ($row = $smcFunc['db_fetch_assoc']($request))
361
-			$protected_groups[] = $row['id_group'];
376
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
377
+					$protected_groups[] = $row['id_group'];
378
+		}
362 379
 		$smcFunc['db_free_result']($request);
363 380
 
364 381
 		// If you're not an admin yourself, you can't touch protected groups!
@@ -366,8 +383,9 @@  discard block
 block discarded – undo
366 383
 	}
367 384
 
368 385
 	// Only continue if there are still groups and members left.
369
-	if (empty($groups) || empty($members))
370
-		return false;
386
+	if (empty($groups) || empty($members)) {
387
+			return false;
388
+	}
371 389
 
372 390
 	// First, reset those who have this as their primary group - this is the easy one.
373 391
 	$log_inserts = array();
@@ -381,8 +399,9 @@  discard block
 block discarded – undo
381 399
 			'member_list' => $members,
382 400
 		)
383 401
 	);
384
-	while ($row = $smcFunc['db_fetch_assoc']($request))
385
-		$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
402
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
403
+			$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
404
+	}
386 405
 	$smcFunc['db_free_result']($request);
387 406
 
388 407
 	$smcFunc['db_query']('', '
@@ -414,16 +433,17 @@  discard block
 block discarded – undo
414 433
 	while ($row = $smcFunc['db_fetch_assoc']($request))
415 434
 	{
416 435
 		// What log entries must we make for this one, eh?
417
-		foreach (explode(',', $row['additional_groups']) as $group)
418
-			if (in_array($group, $groups))
436
+		foreach (explode(',', $row['additional_groups']) as $group) {
437
+					if (in_array($group, $groups))
419 438
 				$log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
439
+		}
420 440
 
421 441
 		$updates[$row['additional_groups']][] = $row['id_member'];
422 442
 	}
423 443
 	$smcFunc['db_free_result']($request);
424 444
 
425
-	foreach ($updates as $additional_groups => $memberArray)
426
-		$smcFunc['db_query']('', '
445
+	foreach ($updates as $additional_groups => $memberArray) {
446
+			$smcFunc['db_query']('', '
427 447
 			UPDATE {db_prefix}members
428 448
 			SET additional_groups = {string:additional_groups}
429 449
 			WHERE id_member IN ({array_int:member_list})',
@@ -432,6 +452,7 @@  discard block
 block discarded – undo
432 452
 				'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
433 453
 			)
434 454
 		);
455
+	}
435 456
 
436 457
 	// Their post groups may have changed now...
437 458
 	updateStats('postgroups', $members);
@@ -440,8 +461,9 @@  discard block
 block discarded – undo
440 461
 	if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
441 462
 	{
442 463
 		require_once($sourcedir . '/Logging.php');
443
-		foreach ($log_inserts as $extra)
444
-			logAction('removed_from_group', $extra, 'admin');
464
+		foreach ($log_inserts as $extra) {
465
+					logAction('removed_from_group', $extra, 'admin');
466
+		}
445 467
 	}
446 468
 
447 469
 	// Mission successful.
@@ -477,21 +499,23 @@  discard block
 block discarded – undo
477 499
 	global $smcFunc, $sourcedir;
478 500
 
479 501
 	// Show your licence, but only if it hasn't been done yet.
480
-	if (!$permissionCheckDone)
481
-		isAllowedTo('manage_membergroups');
502
+	if (!$permissionCheckDone) {
503
+			isAllowedTo('manage_membergroups');
504
+	}
482 505
 
483 506
 	// Make sure we don't keep old stuff cached.
484 507
 	updateSettings(array('settings_updated' => time()));
485 508
 
486
-	if (!is_array($members))
487
-		$members = array((int) $members);
488
-	else
509
+	if (!is_array($members)) {
510
+			$members = array((int) $members);
511
+	} else
489 512
 	{
490 513
 		$members = array_unique($members);
491 514
 
492 515
 		// Make sure all members are integer.
493
-		foreach ($members as $key => $value)
494
-			$members[$key] = (int) $value;
516
+		foreach ($members as $key => $value) {
517
+					$members[$key] = (int) $value;
518
+		}
495 519
 	}
496 520
 	$group = (int) $group;
497 521
 
@@ -508,20 +532,23 @@  discard block
 block discarded – undo
508 532
 	$group_names = array();
509 533
 	while ($row = $smcFunc['db_fetch_assoc']($request))
510 534
 	{
511
-		if ($row['min_posts'] != -1)
512
-			$implicitGroups[] = $row['id_group'];
513
-		else
514
-			$group_names[$row['id_group']] = $row['group_name'];
535
+		if ($row['min_posts'] != -1) {
536
+					$implicitGroups[] = $row['id_group'];
537
+		} else {
538
+					$group_names[$row['id_group']] = $row['group_name'];
539
+		}
515 540
 	}
516 541
 	$smcFunc['db_free_result']($request);
517 542
 
518 543
 	// Sorry, you can't join an implicit group.
519
-	if (in_array($group, $implicitGroups) || empty($members))
520
-		return false;
544
+	if (in_array($group, $implicitGroups) || empty($members)) {
545
+			return false;
546
+	}
521 547
 
522 548
 	// Only admins can add admins...
523
-	if (!allowedTo('admin_forum') && $group == 1)
524
-		return false;
549
+	if (!allowedTo('admin_forum') && $group == 1) {
550
+			return false;
551
+	}
525 552
 	// ... and assign protected groups!
526 553
 	elseif (!allowedTo('admin_forum') && !$ignoreProtected)
527 554
 	{
@@ -539,13 +566,14 @@  discard block
 block discarded – undo
539 566
 		$smcFunc['db_free_result']($request);
540 567
 
541 568
 		// Is it protected?
542
-		if ($is_protected == 1)
543
-			return false;
569
+		if ($is_protected == 1) {
570
+					return false;
571
+		}
544 572
 	}
545 573
 
546 574
 	// Do the actual updates.
547
-	if ($type == 'only_additional')
548
-		$smcFunc['db_query']('', '
575
+	if ($type == 'only_additional') {
576
+			$smcFunc['db_query']('', '
549 577
 			UPDATE {db_prefix}members
550 578
 			SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
551 579
 			WHERE id_member IN ({array_int:member_list})
@@ -559,8 +587,8 @@  discard block
 block discarded – undo
559 587
 				'blank_string' => '',
560 588
 			)
561 589
 		);
562
-	elseif ($type == 'only_primary' || $type == 'force_primary')
563
-		$smcFunc['db_query']('', '
590
+	} elseif ($type == 'only_primary' || $type == 'force_primary') {
591
+			$smcFunc['db_query']('', '
564 592
 			UPDATE {db_prefix}members
565 593
 			SET id_group = {int:id_group}
566 594
 			WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
@@ -572,8 +600,8 @@  discard block
 block discarded – undo
572 600
 				'regular_group' => 0,
573 601
 			)
574 602
 		);
575
-	elseif ($type == 'auto')
576
-		$smcFunc['db_query']('', '
603
+	} elseif ($type == 'auto') {
604
+			$smcFunc['db_query']('', '
577 605
 			UPDATE {db_prefix}members
578 606
 			SET
579 607
 				id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
@@ -592,9 +620,11 @@  discard block
 block discarded – undo
592 620
 				'id_group_string_extend' => ',' . $group,
593 621
 			)
594 622
 		);
623
+	}
595 624
 	// Ack!!?  What happened?
596
-	else
597
-		trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
625
+	else {
626
+			trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
627
+	}
598 628
 
599 629
 	call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names));
600 630
 
@@ -603,8 +633,9 @@  discard block
 block discarded – undo
603 633
 
604 634
 	// Log the data.
605 635
 	require_once($sourcedir . '/Logging.php');
606
-	foreach ($members as $member)
607
-		logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');
636
+	foreach ($members as $member) {
637
+			logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');
638
+	}
608 639
 
609 640
 	return true;
610 641
 }
@@ -632,8 +663,9 @@  discard block
 block discarded – undo
632 663
 		)
633 664
 	);
634 665
 	$members = array();
635
-	while ($row = $smcFunc['db_fetch_assoc']($request))
636
-		$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
666
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
667
+			$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
668
+	}
637 669
 	$smcFunc['db_free_result']($request);
638 670
 
639 671
 	// If there are more than $limit members, add a 'more' link.
@@ -641,10 +673,10 @@  discard block
 block discarded – undo
641 673
 	{
642 674
 		array_pop($members);
643 675
 		return true;
676
+	} else {
677
+			return false;
678
+	}
644 679
 	}
645
-	else
646
-		return false;
647
-}
648 680
 
649 681
 /**
650 682
  * Retrieve a list of (visible) membergroups used by the cache.
@@ -669,8 +701,9 @@  discard block
 block discarded – undo
669 701
 		)
670 702
 	);
671 703
 	$groupCache = array();
672
-	while ($row = $smcFunc['db_fetch_assoc']($request))
673
-		$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
704
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
705
+			$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
706
+	}
674 707
 	$smcFunc['db_free_result']($request);
675 708
 
676 709
 	return array(
@@ -718,8 +751,9 @@  discard block
 block discarded – undo
718 751
 	while ($row = $smcFunc['db_fetch_assoc']($request))
719 752
 	{
720 753
 		// We only list the groups they can see.
721
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
722
-			continue;
754
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
755
+					continue;
756
+		}
723 757
 
724 758
 		$row['icons'] = explode('#', $row['icons']);
725 759
 
@@ -754,12 +788,11 @@  discard block
 block discarded – undo
754 788
 					'group_list' => $group_ids,
755 789
 				)
756 790
 			);
757
-			while ($row = $smcFunc['db_fetch_assoc']($query))
758
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
791
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
792
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
793
+			}
759 794
 			$smcFunc['db_free_result']($query);
760
-		}
761
-
762
-		else
795
+		} else
763 796
 		{
764 797
 			$query = $smcFunc['db_query']('', '
765 798
 				SELECT id_group, COUNT(*) AS num_members
@@ -770,8 +803,9 @@  discard block
 block discarded – undo
770 803
 					'group_list' => $group_ids,
771 804
 				)
772 805
 			);
773
-			while ($row = $smcFunc['db_fetch_assoc']($query))
774
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
806
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
807
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
808
+			}
775 809
 			$smcFunc['db_free_result']($query);
776 810
 
777 811
 			// Only do additional groups if we can moderate...
@@ -790,8 +824,9 @@  discard block
 block discarded – undo
790 824
 						'blank_string' => '',
791 825
 					)
792 826
 				);
793
-				while ($row = $smcFunc['db_fetch_assoc']($query))
794
-					$groups[$row['id_group']]['num_members'] += $row['num_members'];
827
+				while ($row = $smcFunc['db_fetch_assoc']($query)) {
828
+									$groups[$row['id_group']]['num_members'] += $row['num_members'];
829
+				}
795 830
 				$smcFunc['db_free_result']($query);
796 831
 			}
797 832
 		}
@@ -805,8 +840,9 @@  discard block
 block discarded – undo
805 840
 				'group_list' => $group_ids,
806 841
 			)
807 842
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($query))
809
-			$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
843
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
844
+					$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
845
+		}
810 846
 		$smcFunc['db_free_result']($query);
811 847
 	}
812 848
 
@@ -815,8 +851,9 @@  discard block
 block discarded – undo
815 851
 	{
816 852
 		$sort_ascending = strpos($sort, 'DESC') === false;
817 853
 
818
-		foreach ($groups as $group)
819
-			$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
854
+		foreach ($groups as $group) {
855
+					$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
856
+		}
820 857
 
821 858
 		array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
822 859
 	}
Please login to merge, or discard this patch.
Sources/Subs-Menu.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -286,7 +286,7 @@
 block discarded – undo
286 286
 /**
287 287
  * Delete a menu.
288 288
  * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one
289
- * @return bool|void False if the menu doesn't exist, nothing otherwise
289
+ * @return false|null False if the menu doesn't exist, nothing otherwise
290 290
  */
291 291
 function destroyMenu($menu_id = 'last')
292 292
 {
Please login to merge, or discard this patch.
Braces   +87 added lines, -63 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,41 +116,45 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124
-						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125
-							$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
126
-						elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
127
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
128
-						elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
129
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
130
-						elseif (isset($area['icon']))
131
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
132
-						else
133
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
134
-
135
-						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
136
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
137
-						elseif (isset($area['icon']))
132
+						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') {
133
+													$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
134
+						} elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) {
135
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
136
+						} elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) {
137
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
138
+						} elseif (isset($area['icon'])) {
139
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
140
+						} else {
141
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
142
+						}
143
+
144
+						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) {
145
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
146
+						} elseif (isset($area['icon']))
138 147
 						{
139
-							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
140
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
141
-							elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
142
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
148
+							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) {
149
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
150
+							} elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) {
151
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
152
+							}
143 153
 
144 154
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
155
+						} else {
156
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
145 157
 						}
146
-						else
147
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
148 158
 
149 159
 						// Some areas may be listed but not active, which we show as greyed out.
150 160
 						$menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']);
@@ -158,35 +168,41 @@  discard block
 block discarded – undo
158 168
 							{
159 169
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
160 170
 								{
161
-									if ($first_sa == null)
162
-										$first_sa = $sa;
171
+									if ($first_sa == null) {
172
+																			$first_sa = $sa;
173
+									}
163 174
 
164 175
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
165 176
 									// Custom URL?
166
-									if (isset($sub['url']))
167
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
177
+									if (isset($sub['url'])) {
178
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
179
+									}
168 180
 
169 181
 									// A bit complicated - but is this set?
170 182
 									if ($menu_context['current_area'] == $area_id)
171 183
 									{
172 184
 										// Save which is the first...
173
-										if (empty($first_sa))
174
-											$first_sa = $sa;
185
+										if (empty($first_sa)) {
186
+																					$first_sa = $sa;
187
+										}
175 188
 
176 189
 										// Is this the current subsection?
177
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
178
-											$menu_context['current_subsection'] = $sa;
190
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
191
+																					$menu_context['current_subsection'] = $sa;
192
+										}
179 193
 										// Otherwise is it the default?
180
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
181
-											$menu_context['current_subsection'] = $sa;
194
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
195
+																					$menu_context['current_subsection'] = $sa;
196
+										}
182 197
 									}
183 198
 
184 199
 									// Let's assume this is the last, for now.
185 200
 									$last_sa = $sa;
186 201
 								}
187 202
 								// Mark it as disabled...
188
-								else
189
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
203
+								else {
204
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
205
+								}
190 206
 							}
191 207
 
192 208
 							// Set which one is first, last and selected in the group.
@@ -195,8 +211,9 @@  discard block
 block discarded – undo
195 211
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
196 212
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
197 213
 
198
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
199
-									$menu_context['current_subsection'] = $first_sa;
214
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
215
+																	$menu_context['current_subsection'] = $first_sa;
216
+								}
200 217
 							}
201 218
 						}
202 219
 					}
@@ -230,23 +247,26 @@  discard block
 block discarded – undo
230 247
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
231 248
 
232 249
 	// If we didn't find the area we were looking for go to a default one.
233
-	if (isset($backup_area) && empty($found_section))
234
-		$menu_context['current_area'] = $backup_area;
250
+	if (isset($backup_area) && empty($found_section)) {
251
+			$menu_context['current_area'] = $backup_area;
252
+	}
235 253
 
236 254
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
237 255
 	if (!empty($menu_context['current_section']))
238 256
 	{
239 257
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
240 258
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
241
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
242
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
259
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
260
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
261
+		}
243 262
 
244
-		foreach ($menu_context['sections'] as $section_id => $section)
245
-			foreach ($section['areas'] as $area_id => $area)
263
+		foreach ($menu_context['sections'] as $section_id => $section) {
264
+					foreach ($section['areas'] as $area_id => $area)
246 265
 			{
247 266
 				if (!isset($menu_context['sections'][$section_id]['url']))
248 267
 				{
249 268
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
269
+		}
250 270
 					break;
251 271
 				}
252 272
 			}
@@ -257,8 +277,9 @@  discard block
 block discarded – undo
257 277
 	{
258 278
 		// Never happened!
259 279
 		$context['max_menu_id']--;
260
-		if ($context['max_menu_id'] == 0)
261
-			unset($context['max_menu_id']);
280
+		if ($context['max_menu_id'] == 0) {
281
+					unset($context['max_menu_id']);
282
+		}
262 283
 
263 284
 		return false;
264 285
 	}
@@ -269,8 +290,9 @@  discard block
 block discarded – undo
269 290
 	$context['template_layers'][] = $menu_context['layer_name'];
270 291
 
271 292
 	// Check we had something - for sanity sake.
272
-	if (empty($include_data))
273
-		return false;
293
+	if (empty($include_data)) {
294
+			return false;
295
+	}
274 296
 
275 297
 	// Finally - return information on the selected item.
276 298
 	$include_data += array(
@@ -293,12 +315,14 @@  discard block
 block discarded – undo
293 315
 	global $context;
294 316
 
295 317
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
296
-	if (!isset($context[$menu_name]))
297
-		return false;
318
+	if (!isset($context[$menu_name])) {
319
+			return false;
320
+	}
298 321
 
299 322
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
300
-	if ($layer_index !== false)
301
-		unset($context['template_layers'][$layer_index]);
323
+	if ($layer_index !== false) {
324
+			unset($context['template_layers'][$layer_index]);
325
+	}
302 326
 
303 327
 	unset($context[$menu_name]);
304 328
 }
Please login to merge, or discard this patch.
Sources/Subs-Post.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
  * @param resource $socket Socket to send on
1452 1452
  * @param string $code The expected response code
1453 1453
  * @param string $response The response from the SMTP server
1454
- * @return bool Whether it responded as such.
1454
+ * @return string|boolean Whether it responded as such.
1455 1455
  */
1456 1456
 function server_parse($message, $socket, $code, &$response = null)
1457 1457
 {
@@ -2265,7 +2265,7 @@  discard block
 block discarded – undo
2265 2265
  * @param array $msgs Array of message ids
2266 2266
  * @param bool $approve Whether to approve the posts (if false, posts are unapproved)
2267 2267
  * @param bool $notify Whether to notify users
2268
- * @return bool Whether the operation was successful
2268
+ * @return null|boolean Whether the operation was successful
2269 2269
  */
2270 2270
 function approvePosts($msgs, $approve = true, $notify = true)
2271 2271
 {
@@ -2518,7 +2518,7 @@  discard block
 block discarded – undo
2518 2518
  *
2519 2519
  * @param array $topics Array of topic ids
2520 2520
  * @param bool $approve Whether to approve the topics. If false, unapproves them instead
2521
- * @return bool Whether the operation was successful
2521
+ * @return null|boolean Whether the operation was successful
2522 2522
  */
2523 2523
 function approveTopics($topics, $approve = true)
2524 2524
 {
@@ -2908,7 +2908,7 @@  discard block
 block discarded – undo
2908 2908
  *
2909 2909
  * @param resource $dict An enchant or pspell dictionary resource set up by {@link spell_init()}
2910 2910
  * @param string $word A word to check the spelling of
2911
- * @return bool Whether or not the specified word is spelled properly
2911
+ * @return boolean|null Whether or not the specified word is spelled properly
2912 2912
  */
2913 2913
 function spell_check($dict, $word)
2914 2914
 {
Please login to merge, or discard this patch.
Braces   +528 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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
  * Takes a message and parses it, returning nothing.
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 	$message = preg_replace('~\.{100,}~', '...', $message);
47 48
 
48 49
 	// Trim off trailing quotes - these often happen by accident.
49
-	while (substr($message, -7) == '[quote]')
50
-		$message = substr($message, 0, -7);
51
-	while (substr($message, 0, 8) == '[/quote]')
52
-		$message = substr($message, 8);
50
+	while (substr($message, -7) == '[quote]') {
51
+			$message = substr($message, 0, -7);
52
+	}
53
+	while (substr($message, 0, 8) == '[/quote]') {
54
+			$message = substr($message, 8);
55
+	}
53 56
 
54 57
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
55 58
 	$in_tag = false;
56 59
 	$had_tag = false;
57 60
 	$codeopen = 0;
58
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
59
-		foreach ($matches[0] as $index => $dummy)
61
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
62
+			foreach ($matches[0] as $index => $dummy)
60 63
 		{
61 64
 			// Closing?
62 65
 			if (!empty($matches[2][$index]))
@@ -64,6 +67,7 @@  discard block
 block discarded – undo
64 67
 				// If it's closing and we're not in a tag we need to open it...
65 68
 				if (!$in_tag)
66 69
 					$codeopen = true;
70
+	}
67 71
 				// Either way we ain't in one any more.
68 72
 				$in_tag = false;
69 73
 			}
@@ -72,17 +76,20 @@  discard block
 block discarded – undo
72 76
 			{
73 77
 				$had_tag = true;
74 78
 				// If we're in a tag don't do nought!
75
-				if (!$in_tag)
76
-					$in_tag = true;
79
+				if (!$in_tag) {
80
+									$in_tag = true;
81
+				}
77 82
 			}
78 83
 		}
79 84
 
80 85
 	// If we have an open tag, close it.
81
-	if ($in_tag)
82
-		$message .= '[/code]';
86
+	if ($in_tag) {
87
+			$message .= '[/code]';
88
+	}
83 89
 	// Open any ones that need to be open, only if we've never had a tag.
84
-	if ($codeopen && !$had_tag)
85
-		$message = '[code]' . $message;
90
+	if ($codeopen && !$had_tag) {
91
+			$message = '[code]' . $message;
92
+	}
86 93
 
87 94
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
88 95
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +115,26 @@  discard block
 block discarded – undo
108 115
 	fixTags($message);
109 116
 
110 117
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
118
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
119
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
120
+	} else {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
122
+	}
115 123
 
116 124
 	if (!$previewing && strpos($message, '[html]') !== false)
117 125
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
126
+		if (allowedTo('admin_forum')) {
127
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 128
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
129
+		}
121 130
 			}, $message);
122 131
 
123 132
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 133
 		else
125 134
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
135
+			while (strpos($message, '[html]') !== false) {
136
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			}
128 138
 		}
129 139
 	}
130 140
 
@@ -146,10 +156,12 @@  discard block
 block discarded – undo
146 156
 
147 157
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 158
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
159
+	if ($list_close - $list_open > 0) {
160
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
161
+	}
162
+	if ($list_open - $list_close > 0) {
163
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
164
+	}
153 165
 
154 166
 	$mistake_fixes = array(
155 167
 		// Find [table]s not followed by [tr].
@@ -198,8 +210,9 @@  discard block
 block discarded – undo
198 210
 	);
199 211
 
200 212
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
213
+	for ($j = 0; $j < 3; $j++) {
214
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	}
203 216
 
204 217
 	// Remove empty bbc from the sections outside the code tags
205 218
 	$allowedEmpty = array(
@@ -209,24 +222,28 @@  discard block
 block discarded – undo
209 222
 
210 223
 	require_once($sourcedir . '/Subs.php');
211 224
 
212
-	foreach (($codes = parse_bbc(false)) as $code)
213
-		if (!in_array($code['tag'], $allowedEmpty))
225
+	foreach (($codes = parse_bbc(false)) as $code) {
226
+			if (!in_array($code['tag'], $allowedEmpty))
214 227
 			$alltags[] = $code['tag'];
228
+	}
215 229
 
216 230
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
217 231
 
218
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
219
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
232
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
233
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	}
220 235
 
221 236
 	// Restore code blocks
222
-	if (!empty($code_tags))
223
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
237
+	if (!empty($code_tags)) {
238
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	}
224 240
 
225 241
 	// Restore white space entities
226
-	if (!$previewing)
227
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
228
-	else
229
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
242
+	if (!$previewing) {
243
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	} else {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	}
230 247
 
231 248
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
232 249
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
270 287
 	}, $message);
271 288
 
272
-	if (!empty($code_tags))
273
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
289
+	if (!empty($code_tags)) {
290
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	}
274 292
 
275 293
 	// Change breaks back to \n's and &nsbp; back to spaces.
276 294
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -351,8 +369,9 @@  discard block
 block discarded – undo
351 369
 	);
352 370
 
353 371
 	// Fix each type of tag.
354
-	foreach ($fixArray as $param)
355
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
372
+	foreach ($fixArray as $param) {
373
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	}
356 375
 
357 376
 	// Now fix possible security problems with images loading links automatically...
358 377
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -388,16 +407,19 @@  discard block
 block discarded – undo
388 407
 					$desired_height = $height;
389 408
 				}
390 409
 				// Scale it to the width...
391
-				elseif (empty($desired_width) && !empty($height))
392
-					$desired_width = (int) (($desired_height * $width) / $height);
410
+				elseif (empty($desired_width) && !empty($height)) {
411
+									$desired_width = (int) (($desired_height * $width) / $height);
412
+				}
393 413
 				// Scale if to the height.
394
-				elseif (!empty($width))
395
-					$desired_height = (int) (($desired_width * $height) / $width);
414
+				elseif (!empty($width)) {
415
+									$desired_height = (int) (($desired_width * $height) / $width);
416
+				}
396 417
 			}
397 418
 
398 419
 			// If the width and height are fine, just continue along...
399
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
400
-				continue;
420
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
421
+							continue;
422
+			}
401 423
 
402 424
 			// Too bad, it's too wide.  Make it as wide as the maximum.
403 425
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -417,8 +439,9 @@  discard block
 block discarded – undo
417 439
 		}
418 440
 
419 441
 		// If any img tags were actually changed...
420
-		if (!empty($replaces))
421
-			$message = strtr($message, $replaces);
442
+		if (!empty($replaces)) {
443
+					$message = strtr($message, $replaces);
444
+		}
422 445
 	}
423 446
 }
424 447
 
@@ -437,10 +460,11 @@  discard block
 block discarded – undo
437 460
 {
438 461
 	global $boardurl, $scripturl;
439 462
 
440
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
441
-		$domain_url = $match[1];
442
-	else
443
-		$domain_url = $boardurl . '/';
463
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
464
+			$domain_url = $match[1];
465
+	} else {
466
+			$domain_url = $boardurl . '/';
467
+	}
444 468
 
445 469
 	$replaces = array();
446 470
 
@@ -448,11 +472,11 @@  discard block
 block discarded – undo
448 472
 	{
449 473
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
450 474
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
475
+	} elseif ($hasEqualSign) {
476
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} else {
478
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
451 479
 	}
452
-	elseif ($hasEqualSign)
453
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
454
-	else
455
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
456 480
 
457 481
 	foreach ($matches[0] as $k => $dummy)
458 482
 	{
@@ -465,49 +489,53 @@  discard block
 block discarded – undo
465 489
 		foreach ($protocols as $protocol)
466 490
 		{
467 491
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
468
-			if ($found)
469
-				break;
492
+			if ($found) {
493
+							break;
494
+			}
470 495
 		}
471 496
 
472 497
 		if (!$found && $protocols[0] == 'http')
473 498
 		{
474
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
475
-				$replace = $domain_url . $replace;
476
-			elseif (substr($replace, 0, 1) == '?')
477
-				$replace = $scripturl . $replace;
478
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
499
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
500
+							$replace = $domain_url . $replace;
501
+			} elseif (substr($replace, 0, 1) == '?') {
502
+							$replace = $scripturl . $replace;
503
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
479 504
 			{
480 505
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
481 506
 				$this_tag = 'iurl';
482 507
 				$this_close = 'iurl';
508
+			} elseif (substr($replace, 0, 2) != '//') {
509
+							$replace = $protocols[0] . '://' . $replace;
483 510
 			}
484
-			elseif (substr($replace, 0, 2) != '//')
485
-				$replace = $protocols[0] . '://' . $replace;
486
-		}
487
-		elseif (!$found && $protocols[0] == 'ftp')
488
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
489
-		elseif (!$found)
490
-			$replace = $protocols[0] . '://' . $replace;
491
-
492
-		if ($hasEqualSign && $embeddedUrl)
493
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
494
-		elseif ($hasEqualSign)
495
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
496
-		elseif ($embeddedUrl)
497
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
498
-		else
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
511
+		} elseif (!$found && $protocols[0] == 'ftp') {
512
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
513
+		} elseif (!$found) {
514
+					$replace = $protocols[0] . '://' . $replace;
515
+		}
516
+
517
+		if ($hasEqualSign && $embeddedUrl) {
518
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
519
+		} elseif ($hasEqualSign) {
520
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
521
+		} elseif ($embeddedUrl) {
522
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
523
+		} else {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
525
+		}
500 526
 	}
501 527
 
502 528
 	foreach ($replaces as $k => $v)
503 529
 	{
504
-		if ($k == $v)
505
-			unset($replaces[$k]);
530
+		if ($k == $v) {
531
+					unset($replaces[$k]);
532
+		}
506 533
 	}
507 534
 
508
-	if (!empty($replaces))
509
-		$message = strtr($message, $replaces);
510
-}
535
+	if (!empty($replaces)) {
536
+			$message = strtr($message, $replaces);
537
+	}
538
+	}
511 539
 
512 540
 /**
513 541
  * This function sends an email to the specified recipient(s).
@@ -551,8 +579,9 @@  discard block
 block discarded – undo
551 579
 	}
552 580
 
553 581
 	// Nothing left? Nothing else to do
554
-	if (empty($to_array))
555
-		return true;
582
+	if (empty($to_array)) {
583
+			return true;
584
+	}
556 585
 
557 586
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
558 587
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -569,15 +598,17 @@  discard block
 block discarded – undo
569 598
 		}
570 599
 
571 600
 		// Call this function recursively for the hotmail addresses.
572
-		if (!empty($hotmail_to))
573
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
601
+		if (!empty($hotmail_to)) {
602
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		}
574 604
 
575 605
 		// The remaining addresses no longer need the fix.
576 606
 		$hotmail_fix = false;
577 607
 
578 608
 		// No other addresses left? Return instantly.
579
-		if (empty($to_array))
580
-			return $mail_result;
609
+		if (empty($to_array)) {
610
+					return $mail_result;
611
+		}
581 612
 	}
582 613
 
583 614
 	// Get rid of entities.
@@ -602,13 +633,15 @@  discard block
 block discarded – undo
602 633
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
603 634
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
604 635
 
605
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
606
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
636
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
637
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	}
607 639
 	$headers .= 'X-Mailer: SMF' . $line_break;
608 640
 
609 641
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
610
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
611
-		return false;
642
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
643
+			return false;
644
+	}
612 645
 
613 646
 	// Save the original message...
614 647
 	$orig_message = $message;
@@ -657,17 +690,19 @@  discard block
 block discarded – undo
657 690
 	}
658 691
 
659 692
 	// Are we using the mail queue, if so this is where we butt in...
660
-	if ($priority != 0)
661
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
693
+	if ($priority != 0) {
694
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	}
662 696
 
663 697
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
664 698
 	elseif (!empty($modSettings['mail_limit']))
665 699
 	{
666 700
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
667
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
668
-			$new_queue_stat = time() . '|' . 1;
669
-		else
670
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
701
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
702
+					$new_queue_stat = time() . '|' . 1;
703
+		} else {
704
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
705
+		}
671 706
 
672 707
 		updateSettings(array('mail_recent' => $new_queue_stat));
673 708
 	}
@@ -692,12 +727,13 @@  discard block
 block discarded – undo
692 727
 
693 728
 			// Wait, wait, I'm still sending here!
694 729
 			@set_time_limit(300);
695
-			if (function_exists('apache_reset_timeout'))
696
-				@apache_reset_timeout();
730
+			if (function_exists('apache_reset_timeout')) {
731
+							@apache_reset_timeout();
732
+			}
697 733
 		}
734
+	} else {
735
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
698 736
 	}
699
-	else
700
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
701 737
 
702 738
 	// Everything go smoothly?
703 739
 	return $mail_result;
@@ -723,8 +759,9 @@  discard block
 block discarded – undo
723 759
 	static $cur_insert = array();
724 760
 	static $cur_insert_len = 0;
725 761
 
726
-	if ($cur_insert_len == 0)
727
-		$cur_insert = array();
762
+	if ($cur_insert_len == 0) {
763
+			$cur_insert = array();
764
+	}
728 765
 
729 766
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
730 767
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -799,8 +836,9 @@  discard block
 block discarded – undo
799 836
 	}
800 837
 
801 838
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
802
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
803
-		return AddMailQueue(true);
839
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
840
+			return AddMailQueue(true);
841
+	}
804 842
 
805 843
 	return true;
806 844
 }
@@ -831,23 +869,26 @@  discard block
 block discarded – undo
831 869
 		'sent' => array()
832 870
 	);
833 871
 
834
-	if ($from === null)
835
-		$from = array(
872
+	if ($from === null) {
873
+			$from = array(
836 874
 			'id' => $user_info['id'],
837 875
 			'name' => $user_info['name'],
838 876
 			'username' => $user_info['username']
839 877
 		);
878
+	}
840 879
 
841 880
 	// This is the one that will go in their inbox.
842 881
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
843 882
 	preparsecode($htmlmessage);
844 883
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
845
-	if ($smcFunc['strlen']($htmlsubject) > 100)
846
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
884
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
885
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	}
847 887
 
848 888
 	// Make sure is an array
849
-	if (!is_array($recipients))
850
-		$recipients = array($recipients);
889
+	if (!is_array($recipients)) {
890
+			$recipients = array($recipients);
891
+	}
851 892
 
852 893
 	// Integrated PMs
853 894
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -875,21 +916,23 @@  discard block
 block discarded – undo
875 916
 				'usernames' => array_keys($usernames),
876 917
 			)
877 918
 		);
878
-		while ($row = $smcFunc['db_fetch_assoc']($request))
879
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
919
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
920
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
880 921
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
922
+		}
881 923
 		$smcFunc['db_free_result']($request);
882 924
 
883 925
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
884
-		foreach ($recipients as $rec_type => $rec)
885
-			foreach ($rec as $id => $member)
926
+		foreach ($recipients as $rec_type => $rec) {
927
+					foreach ($rec as $id => $member)
886 928
 			{
887 929
 				if (is_numeric($recipients[$rec_type][$id]))
888 930
 					continue;
931
+		}
889 932
 
890
-				if (!empty($usernames[$member]))
891
-					$recipients[$rec_type][$id] = $usernames[$member];
892
-				else
933
+				if (!empty($usernames[$member])) {
934
+									$recipients[$rec_type][$id] = $usernames[$member];
935
+				} else
893 936
 				{
894 937
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
895 938
 					unset($recipients[$rec_type][$id]);
@@ -927,8 +970,9 @@  discard block
 block discarded – undo
927 970
 		$delete = false;
928 971
 		foreach ($criteria as $criterium)
929 972
 		{
930
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
931
-				$delete = true;
973
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
974
+							$delete = true;
975
+			}
932 976
 			// If we're adding and one criteria don't match then we stop!
933 977
 			elseif (!$row['is_or'])
934 978
 			{
@@ -936,8 +980,9 @@  discard block
 block discarded – undo
936 980
 				break;
937 981
 			}
938 982
 		}
939
-		if ($delete)
940
-			$deletes[$row['id_member']] = 1;
983
+		if ($delete) {
984
+					$deletes[$row['id_member']] = 1;
985
+		}
941 986
 	}
942 987
 	$smcFunc['db_free_result']($request);
943 988
 
@@ -952,8 +997,9 @@  discard block
 block discarded – undo
952 997
 			array(
953 998
 			)
954 999
 		);
955
-		while ($row = $smcFunc['db_fetch_assoc']($request))
956
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1000
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1001
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 	}
959 1005
 
@@ -961,8 +1007,9 @@  discard block
 block discarded – undo
961 1007
 	require_once($sourcedir . '/Subs-Members.php');
962 1008
 	$pmReadGroups = groupsAllowedTo('pm_read');
963 1009
 
964
-	if (empty($modSettings['permission_enable_deny']))
965
-		$pmReadGroups['denied'] = array();
1010
+	if (empty($modSettings['permission_enable_deny'])) {
1011
+			$pmReadGroups['denied'] = array();
1012
+	}
966 1013
 
967 1014
 	// Load their alert preferences
968 1015
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -994,8 +1041,9 @@  discard block
 block discarded – undo
994 1041
 	while ($row = $smcFunc['db_fetch_assoc']($request))
995 1042
 	{
996 1043
 		// Don't do anything for members to be deleted!
997
-		if (isset($deletes[$row['id_member']]))
998
-			continue;
1044
+		if (isset($deletes[$row['id_member']])) {
1045
+					continue;
1046
+		}
999 1047
 
1000 1048
 		// Load the preferences for this member (if any)
1001 1049
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1016,8 +1064,9 @@  discard block
 block discarded – undo
1016 1064
 		{
1017 1065
 			foreach ($groups as $id)
1018 1066
 			{
1019
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1020
-					$message_limit = $message_limit_cache[$id];
1067
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1068
+									$message_limit = $message_limit_cache[$id];
1069
+				}
1021 1070
 			}
1022 1071
 
1023 1072
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1065,8 +1114,9 @@  discard block
 block discarded – undo
1065 1114
 	$smcFunc['db_free_result']($request);
1066 1115
 
1067 1116
 	// Only 'send' the message if there are any recipients left.
1068
-	if (empty($all_to))
1069
-		return $log;
1117
+	if (empty($all_to)) {
1118
+			return $log;
1119
+	}
1070 1120
 
1071 1121
 	// Insert the message itself and then grab the last insert id.
1072 1122
 	$id_pm = $smcFunc['db_insert']('',
@@ -1087,8 +1137,8 @@  discard block
 block discarded – undo
1087 1137
 	if (!empty($id_pm))
1088 1138
 	{
1089 1139
 		// If this is new we need to set it part of it's own conversation.
1090
-		if (empty($pm_head))
1091
-			$smcFunc['db_query']('', '
1140
+		if (empty($pm_head)) {
1141
+					$smcFunc['db_query']('', '
1092 1142
 				UPDATE {db_prefix}personal_messages
1093 1143
 				SET id_pm_head = {int:id_pm_head}
1094 1144
 				WHERE id_pm = {int:id_pm_head}',
@@ -1096,6 +1146,7 @@  discard block
 block discarded – undo
1096 1146
 					'id_pm_head' => $id_pm,
1097 1147
 				)
1098 1148
 			);
1149
+		}
1099 1150
 
1100 1151
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1101 1152
 		$smcFunc['db_query']('', '
@@ -1111,8 +1162,9 @@  discard block
 block discarded – undo
1111 1162
 		foreach ($all_to as $to)
1112 1163
 		{
1113 1164
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1114
-			if (!in_array($to, $recipients['bcc']))
1115
-				$to_list[] = $to;
1165
+			if (!in_array($to, $recipients['bcc'])) {
1166
+							$to_list[] = $to;
1167
+			}
1116 1168
 		}
1117 1169
 
1118 1170
 		$smcFunc['db_insert']('insert',
@@ -1130,9 +1182,9 @@  discard block
 block discarded – undo
1130 1182
 	{
1131 1183
 		censorText($message);
1132 1184
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1185
+	} else {
1186
+			$message = '';
1133 1187
 	}
1134
-	else
1135
-		$message = '';
1136 1188
 
1137 1189
 	$to_names = array();
1138 1190
 	if (count($to_list) > 1)
@@ -1145,8 +1197,9 @@  discard block
 block discarded – undo
1145 1197
 				'to_members' => $to_list,
1146 1198
 			)
1147 1199
 		);
1148
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1149
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1200
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1201
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		}
1150 1203
 		$smcFunc['db_free_result']($request);
1151 1204
 	}
1152 1205
 	$replacements = array(
@@ -1174,11 +1227,13 @@  discard block
 block discarded – undo
1174 1227
 	loadLanguage('index+PersonalMessage');
1175 1228
 
1176 1229
 	// Add one to their unread and read message counts.
1177
-	foreach ($all_to as $k => $id)
1178
-		if (isset($deletes[$id]))
1230
+	foreach ($all_to as $k => $id) {
1231
+			if (isset($deletes[$id]))
1179 1232
 			unset($all_to[$k]);
1180
-	if (!empty($all_to))
1181
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1233
+	}
1234
+	if (!empty($all_to)) {
1235
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1182 1237
 
1183 1238
 	return $log;
1184 1239
 }
@@ -1208,15 +1263,17 @@  discard block
 block discarded – undo
1208 1263
 		// Let's, for now, assume there are only &#021;'ish characters.
1209 1264
 		$simple = true;
1210 1265
 
1211
-		foreach ($matches[1] as $entity)
1212
-			if ($entity > 128)
1266
+		foreach ($matches[1] as $entity) {
1267
+					if ($entity > 128)
1213 1268
 				$simple = false;
1269
+		}
1214 1270
 		unset($matches);
1215 1271
 
1216
-		if ($simple)
1217
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1272
+		if ($simple) {
1273
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1218 1274
 			{
1219 1275
 				return chr("$m[1]");
1276
+		}
1220 1277
 			}, $string);
1221 1278
 		else
1222 1279
 		{
@@ -1224,8 +1281,9 @@  discard block
 block discarded – undo
1224 1281
 			if (!$context['utf8'] && function_exists('iconv'))
1225 1282
 			{
1226 1283
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1227
-				if ($newstring)
1228
-					$string = $newstring;
1284
+				if ($newstring) {
1285
+									$string = $newstring;
1286
+				}
1229 1287
 			}
1230 1288
 
1231 1289
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1241,23 +1299,25 @@  discard block
 block discarded – undo
1241 1299
 		if (!$context['utf8'] && function_exists('iconv'))
1242 1300
 		{
1243 1301
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1244
-			if ($newstring)
1245
-				$string = $newstring;
1302
+			if ($newstring) {
1303
+							$string = $newstring;
1304
+			}
1246 1305
 		}
1247 1306
 
1248 1307
 		$entityConvert = function($m)
1249 1308
 		{
1250 1309
 			$c = $m[1];
1251
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1252
-				return $c;
1253
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1254
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1255
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1256
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1257
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1258
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1259
-			else
1260
-				return "";
1310
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1311
+							return $c;
1312
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1313
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1314
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1318
+			} else {
1319
+							return "";
1320
+			}
1261 1321
 		};
1262 1322
 
1263 1323
 		// Convert all 'special' characters to HTML entities.
@@ -1271,19 +1331,20 @@  discard block
 block discarded – undo
1271 1331
 		$string = base64_encode($string);
1272 1332
 
1273 1333
 		// Show the characterset and the transfer-encoding for header strings.
1274
-		if ($with_charset)
1275
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1334
+		if ($with_charset) {
1335
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		}
1276 1337
 
1277 1338
 		// Break it up in lines (mail body).
1278
-		else
1279
-			$string = chunk_split($string, 76, $line_break);
1339
+		else {
1340
+					$string = chunk_split($string, 76, $line_break);
1341
+		}
1280 1342
 
1281 1343
 		return array($charset, $string, 'base64');
1344
+	} else {
1345
+			return array($charset, $string, '7bit');
1346
+	}
1282 1347
 	}
1283
-
1284
-	else
1285
-		return array($charset, $string, '7bit');
1286
-}
1287 1348
 
1288 1349
 /**
1289 1350
  * Sends mail, like mail() but over SMTP.
@@ -1307,8 +1368,9 @@  discard block
 block discarded – undo
1307 1368
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1308 1369
 	{
1309 1370
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1310
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1311
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1371
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1372
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		}
1312 1374
 
1313 1375
 		if ($socket)
1314 1376
 		{
@@ -1329,8 +1391,9 @@  discard block
 block discarded – undo
1329 1391
 		// Maybe we can still save this?  The port might be wrong.
1330 1392
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1331 1393
 		{
1332
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1333
-				log_error($txt['smtp_port_ssl']);
1394
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1395
+							log_error($txt['smtp_port_ssl']);
1396
+			}
1334 1397
 		}
1335 1398
 
1336 1399
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1342,20 +1405,23 @@  discard block
 block discarded – undo
1342 1405
 	}
1343 1406
 
1344 1407
 	// Wait for a response of 220, without "-" continuer.
1345
-	if (!server_parse(null, $socket, '220'))
1346
-		return false;
1408
+	if (!server_parse(null, $socket, '220')) {
1409
+			return false;
1410
+	}
1347 1411
 
1348 1412
 	// Try and determine the servers name, fall back to the mail servers if not found
1349 1413
 	$helo = false;
1350
-	if (function_exists('gethostname') && gethostname() !== false)
1351
-		$helo = gethostname();
1352
-	elseif (function_exists('php_uname'))
1353
-		$helo = php_uname('n');
1354
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1355
-		$helo = $_SERVER['SERVER_NAME'];
1414
+	if (function_exists('gethostname') && gethostname() !== false) {
1415
+			$helo = gethostname();
1416
+	} elseif (function_exists('php_uname')) {
1417
+			$helo = php_uname('n');
1418
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1419
+			$helo = $_SERVER['SERVER_NAME'];
1420
+	}
1356 1421
 
1357
-	if (empty($helo))
1358
-		$helo = $modSettings['smtp_host'];
1422
+	if (empty($helo)) {
1423
+			$helo = $modSettings['smtp_host'];
1424
+	}
1359 1425
 
1360 1426
 	// SMTP = 1, SMTP - STARTTLS = 2
1361 1427
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1367,33 +1433,39 @@  discard block
 block discarded – undo
1367 1433
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1368 1434
 			{
1369 1435
 				// Send STARTTLS to enable encryption
1370
-				if (!server_parse('STARTTLS', $socket, '220'))
1371
-					return false;
1436
+				if (!server_parse('STARTTLS', $socket, '220')) {
1437
+									return false;
1438
+				}
1372 1439
 				// Enable the encryption
1373
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1374
-					return false;
1440
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1441
+									return false;
1442
+				}
1375 1443
 				// Send the EHLO command again
1376
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1377
-					return false;
1444
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1445
+									return false;
1446
+				}
1378 1447
 			}
1379 1448
 
1380
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1381
-				return false;
1449
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1450
+							return false;
1451
+			}
1382 1452
 			// Send the username and password, encoded.
1383
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1384
-				return false;
1453
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1454
+							return false;
1455
+			}
1385 1456
 			// The password is already encoded ;)
1386
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1387
-				return false;
1457
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1458
+							return false;
1459
+			}
1460
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1461
+					return false;
1388 1462
 		}
1389
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1390
-			return false;
1391
-	}
1392
-	else
1463
+	} else
1393 1464
 	{
1394 1465
 		// Just say "helo".
1395
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1396
-			return false;
1466
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1467
+					return false;
1468
+		}
1397 1469
 	}
1398 1470
 
1399 1471
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1406,31 +1478,38 @@  discard block
 block discarded – undo
1406 1478
 		// Reset the connection to send another email.
1407 1479
 		if ($i != 0)
1408 1480
 		{
1409
-			if (!server_parse('RSET', $socket, '250'))
1410
-				return false;
1481
+			if (!server_parse('RSET', $socket, '250')) {
1482
+							return false;
1483
+			}
1411 1484
 		}
1412 1485
 
1413 1486
 		// From, to, and then start the data...
1414
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1415
-			return false;
1416
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1417
-			return false;
1418
-		if (!server_parse('DATA', $socket, '354'))
1419
-			return false;
1487
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1488
+					return false;
1489
+		}
1490
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('DATA', $socket, '354')) {
1494
+					return false;
1495
+		}
1420 1496
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1421
-		if (strlen($mail_to) > 0)
1422
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1497
+		if (strlen($mail_to) > 0) {
1498
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		}
1423 1500
 		fputs($socket, $headers . "\r\n\r\n");
1424 1501
 		fputs($socket, $message . "\r\n");
1425 1502
 
1426 1503
 		// Send a ., or in other words "end of data".
1427
-		if (!server_parse('.', $socket, '250'))
1428
-			return false;
1504
+		if (!server_parse('.', $socket, '250')) {
1505
+					return false;
1506
+		}
1429 1507
 
1430 1508
 		// Almost done, almost done... don't stop me just yet!
1431 1509
 		@set_time_limit(300);
1432
-		if (function_exists('apache_reset_timeout'))
1433
-			@apache_reset_timeout();
1510
+		if (function_exists('apache_reset_timeout')) {
1511
+					@apache_reset_timeout();
1512
+		}
1434 1513
 	}
1435 1514
 	fputs($socket, 'QUIT' . "\r\n");
1436 1515
 	fclose($socket);
@@ -1454,8 +1533,9 @@  discard block
 block discarded – undo
1454 1533
 {
1455 1534
 	global $txt;
1456 1535
 
1457
-	if ($message !== null)
1458
-		fputs($socket, $message . "\r\n");
1536
+	if ($message !== null) {
1537
+			fputs($socket, $message . "\r\n");
1538
+	}
1459 1539
 
1460 1540
 	// No response yet.
1461 1541
 	$server_response = '';
@@ -1471,8 +1551,9 @@  discard block
 block discarded – undo
1471 1551
 		$response .= $server_response;
1472 1552
 	}
1473 1553
 
1474
-	if ($code === null)
1475
-		return substr($server_response, 0, 3);
1554
+	if ($code === null) {
1555
+			return substr($server_response, 0, 3);
1556
+	}
1476 1557
 
1477 1558
 	if (substr($server_response, 0, 3) != $code)
1478 1559
 	{
@@ -1502,8 +1583,9 @@  discard block
 block discarded – undo
1502 1583
 	// Create a pspell or enchant dictionary resource
1503 1584
 	$dict = spell_init();
1504 1585
 
1505
-	if (!isset($_POST['spellstring']) || !$dict)
1506
-		die;
1586
+	if (!isset($_POST['spellstring']) || !$dict) {
1587
+			die;
1588
+	}
1507 1589
 
1508 1590
 	// Construct a bit of Javascript code.
1509 1591
 	$context['spell_js'] = '
@@ -1521,8 +1603,9 @@  discard block
 block discarded – undo
1521 1603
 		$check_word = explode('|', $alphas[$i]);
1522 1604
 
1523 1605
 		// If the word is a known word, or spelled right...
1524
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1525
-			continue;
1606
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1607
+					continue;
1608
+		}
1526 1609
 
1527 1610
 		// Find the word, and move up the "last occurrence" to here.
1528 1611
 		$found_words = true;
@@ -1536,20 +1619,23 @@  discard block
 block discarded – undo
1536 1619
 		if (!empty($suggestions))
1537 1620
 		{
1538 1621
 			// But first check they aren't going to be censored - no naughty words!
1539
-			foreach ($suggestions as $k => $word)
1540
-				if ($suggestions[$k] != censorText($word))
1622
+			foreach ($suggestions as $k => $word) {
1623
+							if ($suggestions[$k] != censorText($word))
1541 1624
 					unset($suggestions[$k]);
1625
+			}
1542 1626
 
1543
-			if (!empty($suggestions))
1544
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1627
+			if (!empty($suggestions)) {
1628
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			}
1545 1630
 		}
1546 1631
 
1547 1632
 		$context['spell_js'] .= ']),';
1548 1633
 	}
1549 1634
 
1550 1635
 	// If words were found, take off the last comma.
1551
-	if ($found_words)
1552
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1636
+	if ($found_words) {
1637
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	}
1553 1639
 
1554 1640
 	$context['spell_js'] .= '
1555 1641
 		);';
@@ -1584,11 +1670,13 @@  discard block
 block discarded – undo
1584 1670
 	global $user_info, $smcFunc;
1585 1671
 
1586 1672
 	// Can't do it if there's no topics.
1587
-	if (empty($topics))
1588
-		return;
1673
+	if (empty($topics)) {
1674
+			return;
1675
+	}
1589 1676
 	// It must be an array - it must!
1590
-	if (!is_array($topics))
1591
-		$topics = array($topics);
1677
+	if (!is_array($topics)) {
1678
+			$topics = array($topics);
1679
+	}
1592 1680
 
1593 1681
 	// Get the subject and body...
1594 1682
 	$result = $smcFunc['db_query']('', '
@@ -1636,14 +1724,15 @@  discard block
 block discarded – undo
1636 1724
 	}
1637 1725
 	$smcFunc['db_free_result']($result);
1638 1726
 
1639
-	if (!empty($task_rows))
1640
-		$smcFunc['db_insert']('',
1727
+	if (!empty($task_rows)) {
1728
+			$smcFunc['db_insert']('',
1641 1729
 			'{db_prefix}background_tasks',
1642 1730
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1643 1731
 			$task_rows,
1644 1732
 			array('id_task')
1645 1733
 		);
1646
-}
1734
+	}
1735
+	}
1647 1736
 
1648 1737
 /**
1649 1738
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1681,9 +1770,9 @@  discard block
 block discarded – undo
1681 1770
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1682 1771
 
1683 1772
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1684
-	if (!$modSettings['postmod_active'])
1685
-		$topicOptions['is_approved'] = true;
1686
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1773
+	if (!$modSettings['postmod_active']) {
1774
+			$topicOptions['is_approved'] = true;
1775
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1687 1776
 	{
1688 1777
 		$request = $smcFunc['db_query']('', '
1689 1778
 			SELECT approved
@@ -1706,8 +1795,7 @@  discard block
 block discarded – undo
1706 1795
 			$posterOptions['id'] = 0;
1707 1796
 			$posterOptions['name'] = $txt['guest_title'];
1708 1797
 			$posterOptions['email'] = '';
1709
-		}
1710
-		elseif ($posterOptions['id'] != $user_info['id'])
1798
+		} elseif ($posterOptions['id'] != $user_info['id'])
1711 1799
 		{
1712 1800
 			$request = $smcFunc['db_query']('', '
1713 1801
 				SELECT member_name, email_address
@@ -1725,12 +1813,11 @@  discard block
 block discarded – undo
1725 1813
 				$posterOptions['id'] = 0;
1726 1814
 				$posterOptions['name'] = $txt['guest_title'];
1727 1815
 				$posterOptions['email'] = '';
1816
+			} else {
1817
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1728 1818
 			}
1729
-			else
1730
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1731 1819
 			$smcFunc['db_free_result']($request);
1732
-		}
1733
-		else
1820
+		} else
1734 1821
 		{
1735 1822
 			$posterOptions['name'] = $user_info['name'];
1736 1823
 			$posterOptions['email'] = $user_info['email'];
@@ -1740,8 +1827,9 @@  discard block
 block discarded – undo
1740 1827
 	if (!empty($modSettings['enable_mentions']))
1741 1828
 	{
1742 1829
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1743
-		if (!empty($msgOptions['mentioned_members']))
1744
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1830
+		if (!empty($msgOptions['mentioned_members'])) {
1831
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		}
1745 1833
 	}
1746 1834
 
1747 1835
 	// It's do or die time: forget any user aborts!
@@ -1774,12 +1862,13 @@  discard block
 block discarded – undo
1774 1862
 	);
1775 1863
 
1776 1864
 	// Something went wrong creating the message...
1777
-	if (empty($msgOptions['id']))
1778
-		return false;
1865
+	if (empty($msgOptions['id'])) {
1866
+			return false;
1867
+	}
1779 1868
 
1780 1869
 	// Fix the attachments.
1781
-	if (!empty($msgOptions['attachments']))
1782
-		$smcFunc['db_query']('', '
1870
+	if (!empty($msgOptions['attachments'])) {
1871
+			$smcFunc['db_query']('', '
1783 1872
 			UPDATE {db_prefix}attachments
1784 1873
 			SET id_msg = {int:id_msg}
1785 1874
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1788,6 +1877,7 @@  discard block
 block discarded – undo
1788 1877
 				'id_msg' => $msgOptions['id'],
1789 1878
 			)
1790 1879
 		);
1880
+	}
1791 1881
 
1792 1882
 	// What if we want to export new posts out to a CMS?
1793 1883
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1864,20 +1954,23 @@  discard block
 block discarded – undo
1864 1954
 			'id_topic' => $topicOptions['id'],
1865 1955
 			'counter_increment' => 1,
1866 1956
 		);
1867
-		if ($msgOptions['approved'])
1868
-			$topics_columns = array(
1957
+		if ($msgOptions['approved']) {
1958
+					$topics_columns = array(
1869 1959
 				'id_member_updated = {int:poster_id}',
1870 1960
 				'id_last_msg = {int:id_msg}',
1871 1961
 				'num_replies = num_replies + {int:counter_increment}',
1872 1962
 			);
1873
-		else
1874
-			$topics_columns = array(
1963
+		} else {
1964
+					$topics_columns = array(
1875 1965
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1876 1966
 			);
1877
-		if ($topicOptions['lock_mode'] !== null)
1878
-			$topics_columns[] = 'locked = {int:locked}';
1879
-		if ($topicOptions['sticky_mode'] !== null)
1880
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1967
+		}
1968
+		if ($topicOptions['lock_mode'] !== null) {
1969
+					$topics_columns[] = 'locked = {int:locked}';
1970
+		}
1971
+		if ($topicOptions['sticky_mode'] !== null) {
1972
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1973
+		}
1881 1974
 
1882 1975
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1883 1976
 
@@ -1906,8 +1999,8 @@  discard block
 block discarded – undo
1906 1999
 	);
1907 2000
 
1908 2001
 	// Increase the number of posts and topics on the board.
1909
-	if ($msgOptions['approved'])
1910
-		$smcFunc['db_query']('', '
2002
+	if ($msgOptions['approved']) {
2003
+			$smcFunc['db_query']('', '
1911 2004
 			UPDATE {db_prefix}boards
1912 2005
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1913 2006
 			WHERE id_board = {int:id_board}',
@@ -1915,7 +2008,7 @@  discard block
 block discarded – undo
1915 2008
 				'id_board' => $topicOptions['board'],
1916 2009
 			)
1917 2010
 		);
1918
-	else
2011
+	} else
1919 2012
 	{
1920 2013
 		$smcFunc['db_query']('', '
1921 2014
 			UPDATE {db_prefix}boards
@@ -1985,8 +2078,8 @@  discard block
 block discarded – undo
1985 2078
 		}
1986 2079
 	}
1987 2080
 
1988
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1989
-		$smcFunc['db_insert']('',
2081
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2082
+			$smcFunc['db_insert']('',
1990 2083
 			'{db_prefix}background_tasks',
1991 2084
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1992 2085
 			array(
@@ -1998,19 +2091,22 @@  discard block
 block discarded – undo
1998 2091
 			),
1999 2092
 			array('id_task')
2000 2093
 		);
2094
+	}
2001 2095
 
2002 2096
 	// If there's a custom search index, it may need updating...
2003 2097
 	require_once($sourcedir . '/Search.php');
2004 2098
 	$searchAPI = findSearchAPI();
2005
-	if (is_callable(array($searchAPI, 'postCreated')))
2006
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2099
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2100
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	}
2007 2102
 
2008 2103
 	// Increase the post counter for the user that created the post.
2009 2104
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2010 2105
 	{
2011 2106
 		// Are you the one that happened to create this post?
2012
-		if ($user_info['id'] == $posterOptions['id'])
2013
-			$user_info['posts']++;
2107
+		if ($user_info['id'] == $posterOptions['id']) {
2108
+					$user_info['posts']++;
2109
+		}
2014 2110
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2015 2111
 	}
2016 2112
 
@@ -2018,19 +2114,21 @@  discard block
 block discarded – undo
2018 2114
 	$_SESSION['last_read_topic'] = 0;
2019 2115
 
2020 2116
 	// Better safe than sorry.
2021
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2022
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2117
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2118
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	}
2023 2120
 
2024 2121
 	// Update all the stats so everyone knows about this new topic and message.
2025 2122
 	updateStats('message', true, $msgOptions['id']);
2026 2123
 
2027 2124
 	// Update the last message on the board assuming it's approved AND the topic is.
2028
-	if ($msgOptions['approved'])
2029
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2125
+	if ($msgOptions['approved']) {
2126
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	}
2030 2128
 
2031 2129
 	// Queue createPost background notification
2032
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2033
-		$smcFunc['db_insert']('',
2130
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2131
+			$smcFunc['db_insert']('',
2034 2132
 			'{db_prefix}background_tasks',
2035 2133
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2036 2134
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
@@ -2041,6 +2139,7 @@  discard block
 block discarded – undo
2041 2139
 			)), 0),
2042 2140
 			array('id_task')
2043 2141
 		);
2142
+	}
2044 2143
 
2045 2144
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2046 2145
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2067,14 +2166,18 @@  discard block
 block discarded – undo
2067 2166
 
2068 2167
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2069 2168
 	$messages_columns = array();
2070
-	if (isset($posterOptions['name']))
2071
-		$messages_columns['poster_name'] = $posterOptions['name'];
2072
-	if (isset($posterOptions['email']))
2073
-		$messages_columns['poster_email'] = $posterOptions['email'];
2074
-	if (isset($msgOptions['icon']))
2075
-		$messages_columns['icon'] = $msgOptions['icon'];
2076
-	if (isset($msgOptions['subject']))
2077
-		$messages_columns['subject'] = $msgOptions['subject'];
2169
+	if (isset($posterOptions['name'])) {
2170
+			$messages_columns['poster_name'] = $posterOptions['name'];
2171
+	}
2172
+	if (isset($posterOptions['email'])) {
2173
+			$messages_columns['poster_email'] = $posterOptions['email'];
2174
+	}
2175
+	if (isset($msgOptions['icon'])) {
2176
+			$messages_columns['icon'] = $msgOptions['icon'];
2177
+	}
2178
+	if (isset($msgOptions['subject'])) {
2179
+			$messages_columns['subject'] = $msgOptions['subject'];
2180
+	}
2078 2181
 	if (isset($msgOptions['body']))
2079 2182
 	{
2080 2183
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2101,8 +2204,9 @@  discard block
 block discarded – undo
2101 2204
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2102 2205
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2103 2206
 	}
2104
-	if (isset($msgOptions['smileys_enabled']))
2105
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2207
+	if (isset($msgOptions['smileys_enabled'])) {
2208
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	}
2106 2210
 
2107 2211
 	// Which columns need to be ints?
2108 2212
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2120,23 +2224,27 @@  discard block
 block discarded – undo
2120 2224
 		{
2121 2225
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2122 2226
 
2123
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2124
-				foreach ($match[1] as $i => $oldID)
2227
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2228
+							foreach ($match[1] as $i => $oldID)
2125 2229
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2230
+			}
2126 2231
 
2127
-			if (empty($modSettings['search_custom_index_config']))
2128
-				unset($msgOptions['old_body']);
2232
+			if (empty($modSettings['search_custom_index_config'])) {
2233
+							unset($msgOptions['old_body']);
2234
+			}
2129 2235
 		}
2130 2236
 
2131 2237
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2132 2238
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2133 2239
 
2134 2240
 		// Remove the poster.
2135
-		if (isset($mentions[$user_info['id']]))
2136
-			unset($mentions[$user_info['id']]);
2241
+		if (isset($mentions[$user_info['id']])) {
2242
+					unset($mentions[$user_info['id']]);
2243
+		}
2137 2244
 
2138
-		if (isset($oldmentions[$user_info['id']]))
2139
-			unset($oldmentions[$user_info['id']]);
2245
+		if (isset($oldmentions[$user_info['id']])) {
2246
+					unset($oldmentions[$user_info['id']]);
2247
+		}
2140 2248
 
2141 2249
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2142 2250
 		{
@@ -2166,8 +2274,9 @@  discard block
 block discarded – undo
2166 2274
 	}
2167 2275
 
2168 2276
 	// Nothing to do?
2169
-	if (empty($messages_columns))
2170
-		return true;
2277
+	if (empty($messages_columns)) {
2278
+			return true;
2279
+	}
2171 2280
 
2172 2281
 	// Change the post.
2173 2282
 	$smcFunc['db_query']('', '
@@ -2228,8 +2337,9 @@  discard block
 block discarded – undo
2228 2337
 	// If there's a custom search index, it needs to be modified...
2229 2338
 	require_once($sourcedir . '/Search.php');
2230 2339
 	$searchAPI = findSearchAPI();
2231
-	if (is_callable(array($searchAPI, 'postModified')))
2232
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2340
+	if (is_callable(array($searchAPI, 'postModified'))) {
2341
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	}
2233 2343
 
2234 2344
 	if (isset($msgOptions['subject']))
2235 2345
 	{
@@ -2243,14 +2353,16 @@  discard block
 block discarded – undo
2243 2353
 				'id_first_msg' => $msgOptions['id'],
2244 2354
 			)
2245 2355
 		);
2246
-		if ($smcFunc['db_num_rows']($request) == 1)
2247
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2356
+		if ($smcFunc['db_num_rows']($request) == 1) {
2357
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		}
2248 2359
 		$smcFunc['db_free_result']($request);
2249 2360
 	}
2250 2361
 
2251 2362
 	// Finally, if we are setting the approved state we need to do much more work :(
2252
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2253
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2363
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2364
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	}
2254 2366
 
2255 2367
 	return true;
2256 2368
 }
@@ -2267,11 +2379,13 @@  discard block
 block discarded – undo
2267 2379
 {
2268 2380
 	global $smcFunc;
2269 2381
 
2270
-	if (!is_array($msgs))
2271
-		$msgs = array($msgs);
2382
+	if (!is_array($msgs)) {
2383
+			$msgs = array($msgs);
2384
+	}
2272 2385
 
2273
-	if (empty($msgs))
2274
-		return false;
2386
+	if (empty($msgs)) {
2387
+			return false;
2388
+	}
2275 2389
 
2276 2390
 	// May as well start at the beginning, working out *what* we need to change.
2277 2391
 	$request = $smcFunc['db_query']('', '
@@ -2303,20 +2417,22 @@  discard block
 block discarded – undo
2303 2417
 		$topics[] = $row['id_topic'];
2304 2418
 
2305 2419
 		// Ensure our change array exists already.
2306
-		if (!isset($topic_changes[$row['id_topic']]))
2307
-			$topic_changes[$row['id_topic']] = array(
2420
+		if (!isset($topic_changes[$row['id_topic']])) {
2421
+					$topic_changes[$row['id_topic']] = array(
2308 2422
 				'id_last_msg' => $row['id_last_msg'],
2309 2423
 				'approved' => $row['topic_approved'],
2310 2424
 				'replies' => 0,
2311 2425
 				'unapproved_posts' => 0,
2312 2426
 			);
2313
-		if (!isset($board_changes[$row['id_board']]))
2314
-			$board_changes[$row['id_board']] = array(
2427
+		}
2428
+		if (!isset($board_changes[$row['id_board']])) {
2429
+					$board_changes[$row['id_board']] = array(
2315 2430
 				'posts' => 0,
2316 2431
 				'topics' => 0,
2317 2432
 				'unapproved_posts' => 0,
2318 2433
 				'unapproved_topics' => 0,
2319 2434
 			);
2435
+		}
2320 2436
 
2321 2437
 		// If it's the first message then the topic state changes!
2322 2438
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2337,14 +2453,13 @@  discard block
 block discarded – undo
2337 2453
 				'poster' => $row['id_member'],
2338 2454
 				'new_topic' => true,
2339 2455
 			);
2340
-		}
2341
-		else
2456
+		} else
2342 2457
 		{
2343 2458
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2344 2459
 
2345 2460
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2346
-			if ($row['id_msg'] > $row['id_last_msg'])
2347
-				$notification_posts[$row['id_topic']] = array(
2461
+			if ($row['id_msg'] > $row['id_last_msg']) {
2462
+							$notification_posts[$row['id_topic']] = array(
2348 2463
 					'id' => $row['id_msg'],
2349 2464
 					'body' => $row['body'],
2350 2465
 					'subject' => $row['subject'],
@@ -2355,28 +2470,33 @@  discard block
 block discarded – undo
2355 2470
 					'new_topic' => false,
2356 2471
 					'msg' => $row['id_msg'],
2357 2472
 				);
2473
+			}
2358 2474
 		}
2359 2475
 
2360 2476
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2361
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2362
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2477
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2478
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		}
2363 2480
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2364
-		elseif (!$approve)
2365
-			// Default to the first message and then we'll override in a bit ;)
2481
+		elseif (!$approve) {
2482
+					// Default to the first message and then we'll override in a bit ;)
2366 2483
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2484
+		}
2367 2485
 
2368 2486
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2369 2487
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2488
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2371 2489
 
2372 2490
 		// Post count for the user?
2373
-		if ($row['id_member'] && empty($row['count_posts']))
2374
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2491
+		if ($row['id_member'] && empty($row['count_posts'])) {
2492
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		}
2375 2494
 	}
2376 2495
 	$smcFunc['db_free_result']($request);
2377 2496
 
2378
-	if (empty($msgs))
2379
-		return;
2497
+	if (empty($msgs)) {
2498
+			return;
2499
+	}
2380 2500
 
2381 2501
 	// Now we have the differences make the changes, first the easy one.
2382 2502
 	$smcFunc['db_query']('', '
@@ -2403,14 +2523,15 @@  discard block
 block discarded – undo
2403 2523
 				'approved' => 1,
2404 2524
 			)
2405 2525
 		);
2406
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2407
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2526
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2527
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		}
2408 2529
 		$smcFunc['db_free_result']($request);
2409 2530
 	}
2410 2531
 
2411 2532
 	// ... next the topics...
2412
-	foreach ($topic_changes as $id => $changes)
2413
-		$smcFunc['db_query']('', '
2533
+	foreach ($topic_changes as $id => $changes) {
2534
+			$smcFunc['db_query']('', '
2414 2535
 			UPDATE {db_prefix}topics
2415 2536
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2416 2537
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2423,10 +2544,11 @@  discard block
 block discarded – undo
2423 2544
 				'id_topic' => $id,
2424 2545
 			)
2425 2546
 		);
2547
+	}
2426 2548
 
2427 2549
 	// ... finally the boards...
2428
-	foreach ($board_changes as $id => $changes)
2429
-		$smcFunc['db_query']('', '
2550
+	foreach ($board_changes as $id => $changes) {
2551
+			$smcFunc['db_query']('', '
2430 2552
 			UPDATE {db_prefix}boards
2431 2553
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2432 2554
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2439,13 +2561,14 @@  discard block
 block discarded – undo
2439 2561
 				'id_board' => $id,
2440 2562
 			)
2441 2563
 		);
2564
+	}
2442 2565
 
2443 2566
 	// Finally, least importantly, notifications!
2444 2567
 	if ($approve)
2445 2568
 	{
2446 2569
 		$task_rows = array();
2447
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2448
-			$task_rows[] = array(
2570
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2571
+					$task_rows[] = array(
2449 2572
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
2450 2573
 					'msgOptions' => array(
2451 2574
 						'id' => $topic['msg'],
@@ -2463,14 +2586,16 @@  discard block
 block discarded – undo
2463 2586
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2464 2587
 				)), 0
2465 2588
 			);
2589
+		}
2466 2590
 
2467
-		if ($notify)
2468
-			$smcFunc['db_insert']('',
2591
+		if ($notify) {
2592
+					$smcFunc['db_insert']('',
2469 2593
 				'{db_prefix}background_tasks',
2470 2594
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2471 2595
 				$task_rows,
2472 2596
 				array('id_task')
2473 2597
 			);
2598
+		}
2474 2599
 
2475 2600
 		$smcFunc['db_query']('', '
2476 2601
 			DELETE FROM {db_prefix}approval_queue
@@ -2486,8 +2611,9 @@  discard block
 block discarded – undo
2486 2611
 	else
2487 2612
 	{
2488 2613
 		$msgInserts = array();
2489
-		foreach ($msgs as $msg)
2490
-			$msgInserts[] = array($msg);
2614
+		foreach ($msgs as $msg) {
2615
+					$msgInserts[] = array($msg);
2616
+		}
2491 2617
 
2492 2618
 		$smcFunc['db_insert']('ignore',
2493 2619
 			'{db_prefix}approval_queue',
@@ -2501,9 +2627,10 @@  discard block
 block discarded – undo
2501 2627
 	updateLastMessages(array_keys($board_changes));
2502 2628
 
2503 2629
 	// Post count for the members?
2504
-	if (!empty($member_post_changes))
2505
-		foreach ($member_post_changes as $id_member => $count_change)
2630
+	if (!empty($member_post_changes)) {
2631
+			foreach ($member_post_changes as $id_member => $count_change)
2506 2632
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2633
+	}
2507 2634
 
2508 2635
 	return true;
2509 2636
 }
@@ -2520,11 +2647,13 @@  discard block
 block discarded – undo
2520 2647
 {
2521 2648
 	global $smcFunc;
2522 2649
 
2523
-	if (!is_array($topics))
2524
-		$topics = array($topics);
2650
+	if (!is_array($topics)) {
2651
+			$topics = array($topics);
2652
+	}
2525 2653
 
2526
-	if (empty($topics))
2527
-		return false;
2654
+	if (empty($topics)) {
2655
+			return false;
2656
+	}
2528 2657
 
2529 2658
 	$approve_type = $approve ? 0 : 1;
2530 2659
 
@@ -2540,8 +2669,9 @@  discard block
 block discarded – undo
2540 2669
 		)
2541 2670
 	);
2542 2671
 	$msgs = array();
2543
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2544
-		$msgs[] = $row['id_msg'];
2672
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2673
+			$msgs[] = $row['id_msg'];
2674
+	}
2545 2675
 	$smcFunc['db_free_result']($request);
2546 2676
 
2547 2677
 	return approvePosts($msgs, $approve);
@@ -2564,11 +2694,13 @@  discard block
 block discarded – undo
2564 2694
 	global $board_info, $board, $smcFunc;
2565 2695
 
2566 2696
 	// Please - let's be sane.
2567
-	if (empty($setboards))
2568
-		return false;
2697
+	if (empty($setboards)) {
2698
+			return false;
2699
+	}
2569 2700
 
2570
-	if (!is_array($setboards))
2571
-		$setboards = array($setboards);
2701
+	if (!is_array($setboards)) {
2702
+			$setboards = array($setboards);
2703
+	}
2572 2704
 
2573 2705
 	// If we don't know the id_msg we need to find it.
2574 2706
 	if (!$id_msg)
@@ -2586,15 +2718,16 @@  discard block
 block discarded – undo
2586 2718
 			)
2587 2719
 		);
2588 2720
 		$lastMsg = array();
2589
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2590
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2721
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2722
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		}
2591 2724
 		$smcFunc['db_free_result']($request);
2592
-	}
2593
-	else
2725
+	} else
2594 2726
 	{
2595 2727
 		// Just to note - there should only be one board passed if we are doing this.
2596
-		foreach ($setboards as $id_board)
2597
-			$lastMsg[$id_board] = $id_msg;
2728
+		foreach ($setboards as $id_board) {
2729
+					$lastMsg[$id_board] = $id_msg;
2730
+		}
2598 2731
 	}
2599 2732
 
2600 2733
 	$parent_boards = array();
@@ -2609,10 +2742,11 @@  discard block
 block discarded – undo
2609 2742
 			$lastModified[$id_board] = 0;
2610 2743
 		}
2611 2744
 
2612
-		if (!empty($board) && $id_board == $board)
2613
-			$parents = $board_info['parent_boards'];
2614
-		else
2615
-			$parents = getBoardParents($id_board);
2745
+		if (!empty($board) && $id_board == $board) {
2746
+					$parents = $board_info['parent_boards'];
2747
+		} else {
2748
+					$parents = getBoardParents($id_board);
2749
+		}
2616 2750
 
2617 2751
 		// Ignore any parents on the top child level.
2618 2752
 		// @todo Why?
@@ -2621,10 +2755,11 @@  discard block
 block discarded – undo
2621 2755
 			if ($parent['level'] != 0)
2622 2756
 			{
2623 2757
 				// If we're already doing this one as a board, is this a higher last modified?
2624
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2625
-					$lastModified[$id] = $lastModified[$id_board];
2626
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2627
-					$parent_boards[$id] = $lastModified[$id_board];
2758
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2759
+									$lastModified[$id] = $lastModified[$id_board];
2760
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2761
+									$parent_boards[$id] = $lastModified[$id_board];
2762
+				}
2628 2763
 			}
2629 2764
 		}
2630 2765
 	}
@@ -2637,23 +2772,24 @@  discard block
 block discarded – undo
2637 2772
 	// Finally, to save on queries make the changes...
2638 2773
 	foreach ($parent_boards as $id => $msg)
2639 2774
 	{
2640
-		if (!isset($parent_updates[$msg]))
2641
-			$parent_updates[$msg] = array($id);
2642
-		else
2643
-			$parent_updates[$msg][] = $id;
2775
+		if (!isset($parent_updates[$msg])) {
2776
+					$parent_updates[$msg] = array($id);
2777
+		} else {
2778
+					$parent_updates[$msg][] = $id;
2779
+		}
2644 2780
 	}
2645 2781
 
2646 2782
 	foreach ($lastMsg as $id => $msg)
2647 2783
 	{
2648
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2649
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2784
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2785
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2650 2786
 				'id' => $msg,
2651 2787
 				'updated' => $lastModified[$id],
2652 2788
 				'boards' => array($id)
2653 2789
 			);
2654
-
2655
-		else
2656
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2790
+		} else {
2791
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		}
2657 2793
 	}
2658 2794
 
2659 2795
 	// Now commit the changes!
@@ -2745,11 +2881,13 @@  discard block
 block discarded – undo
2745 2881
 	global $txt, $mbname, $scripturl, $settings;
2746 2882
 
2747 2883
 	// First things first, load up the email templates language file, if we need to.
2748
-	if ($loadLang)
2749
-		loadLanguage('EmailTemplates', $lang);
2884
+	if ($loadLang) {
2885
+			loadLanguage('EmailTemplates', $lang);
2886
+	}
2750 2887
 
2751
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2752
-		fatal_lang_error('email_no_template', 'template', array($template));
2888
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2889
+			fatal_lang_error('email_no_template', 'template', array($template));
2890
+	}
2753 2891
 
2754 2892
 	$ret = array(
2755 2893
 		'subject' => $txt[$template . '_subject'],
@@ -2799,17 +2937,18 @@  discard block
 block discarded – undo
2799 2937
 function user_info_callback($matches)
2800 2938
 {
2801 2939
 	global $user_info;
2802
-	if (empty($matches[1]))
2803
-		return '';
2940
+	if (empty($matches[1])) {
2941
+			return '';
2942
+	}
2804 2943
 
2805 2944
 	$use_ref = true;
2806 2945
 	$ref = &$user_info;
2807 2946
 
2808 2947
 	foreach (explode('.', $matches[1]) as $index)
2809 2948
 	{
2810
-		if ($use_ref && isset($ref[$index]))
2811
-			$ref = &$ref[$index];
2812
-		else
2949
+		if ($use_ref && isset($ref[$index])) {
2950
+					$ref = &$ref[$index];
2951
+		} else
2813 2952
 		{
2814 2953
 			$use_ref = false;
2815 2954
 			break;
@@ -2846,8 +2985,7 @@  discard block
 block discarded – undo
2846 2985
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2847 2986
 		{
2848 2987
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2849
-		}
2850
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2988
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2851 2989
 		{
2852 2990
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2853 2991
 		}
@@ -2857,8 +2995,7 @@  discard block
 block discarded – undo
2857 2995
 		{
2858 2996
 			$context['provider'] = 'enchant';
2859 2997
 			return $enchant_link;
2860
-		}
2861
-		else
2998
+		} else
2862 2999
 		{
2863 3000
 			// Free up any resources used...
2864 3001
 			@enchant_broker_free($context['enchant_broker']);
@@ -2879,8 +3016,9 @@  discard block
 block discarded – undo
2879 3016
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2880 3017
 
2881 3018
 		// Most people don't have anything but English installed... So we use English as a last resort.
2882
-		if (!$pspell_link)
2883
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3019
+		if (!$pspell_link) {
3020
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		}
2884 3022
 
2885 3023
 		error_reporting($old);
2886 3024
 		ob_end_clean();
@@ -2920,8 +3058,7 @@  discard block
 block discarded – undo
2920 3058
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2921 3059
 		}
2922 3060
 		return enchant_dict_check($dict, $word);
2923
-	}
2924
-	elseif ($context['provider'] == 'pspell')
3061
+	} elseif ($context['provider'] == 'pspell')
2925 3062
 	{
2926 3063
 		return pspell_check($dict, $word);
2927 3064
 	}
@@ -2957,13 +3094,11 @@  discard block
 block discarded – undo
2957 3094
 			}
2958 3095
 
2959 3096
 			return $suggestions;
2960
-		}
2961
-		else
3097
+		} else
2962 3098
 		{
2963 3099
 			return enchant_dict_suggest($dict, $word);
2964 3100
 		}
2965
-	}
2966
-	elseif ($context['provider'] == 'pspell')
3101
+	} elseif ($context['provider'] == 'pspell')
2967 3102
 	{
2968 3103
 		return pspell_suggest($dict, $word);
2969 3104
 	}
Please login to merge, or discard this patch.
Sources/Subs-ReportedContent.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
  *
567 567
  * @param int $report_id The report ID is used to fire a notification about the event.
568 568
  * @param array $data a formatted array of data to be inserted. Should be already properly sanitized.
569
- * @return bool  Boolean false if no data was provided.
569
+ * @return false|null  Boolean false if no data was provided.
570 570
  */
571 571
 function saveModComment($report_id, $data)
572 572
 {
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
  * Saves the new information whenever a moderator comment is edited.
633 633
  *
634 634
  * @param int $comment_id The edited moderator comment ID.
635
- * @param array $data The new data to de inserted. Should be already properly sanitized.
636
- * @return bool  Boolean false if no data or no comment ID was provided.
635
+ * @param string $edited_comment
636
+ * @return false|null  Boolean false if no data or no comment ID was provided.
637 637
  */
638 638
 function editModComment($comment_id, $edited_comment)
639 639
 {
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
  * Deletes a moderator comment from the DB.
658 658
  *
659 659
  * @param int $comment_id The moderator comment ID used to identify which report will be deleted.
660
- * @return bool  Boolean false if no data was provided.
660
+ * @return false|null  Boolean false if no data was provided.
661 661
  */
662 662
 function deleteModComment($comment_id)
663 663
 {
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -130,7 +130,6 @@
 block discarded – undo
130 130
  *
131 131
  * @param int $closed 1 for counting closed reports, 0 for open ones.
132 132
  * @return integer How many reports.
133
-
134 133
  */
135 134
 function countReports($closed = 0)
136 135
 {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	$smcFunc['db_query']('', '
50 50
 		UPDATE {db_prefix}log_reported
51 51
 		SET  {raw:action} = {string:value}
52
-		'. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') .'
52
+		'. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . '
53 53
 			' . $board_query,
54 54
 		array(
55 55
 			'action' => $action,
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			)
98 98
 		);
99 99
 
100
-		while($row = $smcFunc['db_fetch_assoc']($request))
100
+		while ($row = $smcFunc['db_fetch_assoc']($request))
101 101
 			$extra[$row['id_report']] = array(
102 102
 				'report' => $row['id_report'],
103 103
 				'member' => $row['id_member'],
Please login to merge, or discard this patch.
Braces   +70 added lines, -58 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Updates a report with the given parameters. Logs each action via logAction()
@@ -28,19 +29,20 @@  discard block
 block discarded – undo
28 29
 	global $smcFunc, $user_info, $context;
29 30
 
30 31
 	// Don't bother.
31
-	if (empty($action) || empty($report_id))
32
-		return false;
32
+	if (empty($action) || empty($report_id)) {
33
+			return false;
34
+	}
33 35
 
34 36
 	// Add the "_all" thingy.
35
-	if ($action == 'ignore')
36
-		$action = 'ignore_all';
37
+	if ($action == 'ignore') {
38
+			$action = 'ignore_all';
39
+	}
37 40
 
38 41
 	// We don't need the board query for reported members
39 42
 	if ($context['report_type'] == 'members')
40 43
 	{
41 44
 		$board_query = '';
42
-	}
43
-	else
45
+	} else
44 46
 	{
45 47
 		$board_query = ' AND ' . $user_info['mod_cache']['bq'];
46 48
 	}
@@ -76,17 +78,17 @@  discard block
 block discarded – undo
76 78
 			)
77 79
 		);
78 80
 
79
-		while ($row = $smcFunc['db_fetch_assoc']($request))
80
-			$extra[$row['id_report']] = array(
81
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
82
+					$extra[$row['id_report']] = array(
81 83
 				'report' => $row['id_report'],
82 84
 				'board' => $row['id_board'],
83 85
 				'message' => $row['id_msg'],
84 86
 				'topic' => $row['id_topic'],
85 87
 			);
88
+		}
86 89
 
87 90
 		$smcFunc['db_free_result']($request);
88
-	}
89
-	else
91
+	} else
90 92
 	{
91 93
 		$request = $smcFunc['db_query']('', '
92 94
 			SELECT id_report, id_member, membername
@@ -97,28 +99,32 @@  discard block
 block discarded – undo
97 99
 			)
98 100
 		);
99 101
 
100
-		while($row = $smcFunc['db_fetch_assoc']($request))
101
-			$extra[$row['id_report']] = array(
102
+		while($row = $smcFunc['db_fetch_assoc']($request)) {
103
+					$extra[$row['id_report']] = array(
102 104
 				'report' => $row['id_report'],
103 105
 				'member' => $row['id_member'],
104 106
 			);
107
+		}
105 108
 
106 109
 		$smcFunc['db_free_result']($request);
107 110
 	}
108 111
 
109 112
 	// Back to "ignore".
110
-	if ($action == 'ignore_all')
111
-		$action = 'ignore';
113
+	if ($action == 'ignore_all') {
114
+			$action = 'ignore';
115
+	}
112 116
 
113 117
 	$log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open');
114 118
 
115
-	if ($context['report_type'] == 'members')
116
-		$log_report .= '_user';
119
+	if ($context['report_type'] == 'members') {
120
+			$log_report .= '_user';
121
+	}
117 122
 
118 123
 	// Log this action.
119
-	if (!empty($extra))
120
-		foreach ($extra as $report)
124
+	if (!empty($extra)) {
125
+			foreach ($extra as $report)
121 126
 			logAction($log_report . '_report', $report);
127
+	}
122 128
 
123 129
 	// Time to update.
124 130
 	updateSettings(array('last_mod_report_action' => time()));
@@ -142,14 +148,12 @@  discard block
 block discarded – undo
142 148
 	if ($context['report_type'] == 'members')
143 149
 	{
144 150
 		$and = 'lr.id_board = 0';
145
-	}
146
-	else
151
+	} else
147 152
 	{
148 153
 		if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1')
149 154
 		{
150 155
 			$bq = $user_info['mod_cache']['bq'];
151
-		}
152
-		else
156
+		} else
153 157
 		{
154 158
 			$bq = 'lr.' . $user_info['mod_cache']['bq'];
155 159
 		}
@@ -205,8 +209,7 @@  discard block
 block discarded – undo
205 209
 				'max' => 10,
206 210
 			)
207 211
 		);
208
-	}
209
-	else
212
+	} else
210 213
 	{
211 214
 		$request = $smcFunc['db_query']('', '
212 215
 			SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
@@ -254,8 +257,7 @@  discard block
 block discarded – undo
254 257
 					'href' => $scripturl . '?action=profile;u=' . $row['id_user'],
255 258
 				),
256 259
 			);
257
-		}
258
-		else
260
+		} else
259 261
 		{
260 262
 			$report_boards_ids[] = $row['id_board'];
261 263
 			$extraDetails = array(
@@ -295,14 +297,16 @@  discard block
 block discarded – undo
295 297
 			)
296 298
 		);
297 299
 
298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
299
-			$board_names[$row['id_board']] = $row['name'];
300
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
301
+					$board_names[$row['id_board']] = $row['name'];
302
+		}
300 303
 
301 304
 		$smcFunc['db_free_result']($request);
302 305
 
303
-		foreach ($reports as $id_report => $report)
304
-			if (!empty($board_names[$report['topic']['id_board']]))
306
+		foreach ($reports as $id_report => $report) {
307
+					if (!empty($board_names[$report['topic']['id_board']]))
305 308
 				$reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']];
309
+		}
306 310
 	}
307 311
 
308 312
 	// Now get all the people who reported it.
@@ -352,10 +356,11 @@  discard block
 block discarded – undo
352 356
 {
353 357
 	global $user_info, $smcFunc;
354 358
 
355
-	if ($type == 'members')
356
-		$bq = '';
357
-	else
358
-		$bq = '	AND ' . $user_info['mod_cache']['bq'];
359
+	if ($type == 'members') {
360
+			$bq = '';
361
+	} else {
362
+			$bq = '	AND ' . $user_info['mod_cache']['bq'];
363
+	}
359 364
 
360 365
 	$request = $smcFunc['db_query']('', '
361 366
 		SELECT COUNT(*)
@@ -394,8 +399,9 @@  discard block
 block discarded – undo
394 399
 {
395 400
 	global $smcFunc, $user_info, $context;
396 401
 
397
-	if (empty($report_id))
398
-		return false;
402
+	if (empty($report_id)) {
403
+			return false;
404
+	}
399 405
 
400 406
 	// We don't need all this info if we're only getting user info
401 407
 	if ($context['report_type'] == 'members')
@@ -413,8 +419,7 @@  discard block
 block discarded – undo
413 419
 				'id_report' => $report_id,
414 420
 			)
415 421
 		);
416
-	}
417
-	else
422
+	} else
418 423
 	{
419 424
 		// Get the report details, need this so we can limit access to a particular board.
420 425
 		$request = $smcFunc['db_query']('', '
@@ -433,8 +438,9 @@  discard block
 block discarded – undo
433 438
 	}
434 439
 
435 440
 	// So did we find anything?
436
-	if (!$smcFunc['db_num_rows']($request))
437
-		return false;
441
+	if (!$smcFunc['db_num_rows']($request)) {
442
+			return false;
443
+	}
438 444
 
439 445
 	// Woohoo we found a report and they can see it!
440 446
 	$row = $smcFunc['db_fetch_assoc']($request);
@@ -453,8 +459,9 @@  discard block
 block discarded – undo
453 459
 {
454 460
 	global $smcFunc, $scripturl, $user_info, $txt;
455 461
 
456
-	if (empty($report_id))
457
-		return false;
462
+	if (empty($report_id)) {
463
+			return false;
464
+	}
458 465
 
459 466
 	$report = array(
460 467
 		'comments' => array(),
@@ -535,8 +542,9 @@  discard block
 block discarded – undo
535 542
 {
536 543
 	global $smcFunc, $user_info;
537 544
 
538
-	if (empty($comment_id))
539
-		return false;
545
+	if (empty($comment_id)) {
546
+			return false;
547
+	}
540 548
 
541 549
 	$request = $smcFunc['db_query']('', '
542 550
 		SELECT id_comment, id_notice, log_time, body, id_member
@@ -553,8 +561,9 @@  discard block
 block discarded – undo
553 561
 	$smcFunc['db_free_result']($request);
554 562
 
555 563
 	// Add the permission
556
-	if (!empty($comment))
557
-		$comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member']));
564
+	if (!empty($comment)) {
565
+			$comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member']));
566
+	}
558 567
 
559 568
 	return $comment;
560 569
 }
@@ -570,8 +579,9 @@  discard block
 block discarded – undo
570 579
 {
571 580
 	global $smcFunc, $user_info, $context;
572 581
 
573
-	if (empty($data))
574
-		return false;
582
+	if (empty($data)) {
583
+			return false;
584
+	}
575 585
 
576 586
 	$data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data);
577 587
 
@@ -600,8 +610,7 @@  discard block
 block discarded – undo
600 610
 			'comment_id' => $last_comment,
601 611
 			'time' => time(),
602 612
 		);
603
-	}
604
-	else
613
+	} else
605 614
 	{
606 615
 		$prefix = 'Msg';
607 616
 		$data = array(
@@ -617,14 +626,15 @@  discard block
 block discarded – undo
617 626
 	}
618 627
 
619 628
 	// And get ready to notify people.
620
-	if (!empty($report))
621
-		$smcFunc['db_insert']('insert',
629
+	if (!empty($report)) {
630
+			$smcFunc['db_insert']('insert',
622 631
 			'{db_prefix}background_tasks',
623 632
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
624 633
 			array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', json_encode($data), 0),
625 634
 			array('id_task')
626 635
 		);
627
-}
636
+	}
637
+	}
628 638
 
629 639
 /**
630 640
  * Saves the new information whenever a moderator comment is edited.
@@ -637,8 +647,9 @@  discard block
 block discarded – undo
637 647
 {
638 648
 	global $smcFunc;
639 649
 
640
-	if (empty($comment_id) || empty($edited_comment))
641
-		return false;
650
+	if (empty($comment_id) || empty($edited_comment)) {
651
+			return false;
652
+	}
642 653
 
643 654
 	$smcFunc['db_query']('', '
644 655
 		UPDATE {db_prefix}log_comments
@@ -661,8 +672,9 @@  discard block
 block discarded – undo
661 672
 {
662 673
 	global $smcFunc;
663 674
 
664
-	if (empty($comment_id))
665
-		return false;
675
+	if (empty($comment_id)) {
676
+			return false;
677
+	}
666 678
 
667 679
 	$smcFunc['db_query']('', '
668 680
 		DELETE FROM {db_prefix}log_comments
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
  * Used by VerificationCode() (Register.php).
25 25
  *
26 26
  * @param string $word
27
- * @return boolean false on failure
27
+ * @return null|false false on failure
28 28
  */
29 29
 
30 30
 function createWaveFile($word)
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 39
 
40 40
 	// Fixate randomization for this word.
41
-    $tmp = unpack('n', md5($word . session_id()));
41
+	$tmp = unpack('n', md5($word . session_id()));
42 42
 	mt_srand(end($tmp));
43 43
 
44 44
 	// Try to see if there's a sound font in the user's language.
Please login to merge, or discard this patch.
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(header('HTTP/1.1 400 Bad Request'));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(header('HTTP/1.1 400 Bad Request'));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (mt_rand(0, 10) === 0)
86
-						$shift += mt_rand(-3, 3);
87
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (mt_rand(0, 10) === 0) {
96
+											$shift += mt_rand(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 
Please login to merge, or discard this patch.
Sources/Subs-Themes.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -425,7 +425,7 @@
 block discarded – undo
425 425
  *
426 426
  * This is a recursive function, it will call itself if there are subdirs inside the main directory.
427 427
  * @param string $path The absolute path to the directory to be removed
428
- * @return bool true when success, false on error.
428
+ * @return false|null true when success, false on error.
429 429
  */
430 430
 function remove_dir($path)
431 431
 {
Please login to merge, or discard this patch.
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Gets a single theme's info.
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	global $smcFunc, $modSettings;
28 29
 
29 30
 	// No data, no fun!
30
-	if (empty($id))
31
-		return false;
31
+	if (empty($id)) {
32
+			return false;
33
+	}
32 34
 
33 35
 	// Make sure $id is an int.
34 36
 	$id = (int) $id;
@@ -171,8 +173,9 @@  discard block
 block discarded – undo
171 173
 	global $sourcedir, $forum_version, $txt, $scripturl, $context;
172 174
 	global $explicit_images;
173 175
 
174
-	if (empty($path))
175
-		return false;
176
+	if (empty($path)) {
177
+			return false;
178
+	}
176 179
 
177 180
 	$xml_data = array();
178 181
 	$explicit_images = false;
@@ -229,9 +232,10 @@  discard block
 block discarded – undo
229 232
 	);
230 233
 
231 234
 	// Assign the values to be stored.
232
-	foreach ($xml_elements as $var => $name)
233
-		if (!empty($theme_info_xml[$name]))
235
+	foreach ($xml_elements as $var => $name) {
236
+			if (!empty($theme_info_xml[$name]))
234 237
 			$xml_data[$var] = $theme_info_xml[$name];
238
+	}
235 239
 
236 240
 	// Add the supported versions.
237 241
 	$xml_data['install_for'] = $install_versions;
@@ -243,8 +247,9 @@  discard block
 block discarded – undo
243 247
 		$explicit_images = true;
244 248
 	}
245 249
 
246
-	if (!empty($theme_info_xml['extra']))
247
-		$xml_data += smf_json_decode($theme_info_xml['extra'], true);
250
+	if (!empty($theme_info_xml['extra'])) {
251
+			$xml_data += smf_json_decode($theme_info_xml['extra'], true);
252
+	}
248 253
 
249 254
 	return $xml_data;
250 255
 }
@@ -262,12 +267,14 @@  discard block
 block discarded – undo
262 267
 	global $settings, $explicit_images;
263 268
 
264 269
 	// External use? no problem!
265
-	if ($to_install)
266
-		$context['to_install'] = $to_install;
270
+	if ($to_install) {
271
+			$context['to_install'] = $to_install;
272
+	}
267 273
 
268 274
 	// One last check.
269
-	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes')
270
-		fatal_lang_error('theme_install_invalid_dir', false);
275
+	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') {
276
+			fatal_lang_error('theme_install_invalid_dir', false);
277
+	}
271 278
 
272 279
 	// OK, is this a newer version of an already installed theme?
273 280
 	if (!empty($context['to_install']['version']))
@@ -292,8 +299,8 @@  discard block
 block discarded – undo
292 299
 		$smcFunc['db_free_result']($request);
293 300
 
294 301
 		// Got something, lets figure it out what to do next.
295
-		if (!empty($to_update) && !empty($to_update['version']))
296
-			switch (compareVersions($context['to_install']['version'], $to_update['version']))
302
+		if (!empty($to_update) && !empty($to_update['version'])) {
303
+					switch (compareVersions($context['to_install']['version'], $to_update['version']))
297 304
 			{
298 305
 				case 1: // Got a newer version, update the old entry.
299 306
 					$smcFunc['db_query']('', '
@@ -307,6 +314,7 @@  discard block
 block discarded – undo
307 314
 							'id_theme' => $to_update['id_theme'],
308 315
 						)
309 316
 					);
317
+		}
310 318
 
311 319
 					// Done with the update, tell the user about it.
312 320
 					$context['to_install']['updated'] = true;
@@ -372,13 +380,15 @@  discard block
 block discarded – undo
372 380
 				$context['to_install']['base_theme_url'] = $temp['theme_url'];
373 381
 				$context['to_install']['base_theme_dir'] = $temp['theme_dir'];
374 382
 
375
-				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url']))
376
-					$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
383
+				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) {
384
+									$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
385
+				}
377 386
 			}
378 387
 
379 388
 			// Nope, sorry, couldn't find any theme already installed.
380
-			else
381
-				fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
389
+			else {
390
+							fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
391
+			}
382 392
 		}
383 393
 
384 394
 		unset($context['to_install']['based_on']);
@@ -401,16 +411,18 @@  discard block
 block discarded – undo
401 411
 	call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme));
402 412
 
403 413
 	$inserts = array();
404
-	foreach ($context['to_install'] as $var => $val)
405
-		$inserts[] = array($id_theme, $var, $val);
414
+	foreach ($context['to_install'] as $var => $val) {
415
+			$inserts[] = array($id_theme, $var, $val);
416
+	}
406 417
 
407
-	if (!empty($inserts))
408
-		$smcFunc['db_insert']('insert',
418
+	if (!empty($inserts)) {
419
+			$smcFunc['db_insert']('insert',
409 420
 			'{db_prefix}themes',
410 421
 			array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
411 422
 			$inserts,
412 423
 			array('id_theme', 'variable')
413 424
 		);
425
+	}
414 426
 
415 427
 	// Update the known and enable Theme's settings.
416 428
 	$known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ','));
@@ -429,21 +441,24 @@  discard block
 block discarded – undo
429 441
  */
430 442
 function remove_dir($path)
431 443
 {
432
-	if (empty($path))
433
-		return false;
444
+	if (empty($path)) {
445
+			return false;
446
+	}
434 447
 
435 448
 	if (is_dir($path))
436 449
 	{
437 450
 		$objects = scandir($path);
438 451
 
439
-		foreach ($objects as $object)
440
-			if ($object != '.' && $object != '..')
452
+		foreach ($objects as $object) {
453
+					if ($object != '.' && $object != '..')
441 454
 			{
442 455
 				if (filetype($path . '/' . $object) == 'dir')
443 456
 					remove_dir($path . '/' . $object);
457
+		}
444 458
 
445
-				else
446
-					unlink($path . '/' . $object);
459
+				else {
460
+									unlink($path . '/' . $object);
461
+				}
447 462
 			}
448 463
 	}
449 464
 
@@ -462,8 +477,9 @@  discard block
 block discarded – undo
462 477
 	global $smcFunc, $modSettings;
463 478
 
464 479
 	// Can't delete the default theme, sorry!
465
-	if (empty($themeID) || $themeID == 1)
466
-		return false;
480
+	if (empty($themeID) || $themeID == 1) {
481
+			return false;
482
+	}
467 483
 
468 484
 	$known = explode(',', $modSettings['knownThemes']);
469 485
 	$enable = explode(',', $modSettings['enableThemes']);
@@ -513,8 +529,9 @@  discard block
 block discarded – undo
513 529
 	updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known));
514 530
 
515 531
 	// Fix it if the theme was the overall default theme.
516
-	if ($modSettings['theme_guests'] == $themeID)
517
-		updateSettings(array('theme_guests' => '1'));
532
+	if ($modSettings['theme_guests'] == $themeID) {
533
+			updateSettings(array('theme_guests' => '1'));
534
+	}
518 535
 
519 536
 	return true;
520 537
 }
@@ -531,13 +548,15 @@  discard block
 block discarded – undo
531 548
 	global $scripturl, $txt, $context;
532 549
 
533 550
 	// Is it even a directory?
534
-	if (!is_dir($path))
535
-		fatal_lang_error('error_invalid_dir', 'critical');
551
+	if (!is_dir($path)) {
552
+			fatal_lang_error('error_invalid_dir', 'critical');
553
+	}
536 554
 
537 555
 	$dir = dir($path);
538 556
 	$entries = array();
539
-	while ($entry = $dir->read())
540
-		$entries[] = $entry;
557
+	while ($entry = $dir->read()) {
558
+			$entries[] = $entry;
559
+	}
541 560
 	$dir->close();
542 561
 
543 562
 	natcasesort($entries);
@@ -548,11 +567,12 @@  discard block
 block discarded – undo
548 567
 	foreach ($entries as $entry)
549 568
 	{
550 569
 		// Skip all dot files, including .htaccess.
551
-		if (substr($entry, 0, 1) == '.' || $entry == 'CVS')
552
-			continue;
570
+		if (substr($entry, 0, 1) == '.' || $entry == 'CVS') {
571
+					continue;
572
+		}
553 573
 
554
-		if (is_dir($path . '/' . $entry))
555
-			$listing1[] = array(
574
+		if (is_dir($path . '/' . $entry)) {
575
+					$listing1[] = array(
556 576
 				'filename' => $entry,
557 577
 				'is_writable' => is_writable($path . '/' . $entry),
558 578
 				'is_directory' => true,
@@ -562,13 +582,14 @@  discard block
 block discarded – undo
562 582
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry,
563 583
 				'size' => '',
564 584
 			);
565
-		else
585
+		} else
566 586
 		{
567 587
 			$size = filesize($path . '/' . $entry);
568
-			if ($size > 2048 || $size == 1024)
569
-				$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
570
-			else
571
-				$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
588
+			if ($size > 2048 || $size == 1024) {
589
+							$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
590
+			} else {
591
+							$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
592
+			}
572 593
 
573 594
 			$listing2[] = array(
574 595
 				'filename' => $entry,
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -4987,7 +4987,7 @@  discard block
 block discarded – undo
4987 4987
 
4988 4988
 /**
4989 4989
  * @param string $ip_address An IP address in IPv4, IPv6 or decimal notation
4990
- * @return binary The IP address in binary or false
4990
+ * @return string The IP address in binary or false
4991 4991
  */
4992 4992
 function inet_ptod($ip_address)
4993 4993
 {
@@ -5385,7 +5385,7 @@  discard block
 block discarded – undo
5385 5385
  * It assumes the data is already a string.
5386 5386
  * @param string $data The data to print
5387 5387
  * @param string $type The content type. Defaults to Json.
5388
- * @return void
5388
+ * @return false|null
5389 5389
  */
5390 5390
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5391 5391
 {
Please login to merge, or discard this patch.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5265,7 +5265,6 @@  discard block
 block discarded – undo
5265 5265
 
5266 5266
 /**
5267 5267
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5268
-
5269 5268
  * @param string $file The file/dir full path.
5270 5269
  * @param int $value Not needed, added for legacy reasons.
5271 5270
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5305,7 +5304,6 @@  discard block
 block discarded – undo
5305 5304
 
5306 5305
 /**
5307 5306
  * Wrapper function for json_decode() with error handling.
5308
-
5309 5307
  * @param string $json The string to decode.
5310 5308
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5311 5309
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1098 1098
 				),
1099 1099
 				'content' => '$1',
1100
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1100
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1101 1101
 				{
1102 1102
 					$returnContext = '';
1103 1103
 
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 						}
1133 1133
 
1134 1134
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$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>';
1135
+							$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>';
1136 1136
 						else
1137 1137
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1138 1138
 					}
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 				'type' => 'unparsed_content',
1162 1162
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1163 1163
 				// @todo Maybe this can be simplified?
1164
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1164
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1165 1165
 				{
1166 1166
 					if (!isset($disabled['code']))
1167 1167
 					{
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 				'type' => 'unparsed_equals_content',
1199 1199
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1200 1200
 				// @todo Maybe this can be simplified?
1201
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1201
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1202 1202
 				{
1203 1203
 					if (!isset($disabled['code']))
1204 1204
 					{
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 				'type' => 'unparsed_content',
1243 1243
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1244 1244
 				// @todo Should this respect guest_hideContacts?
1245
-				'validate' => function (&$tag, &$data, $disabled)
1245
+				'validate' => function(&$tag, &$data, $disabled)
1246 1246
 				{
1247 1247
 					$data = strtr($data, array('<br>' => ''));
1248 1248
 				},
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 				'type' => 'unparsed_commas_content',
1262 1262
 				'test' => '\d+,\d+\]',
1263 1263
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264
-				'validate' => function (&$tag, &$data, $disabled)
1264
+				'validate' => function(&$tag, &$data, $disabled)
1265 1265
 				{
1266 1266
 					if (isset($disabled['url']))
1267 1267
 						$tag['content'] = '$1';
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1278 1278
 				'before' => '<div $1>',
1279 1279
 				'after' => '</div>',
1280
-				'validate' => function (&$tag, &$data, $disabled)
1280
+				'validate' => function(&$tag, &$data, $disabled)
1281 1281
 				{
1282 1282
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1283
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1327 1327
 				),
1328 1328
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1329
-				'validate' => function (&$tag, &$data, $disabled)
1329
+				'validate' => function(&$tag, &$data, $disabled)
1330 1330
 				{
1331 1331
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1332 1332
 
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 				'tag' => 'img',
1350 1350
 				'type' => 'unparsed_content',
1351 1351
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1352
-				'validate' => function (&$tag, &$data, $disabled)
1352
+				'validate' => function(&$tag, &$data, $disabled)
1353 1353
 				{
1354 1354
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1355 1355
 
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
 				'tag' => 'iurl',
1373 1373
 				'type' => 'unparsed_content',
1374 1374
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1375
-				'validate' => function (&$tag, &$data, $disabled)
1375
+				'validate' => function(&$tag, &$data, $disabled)
1376 1376
 				{
1377 1377
 					$data = strtr($data, array('<br>' => ''));
1378 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 				'quoted' => 'optional',
1387 1387
 				'before' => '<a href="$1" class="bbc_link">',
1388 1388
 				'after' => '</a>',
1389
-				'validate' => function (&$tag, &$data, $disabled)
1389
+				'validate' => function(&$tag, &$data, $disabled)
1390 1390
 				{
1391 1391
 					if (substr($data, 0, 1) == '#')
1392 1392
 						$data = '#post_' . substr($data, 1);
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 				'tag' => 'php',
1467 1467
 				'type' => 'unparsed_content',
1468 1468
 				'content' => '<span class="phpcode">$1</span>',
1469
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1469
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1470 1470
 				{
1471 1471
 					if (!isset($disabled['php']))
1472 1472
 					{
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
 				'test' => '[1-7]\]',
1565 1565
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1566 1566
 				'after' => '</span>',
1567
-				'validate' => function (&$tag, &$data, $disabled)
1567
+				'validate' => function(&$tag, &$data, $disabled)
1568 1568
 				{
1569 1569
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1570 1570
 					$data = $sizes[$data] . 'em';
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 				'tag' => 'time',
1603 1603
 				'type' => 'unparsed_content',
1604 1604
 				'content' => '$1',
1605
-				'validate' => function (&$tag, &$data, $disabled)
1605
+				'validate' => function(&$tag, &$data, $disabled)
1606 1606
 				{
1607 1607
 					if (is_numeric($data))
1608 1608
 						$data = timeformat($data);
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 				'tag' => 'url',
1631 1631
 				'type' => 'unparsed_content',
1632 1632
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1633
-				'validate' => function (&$tag, &$data, $disabled)
1633
+				'validate' => function(&$tag, &$data, $disabled)
1634 1634
 				{
1635 1635
 					$data = strtr($data, array('<br>' => ''));
1636 1636
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1644,7 +1644,7 @@  discard block
 block discarded – undo
1644 1644
 				'quoted' => 'optional',
1645 1645
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1646 1646
 				'after' => '</a>',
1647
-				'validate' => function (&$tag, &$data, $disabled)
1647
+				'validate' => function(&$tag, &$data, $disabled)
1648 1648
 				{
1649 1649
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650 1650
 					if (empty($scheme))
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 		{
1671 1671
 			if (isset($temp_bbc))
1672 1672
 				$bbc_codes = $temp_bbc;
1673
-			usort($codes, function ($a, $b) {
1673
+			usort($codes, function($a, $b) {
1674 1674
 				return strcmp($a['tag'], $b['tag']);
1675 1675
 			});
1676 1676
 			return $codes;
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
 										# a run of Unicode domain name characters and a dot
1909 1909
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1910 1910
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1911
-										(?:'. $modSettings['tld_regex'] .'|local)
1911
+										(?:'. $modSettings['tld_regex'] . '|local)
1912 1912
 									)
1913 1913
 									# followed by a non-domain character or end of line
1914 1914
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
 						)?
1977 1977
 						';
1978 1978
 
1979
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
1979
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
1980 1980
 							$url = array_shift($matches);
1981 1981
 
1982 1982
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2714 2714
 		{
2715 2715
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2716
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2716
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2717 2717
 
2718 2718
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2719 2719
 
@@ -2730,7 +2730,7 @@  discard block
 block discarded – undo
2730 2730
 
2731 2731
 	// Replace away!
2732 2732
 	$message = preg_replace_callback($smileyPregSearch,
2733
-		function ($matches) use ($smileyPregReplacements)
2733
+		function($matches) use ($smileyPregReplacements)
2734 2734
 		{
2735 2735
 			return $smileyPregReplacements[$matches[1]];
2736 2736
 		}, $message);
@@ -2796,13 +2796,13 @@  discard block
 block discarded – undo
2796 2796
 	{
2797 2797
 		if (defined('SID') && SID != '')
2798 2798
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799
-				function ($m) use ($scripturl)
2799
+				function($m) use ($scripturl)
2800 2800
 				{
2801
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2801
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2802 2802
 				}, $setLocation);
2803 2803
 		else
2804 2804
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805
-				function ($m) use ($scripturl)
2805
+				function($m) use ($scripturl)
2806 2806
 				{
2807 2807
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2808 2808
 				}, $setLocation);
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
 
3126 3126
 	// Add a generic "Are you sure?" confirmation message.
3127 3127
 	addInlineJavaScript('
3128
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3128
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3129 3129
 
3130 3130
 	// Now add the capping code for avatars.
3131 3131
 	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')
@@ -3486,7 +3486,7 @@  discard block
 block discarded – undo
3486 3486
 
3487 3487
 		else
3488 3488
 			echo '
3489
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3489
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3490 3490
 	}
3491 3491
 
3492 3492
 	// Inline JavaScript - Actually useful some times!
@@ -3564,14 +3564,14 @@  discard block
 block discarded – undo
3564 3564
 
3565 3565
 		else
3566 3566
 			echo '
3567
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3567
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3568 3568
 	}
3569 3569
 
3570 3570
 	// Print the rest after the minified files.
3571 3571
 	if (!empty($normal))
3572 3572
 		foreach ($normal as $nf)
3573 3573
 			echo '
3574
-	<link rel="stylesheet" href="', $nf ,'">';
3574
+	<link rel="stylesheet" href="', $nf, '">';
3575 3575
 
3576 3576
 	if ($db_show_debug === true)
3577 3577
 	{
@@ -3587,7 +3587,7 @@  discard block
 block discarded – undo
3587 3587
 	<style>';
3588 3588
 
3589 3589
 		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3590
+			echo $css . '
3591 3591
 	';
3592 3592
 
3593 3593
 		echo'
@@ -3616,27 +3616,27 @@  discard block
 block discarded – undo
3616 3616
 		return false;
3617 3617
 
3618 3618
 	// Did we already did this?
3619
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3619
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3620 3620
 
3621 3621
 	// Already done?
3622 3622
 	if (!empty($toCache))
3623 3623
 		return true;
3624 3624
 
3625 3625
 	// No namespaces, sorry!
3626
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3626
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3627 3627
 
3628 3628
 	// Temp path.
3629
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3629
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3630 3630
 
3631 3631
 	// What kind of file are we going to create?
3632
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3632
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3633 3633
 
3634 3634
 	// File has to exists, if it isn't try to create it.
3635 3635
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3636 3636
 	{
3637 3637
 		loadLanguage('Errors');
3638 3638
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3639
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3639
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3640 3640
 
3641 3641
 		// The process failed so roll back to print each individual file.
3642 3642
 		return $data;
@@ -3671,14 +3671,14 @@  discard block
 block discarded – undo
3671 3671
 	{
3672 3672
 		loadLanguage('Errors');
3673 3673
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3674
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3674
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3675 3675
 
3676 3676
 		// The process failed so roll back to print each individual file.
3677 3677
 		return $data;
3678 3678
 	}
3679 3679
 
3680 3680
 	// And create a long lived cache entry.
3681
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3681
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3682 3682
 
3683 3683
 	return true;
3684 3684
 }
@@ -3738,7 +3738,7 @@  discard block
 block discarded – undo
3738 3738
 	else
3739 3739
 		$path = $modSettings['attachmentUploadDir'];
3740 3740
 
3741
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3741
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3742 3742
 }
3743 3743
 
3744 3744
 /**
@@ -3782,10 +3782,10 @@  discard block
 block discarded – undo
3782 3782
 		$valid_low = isValidIP($ip_parts[0]);
3783 3783
 		$valid_high = isValidIP($ip_parts[1]);
3784 3784
 		$count = 0;
3785
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3785
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3786 3786
 		$max = ($mode == ':' ? 'ffff' : '255');
3787 3787
 		$min = 0;
3788
-		if(!$valid_low)
3788
+		if (!$valid_low)
3789 3789
 		{
3790 3790
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3791 3791
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 		}
3800 3800
 
3801 3801
 		$count = 0;
3802
-		if(!$valid_high)
3802
+		if (!$valid_high)
3803 3803
 		{
3804 3804
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3805 3805
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3812,7 +3812,7 @@  discard block
 block discarded – undo
3812 3812
 			}
3813 3813
 		}
3814 3814
 
3815
-		if($valid_high && $valid_low)
3815
+		if ($valid_high && $valid_low)
3816 3816
 		{
3817 3817
 			$ip_array['low'] = $ip_parts[0];
3818 3818
 			$ip_array['high'] = $ip_parts[1];
@@ -3994,7 +3994,7 @@  discard block
 block discarded – undo
3994 3994
 		addInlineJavaScript('
3995 3995
 	var user_menus = new smc_PopupMenu();
3996 3996
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3997
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
3998 3998
 		if ($context['allow_pm'])
3999 3999
 			addInlineJavaScript('
4000 4000
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4619,7 +4619,7 @@  discard block
 block discarded – undo
4619 4619
 		// No? try a fallback to $sourcedir
4620 4620
 		else
4621 4621
 		{
4622
-			$absPath = $sourcedir .'/'. $file;
4622
+			$absPath = $sourcedir . '/' . $file;
4623 4623
 
4624 4624
 			if (file_exists($absPath))
4625 4625
 				require_once($absPath);
@@ -4700,15 +4700,15 @@  discard block
 block discarded – undo
4700 4700
 
4701 4701
 	// UTF-8 occurences of MS special characters
4702 4702
 	$findchars_utf8 = array(
4703
-		"\xe2\x80\x9a",	// single low-9 quotation mark
4704
-		"\xe2\x80\x9e",	// double low-9 quotation mark
4705
-		"\xe2\x80\xa6",	// horizontal ellipsis
4706
-		"\xe2\x80\x98",	// left single curly quote
4707
-		"\xe2\x80\x99",	// right single curly quote
4708
-		"\xe2\x80\x9c",	// left double curly quote
4709
-		"\xe2\x80\x9d",	// right double curly quote
4710
-		"\xe2\x80\x93",	// en dash
4711
-		"\xe2\x80\x94",	// em dash
4703
+		"\xe2\x80\x9a", // single low-9 quotation mark
4704
+		"\xe2\x80\x9e", // double low-9 quotation mark
4705
+		"\xe2\x80\xa6", // horizontal ellipsis
4706
+		"\xe2\x80\x98", // left single curly quote
4707
+		"\xe2\x80\x99", // right single curly quote
4708
+		"\xe2\x80\x9c", // left double curly quote
4709
+		"\xe2\x80\x9d", // right double curly quote
4710
+		"\xe2\x80\x93", // en dash
4711
+		"\xe2\x80\x94", // em dash
4712 4712
 	);
4713 4713
 
4714 4714
 	// windows 1252 / iso equivalents
@@ -4726,15 +4726,15 @@  discard block
 block discarded – undo
4726 4726
 
4727 4727
 	// safe replacements
4728 4728
 	$replacechars = array(
4729
-		',',	// &sbquo;
4730
-		',,',	// &bdquo;
4731
-		'...',	// &hellip;
4732
-		"'",	// &lsquo;
4733
-		"'",	// &rsquo;
4734
-		'"',	// &ldquo;
4735
-		'"',	// &rdquo;
4736
-		'-',	// &ndash;
4737
-		'--',	// &mdash;
4729
+		',', // &sbquo;
4730
+		',,', // &bdquo;
4731
+		'...', // &hellip;
4732
+		"'", // &lsquo;
4733
+		"'", // &rsquo;
4734
+		'"', // &ldquo;
4735
+		'"', // &rdquo;
4736
+		'-', // &ndash;
4737
+		'--', // &mdash;
4738 4738
 	);
4739 4739
 
4740 4740
 	if ($context['utf8'])
@@ -5097,7 +5097,7 @@  discard block
 block discarded – undo
5097 5097
  */
5098 5098
 function inet_dtop($bin)
5099 5099
 {
5100
-	if(empty($bin))
5100
+	if (empty($bin))
5101 5101
 		return '';
5102 5102
 
5103 5103
 	global $db_type;
@@ -5128,28 +5128,28 @@  discard block
 block discarded – undo
5128 5128
  */
5129 5129
 function _safe_serialize($value)
5130 5130
 {
5131
-	if(is_null($value))
5131
+	if (is_null($value))
5132 5132
 		return 'N;';
5133 5133
 
5134
-	if(is_bool($value))
5135
-		return 'b:'. (int) $value .';';
5134
+	if (is_bool($value))
5135
+		return 'b:' . (int) $value . ';';
5136 5136
 
5137
-	if(is_int($value))
5138
-		return 'i:'. $value .';';
5137
+	if (is_int($value))
5138
+		return 'i:' . $value . ';';
5139 5139
 
5140
-	if(is_float($value))
5141
-		return 'd:'. str_replace(',', '.', $value) .';';
5140
+	if (is_float($value))
5141
+		return 'd:' . str_replace(',', '.', $value) . ';';
5142 5142
 
5143
-	if(is_string($value))
5144
-		return 's:'. strlen($value) .':"'. $value .'";';
5143
+	if (is_string($value))
5144
+		return 's:' . strlen($value) . ':"' . $value . '";';
5145 5145
 
5146
-	if(is_array($value))
5146
+	if (is_array($value))
5147 5147
 	{
5148 5148
 		$out = '';
5149
-		foreach($value as $k => $v)
5149
+		foreach ($value as $k => $v)
5150 5150
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5151 5151
 
5152
-		return 'a:'. count($value) .':{'. $out .'}';
5152
+		return 'a:' . count($value) . ':{' . $out . '}';
5153 5153
 	}
5154 5154
 
5155 5155
 	// safe_serialize cannot serialize resources or objects.
@@ -5191,7 +5191,7 @@  discard block
 block discarded – undo
5191 5191
 function _safe_unserialize($str)
5192 5192
 {
5193 5193
 	// Input  is not a string.
5194
-	if(empty($str) || !is_string($str))
5194
+	if (empty($str) || !is_string($str))
5195 5195
 		return false;
5196 5196
 
5197 5197
 	$stack = array();
@@ -5205,40 +5205,40 @@  discard block
 block discarded – undo
5205 5205
 	 *   3 - in array, expecting value or another array
5206 5206
 	 */
5207 5207
 	$state = 0;
5208
-	while($state != 1)
5208
+	while ($state != 1)
5209 5209
 	{
5210 5210
 		$type = isset($str[0]) ? $str[0] : '';
5211
-		if($type == '}')
5211
+		if ($type == '}')
5212 5212
 			$str = substr($str, 1);
5213 5213
 
5214
-		else if($type == 'N' && $str[1] == ';')
5214
+		else if ($type == 'N' && $str[1] == ';')
5215 5215
 		{
5216 5216
 			$value = null;
5217 5217
 			$str = substr($str, 2);
5218 5218
 		}
5219
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5219
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5220 5220
 		{
5221 5221
 			$value = $matches[1] == '1' ? true : false;
5222 5222
 			$str = substr($str, 4);
5223 5223
 		}
5224
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5224
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5225 5225
 		{
5226
-			$value = (int)$matches[1];
5226
+			$value = (int) $matches[1];
5227 5227
 			$str = $matches[2];
5228 5228
 		}
5229
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5229
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5230 5230
 		{
5231
-			$value = (float)$matches[1];
5231
+			$value = (float) $matches[1];
5232 5232
 			$str = $matches[3];
5233 5233
 		}
5234
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5234
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5235 5235
 		{
5236
-			$value = substr($matches[2], 0, (int)$matches[1]);
5237
-			$str = substr($matches[2], (int)$matches[1] + 2);
5236
+			$value = substr($matches[2], 0, (int) $matches[1]);
5237
+			$str = substr($matches[2], (int) $matches[1] + 2);
5238 5238
 		}
5239
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5239
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5240 5240
 		{
5241
-			$expectedLength = (int)$matches[1];
5241
+			$expectedLength = (int) $matches[1];
5242 5242
 			$str = $matches[2];
5243 5243
 		}
5244 5244
 
@@ -5246,10 +5246,10 @@  discard block
 block discarded – undo
5246 5246
 		else
5247 5247
 			return false;
5248 5248
 
5249
-		switch($state)
5249
+		switch ($state)
5250 5250
 		{
5251 5251
 			case 3: // In array, expecting value or another array.
5252
-				if($type == 'a')
5252
+				if ($type == 'a')
5253 5253
 				{
5254 5254
 					$stack[] = &$list;
5255 5255
 					$list[$key] = array();
@@ -5258,7 +5258,7 @@  discard block
 block discarded – undo
5258 5258
 					$state = 2;
5259 5259
 					break;
5260 5260
 				}
5261
-				if($type != '}')
5261
+				if ($type != '}')
5262 5262
 				{
5263 5263
 					$list[$key] = $value;
5264 5264
 					$state = 2;
@@ -5269,29 +5269,29 @@  discard block
 block discarded – undo
5269 5269
 				return false;
5270 5270
 
5271 5271
 			case 2: // in array, expecting end of array or a key
5272
-				if($type == '}')
5272
+				if ($type == '}')
5273 5273
 				{
5274 5274
 					// Array size is less than expected.
5275
-					if(count($list) < end($expected))
5275
+					if (count($list) < end($expected))
5276 5276
 						return false;
5277 5277
 
5278 5278
 					unset($list);
5279
-					$list = &$stack[count($stack)-1];
5279
+					$list = &$stack[count($stack) - 1];
5280 5280
 					array_pop($stack);
5281 5281
 
5282 5282
 					// Go to terminal state if we're at the end of the root array.
5283 5283
 					array_pop($expected);
5284 5284
 
5285
-					if(count($expected) == 0)
5285
+					if (count($expected) == 0)
5286 5286
 						$state = 1;
5287 5287
 
5288 5288
 					break;
5289 5289
 				}
5290 5290
 
5291
-				if($type == 'i' || $type == 's')
5291
+				if ($type == 'i' || $type == 's')
5292 5292
 				{
5293 5293
 					// Array size exceeds expected length.
5294
-					if(count($list) >= end($expected))
5294
+					if (count($list) >= end($expected))
5295 5295
 						return false;
5296 5296
 
5297 5297
 					$key = $value;
@@ -5304,7 +5304,7 @@  discard block
 block discarded – undo
5304 5304
 
5305 5305
 			// Expecting array or value.
5306 5306
 			case 0:
5307
-				if($type == 'a')
5307
+				if ($type == 'a')
5308 5308
 				{
5309 5309
 					$data = array();
5310 5310
 					$list = &$data;
@@ -5313,7 +5313,7 @@  discard block
 block discarded – undo
5313 5313
 					break;
5314 5314
 				}
5315 5315
 
5316
-				if($type != '}')
5316
+				if ($type != '}')
5317 5317
 				{
5318 5318
 					$data = $value;
5319 5319
 					$state = 1;
@@ -5326,7 +5326,7 @@  discard block
 block discarded – undo
5326 5326
 	}
5327 5327
 
5328 5328
 	// Trailing data in input.
5329
-	if(!empty($str))
5329
+	if (!empty($str))
5330 5330
 		return false;
5331 5331
 
5332 5332
 	return $data;
@@ -5380,7 +5380,7 @@  discard block
 block discarded – undo
5380 5380
 	// Set different modes.
5381 5381
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5382 5382
 
5383
-	foreach($chmodValues as $val)
5383
+	foreach ($chmodValues as $val)
5384 5384
 	{
5385 5385
 		// If it's writable, break out of the loop.
5386 5386
 		if (is_writable($file))
@@ -5415,13 +5415,13 @@  discard block
 block discarded – undo
5415 5415
 	$returnArray = @json_decode($json, $returnAsArray);
5416 5416
 
5417 5417
 	// PHP 5.3 so no json_last_error_msg()
5418
-	switch(json_last_error())
5418
+	switch (json_last_error())
5419 5419
 	{
5420 5420
 		case JSON_ERROR_NONE:
5421 5421
 			$jsonError = false;
5422 5422
 			break;
5423 5423
 		case JSON_ERROR_DEPTH:
5424
-			$jsonError =  'JSON_ERROR_DEPTH';
5424
+			$jsonError = 'JSON_ERROR_DEPTH';
5425 5425
 			break;
5426 5426
 		case JSON_ERROR_STATE_MISMATCH:
5427 5427
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5449,10 +5449,10 @@  discard block
 block discarded – undo
5449 5449
 		loadLanguage('Errors');
5450 5450
 
5451 5451
 		if (!empty($jsonDebug))
5452
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5452
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5453 5453
 
5454 5454
 		else
5455
-			log_error($txt['json_'. $jsonError], 'critical');
5455
+			log_error($txt['json_' . $jsonError], 'critical');
5456 5456
 
5457 5457
 		// Everyone expects an array.
5458 5458
 		return array();
@@ -5556,7 +5556,7 @@  discard block
 block discarded – undo
5556 5556
 		});
5557 5557
 
5558 5558
 		// Convert Punycode to Unicode
5559
-		$tlds = array_map(function ($input) {
5559
+		$tlds = array_map(function($input) {
5560 5560
 			$prefix = 'xn--';
5561 5561
 			$safe_char = 0xFFFC;
5562 5562
 			$base = 36;
@@ -5572,7 +5572,7 @@  discard block
 block discarded – undo
5572 5572
 
5573 5573
 			foreach ($enco_parts as $encoded)
5574 5574
 			{
5575
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5575
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5576 5576
 				{
5577 5577
 					$output_parts[] = $encoded;
5578 5578
 					continue;
@@ -5583,7 +5583,7 @@  discard block
 block discarded – undo
5583 5583
 				$idx = 0;
5584 5584
 				$char = 0x80;
5585 5585
 				$decoded = array();
5586
-				$output='';
5586
+				$output = '';
5587 5587
 				$delim_pos = strrpos($encoded, '-');
5588 5588
 
5589 5589
 				if ($delim_pos > strlen($prefix))
@@ -5599,7 +5599,7 @@  discard block
 block discarded – undo
5599 5599
 
5600 5600
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5601 5601
 				{
5602
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5602
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5603 5603
 					{
5604 5604
 						$cp = ord($encoded{$enco_idx++});
5605 5605
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5640,15 +5640,15 @@  discard block
 block discarded – undo
5640 5640
 
5641 5641
 					// 2 bytes
5642 5642
 					elseif ($v < (1 << 11))
5643
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5643
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5644 5644
 
5645 5645
 					// 3 bytes
5646 5646
 					elseif ($v < (1 << 16))
5647
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5647
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5648 5648
 
5649 5649
 					// 4 bytes
5650 5650
 					elseif ($v < (1 << 21))
5651
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5651
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5652 5652
 
5653 5653
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5654 5654
 					else
@@ -5755,7 +5755,7 @@  discard block
 block discarded – undo
5755 5755
 	}
5756 5756
 
5757 5757
 	// This recursive function creates the index array from the strings
5758
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5758
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5759 5759
 	{
5760 5760
 		static $depth = 0;
5761 5761
 		$depth++;
@@ -5782,7 +5782,7 @@  discard block
 block discarded – undo
5782 5782
 	};
5783 5783
 
5784 5784
 	// This recursive function turns the index array into a regular expression
5785
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5785
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5786 5786
 	{
5787 5787
 		static $depth = 0;
5788 5788
 		$depth++;
@@ -5806,11 +5806,11 @@  discard block
 block discarded – undo
5806 5806
 
5807 5807
 				if (count(array_keys($value)) == 1)
5808 5808
 				{
5809
-					$new_key_array = explode('(?'.'>', $sub_regex);
5809
+					$new_key_array = explode('(?' . '>', $sub_regex);
5810 5810
 					$new_key .= $new_key_array[0];
5811 5811
 				}
5812 5812
 				else
5813
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5813
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5814 5814
 			}
5815 5815
 
5816 5816
 			if ($depth > 1)
@@ -5850,7 +5850,7 @@  discard block
 block discarded – undo
5850 5850
 		$index = $add_string_to_index($string, $index);
5851 5851
 
5852 5852
 	while (!empty($index))
5853
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5853
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5854 5854
 
5855 5855
 	// Restore PHP's internal character encoding to whatever it was originally
5856 5856
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Braces   +1287 added lines, -957 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// 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...
760
-		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))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		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)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$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>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$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>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1281,10 +1345,11 @@  discard block
 block discarded – undo
1281 1345
 				{
1282 1346
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1347
 
1284
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1285
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1286
-					else
1287
-						$css = '';
1348
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1349
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1350
+					} else {
1351
+											$css = '';
1352
+					}
1288 1353
 
1289 1354
 					$data = $class . $css;
1290 1355
 				},
@@ -1334,14 +1399,16 @@  discard block
 block discarded – undo
1334 1399
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1335 1400
 					if ($image_proxy_enabled)
1336 1401
 					{
1337
-						if (empty($scheme))
1338
-							$data = 'http://' . ltrim($data, ':/');
1402
+						if (empty($scheme)) {
1403
+													$data = 'http://' . ltrim($data, ':/');
1404
+						}
1339 1405
 
1340
-						if ($scheme != 'https')
1341
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1406
+						if ($scheme != 'https') {
1407
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1408
+						}
1409
+					} elseif (empty($scheme)) {
1410
+											$data = '//' . ltrim($data, ':/');
1342 1411
 					}
1343
-					elseif (empty($scheme))
1344
-						$data = '//' . ltrim($data, ':/');
1345 1412
 				},
1346 1413
 				'disabled_content' => '($1)',
1347 1414
 			),
@@ -1357,14 +1424,16 @@  discard block
 block discarded – undo
1357 1424
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1358 1425
 					if ($image_proxy_enabled)
1359 1426
 					{
1360
-						if (empty($scheme))
1361
-							$data = 'http://' . ltrim($data, ':/');
1427
+						if (empty($scheme)) {
1428
+													$data = 'http://' . ltrim($data, ':/');
1429
+						}
1362 1430
 
1363
-						if ($scheme != 'https')
1364
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1431
+						if ($scheme != 'https') {
1432
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1433
+						}
1434
+					} elseif (empty($scheme)) {
1435
+											$data = '//' . ltrim($data, ':/');
1365 1436
 					}
1366
-					elseif (empty($scheme))
1367
-						$data = '//' . ltrim($data, ':/');
1368 1437
 				},
1369 1438
 				'disabled_content' => '($1)',
1370 1439
 			),
@@ -1376,8 +1445,9 @@  discard block
 block discarded – undo
1376 1445
 				{
1377 1446
 					$data = strtr($data, array('<br>' => ''));
1378 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1379
-					if (empty($scheme))
1380
-						$data = '//' . ltrim($data, ':/');
1448
+					if (empty($scheme)) {
1449
+											$data = '//' . ltrim($data, ':/');
1450
+					}
1381 1451
 				},
1382 1452
 			),
1383 1453
 			array(
@@ -1388,13 +1458,14 @@  discard block
 block discarded – undo
1388 1458
 				'after' => '</a>',
1389 1459
 				'validate' => function (&$tag, &$data, $disabled)
1390 1460
 				{
1391
-					if (substr($data, 0, 1) == '#')
1392
-						$data = '#post_' . substr($data, 1);
1393
-					else
1461
+					if (substr($data, 0, 1) == '#') {
1462
+											$data = '#post_' . substr($data, 1);
1463
+					} else
1394 1464
 					{
1395 1465
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1396
-						if (empty($scheme))
1397
-							$data = '//' . ltrim($data, ':/');
1466
+						if (empty($scheme)) {
1467
+													$data = '//' . ltrim($data, ':/');
1468
+						}
1398 1469
 					}
1399 1470
 				},
1400 1471
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1472,8 +1543,9 @@  discard block
 block discarded – undo
1472 1543
 					{
1473 1544
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1474 1545
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1475
-						if ($add_begin)
1476
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1546
+						if ($add_begin) {
1547
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1548
+						}
1477 1549
 					}
1478 1550
 				},
1479 1551
 				'block_level' => false,
@@ -1604,10 +1676,11 @@  discard block
 block discarded – undo
1604 1676
 				'content' => '$1',
1605 1677
 				'validate' => function (&$tag, &$data, $disabled)
1606 1678
 				{
1607
-					if (is_numeric($data))
1608
-						$data = timeformat($data);
1609
-					else
1610
-						$tag['content'] = '[time]$1[/time]';
1679
+					if (is_numeric($data)) {
1680
+											$data = timeformat($data);
1681
+					} else {
1682
+											$tag['content'] = '[time]$1[/time]';
1683
+					}
1611 1684
 				},
1612 1685
 			),
1613 1686
 			array(
@@ -1634,8 +1707,9 @@  discard block
 block discarded – undo
1634 1707
 				{
1635 1708
 					$data = strtr($data, array('<br>' => ''));
1636 1709
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1637
-					if (empty($scheme))
1638
-						$data = '//' . ltrim($data, ':/');
1710
+					if (empty($scheme)) {
1711
+											$data = '//' . ltrim($data, ':/');
1712
+					}
1639 1713
 				},
1640 1714
 			),
1641 1715
 			array(
@@ -1647,8 +1721,9 @@  discard block
 block discarded – undo
1647 1721
 				'validate' => function (&$tag, &$data, $disabled)
1648 1722
 				{
1649 1723
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650
-					if (empty($scheme))
1651
-						$data = '//' . ltrim($data, ':/');
1724
+					if (empty($scheme)) {
1725
+											$data = '//' . ltrim($data, ':/');
1726
+					}
1652 1727
 				},
1653 1728
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1654 1729
 				'disabled_after' => ' ($1)',
@@ -1668,8 +1743,9 @@  discard block
 block discarded – undo
1668 1743
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1669 1744
 		if ($message === false)
1670 1745
 		{
1671
-			if (isset($temp_bbc))
1672
-				$bbc_codes = $temp_bbc;
1746
+			if (isset($temp_bbc)) {
1747
+							$bbc_codes = $temp_bbc;
1748
+			}
1673 1749
 			usort($codes, function ($a, $b) {
1674 1750
 				return strcmp($a['tag'], $b['tag']);
1675 1751
 			});
@@ -1689,8 +1765,9 @@  discard block
 block discarded – undo
1689 1765
 		);
1690 1766
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1691 1767
 		{
1692
-			foreach ($itemcodes as $c => $dummy)
1693
-				$bbc_codes[$c] = array();
1768
+			foreach ($itemcodes as $c => $dummy) {
1769
+							$bbc_codes[$c] = array();
1770
+			}
1694 1771
 		}
1695 1772
 
1696 1773
 		// Shhhh!
@@ -1711,12 +1788,14 @@  discard block
 block discarded – undo
1711 1788
 		foreach ($codes as $code)
1712 1789
 		{
1713 1790
 			// Make it easier to process parameters later
1714
-			if (!empty($code['parameters']))
1715
-				ksort($code['parameters'], SORT_STRING);
1791
+			if (!empty($code['parameters'])) {
1792
+							ksort($code['parameters'], SORT_STRING);
1793
+			}
1716 1794
 
1717 1795
 			// If we are not doing every tag only do ones we are interested in.
1718
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1719
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1796
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1797
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1798
+			}
1720 1799
 		}
1721 1800
 		$codes = null;
1722 1801
 	}
@@ -1727,8 +1806,9 @@  discard block
 block discarded – undo
1727 1806
 		// It's likely this will change if the message is modified.
1728 1807
 		$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']);
1729 1808
 
1730
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1731
-			return $temp;
1809
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1810
+					return $temp;
1811
+		}
1732 1812
 
1733 1813
 		$cache_t = microtime();
1734 1814
 	}
@@ -1760,8 +1840,9 @@  discard block
 block discarded – undo
1760 1840
 		$disabled['flash'] = true;
1761 1841
 
1762 1842
 		// @todo Change maybe?
1763
-		if (!isset($_GET['images']))
1764
-			$disabled['img'] = true;
1843
+		if (!isset($_GET['images'])) {
1844
+					$disabled['img'] = true;
1845
+		}
1765 1846
 
1766 1847
 		// @todo Interface/setting to add more?
1767 1848
 	}
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1786 1867
 
1787 1868
 		// Failsafe.
1788
-		if ($pos === false || $last_pos > $pos)
1789
-			$pos = strlen($message) + 1;
1869
+		if ($pos === false || $last_pos > $pos) {
1870
+					$pos = strlen($message) + 1;
1871
+		}
1790 1872
 
1791 1873
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1792 1874
 		if ($last_pos < $pos - 1)
@@ -1805,8 +1887,9 @@  discard block
 block discarded – undo
1805 1887
 
1806 1888
 				// <br> should be empty.
1807 1889
 				$empty_tags = array('br', 'hr');
1808
-				foreach ($empty_tags as $tag)
1809
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1890
+				foreach ($empty_tags as $tag) {
1891
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1892
+				}
1810 1893
 
1811 1894
 				// b, u, i, s, pre... basic tags.
1812 1895
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1815,8 +1898,9 @@  discard block
 block discarded – undo
1815 1898
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1816 1899
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1817 1900
 
1818
-					if ($diff > 0)
1819
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1901
+					if ($diff > 0) {
1902
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1903
+					}
1820 1904
 				}
1821 1905
 
1822 1906
 				// Do <img ...> - with security... action= -> action-.
@@ -1829,8 +1913,9 @@  discard block
 block discarded – undo
1829 1913
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1830 1914
 
1831 1915
 						// Remove action= from the URL - no funny business, now.
1832
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1833
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1916
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1917
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1918
+						}
1834 1919
 
1835 1920
 						// Check if the image is larger than allowed.
1836 1921
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1851,9 +1936,9 @@  discard block
 block discarded – undo
1851 1936
 
1852 1937
 							// Set the new image tag.
1853 1938
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1939
+						} else {
1940
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1854 1941
 						}
1855
-						else
1856
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1857 1942
 					}
1858 1943
 
1859 1944
 					$data = strtr($data, $replaces);
@@ -1866,16 +1951,18 @@  discard block
 block discarded – undo
1866 1951
 				$no_autolink_area = false;
1867 1952
 				if (!empty($open_tags))
1868 1953
 				{
1869
-					foreach ($open_tags as $open_tag)
1870
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1954
+					foreach ($open_tags as $open_tag) {
1955
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1871 1956
 							$no_autolink_area = true;
1957
+					}
1872 1958
 				}
1873 1959
 
1874 1960
 				// Don't go backwards.
1875 1961
 				// @todo Don't think is the real solution....
1876 1962
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1877
-				if ($pos < $lastAutoPos)
1878
-					$no_autolink_area = true;
1963
+				if ($pos < $lastAutoPos) {
1964
+									$no_autolink_area = true;
1965
+				}
1879 1966
 				$lastAutoPos = $pos;
1880 1967
 
1881 1968
 				if (!$no_autolink_area)
@@ -1984,17 +2071,19 @@  discard block
 block discarded – undo
1984 2071
 							if ($scheme == 'mailto')
1985 2072
 							{
1986 2073
 								$email_address = str_replace('mailto:', '', $url);
1987
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1988
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1989
-								else
1990
-									return $url;
2074
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2075
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2076
+								} else {
2077
+																	return $url;
2078
+								}
1991 2079
 							}
1992 2080
 
1993 2081
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1994
-							if (empty($scheme))
1995
-								$fullUrl = '//' . ltrim($url, ':/');
1996
-							else
1997
-								$fullUrl = $url;
2082
+							if (empty($scheme)) {
2083
+															$fullUrl = '//' . ltrim($url, ':/');
2084
+							} else {
2085
+															$fullUrl = $url;
2086
+							}
1998 2087
 
1999 2088
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2000 2089
 						}, $data);
@@ -2043,16 +2132,18 @@  discard block
 block discarded – undo
2043 2132
 		}
2044 2133
 
2045 2134
 		// Are we there yet?  Are we there yet?
2046
-		if ($pos >= strlen($message) - 1)
2047
-			break;
2135
+		if ($pos >= strlen($message) - 1) {
2136
+					break;
2137
+		}
2048 2138
 
2049 2139
 		$tags = strtolower($message[$pos + 1]);
2050 2140
 
2051 2141
 		if ($tags == '/' && !empty($open_tags))
2052 2142
 		{
2053 2143
 			$pos2 = strpos($message, ']', $pos + 1);
2054
-			if ($pos2 == $pos + 2)
2055
-				continue;
2144
+			if ($pos2 == $pos + 2) {
2145
+							continue;
2146
+			}
2056 2147
 
2057 2148
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2058 2149
 
@@ -2062,8 +2153,9 @@  discard block
 block discarded – undo
2062 2153
 			do
2063 2154
 			{
2064 2155
 				$tag = array_pop($open_tags);
2065
-				if (!$tag)
2066
-					break;
2156
+				if (!$tag) {
2157
+									break;
2158
+				}
2067 2159
 
2068 2160
 				if (!empty($tag['block_level']))
2069 2161
 				{
@@ -2077,10 +2169,11 @@  discard block
 block discarded – undo
2077 2169
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2078 2170
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2079 2171
 					{
2080
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2081
-							if ($temp['tag'] == $look_for)
2172
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2173
+													if ($temp['tag'] == $look_for)
2082 2174
 							{
2083 2175
 								$block_level = !empty($temp['block_level']);
2176
+						}
2084 2177
 								break;
2085 2178
 							}
2086 2179
 					}
@@ -2102,15 +2195,15 @@  discard block
 block discarded – undo
2102 2195
 			{
2103 2196
 				$open_tags = $to_close;
2104 2197
 				continue;
2105
-			}
2106
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2198
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2107 2199
 			{
2108 2200
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2109 2201
 				{
2110
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2111
-						if ($temp['tag'] == $look_for)
2202
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2203
+											if ($temp['tag'] == $look_for)
2112 2204
 						{
2113 2205
 							$block_level = !empty($temp['block_level']);
2206
+					}
2114 2207
 							break;
2115 2208
 						}
2116 2209
 				}
@@ -2118,8 +2211,9 @@  discard block
 block discarded – undo
2118 2211
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2119 2212
 				if (!$block_level)
2120 2213
 				{
2121
-					foreach ($to_close as $tag)
2122
-						array_push($open_tags, $tag);
2214
+					foreach ($to_close as $tag) {
2215
+											array_push($open_tags, $tag);
2216
+					}
2123 2217
 					continue;
2124 2218
 				}
2125 2219
 			}
@@ -2132,14 +2226,17 @@  discard block
 block discarded – undo
2132 2226
 
2133 2227
 				// See the comment at the end of the big loop - just eating whitespace ;).
2134 2228
 				$whitespace_regex = '';
2135
-				if (!empty($tag['block_level']))
2136
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2229
+				if (!empty($tag['block_level'])) {
2230
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2231
+				}
2137 2232
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2138
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2139
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2233
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2234
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2235
+				}
2140 2236
 
2141
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2142
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2237
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2238
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2239
+				}
2143 2240
 			}
2144 2241
 
2145 2242
 			if (!empty($to_close))
@@ -2152,8 +2249,9 @@  discard block
 block discarded – undo
2152 2249
 		}
2153 2250
 
2154 2251
 		// No tags for this character, so just keep going (fastest possible course.)
2155
-		if (!isset($bbc_codes[$tags]))
2156
-			continue;
2252
+		if (!isset($bbc_codes[$tags])) {
2253
+					continue;
2254
+		}
2157 2255
 
2158 2256
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2159 2257
 		$tag = null;
@@ -2162,44 +2260,52 @@  discard block
 block discarded – undo
2162 2260
 			$pt_strlen = strlen($possible['tag']);
2163 2261
 
2164 2262
 			// Not a match?
2165
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2166
-				continue;
2263
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2264
+							continue;
2265
+			}
2167 2266
 
2168 2267
 			$next_c = $message[$pos + 1 + $pt_strlen];
2169 2268
 
2170 2269
 			// A test validation?
2171
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2172
-				continue;
2270
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2271
+							continue;
2272
+			}
2173 2273
 			// Do we want parameters?
2174 2274
 			elseif (!empty($possible['parameters']))
2175 2275
 			{
2176
-				if ($next_c != ' ')
2177
-					continue;
2178
-			}
2179
-			elseif (isset($possible['type']))
2276
+				if ($next_c != ' ') {
2277
+									continue;
2278
+				}
2279
+			} elseif (isset($possible['type']))
2180 2280
 			{
2181 2281
 				// Do we need an equal sign?
2182
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2183
-					continue;
2282
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2283
+									continue;
2284
+				}
2184 2285
 				// Maybe we just want a /...
2185
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2186
-					continue;
2286
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2287
+									continue;
2288
+				}
2187 2289
 				// An immediate ]?
2188
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2189
-					continue;
2290
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2291
+									continue;
2292
+				}
2190 2293
 			}
2191 2294
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2192
-			elseif ($next_c != ']')
2193
-				continue;
2295
+			elseif ($next_c != ']') {
2296
+							continue;
2297
+			}
2194 2298
 
2195 2299
 			// Check allowed tree?
2196
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2197
-				continue;
2198
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2199
-				continue;
2300
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2301
+							continue;
2302
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2303
+							continue;
2304
+			}
2200 2305
 			// If this is in the list of disallowed child tags, don't parse it.
2201
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2202
-				continue;
2306
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2307
+							continue;
2308
+			}
2203 2309
 
2204 2310
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2205 2311
 
@@ -2211,8 +2317,9 @@  discard block
 block discarded – undo
2211 2317
 				foreach ($open_tags as $open_quote)
2212 2318
 				{
2213 2319
 					// Every parent quote this quote has flips the styling
2214
-					if ($open_quote['tag'] == 'quote')
2215
-						$quote_alt = !$quote_alt;
2320
+					if ($open_quote['tag'] == 'quote') {
2321
+											$quote_alt = !$quote_alt;
2322
+					}
2216 2323
 				}
2217 2324
 				// Add a class to the quote to style alternating blockquotes
2218 2325
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2223,8 +2330,9 @@  discard block
 block discarded – undo
2223 2330
 			{
2224 2331
 				// Build a regular expression for each parameter for the current tag.
2225 2332
 				$preg = array();
2226
-				foreach ($possible['parameters'] as $p => $info)
2227
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2333
+				foreach ($possible['parameters'] as $p => $info) {
2334
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2335
+				}
2228 2336
 
2229 2337
 				// Extract the string that potentially holds our parameters.
2230 2338
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2244,24 +2352,27 @@  discard block
 block discarded – undo
2244 2352
 
2245 2353
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2246 2354
 
2247
-					if ($match)
2248
-						$blob_counter = count($blobs) + 1;
2355
+					if ($match) {
2356
+											$blob_counter = count($blobs) + 1;
2357
+					}
2249 2358
 				}
2250 2359
 
2251 2360
 				// Didn't match our parameter list, try the next possible.
2252
-				if (!$match)
2253
-					continue;
2361
+				if (!$match) {
2362
+									continue;
2363
+				}
2254 2364
 
2255 2365
 				$params = array();
2256 2366
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2257 2367
 				{
2258 2368
 					$key = strtok(ltrim($matches[$i]), '=');
2259
-					if (isset($possible['parameters'][$key]['value']))
2260
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2261
-					elseif (isset($possible['parameters'][$key]['validate']))
2262
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2263
-					else
2264
-						$params['{' . $key . '}'] = $matches[$i + 1];
2369
+					if (isset($possible['parameters'][$key]['value'])) {
2370
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2372
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
+					} else {
2374
+											$params['{' . $key . '}'] = $matches[$i + 1];
2375
+					}
2265 2376
 
2266 2377
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2267 2378
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2269,23 +2380,26 @@  discard block
 block discarded – undo
2269 2380
 
2270 2381
 				foreach ($possible['parameters'] as $p => $info)
2271 2382
 				{
2272
-					if (!isset($params['{' . $p . '}']))
2273
-						$params['{' . $p . '}'] = '';
2383
+					if (!isset($params['{' . $p . '}'])) {
2384
+											$params['{' . $p . '}'] = '';
2385
+					}
2274 2386
 				}
2275 2387
 
2276 2388
 				$tag = $possible;
2277 2389
 
2278 2390
 				// Put the parameters into the string.
2279
-				if (isset($tag['before']))
2280
-					$tag['before'] = strtr($tag['before'], $params);
2281
-				if (isset($tag['after']))
2282
-					$tag['after'] = strtr($tag['after'], $params);
2283
-				if (isset($tag['content']))
2284
-					$tag['content'] = strtr($tag['content'], $params);
2391
+				if (isset($tag['before'])) {
2392
+									$tag['before'] = strtr($tag['before'], $params);
2393
+				}
2394
+				if (isset($tag['after'])) {
2395
+									$tag['after'] = strtr($tag['after'], $params);
2396
+				}
2397
+				if (isset($tag['content'])) {
2398
+									$tag['content'] = strtr($tag['content'], $params);
2399
+				}
2285 2400
 
2286 2401
 				$pos1 += strlen($given_param_string);
2287
-			}
2288
-			else
2402
+			} else
2289 2403
 			{
2290 2404
 				$tag = $possible;
2291 2405
 				$params = array();
@@ -2296,8 +2410,9 @@  discard block
 block discarded – undo
2296 2410
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2297 2411
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2298 2412
 		{
2299
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2300
-				continue;
2413
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2414
+							continue;
2415
+			}
2301 2416
 
2302 2417
 			$tag = $itemcodes[$message[$pos + 1]];
2303 2418
 
@@ -2318,9 +2433,9 @@  discard block
 block discarded – undo
2318 2433
 			{
2319 2434
 				array_pop($open_tags);
2320 2435
 				$code = '</li>';
2436
+			} else {
2437
+							$code = '';
2321 2438
 			}
2322
-			else
2323
-				$code = '';
2324 2439
 
2325 2440
 			// Now we open a new tag.
2326 2441
 			$open_tags[] = array(
@@ -2367,12 +2482,14 @@  discard block
 block discarded – undo
2367 2482
 		}
2368 2483
 
2369 2484
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2370
-		if ($tag === null)
2371
-			continue;
2485
+		if ($tag === null) {
2486
+					continue;
2487
+		}
2372 2488
 
2373 2489
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2374
-		if (isset($inside['disallow_children']))
2375
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2490
+		if (isset($inside['disallow_children'])) {
2491
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2492
+		}
2376 2493
 
2377 2494
 		// Is this tag disabled?
2378 2495
 		if (isset($disabled[$tag['tag']]))
@@ -2382,14 +2499,13 @@  discard block
 block discarded – undo
2382 2499
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2383 2500
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2384 2501
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2385
-			}
2386
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2502
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2387 2503
 			{
2388 2504
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2389 2505
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2506
+			} else {
2507
+							$tag['content'] = $tag['disabled_content'];
2390 2508
 			}
2391
-			else
2392
-				$tag['content'] = $tag['disabled_content'];
2393 2509
 		}
2394 2510
 
2395 2511
 		// we use this a lot
@@ -2399,8 +2515,9 @@  discard block
 block discarded – undo
2399 2515
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2400 2516
 		{
2401 2517
 			$n = count($open_tags) - 1;
2402
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2403
-				$n--;
2518
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2519
+							$n--;
2520
+			}
2404 2521
 
2405 2522
 			// Close all the non block level tags so this tag isn't surrounded by them.
2406 2523
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2412,12 +2529,15 @@  discard block
 block discarded – undo
2412 2529
 
2413 2530
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2414 2531
 				$whitespace_regex = '';
2415
-				if (!empty($tag['block_level']))
2416
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2417
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2418
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2419
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2420
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2532
+				if (!empty($tag['block_level'])) {
2533
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2534
+				}
2535
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2536
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2537
+				}
2538
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2539
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2540
+				}
2421 2541
 
2422 2542
 				array_pop($open_tags);
2423 2543
 			}
@@ -2435,16 +2555,19 @@  discard block
 block discarded – undo
2435 2555
 		elseif ($tag['type'] == 'unparsed_content')
2436 2556
 		{
2437 2557
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2438
-			if ($pos2 === false)
2439
-				continue;
2558
+			if ($pos2 === false) {
2559
+							continue;
2560
+			}
2440 2561
 
2441 2562
 			$data = substr($message, $pos1, $pos2 - $pos1);
2442 2563
 
2443
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2444
-				$data = substr($data, 4);
2564
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2565
+							$data = substr($data, 4);
2566
+			}
2445 2567
 
2446
-			if (isset($tag['validate']))
2447
-				$tag['validate']($tag, $data, $disabled, $params);
2568
+			if (isset($tag['validate'])) {
2569
+							$tag['validate']($tag, $data, $disabled, $params);
2570
+			}
2448 2571
 
2449 2572
 			$code = strtr($tag['content'], array('$1' => $data));
2450 2573
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2460,34 +2583,40 @@  discard block
 block discarded – undo
2460 2583
 			if (isset($tag['quoted']))
2461 2584
 			{
2462 2585
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2463
-				if ($tag['quoted'] != 'optional' && !$quoted)
2464
-					continue;
2586
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2587
+									continue;
2588
+				}
2465 2589
 
2466
-				if ($quoted)
2467
-					$pos1 += 6;
2590
+				if ($quoted) {
2591
+									$pos1 += 6;
2592
+				}
2593
+			} else {
2594
+							$quoted = false;
2468 2595
 			}
2469
-			else
2470
-				$quoted = false;
2471 2596
 
2472 2597
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2473
-			if ($pos2 === false)
2474
-				continue;
2598
+			if ($pos2 === false) {
2599
+							continue;
2600
+			}
2475 2601
 
2476 2602
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2477
-			if ($pos3 === false)
2478
-				continue;
2603
+			if ($pos3 === false) {
2604
+							continue;
2605
+			}
2479 2606
 
2480 2607
 			$data = array(
2481 2608
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2482 2609
 				substr($message, $pos1, $pos2 - $pos1)
2483 2610
 			);
2484 2611
 
2485
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2486
-				$data[0] = substr($data[0], 4);
2612
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2613
+							$data[0] = substr($data[0], 4);
2614
+			}
2487 2615
 
2488 2616
 			// Validation for my parking, please!
2489
-			if (isset($tag['validate']))
2490
-				$tag['validate']($tag, $data, $disabled, $params);
2617
+			if (isset($tag['validate'])) {
2618
+							$tag['validate']($tag, $data, $disabled, $params);
2619
+			}
2491 2620
 
2492 2621
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2493 2622
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2504,23 +2633,27 @@  discard block
 block discarded – undo
2504 2633
 		elseif ($tag['type'] == 'unparsed_commas_content')
2505 2634
 		{
2506 2635
 			$pos2 = strpos($message, ']', $pos1);
2507
-			if ($pos2 === false)
2508
-				continue;
2636
+			if ($pos2 === false) {
2637
+							continue;
2638
+			}
2509 2639
 
2510 2640
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2511
-			if ($pos3 === false)
2512
-				continue;
2641
+			if ($pos3 === false) {
2642
+							continue;
2643
+			}
2513 2644
 
2514 2645
 			// We want $1 to be the content, and the rest to be csv.
2515 2646
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2516 2647
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2517 2648
 
2518
-			if (isset($tag['validate']))
2519
-				$tag['validate']($tag, $data, $disabled, $params);
2649
+			if (isset($tag['validate'])) {
2650
+							$tag['validate']($tag, $data, $disabled, $params);
2651
+			}
2520 2652
 
2521 2653
 			$code = $tag['content'];
2522
-			foreach ($data as $k => $d)
2523
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2524 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2525 2658
 			$pos += strlen($code) - 1 + 2;
2526 2659
 		}
@@ -2528,24 +2661,28 @@  discard block
 block discarded – undo
2528 2661
 		elseif ($tag['type'] == 'unparsed_commas')
2529 2662
 		{
2530 2663
 			$pos2 = strpos($message, ']', $pos1);
2531
-			if ($pos2 === false)
2532
-				continue;
2664
+			if ($pos2 === false) {
2665
+							continue;
2666
+			}
2533 2667
 
2534 2668
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2535 2669
 
2536
-			if (isset($tag['validate']))
2537
-				$tag['validate']($tag, $data, $disabled, $params);
2670
+			if (isset($tag['validate'])) {
2671
+							$tag['validate']($tag, $data, $disabled, $params);
2672
+			}
2538 2673
 
2539 2674
 			// Fix after, for disabled code mainly.
2540
-			foreach ($data as $k => $d)
2541
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2675
+			foreach ($data as $k => $d) {
2676
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2677
+			}
2542 2678
 
2543 2679
 			$open_tags[] = $tag;
2544 2680
 
2545 2681
 			// Replace them out, $1, $2, $3, $4, etc.
2546 2682
 			$code = $tag['before'];
2547
-			foreach ($data as $k => $d)
2548
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2683
+			foreach ($data as $k => $d) {
2684
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2685
+			}
2549 2686
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2550 2687
 			$pos += strlen($code) - 1 + 2;
2551 2688
 		}
@@ -2556,28 +2693,33 @@  discard block
 block discarded – undo
2556 2693
 			if (isset($tag['quoted']))
2557 2694
 			{
2558 2695
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2559
-				if ($tag['quoted'] != 'optional' && !$quoted)
2560
-					continue;
2696
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2697
+									continue;
2698
+				}
2561 2699
 
2562
-				if ($quoted)
2563
-					$pos1 += 6;
2700
+				if ($quoted) {
2701
+									$pos1 += 6;
2702
+				}
2703
+			} else {
2704
+							$quoted = false;
2564 2705
 			}
2565
-			else
2566
-				$quoted = false;
2567 2706
 
2568 2707
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2569
-			if ($pos2 === false)
2570
-				continue;
2708
+			if ($pos2 === false) {
2709
+							continue;
2710
+			}
2571 2711
 
2572 2712
 			$data = substr($message, $pos1, $pos2 - $pos1);
2573 2713
 
2574 2714
 			// Validation for my parking, please!
2575
-			if (isset($tag['validate']))
2576
-				$tag['validate']($tag, $data, $disabled, $params);
2715
+			if (isset($tag['validate'])) {
2716
+							$tag['validate']($tag, $data, $disabled, $params);
2717
+			}
2577 2718
 
2578 2719
 			// For parsed content, we must recurse to avoid security problems.
2579
-			if ($tag['type'] != 'unparsed_equals')
2580
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2720
+			if ($tag['type'] != 'unparsed_equals') {
2721
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2722
+			}
2581 2723
 
2582 2724
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2583 2725
 
@@ -2589,34 +2731,40 @@  discard block
 block discarded – undo
2589 2731
 		}
2590 2732
 
2591 2733
 		// If this is block level, eat any breaks after it.
2592
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2593
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2734
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2735
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2736
+		}
2594 2737
 
2595 2738
 		// Are we trimming outside this tag?
2596
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2597
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2739
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2740
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2741
+		}
2598 2742
 	}
2599 2743
 
2600 2744
 	// Close any remaining tags.
2601
-	while ($tag = array_pop($open_tags))
2602
-		$message .= "\n" . $tag['after'] . "\n";
2745
+	while ($tag = array_pop($open_tags)) {
2746
+			$message .= "\n" . $tag['after'] . "\n";
2747
+	}
2603 2748
 
2604 2749
 	// Parse the smileys within the parts where it can be done safely.
2605 2750
 	if ($smileys === true)
2606 2751
 	{
2607 2752
 		$message_parts = explode("\n", $message);
2608
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2609
-			parsesmileys($message_parts[$i]);
2753
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2754
+					parsesmileys($message_parts[$i]);
2755
+		}
2610 2756
 
2611 2757
 		$message = implode('', $message_parts);
2612 2758
 	}
2613 2759
 
2614 2760
 	// No smileys, just get rid of the markers.
2615
-	else
2616
-		$message = strtr($message, array("\n" => ''));
2761
+	else {
2762
+			$message = strtr($message, array("\n" => ''));
2763
+	}
2617 2764
 
2618
-	if ($message !== '' && $message[0] === ' ')
2619
-		$message = '&nbsp;' . substr($message, 1);
2765
+	if ($message !== '' && $message[0] === ' ') {
2766
+			$message = '&nbsp;' . substr($message, 1);
2767
+	}
2620 2768
 
2621 2769
 	// Cleanup whitespace.
2622 2770
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2625,15 +2773,16 @@  discard block
 block discarded – undo
2625 2773
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2626 2774
 
2627 2775
 	// Cache the output if it took some time...
2628
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2629
-		cache_put_data($cache_key, $message, 240);
2776
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2777
+			cache_put_data($cache_key, $message, 240);
2778
+	}
2630 2779
 
2631 2780
 	// If this was a force parse revert if needed.
2632 2781
 	if (!empty($parse_tags))
2633 2782
 	{
2634
-		if (empty($temp_bbc))
2635
-			$bbc_codes = array();
2636
-		else
2783
+		if (empty($temp_bbc)) {
2784
+					$bbc_codes = array();
2785
+		} else
2637 2786
 		{
2638 2787
 			$bbc_codes = $temp_bbc;
2639 2788
 			unset($temp_bbc);
@@ -2660,8 +2809,9 @@  discard block
 block discarded – undo
2660 2809
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2661 2810
 
2662 2811
 	// No smiley set at all?!
2663
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2664
-		return;
2812
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2813
+			return;
2814
+	}
2665 2815
 
2666 2816
 	// If smileyPregSearch hasn't been set, do it now.
2667 2817
 	if (empty($smileyPregSearch))
@@ -2672,8 +2822,7 @@  discard block
 block discarded – undo
2672 2822
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2673 2823
 			$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');
2674 2824
 			$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'], '', '', '', '');
2675
-		}
2676
-		else
2825
+		} else
2677 2826
 		{
2678 2827
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2679 2828
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2697,9 +2846,9 @@  discard block
 block discarded – undo
2697 2846
 				$smcFunc['db_free_result']($result);
2698 2847
 
2699 2848
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2849
+			} else {
2850
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2700 2851
 			}
2701
-			else
2702
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2703 2852
 		}
2704 2853
 
2705 2854
 		// The non-breaking-space is a complex thing...
@@ -2776,35 +2925,41 @@  discard block
 block discarded – undo
2776 2925
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2777 2926
 
2778 2927
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2779
-	if (!empty($context['flush_mail']))
2780
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2928
+	if (!empty($context['flush_mail'])) {
2929
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2781 2930
 		AddMailQueue(true);
2931
+	}
2782 2932
 
2783 2933
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2784 2934
 
2785
-	if ($add)
2786
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2935
+	if ($add) {
2936
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2937
+	}
2787 2938
 
2788 2939
 	// Put the session ID in.
2789
-	if (defined('SID') && SID != '')
2790
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2940
+	if (defined('SID') && SID != '') {
2941
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2942
+	}
2791 2943
 	// Keep that debug in their for template debugging!
2792
-	elseif (isset($_GET['debug']))
2793
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2944
+	elseif (isset($_GET['debug'])) {
2945
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2946
+	}
2794 2947
 
2795 2948
 	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'])))
2796 2949
 	{
2797
-		if (defined('SID') && SID != '')
2798
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2950
+		if (defined('SID') && SID != '') {
2951
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799 2952
 				function ($m) use ($scripturl)
2800 2953
 				{
2801 2954
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2955
+		}
2802 2956
 				}, $setLocation);
2803
-		else
2804
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2957
+		else {
2958
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805 2959
 				function ($m) use ($scripturl)
2806 2960
 				{
2807 2961
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2962
+		}
2808 2963
 				}, $setLocation);
2809 2964
 	}
2810 2965
 
@@ -2815,8 +2970,9 @@  discard block
 block discarded – undo
2815 2970
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2816 2971
 
2817 2972
 	// Debugging.
2818
-	if (isset($db_show_debug) && $db_show_debug === true)
2819
-		$_SESSION['debug_redirect'] = $db_cache;
2973
+	if (isset($db_show_debug) && $db_show_debug === true) {
2974
+			$_SESSION['debug_redirect'] = $db_cache;
2975
+	}
2820 2976
 
2821 2977
 	obExit(false);
2822 2978
 }
@@ -2835,51 +2991,60 @@  discard block
 block discarded – undo
2835 2991
 
2836 2992
 	// Attempt to prevent a recursive loop.
2837 2993
 	++$level;
2838
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2839
-		exit;
2840
-	if ($from_fatal_error)
2841
-		$has_fatal_error = true;
2994
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2995
+			exit;
2996
+	}
2997
+	if ($from_fatal_error) {
2998
+			$has_fatal_error = true;
2999
+	}
2842 3000
 
2843 3001
 	// Clear out the stat cache.
2844 3002
 	trackStats();
2845 3003
 
2846 3004
 	// If we have mail to send, send it.
2847
-	if (!empty($context['flush_mail']))
2848
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3005
+	if (!empty($context['flush_mail'])) {
3006
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2849 3007
 		AddMailQueue(true);
3008
+	}
2850 3009
 
2851 3010
 	$do_header = $header === null ? !$header_done : $header;
2852
-	if ($do_footer === null)
2853
-		$do_footer = $do_header;
3011
+	if ($do_footer === null) {
3012
+			$do_footer = $do_header;
3013
+	}
2854 3014
 
2855 3015
 	// Has the template/header been done yet?
2856 3016
 	if ($do_header)
2857 3017
 	{
2858 3018
 		// Was the page title set last minute? Also update the HTML safe one.
2859
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2860
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3019
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3020
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3021
+		}
2861 3022
 
2862 3023
 		// Start up the session URL fixer.
2863 3024
 		ob_start('ob_sessrewrite');
2864 3025
 
2865
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2866
-			$buffers = explode(',', $settings['output_buffers']);
2867
-		elseif (!empty($settings['output_buffers']))
2868
-			$buffers = $settings['output_buffers'];
2869
-		else
2870
-			$buffers = array();
3026
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3027
+					$buffers = explode(',', $settings['output_buffers']);
3028
+		} elseif (!empty($settings['output_buffers'])) {
3029
+					$buffers = $settings['output_buffers'];
3030
+		} else {
3031
+					$buffers = array();
3032
+		}
2871 3033
 
2872
-		if (isset($modSettings['integrate_buffer']))
2873
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3034
+		if (isset($modSettings['integrate_buffer'])) {
3035
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3036
+		}
2874 3037
 
2875
-		if (!empty($buffers))
2876
-			foreach ($buffers as $function)
3038
+		if (!empty($buffers)) {
3039
+					foreach ($buffers as $function)
2877 3040
 			{
2878 3041
 				$call = call_helper($function, true);
3042
+		}
2879 3043
 
2880 3044
 				// Is it valid?
2881
-				if (!empty($call))
2882
-					ob_start($call);
3045
+				if (!empty($call)) {
3046
+									ob_start($call);
3047
+				}
2883 3048
 			}
2884 3049
 
2885 3050
 		// Display the screen in the logical order.
@@ -2891,8 +3056,9 @@  discard block
 block discarded – undo
2891 3056
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2892 3057
 
2893 3058
 		// Anything special to put out?
2894
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2895
-			echo $context['insert_after_template'];
3059
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3060
+					echo $context['insert_after_template'];
3061
+		}
2896 3062
 
2897 3063
 		// Just so we don't get caught in an endless loop of errors from the footer...
2898 3064
 		if (!$footer_done)
@@ -2901,14 +3067,16 @@  discard block
 block discarded – undo
2901 3067
 			template_footer();
2902 3068
 
2903 3069
 			// (since this is just debugging... it's okay that it's after </html>.)
2904
-			if (!isset($_REQUEST['xml']))
2905
-				displayDebug();
3070
+			if (!isset($_REQUEST['xml'])) {
3071
+							displayDebug();
3072
+			}
2906 3073
 		}
2907 3074
 	}
2908 3075
 
2909 3076
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2910
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2911
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3077
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3078
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3079
+	}
2912 3080
 
2913 3081
 	// For session check verification.... don't switch browsers...
2914 3082
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2917,9 +3085,10 @@  discard block
 block discarded – undo
2917 3085
 	call_integration_hook('integrate_exit', array($do_footer));
2918 3086
 
2919 3087
 	// Don't exit if we're coming from index.php; that will pass through normally.
2920
-	if (!$from_index)
2921
-		exit;
2922
-}
3088
+	if (!$from_index) {
3089
+			exit;
3090
+	}
3091
+	}
2923 3092
 
2924 3093
 /**
2925 3094
  * Get the size of a specified image with better error handling.
@@ -2938,8 +3107,9 @@  discard block
 block discarded – undo
2938 3107
 	$url = str_replace(' ', '%20', $url);
2939 3108
 
2940 3109
 	// Can we pull this from the cache... please please?
2941
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2942
-		return $temp;
3110
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3111
+			return $temp;
3112
+	}
2943 3113
 	$t = microtime();
2944 3114
 
2945 3115
 	// Get the host to pester...
@@ -2949,12 +3119,10 @@  discard block
 block discarded – undo
2949 3119
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2950 3120
 	{
2951 3121
 		return false;
2952
-	}
2953
-	elseif (!isset($match[1]))
3122
+	} elseif (!isset($match[1]))
2954 3123
 	{
2955 3124
 		$size = @getimagesize($url);
2956
-	}
2957
-	else
3125
+	} else
2958 3126
 	{
2959 3127
 		// Try to connect to the server... give it half a second.
2960 3128
 		$temp = 0;
@@ -2993,12 +3161,14 @@  discard block
 block discarded – undo
2993 3161
 	}
2994 3162
 
2995 3163
 	// If we didn't get it, we failed.
2996
-	if (!isset($size))
2997
-		$size = false;
3164
+	if (!isset($size)) {
3165
+			$size = false;
3166
+	}
2998 3167
 
2999 3168
 	// If this took a long time, we may never have to do it again, but then again we might...
3000
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3001
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3169
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3170
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3171
+	}
3002 3172
 
3003 3173
 	// Didn't work.
3004 3174
 	return $size;
@@ -3016,8 +3186,9 @@  discard block
 block discarded – undo
3016 3186
 
3017 3187
 	// Under SSI this function can be called more then once.  That can cause some problems.
3018 3188
 	//   So only run the function once unless we are forced to run it again.
3019
-	if ($loaded && !$forceload)
3020
-		return;
3189
+	if ($loaded && !$forceload) {
3190
+			return;
3191
+	}
3021 3192
 
3022 3193
 	$loaded = true;
3023 3194
 
@@ -3029,14 +3200,16 @@  discard block
 block discarded – undo
3029 3200
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3030 3201
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3031 3202
 	{
3032
-		if (trim($context['news_lines'][$i]) == '')
3033
-			continue;
3203
+		if (trim($context['news_lines'][$i]) == '') {
3204
+					continue;
3205
+		}
3034 3206
 
3035 3207
 		// Clean it up for presentation ;).
3036 3208
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3037 3209
 	}
3038
-	if (!empty($context['news_lines']))
3039
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3210
+	if (!empty($context['news_lines'])) {
3211
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3212
+	}
3040 3213
 
3041 3214
 	if (!$user_info['is_guest'])
3042 3215
 	{
@@ -3045,40 +3218,48 @@  discard block
 block discarded – undo
3045 3218
 		$context['user']['alerts'] = &$user_info['alerts'];
3046 3219
 
3047 3220
 		// Personal message popup...
3048
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3049
-			$context['user']['popup_messages'] = true;
3050
-		else
3051
-			$context['user']['popup_messages'] = false;
3221
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3222
+					$context['user']['popup_messages'] = true;
3223
+		} else {
3224
+					$context['user']['popup_messages'] = false;
3225
+		}
3052 3226
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3053 3227
 
3054
-		if (allowedTo('moderate_forum'))
3055
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3228
+		if (allowedTo('moderate_forum')) {
3229
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3230
+		}
3056 3231
 
3057 3232
 		$context['user']['avatar'] = array();
3058 3233
 
3059 3234
 		// Check for gravatar first since we might be forcing them...
3060 3235
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3061 3236
 		{
3062
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3063
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3064
-			else
3065
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3237
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3238
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3239
+			} else {
3240
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3241
+			}
3066 3242
 		}
3067 3243
 		// Uploaded?
3068
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3069
-			$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';
3244
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3245
+					$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';
3246
+		}
3070 3247
 		// Full URL?
3071
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3072
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3248
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3249
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3250
+		}
3073 3251
 		// Otherwise we assume it's server stored.
3074
-		elseif ($user_info['avatar']['url'] != '')
3075
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3252
+		elseif ($user_info['avatar']['url'] != '') {
3253
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3254
+		}
3076 3255
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3077
-		else
3078
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3256
+		else {
3257
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3258
+		}
3079 3259
 
3080
-		if (!empty($context['user']['avatar']))
3081
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3260
+		if (!empty($context['user']['avatar'])) {
3261
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3262
+		}
3082 3263
 
3083 3264
 		// Figure out how long they've been logged in.
3084 3265
 		$context['user']['total_time_logged_in'] = array(
@@ -3086,8 +3267,7 @@  discard block
 block discarded – undo
3086 3267
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3087 3268
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3088 3269
 		);
3089
-	}
3090
-	else
3270
+	} else
3091 3271
 	{
3092 3272
 		$context['user']['messages'] = 0;
3093 3273
 		$context['user']['unread_messages'] = 0;
@@ -3095,12 +3275,14 @@  discard block
 block discarded – undo
3095 3275
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3096 3276
 		$context['user']['popup_messages'] = false;
3097 3277
 
3098
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3099
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3278
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3279
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3280
+		}
3100 3281
 
3101 3282
 		// If we've upgraded recently, go easy on the passwords.
3102
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3103
-			$context['disable_login_hashing'] = true;
3283
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3284
+					$context['disable_login_hashing'] = true;
3285
+		}
3104 3286
 	}
3105 3287
 
3106 3288
 	// Setup the main menu items.
@@ -3113,8 +3295,8 @@  discard block
 block discarded – undo
3113 3295
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3114 3296
 
3115 3297
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3116
-	if ($context['show_pm_popup'])
3117
-		addInlineJavaScript('
3298
+	if ($context['show_pm_popup']) {
3299
+			addInlineJavaScript('
3118 3300
 		jQuery(document).ready(function($) {
3119 3301
 			new smc_Popup({
3120 3302
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3122,15 +3304,17 @@  discard block
 block discarded – undo
3122 3304
 				icon_class: \'generic_icons mail_new\'
3123 3305
 			});
3124 3306
 		});');
3307
+	}
3125 3308
 
3126 3309
 	// Add a generic "Are you sure?" confirmation message.
3127 3310
 	addInlineJavaScript('
3128 3311
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3129 3312
 
3130 3313
 	// Now add the capping code for avatars.
3131
-	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')
3132
-		addInlineCss('
3314
+	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') {
3315
+			addInlineCss('
3133 3316
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3317
+	}
3134 3318
 
3135 3319
 	// This looks weird, but it's because BoardIndex.php references the variable.
3136 3320
 	$context['common_stats']['latest_member'] = array(
@@ -3147,11 +3331,13 @@  discard block
 block discarded – undo
3147 3331
 	);
3148 3332
 	$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']);
3149 3333
 
3150
-	if (empty($settings['theme_version']))
3151
-		addJavaScriptVar('smf_scripturl', $scripturl);
3334
+	if (empty($settings['theme_version'])) {
3335
+			addJavaScriptVar('smf_scripturl', $scripturl);
3336
+	}
3152 3337
 
3153
-	if (!isset($context['page_title']))
3154
-		$context['page_title'] = '';
3338
+	if (!isset($context['page_title'])) {
3339
+			$context['page_title'] = '';
3340
+	}
3155 3341
 
3156 3342
 	// Set some specific vars.
3157 3343
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3161,21 +3347,23 @@  discard block
 block discarded – undo
3161 3347
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3162 3348
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3163 3349
 
3164
-	if (!empty($context['meta_keywords']))
3165
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3350
+	if (!empty($context['meta_keywords'])) {
3351
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3352
+	}
3166 3353
 
3167
-	if (!empty($context['canonical_url']))
3168
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3354
+	if (!empty($context['canonical_url'])) {
3355
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3356
+	}
3169 3357
 
3170
-	if (!empty($settings['og_image']))
3171
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3358
+	if (!empty($settings['og_image'])) {
3359
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3360
+	}
3172 3361
 
3173 3362
 	if (!empty($context['meta_description']))
3174 3363
 	{
3175 3364
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3176 3365
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3177
-	}
3178
-	else
3366
+	} else
3179 3367
 	{
3180 3368
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3181 3369
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3200,8 +3388,9 @@  discard block
 block discarded – undo
3200 3388
 	$memory_needed = memoryReturnBytes($needed);
3201 3389
 
3202 3390
 	// should we account for how much is currently being used?
3203
-	if ($in_use)
3204
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3391
+	if ($in_use) {
3392
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3393
+	}
3205 3394
 
3206 3395
 	// if more is needed, request it
3207 3396
 	if ($memory_current < $memory_needed)
@@ -3224,8 +3413,9 @@  discard block
 block discarded – undo
3224 3413
  */
3225 3414
 function memoryReturnBytes($val)
3226 3415
 {
3227
-	if (is_integer($val))
3228
-		return $val;
3416
+	if (is_integer($val)) {
3417
+			return $val;
3418
+	}
3229 3419
 
3230 3420
 	// Separate the number from the designator
3231 3421
 	$val = trim($val);
@@ -3261,10 +3451,11 @@  discard block
 block discarded – undo
3261 3451
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3262 3452
 
3263 3453
 		// Are we debugging the template/html content?
3264
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3265
-			header('Content-Type: application/xhtml+xml');
3266
-		elseif (!isset($_REQUEST['xml']))
3267
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3454
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3455
+					header('Content-Type: application/xhtml+xml');
3456
+		} elseif (!isset($_REQUEST['xml'])) {
3457
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3458
+		}
3268 3459
 	}
3269 3460
 
3270 3461
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3273,8 +3464,9 @@  discard block
 block discarded – undo
3273 3464
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3274 3465
 	{
3275 3466
 		$position = array_search('body', $context['template_layers']);
3276
-		if ($position === false)
3277
-			$position = array_search('main', $context['template_layers']);
3467
+		if ($position === false) {
3468
+					$position = array_search('main', $context['template_layers']);
3469
+		}
3278 3470
 
3279 3471
 		if ($position !== false)
3280 3472
 		{
@@ -3302,23 +3494,25 @@  discard block
 block discarded – undo
3302 3494
 
3303 3495
 			foreach ($securityFiles as $i => $securityFile)
3304 3496
 			{
3305
-				if (!file_exists($boarddir . '/' . $securityFile))
3306
-					unset($securityFiles[$i]);
3497
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3498
+									unset($securityFiles[$i]);
3499
+				}
3307 3500
 			}
3308 3501
 
3309 3502
 			// We are already checking so many files...just few more doesn't make any difference! :P
3310
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3311
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3312
-
3313
-			else
3314
-				$path = $modSettings['attachmentUploadDir'];
3503
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3504
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3505
+			} else {
3506
+							$path = $modSettings['attachmentUploadDir'];
3507
+			}
3315 3508
 
3316 3509
 			secureDirectory($path, true);
3317 3510
 			secureDirectory($cachedir);
3318 3511
 
3319 3512
 			// If agreement is enabled, at least the english version shall exists
3320
-			if ($modSettings['requireAgreement'])
3321
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3513
+			if ($modSettings['requireAgreement']) {
3514
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3515
+			}
3322 3516
 
3323 3517
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3324 3518
 			{
@@ -3333,18 +3527,21 @@  discard block
 block discarded – undo
3333 3527
 					echo '
3334 3528
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3335 3529
 
3336
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3337
-						echo '
3530
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3531
+											echo '
3338 3532
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3533
+					}
3339 3534
 				}
3340 3535
 
3341
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3342
-					echo '
3536
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3537
+									echo '
3343 3538
 				<strong>', $txt['cache_writable'], '</strong><br>';
3539
+				}
3344 3540
 
3345
-				if (!empty($agreement))
3346
-					echo '
3541
+				if (!empty($agreement)) {
3542
+									echo '
3347 3543
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3544
+				}
3348 3545
 
3349 3546
 				echo '
3350 3547
 			</p>
@@ -3359,16 +3556,18 @@  discard block
 block discarded – undo
3359 3556
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3360 3557
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3361 3558
 
3362
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3363
-				echo '
3559
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3560
+							echo '
3364 3561
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3562
+			}
3365 3563
 
3366
-			if (!empty($_SESSION['ban']['expire_time']))
3367
-				echo '
3564
+			if (!empty($_SESSION['ban']['expire_time'])) {
3565
+							echo '
3368 3566
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3369
-			else
3370
-				echo '
3567
+			} else {
3568
+							echo '
3371 3569
 					<div>', $txt['your_ban_expires_never'], '</div>';
3570
+			}
3372 3571
 
3373 3572
 			echo '
3374 3573
 				</div>';
@@ -3384,8 +3583,9 @@  discard block
 block discarded – undo
3384 3583
 	global $forum_copyright, $software_year, $forum_version;
3385 3584
 
3386 3585
 	// Don't display copyright for things like SSI.
3387
-	if (!isset($forum_version) || !isset($software_year))
3388
-		return;
3586
+	if (!isset($forum_version) || !isset($software_year)) {
3587
+			return;
3588
+	}
3389 3589
 
3390 3590
 	// Put in the version...
3391 3591
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3403,9 +3603,10 @@  discard block
 block discarded – undo
3403 3603
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3404 3604
 	$context['load_queries'] = $db_count;
3405 3605
 
3406
-	foreach (array_reverse($context['template_layers']) as $layer)
3407
-		loadSubTemplate($layer . '_below', true);
3408
-}
3606
+	foreach (array_reverse($context['template_layers']) as $layer) {
3607
+			loadSubTemplate($layer . '_below', true);
3608
+	}
3609
+	}
3409 3610
 
3410 3611
 /**
3411 3612
  * Output the Javascript files
@@ -3436,8 +3637,7 @@  discard block
 block discarded – undo
3436 3637
 			{
3437 3638
 				echo '
3438 3639
 		var ', $key, ';';
3439
-			}
3440
-			else
3640
+			} else
3441 3641
 			{
3442 3642
 				echo '
3443 3643
 		var ', $key, ' = ', $value, ';';
@@ -3452,26 +3652,27 @@  discard block
 block discarded – undo
3452 3652
 	foreach ($context['javascript_files'] as $id => $js_file)
3453 3653
 	{
3454 3654
 		// Last minute call! allow theme authors to disable single files.
3455
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3456
-			continue;
3655
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3656
+					continue;
3657
+		}
3457 3658
 
3458 3659
 		// By default all files don't get minimized unless the file explicitly says so!
3459 3660
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3460 3661
 		{
3461
-			if ($do_deferred && !empty($js_file['options']['defer']))
3462
-				$toMinifyDefer[] = $js_file;
3463
-
3464
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3465
-				$toMinify[] = $js_file;
3662
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3663
+							$toMinifyDefer[] = $js_file;
3664
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3665
+							$toMinify[] = $js_file;
3666
+			}
3466 3667
 
3467 3668
 			// Grab a random seed.
3468
-			if (!isset($minSeed))
3469
-				$minSeed = $js_file['options']['seed'];
3470
-		}
3471
-
3472
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3473
-			echo '
3669
+			if (!isset($minSeed)) {
3670
+							$minSeed = $js_file['options']['seed'];
3671
+			}
3672
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3673
+					echo '
3474 3674
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3675
+		}
3475 3676
 	}
3476 3677
 
3477 3678
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3479,14 +3680,14 @@  discard block
 block discarded – undo
3479 3680
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3480 3681
 
3481 3682
 		// Minify process couldn't work, print each individual files.
3482
-		if (!empty($result) && is_array($result))
3483
-			foreach ($result as $minFailedFile)
3683
+		if (!empty($result) && is_array($result)) {
3684
+					foreach ($result as $minFailedFile)
3484 3685
 				echo '
3485 3686
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3486
-
3487
-		else
3488
-			echo '
3687
+		} else {
3688
+					echo '
3489 3689
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3690
+		}
3490 3691
 	}
3491 3692
 
3492 3693
 	// Inline JavaScript - Actually useful some times!
@@ -3497,8 +3698,9 @@  discard block
 block discarded – undo
3497 3698
 			echo '
3498 3699
 <script>';
3499 3700
 
3500
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3501
-				echo $js_code;
3701
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3702
+							echo $js_code;
3703
+			}
3502 3704
 
3503 3705
 			echo '
3504 3706
 </script>';
@@ -3509,8 +3711,9 @@  discard block
 block discarded – undo
3509 3711
 			echo '
3510 3712
 	<script>';
3511 3713
 
3512
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3513
-				echo $js_code;
3714
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3715
+							echo $js_code;
3716
+			}
3514 3717
 
3515 3718
 			echo '
3516 3719
 	</script>';
@@ -3535,8 +3738,9 @@  discard block
 block discarded – undo
3535 3738
 	foreach ($context['css_files'] as $id => $file)
3536 3739
 	{
3537 3740
 		// Last minute call! allow theme authors to disable single files.
3538
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3539
-			continue;
3741
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3742
+					continue;
3743
+		}
3540 3744
 
3541 3745
 		// By default all files don't get minimized unless the file explicitly says so!
3542 3746
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3544,12 +3748,12 @@  discard block
 block discarded – undo
3544 3748
 			$toMinify[] = $file;
3545 3749
 
3546 3750
 			// Grab a random seed.
3547
-			if (!isset($minSeed))
3548
-				$minSeed = $file['options']['seed'];
3751
+			if (!isset($minSeed)) {
3752
+							$minSeed = $file['options']['seed'];
3753
+			}
3754
+		} else {
3755
+					$normal[] = $file['fileUrl'];
3549 3756
 		}
3550
-
3551
-		else
3552
-			$normal[] = $file['fileUrl'];
3553 3757
 	}
3554 3758
 
3555 3759
 	if (!empty($toMinify))
@@ -3557,28 +3761,30 @@  discard block
 block discarded – undo
3557 3761
 		$result = custMinify($toMinify, 'css');
3558 3762
 
3559 3763
 		// Minify process couldn't work, print each individual files.
3560
-		if (!empty($result) && is_array($result))
3561
-			foreach ($result as $minFailedFile)
3764
+		if (!empty($result) && is_array($result)) {
3765
+					foreach ($result as $minFailedFile)
3562 3766
 				echo '
3563 3767
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3564
-
3565
-		else
3566
-			echo '
3768
+		} else {
3769
+					echo '
3567 3770
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3771
+		}
3568 3772
 	}
3569 3773
 
3570 3774
 	// Print the rest after the minified files.
3571
-	if (!empty($normal))
3572
-		foreach ($normal as $nf)
3775
+	if (!empty($normal)) {
3776
+			foreach ($normal as $nf)
3573 3777
 			echo '
3574 3778
 	<link rel="stylesheet" href="', $nf ,'">';
3779
+	}
3575 3780
 
3576 3781
 	if ($db_show_debug === true)
3577 3782
 	{
3578 3783
 		// Try to keep only what's useful.
3579 3784
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3580
-		foreach ($context['css_files'] as $file)
3581
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3785
+		foreach ($context['css_files'] as $file) {
3786
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3787
+		}
3582 3788
 	}
3583 3789
 
3584 3790
 	if (!empty($context['css_header']))
@@ -3586,9 +3792,10 @@  discard block
 block discarded – undo
3586 3792
 		echo '
3587 3793
 	<style>';
3588 3794
 
3589
-		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3795
+		foreach ($context['css_header'] as $css) {
3796
+					echo $css .'
3591 3797
 	';
3798
+		}
3592 3799
 
3593 3800
 		echo'
3594 3801
 	</style>';
@@ -3612,15 +3819,17 @@  discard block
 block discarded – undo
3612 3819
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3613 3820
 	$data = !empty($data) ? $data : false;
3614 3821
 
3615
-	if (empty($type) || empty($data))
3616
-		return false;
3822
+	if (empty($type) || empty($data)) {
3823
+			return false;
3824
+	}
3617 3825
 
3618 3826
 	// Did we already did this?
3619 3827
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3620 3828
 
3621 3829
 	// Already done?
3622
-	if (!empty($toCache))
3623
-		return true;
3830
+	if (!empty($toCache)) {
3831
+			return true;
3832
+	}
3624 3833
 
3625 3834
 	// No namespaces, sorry!
3626 3835
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3702,8 +3911,9 @@  discard block
 block discarded – undo
3702 3911
 	global $modSettings, $smcFunc;
3703 3912
 
3704 3913
 	// Just make up a nice hash...
3705
-	if ($new)
3706
-		return sha1(md5($filename . time()) . mt_rand());
3914
+	if ($new) {
3915
+			return sha1(md5($filename . time()) . mt_rand());
3916
+	}
3707 3917
 
3708 3918
 	// Just make sure that attachment id is only a int
3709 3919
 	$attachment_id = (int) $attachment_id;
@@ -3720,23 +3930,25 @@  discard block
 block discarded – undo
3720 3930
 				'id_attach' => $attachment_id,
3721 3931
 			));
3722 3932
 
3723
-		if ($smcFunc['db_num_rows']($request) === 0)
3724
-			return false;
3933
+		if ($smcFunc['db_num_rows']($request) === 0) {
3934
+					return false;
3935
+		}
3725 3936
 
3726 3937
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3727 3938
 		$smcFunc['db_free_result']($request);
3728 3939
 	}
3729 3940
 
3730 3941
 	// Still no hash? mmm...
3731
-	if (empty($file_hash))
3732
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3942
+	if (empty($file_hash)) {
3943
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3944
+	}
3733 3945
 
3734 3946
 	// Are we using multiple directories?
3735
-	if (is_array($modSettings['attachmentUploadDir']))
3736
-		$path = $modSettings['attachmentUploadDir'][$dir];
3737
-
3738
-	else
3739
-		$path = $modSettings['attachmentUploadDir'];
3947
+	if (is_array($modSettings['attachmentUploadDir'])) {
3948
+			$path = $modSettings['attachmentUploadDir'][$dir];
3949
+	} else {
3950
+			$path = $modSettings['attachmentUploadDir'];
3951
+	}
3740 3952
 
3741 3953
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3742 3954
 }
@@ -3751,8 +3963,9 @@  discard block
 block discarded – undo
3751 3963
 function ip2range($fullip)
3752 3964
 {
3753 3965
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3754
-	if ($fullip == 'unknown')
3755
-		$fullip = '255.255.255.255';
3966
+	if ($fullip == 'unknown') {
3967
+			$fullip = '255.255.255.255';
3968
+	}
3756 3969
 
3757 3970
 	$ip_parts = explode('-', $fullip);
3758 3971
 	$ip_array = array();
@@ -3776,10 +3989,11 @@  discard block
 block discarded – undo
3776 3989
 		$ip_array['low'] = $ip_parts[0];
3777 3990
 		$ip_array['high'] = $ip_parts[1];
3778 3991
 		return $ip_array;
3779
-	}
3780
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3992
+	} elseif (count($ip_parts) == 2) {
3993
+		// if ip 22.22.*-22.22.*
3781 3994
 	{
3782 3995
 		$valid_low = isValidIP($ip_parts[0]);
3996
+	}
3783 3997
 		$valid_high = isValidIP($ip_parts[1]);
3784 3998
 		$count = 0;
3785 3999
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3794,7 +4008,9 @@  discard block
 block discarded – undo
3794 4008
 				$ip_parts[0] .= $mode . $min;
3795 4009
 				$valid_low = isValidIP($ip_parts[0]);
3796 4010
 				$count++;
3797
-				if ($count > 9) break;
4011
+				if ($count > 9) {
4012
+					break;
4013
+				}
3798 4014
 			}
3799 4015
 		}
3800 4016
 
@@ -3808,7 +4024,9 @@  discard block
 block discarded – undo
3808 4024
 				$ip_parts[1] .= $mode . $max;
3809 4025
 				$valid_high = isValidIP($ip_parts[1]);
3810 4026
 				$count++;
3811
-				if ($count > 9) break;
4027
+				if ($count > 9) {
4028
+					break;
4029
+				}
3812 4030
 			}
3813 4031
 		}
3814 4032
 
@@ -3833,46 +4051,54 @@  discard block
 block discarded – undo
3833 4051
 {
3834 4052
 	global $modSettings;
3835 4053
 
3836
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3837
-		return $host;
4054
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4055
+			return $host;
4056
+	}
3838 4057
 	$t = microtime();
3839 4058
 
3840 4059
 	// Try the Linux host command, perhaps?
3841 4060
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3842 4061
 	{
3843
-		if (!isset($modSettings['host_to_dis']))
3844
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3845
-		else
3846
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4062
+		if (!isset($modSettings['host_to_dis'])) {
4063
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4064
+		} else {
4065
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4066
+		}
3847 4067
 
3848 4068
 		// Did host say it didn't find anything?
3849
-		if (strpos($test, 'not found') !== false)
3850
-			$host = '';
4069
+		if (strpos($test, 'not found') !== false) {
4070
+					$host = '';
4071
+		}
3851 4072
 		// Invalid server option?
3852
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3853
-			updateSettings(array('host_to_dis' => 1));
4073
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4074
+					updateSettings(array('host_to_dis' => 1));
4075
+		}
3854 4076
 		// Maybe it found something, after all?
3855
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3856
-			$host = $match[1];
4077
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4078
+					$host = $match[1];
4079
+		}
3857 4080
 	}
3858 4081
 
3859 4082
 	// This is nslookup; usually only Windows, but possibly some Unix?
3860 4083
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3861 4084
 	{
3862 4085
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3863
-		if (strpos($test, 'Non-existent domain') !== false)
3864
-			$host = '';
3865
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3866
-			$host = $match[1];
4086
+		if (strpos($test, 'Non-existent domain') !== false) {
4087
+					$host = '';
4088
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4089
+					$host = $match[1];
4090
+		}
3867 4091
 	}
3868 4092
 
3869 4093
 	// This is the last try :/.
3870
-	if (!isset($host) || $host === false)
3871
-		$host = @gethostbyaddr($ip);
4094
+	if (!isset($host) || $host === false) {
4095
+			$host = @gethostbyaddr($ip);
4096
+	}
3872 4097
 
3873 4098
 	// It took a long time, so let's cache it!
3874
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3875
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4099
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4100
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4101
+	}
3876 4102
 
3877 4103
 	return $host;
3878 4104
 }
@@ -3908,20 +4134,21 @@  discard block
 block discarded – undo
3908 4134
 			{
3909 4135
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3910 4136
 				$total = 0;
3911
-				for ($i = 0; $i < $max_chars; $i++)
3912
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4137
+				for ($i = 0; $i < $max_chars; $i++) {
4138
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4139
+				}
3913 4140
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3914 4141
 			}
3915 4142
 		}
3916 4143
 		return array_unique($returned_ints);
3917
-	}
3918
-	else
4144
+	} else
3919 4145
 	{
3920 4146
 		// Trim characters before and after and add slashes for database insertion.
3921 4147
 		$returned_words = array();
3922
-		foreach ($words as $word)
3923
-			if (($word = trim($word, '-_\'')) !== '')
4148
+		foreach ($words as $word) {
4149
+					if (($word = trim($word, '-_\'')) !== '')
3924 4150
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4151
+		}
3925 4152
 
3926 4153
 		// Filter out all words that occur more than once.
3927 4154
 		return array_unique($returned_words);
@@ -3943,16 +4170,18 @@  discard block
 block discarded – undo
3943 4170
 	global $settings, $txt;
3944 4171
 
3945 4172
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3946
-	if (function_exists('template_create_button') && !$force_use)
3947
-		return template_create_button($name, $alt, $label = '', $custom = '');
4173
+	if (function_exists('template_create_button') && !$force_use) {
4174
+			return template_create_button($name, $alt, $label = '', $custom = '');
4175
+	}
3948 4176
 
3949
-	if (!$settings['use_image_buttons'])
3950
-		return $txt[$alt];
3951
-	elseif (!empty($settings['use_buttons']))
3952
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3953
-	else
3954
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3955
-}
4177
+	if (!$settings['use_image_buttons']) {
4178
+			return $txt[$alt];
4179
+	} elseif (!empty($settings['use_buttons'])) {
4180
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4181
+	} else {
4182
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4183
+	}
4184
+	}
3956 4185
 
3957 4186
 /**
3958 4187
  * Sets up all of the top menu buttons
@@ -3995,9 +4224,10 @@  discard block
 block discarded – undo
3995 4224
 	var user_menus = new smc_PopupMenu();
3996 4225
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997 4226
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3998
-		if ($context['allow_pm'])
3999
-			addInlineJavaScript('
4227
+		if ($context['allow_pm']) {
4228
+					addInlineJavaScript('
4000 4229
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4230
+		}
4001 4231
 
4002 4232
 		if (!empty($modSettings['enable_ajax_alerts']))
4003 4233
 		{
@@ -4157,88 +4387,96 @@  discard block
 block discarded – undo
4157 4387
 
4158 4388
 		// Now we put the buttons in the context so the theme can use them.
4159 4389
 		$menu_buttons = array();
4160
-		foreach ($buttons as $act => $button)
4161
-			if (!empty($button['show']))
4390
+		foreach ($buttons as $act => $button) {
4391
+					if (!empty($button['show']))
4162 4392
 			{
4163 4393
 				$button['active_button'] = false;
4394
+		}
4164 4395
 
4165 4396
 				// This button needs some action.
4166
-				if (isset($button['action_hook']))
4167
-					$needs_action_hook = true;
4397
+				if (isset($button['action_hook'])) {
4398
+									$needs_action_hook = true;
4399
+				}
4168 4400
 
4169 4401
 				// Make sure the last button truly is the last button.
4170 4402
 				if (!empty($button['is_last']))
4171 4403
 				{
4172
-					if (isset($last_button))
4173
-						unset($menu_buttons[$last_button]['is_last']);
4404
+					if (isset($last_button)) {
4405
+											unset($menu_buttons[$last_button]['is_last']);
4406
+					}
4174 4407
 					$last_button = $act;
4175 4408
 				}
4176 4409
 
4177 4410
 				// Go through the sub buttons if there are any.
4178
-				if (!empty($button['sub_buttons']))
4179
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4411
+				if (!empty($button['sub_buttons'])) {
4412
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4180 4413
 					{
4181 4414
 						if (empty($subbutton['show']))
4182 4415
 							unset($button['sub_buttons'][$key]);
4416
+				}
4183 4417
 
4184 4418
 						// 2nd level sub buttons next...
4185 4419
 						if (!empty($subbutton['sub_buttons']))
4186 4420
 						{
4187 4421
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4188 4422
 							{
4189
-								if (empty($sub_button2['show']))
4190
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4423
+								if (empty($sub_button2['show'])) {
4424
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4425
+								}
4191 4426
 							}
4192 4427
 						}
4193 4428
 					}
4194 4429
 
4195 4430
 				// Does this button have its own icon?
4196
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4197
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4198
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4199
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4200
-				elseif (isset($button['icon']))
4201
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4202
-				else
4203
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4431
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4432
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4433
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4434
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4435
+				} elseif (isset($button['icon'])) {
4436
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4437
+				} else {
4438
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4439
+				}
4204 4440
 
4205 4441
 				$menu_buttons[$act] = $button;
4206 4442
 			}
4207 4443
 
4208
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4209
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4444
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4445
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4446
+		}
4210 4447
 	}
4211 4448
 
4212 4449
 	$context['menu_buttons'] = $menu_buttons;
4213 4450
 
4214 4451
 	// Logging out requires the session id in the url.
4215
-	if (isset($context['menu_buttons']['logout']))
4216
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4452
+	if (isset($context['menu_buttons']['logout'])) {
4453
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4454
+	}
4217 4455
 
4218 4456
 	// Figure out which action we are doing so we can set the active tab.
4219 4457
 	// Default to home.
4220 4458
 	$current_action = 'home';
4221 4459
 
4222
-	if (isset($context['menu_buttons'][$context['current_action']]))
4223
-		$current_action = $context['current_action'];
4224
-	elseif ($context['current_action'] == 'search2')
4225
-		$current_action = 'search';
4226
-	elseif ($context['current_action'] == 'theme')
4227
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4228
-	elseif ($context['current_action'] == 'register2')
4229
-		$current_action = 'register';
4230
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4231
-		$current_action = 'login';
4232
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4233
-		$current_action = 'moderate';
4460
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4461
+			$current_action = $context['current_action'];
4462
+	} elseif ($context['current_action'] == 'search2') {
4463
+			$current_action = 'search';
4464
+	} elseif ($context['current_action'] == 'theme') {
4465
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4466
+	} elseif ($context['current_action'] == 'register2') {
4467
+			$current_action = 'register';
4468
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4469
+			$current_action = 'login';
4470
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4471
+			$current_action = 'moderate';
4472
+	}
4234 4473
 
4235 4474
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4236 4475
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4237 4476
 	{
4238 4477
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4239 4478
 		$context[$current_action] = true;
4240
-	}
4241
-	elseif ($context['current_action'] == 'pm')
4479
+	} elseif ($context['current_action'] == 'pm')
4242 4480
 	{
4243 4481
 		$current_action = 'self_pm';
4244 4482
 		$context['self_pm'] = true;
@@ -4281,12 +4519,14 @@  discard block
 block discarded – undo
4281 4519
 	}
4282 4520
 
4283 4521
 	// Not all actions are simple.
4284
-	if (!empty($needs_action_hook))
4285
-		call_integration_hook('integrate_current_action', array(&$current_action));
4522
+	if (!empty($needs_action_hook)) {
4523
+			call_integration_hook('integrate_current_action', array(&$current_action));
4524
+	}
4286 4525
 
4287
-	if (isset($context['menu_buttons'][$current_action]))
4288
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4289
-}
4526
+	if (isset($context['menu_buttons'][$current_action])) {
4527
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4528
+	}
4529
+	}
4290 4530
 
4291 4531
 /**
4292 4532
  * Generate a random seed and ensure it's stored in settings.
@@ -4310,16 +4550,19 @@  discard block
 block discarded – undo
4310 4550
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4311 4551
 	global $context, $txt;
4312 4552
 
4313
-	if ($db_show_debug === true)
4314
-		$context['debug']['hooks'][] = $hook;
4553
+	if ($db_show_debug === true) {
4554
+			$context['debug']['hooks'][] = $hook;
4555
+	}
4315 4556
 
4316 4557
 	// Need to have some control.
4317
-	if (!isset($context['instances']))
4318
-		$context['instances'] = array();
4558
+	if (!isset($context['instances'])) {
4559
+			$context['instances'] = array();
4560
+	}
4319 4561
 
4320 4562
 	$results = array();
4321
-	if (empty($modSettings[$hook]))
4322
-		return $results;
4563
+	if (empty($modSettings[$hook])) {
4564
+			return $results;
4565
+	}
4323 4566
 
4324 4567
 	// Define some needed vars.
4325 4568
 	$function = false;
@@ -4329,14 +4572,16 @@  discard block
 block discarded – undo
4329 4572
 	foreach ($functions as $function)
4330 4573
 	{
4331 4574
 		// Hook has been marked as "disabled". Skip it!
4332
-		if (strpos($function, '!') !== false)
4333
-			continue;
4575
+		if (strpos($function, '!') !== false) {
4576
+					continue;
4577
+		}
4334 4578
 
4335 4579
 		$call = call_helper($function, true);
4336 4580
 
4337 4581
 		// Is it valid?
4338
-		if (!empty($call))
4339
-			$results[$function] = call_user_func_array($call, $parameters);
4582
+		if (!empty($call)) {
4583
+					$results[$function] = call_user_func_array($call, $parameters);
4584
+		}
4340 4585
 
4341 4586
 		// Whatever it was suppose to call, it failed :(
4342 4587
 		elseif (!empty($function))
@@ -4352,8 +4597,9 @@  discard block
 block discarded – undo
4352 4597
 			}
4353 4598
 
4354 4599
 			// "Assume" the file resides on $boarddir somewhere...
4355
-			else
4356
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4600
+			else {
4601
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4602
+			}
4357 4603
 		}
4358 4604
 	}
4359 4605
 
@@ -4375,12 +4621,14 @@  discard block
 block discarded – undo
4375 4621
 	global $smcFunc, $modSettings;
4376 4622
 
4377 4623
 	// Any objects?
4378
-	if ($object)
4379
-		$function = $function . '#';
4624
+	if ($object) {
4625
+			$function = $function . '#';
4626
+	}
4380 4627
 
4381 4628
 	// Any files  to load?
4382
-	if (!empty($file) && is_string($file))
4383
-		$function = $file . (!empty($function) ? '|' . $function : '');
4629
+	if (!empty($file) && is_string($file)) {
4630
+			$function = $file . (!empty($function) ? '|' . $function : '');
4631
+	}
4384 4632
 
4385 4633
 	// Get the correct string.
4386 4634
 	$integration_call = $function;
@@ -4402,13 +4650,14 @@  discard block
 block discarded – undo
4402 4650
 		if (!empty($current_functions))
4403 4651
 		{
4404 4652
 			$current_functions = explode(',', $current_functions);
4405
-			if (in_array($integration_call, $current_functions))
4406
-				return;
4653
+			if (in_array($integration_call, $current_functions)) {
4654
+							return;
4655
+			}
4407 4656
 
4408 4657
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4658
+		} else {
4659
+					$permanent_functions = array($integration_call);
4409 4660
 		}
4410
-		else
4411
-			$permanent_functions = array($integration_call);
4412 4661
 
4413 4662
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4414 4663
 	}
@@ -4417,8 +4666,9 @@  discard block
 block discarded – undo
4417 4666
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4418 4667
 
4419 4668
 	// Do nothing, if it's already there.
4420
-	if (in_array($integration_call, $functions))
4421
-		return;
4669
+	if (in_array($integration_call, $functions)) {
4670
+			return;
4671
+	}
4422 4672
 
4423 4673
 	$functions[] = $integration_call;
4424 4674
 	$modSettings[$hook] = implode(',', $functions);
@@ -4441,12 +4691,14 @@  discard block
 block discarded – undo
4441 4691
 	global $smcFunc, $modSettings;
4442 4692
 
4443 4693
 	// Any objects?
4444
-	if ($object)
4445
-		$function = $function . '#';
4694
+	if ($object) {
4695
+			$function = $function . '#';
4696
+	}
4446 4697
 
4447 4698
 	// Any files  to load?
4448
-	if (!empty($file) && is_string($file))
4449
-		$function = $file . '|' . $function;
4699
+	if (!empty($file) && is_string($file)) {
4700
+			$function = $file . '|' . $function;
4701
+	}
4450 4702
 
4451 4703
 	// Get the correct string.
4452 4704
 	$integration_call = $function;
@@ -4467,16 +4719,18 @@  discard block
 block discarded – undo
4467 4719
 	{
4468 4720
 		$current_functions = explode(',', $current_functions);
4469 4721
 
4470
-		if (in_array($integration_call, $current_functions))
4471
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4722
+		if (in_array($integration_call, $current_functions)) {
4723
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4724
+		}
4472 4725
 	}
4473 4726
 
4474 4727
 	// Turn the function list into something usable.
4475 4728
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4476 4729
 
4477 4730
 	// You can only remove it if it's available.
4478
-	if (!in_array($integration_call, $functions))
4479
-		return;
4731
+	if (!in_array($integration_call, $functions)) {
4732
+			return;
4733
+	}
4480 4734
 
4481 4735
 	$functions = array_diff($functions, array($integration_call));
4482 4736
 	$modSettings[$hook] = implode(',', $functions);
@@ -4497,17 +4751,20 @@  discard block
 block discarded – undo
4497 4751
 	global $context, $smcFunc, $txt, $db_show_debug;
4498 4752
 
4499 4753
 	// Really?
4500
-	if (empty($string))
4501
-		return false;
4754
+	if (empty($string)) {
4755
+			return false;
4756
+	}
4502 4757
 
4503 4758
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4504 4759
 	// A closure? should be a callable one.
4505
-	if (is_array($string) || $string instanceof Closure)
4506
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4760
+	if (is_array($string) || $string instanceof Closure) {
4761
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4762
+	}
4507 4763
 
4508 4764
 	// No full objects, sorry! pass a method or a property instead!
4509
-	if (is_object($string))
4510
-		return false;
4765
+	if (is_object($string)) {
4766
+			return false;
4767
+	}
4511 4768
 
4512 4769
 	// Stay vitaminized my friends...
4513 4770
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4516,8 +4773,9 @@  discard block
 block discarded – undo
4516 4773
 	$string = load_file($string);
4517 4774
 
4518 4775
 	// Loaded file failed
4519
-	if (empty($string))
4520
-		return false;
4776
+	if (empty($string)) {
4777
+			return false;
4778
+	}
4521 4779
 
4522 4780
 	// Found a method.
4523 4781
 	if (strpos($string, '::') !== false)
@@ -4538,8 +4796,9 @@  discard block
 block discarded – undo
4538 4796
 				// Add another one to the list.
4539 4797
 				if ($db_show_debug === true)
4540 4798
 				{
4541
-					if (!isset($context['debug']['instances']))
4542
-						$context['debug']['instances'] = array();
4799
+					if (!isset($context['debug']['instances'])) {
4800
+											$context['debug']['instances'] = array();
4801
+					}
4543 4802
 
4544 4803
 					$context['debug']['instances'][$class] = $class;
4545 4804
 				}
@@ -4549,13 +4808,15 @@  discard block
 block discarded – undo
4549 4808
 		}
4550 4809
 
4551 4810
 		// Right then. This is a call to a static method.
4552
-		else
4553
-			$func = array($class, $method);
4811
+		else {
4812
+					$func = array($class, $method);
4813
+		}
4554 4814
 	}
4555 4815
 
4556 4816
 	// Nope! just a plain regular function.
4557
-	else
4558
-		$func = $string;
4817
+	else {
4818
+			$func = $string;
4819
+	}
4559 4820
 
4560 4821
 	// Right, we got what we need, time to do some checks.
4561 4822
 	if (!is_callable($func, false, $callable_name))
@@ -4571,17 +4832,18 @@  discard block
 block discarded – undo
4571 4832
 	else
4572 4833
 	{
4573 4834
 		// What are we gonna do about it?
4574
-		if ($return)
4575
-			return $func;
4835
+		if ($return) {
4836
+					return $func;
4837
+		}
4576 4838
 
4577 4839
 		// If this is a plain function, avoid the heat of calling call_user_func().
4578 4840
 		else
4579 4841
 		{
4580
-			if (is_array($func))
4581
-				call_user_func($func);
4582
-
4583
-			else
4584
-				$func();
4842
+			if (is_array($func)) {
4843
+							call_user_func($func);
4844
+			} else {
4845
+							$func();
4846
+			}
4585 4847
 		}
4586 4848
 	}
4587 4849
 }
@@ -4598,31 +4860,34 @@  discard block
 block discarded – undo
4598 4860
 {
4599 4861
 	global $sourcedir, $txt, $boarddir, $settings;
4600 4862
 
4601
-	if (empty($string))
4602
-		return false;
4863
+	if (empty($string)) {
4864
+			return false;
4865
+	}
4603 4866
 
4604 4867
 	if (strpos($string, '|') !== false)
4605 4868
 	{
4606 4869
 		list ($file, $string) = explode('|', $string);
4607 4870
 
4608 4871
 		// Match the wildcards to their regular vars.
4609
-		if (empty($settings['theme_dir']))
4610
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4611
-
4612
-		else
4613
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4872
+		if (empty($settings['theme_dir'])) {
4873
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4874
+		} else {
4875
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4876
+		}
4614 4877
 
4615 4878
 		// Load the file if it can be loaded.
4616
-		if (file_exists($absPath))
4617
-			require_once($absPath);
4879
+		if (file_exists($absPath)) {
4880
+					require_once($absPath);
4881
+		}
4618 4882
 
4619 4883
 		// No? try a fallback to $sourcedir
4620 4884
 		else
4621 4885
 		{
4622 4886
 			$absPath = $sourcedir .'/'. $file;
4623 4887
 
4624
-			if (file_exists($absPath))
4625
-				require_once($absPath);
4888
+			if (file_exists($absPath)) {
4889
+							require_once($absPath);
4890
+			}
4626 4891
 
4627 4892
 			// Sorry, can't do much for you at this point.
4628 4893
 			else
@@ -4649,8 +4914,9 @@  discard block
 block discarded – undo
4649 4914
 	global $user_info, $smcFunc;
4650 4915
 
4651 4916
 	// Make sure we have something to work with.
4652
-	if (empty($topic))
4653
-		return array();
4917
+	if (empty($topic)) {
4918
+			return array();
4919
+	}
4654 4920
 
4655 4921
 
4656 4922
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4673,8 +4939,9 @@  discard block
 block discarded – undo
4673 4939
 				'topic' => $topic,
4674 4940
 			)
4675 4941
 		);
4676
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4677
-			$temp[] = (int) $row['content_id'];
4942
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4943
+					$temp[] = (int) $row['content_id'];
4944
+		}
4678 4945
 
4679 4946
 		cache_put_data($cache_key, $temp, $ttl);
4680 4947
 	}
@@ -4695,8 +4962,9 @@  discard block
 block discarded – undo
4695 4962
 {
4696 4963
 	global $context;
4697 4964
 
4698
-	if (empty($string))
4699
-		return $string;
4965
+	if (empty($string)) {
4966
+			return $string;
4967
+	}
4700 4968
 
4701 4969
 	// UTF-8 occurences of MS special characters
4702 4970
 	$findchars_utf8 = array(
@@ -4737,10 +5005,11 @@  discard block
 block discarded – undo
4737 5005
 		'--',	// &mdash;
4738 5006
 	);
4739 5007
 
4740
-	if ($context['utf8'])
4741
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4742
-	else
4743
-		$string = str_replace($findchars_iso, $replacechars, $string);
5008
+	if ($context['utf8']) {
5009
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5010
+	} else {
5011
+			$string = str_replace($findchars_iso, $replacechars, $string);
5012
+	}
4744 5013
 
4745 5014
 	return $string;
4746 5015
 }
@@ -4759,49 +5028,59 @@  discard block
 block discarded – undo
4759 5028
 {
4760 5029
 	global $context;
4761 5030
 
4762
-	if (!isset($matches[2]))
4763
-		return '';
5031
+	if (!isset($matches[2])) {
5032
+			return '';
5033
+	}
4764 5034
 
4765 5035
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4766 5036
 
4767 5037
 	// remove left to right / right to left overrides
4768
-	if ($num === 0x202D || $num === 0x202E)
4769
-		return '';
5038
+	if ($num === 0x202D || $num === 0x202E) {
5039
+			return '';
5040
+	}
4770 5041
 
4771 5042
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4772
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4773
-		return '&#' . $num . ';';
5043
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5044
+			return '&#' . $num . ';';
5045
+	}
4774 5046
 
4775 5047
 	if (empty($context['utf8']))
4776 5048
 	{
4777 5049
 		// no control characters
4778
-		if ($num < 0x20)
4779
-			return '';
5050
+		if ($num < 0x20) {
5051
+					return '';
5052
+		}
4780 5053
 		// text is text
4781
-		elseif ($num < 0x80)
4782
-			return chr($num);
5054
+		elseif ($num < 0x80) {
5055
+					return chr($num);
5056
+		}
4783 5057
 		// all others get html-ised
4784
-		else
4785
-			return '&#' . $matches[2] . ';';
4786
-	}
4787
-	else
5058
+		else {
5059
+					return '&#' . $matches[2] . ';';
5060
+		}
5061
+	} else
4788 5062
 	{
4789 5063
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4790 5064
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4791
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4792
-			return '';
5065
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5066
+					return '';
5067
+		}
4793 5068
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4794
-		elseif ($num < 0x80)
4795
-			return chr($num);
5069
+		elseif ($num < 0x80) {
5070
+					return chr($num);
5071
+		}
4796 5072
 		// <0x800 (2048)
4797
-		elseif ($num < 0x800)
4798
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5073
+		elseif ($num < 0x800) {
5074
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5075
+		}
4799 5076
 		// < 0x10000 (65536)
4800
-		elseif ($num < 0x10000)
4801
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5077
+		elseif ($num < 0x10000) {
5078
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5079
+		}
4802 5080
 		// <= 0x10FFFF (1114111)
4803
-		else
4804
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5081
+		else {
5082
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5083
+		}
4805 5084
 	}
4806 5085
 }
4807 5086
 
@@ -4817,28 +5096,34 @@  discard block
 block discarded – undo
4817 5096
  */
4818 5097
 function fixchar__callback($matches)
4819 5098
 {
4820
-	if (!isset($matches[1]))
4821
-		return '';
5099
+	if (!isset($matches[1])) {
5100
+			return '';
5101
+	}
4822 5102
 
4823 5103
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4824 5104
 
4825 5105
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4826 5106
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4827
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4828
-		return '';
5107
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5108
+			return '';
5109
+	}
4829 5110
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4830
-	elseif ($num < 0x80)
4831
-		return chr($num);
5111
+	elseif ($num < 0x80) {
5112
+			return chr($num);
5113
+	}
4832 5114
 	// <0x800 (2048)
4833
-	elseif ($num < 0x800)
4834
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5115
+	elseif ($num < 0x800) {
5116
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5117
+	}
4835 5118
 	// < 0x10000 (65536)
4836
-	elseif ($num < 0x10000)
4837
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5119
+	elseif ($num < 0x10000) {
5120
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5121
+	}
4838 5122
 	// <= 0x10FFFF (1114111)
4839
-	else
4840
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4841
-}
5123
+	else {
5124
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5125
+	}
5126
+	}
4842 5127
 
4843 5128
 /**
4844 5129
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4851,17 +5136,19 @@  discard block
 block discarded – undo
4851 5136
  */
4852 5137
 function entity_fix__callback($matches)
4853 5138
 {
4854
-	if (!isset($matches[2]))
4855
-		return '';
5139
+	if (!isset($matches[2])) {
5140
+			return '';
5141
+	}
4856 5142
 
4857 5143
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4858 5144
 
4859 5145
 	// we don't allow control characters, characters out of range, byte markers, etc
4860
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4861
-		return '';
4862
-	else
4863
-		return '&#' . $num . ';';
4864
-}
5146
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5147
+			return '';
5148
+	} else {
5149
+			return '&#' . $num . ';';
5150
+	}
5151
+	}
4865 5152
 
4866 5153
 /**
4867 5154
  * Return a Gravatar URL based on
@@ -4885,18 +5172,23 @@  discard block
 block discarded – undo
4885 5172
 		$ratings = array('G', 'PG', 'R', 'X');
4886 5173
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4887 5174
 		$url_params = array();
4888
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4889
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4890
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4891
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4892
-		if (!empty($modSettings['avatar_max_width_external']))
4893
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4894
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4895
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5175
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5176
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5177
+		}
5178
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5179
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5180
+		}
5181
+		if (!empty($modSettings['avatar_max_width_external'])) {
5182
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5183
+		}
5184
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5185
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4896 5186
 				$size_string = $modSettings['avatar_max_height_external'];
5187
+		}
4897 5188
 
4898
-		if (!empty($size_string))
4899
-			$url_params[] = 's=' . $size_string;
5189
+		if (!empty($size_string)) {
5190
+					$url_params[] = 's=' . $size_string;
5191
+		}
4900 5192
 	}
4901 5193
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4902 5194
 
@@ -4915,22 +5207,26 @@  discard block
 block discarded – undo
4915 5207
 	static $timezones = null, $lastwhen = null;
4916 5208
 
4917 5209
 	// No point doing this over if we already did it once
4918
-	if (!empty($timezones) && $when == $lastwhen)
4919
-		return $timezones;
4920
-	else
4921
-		$lastwhen = $when;
5210
+	if (!empty($timezones) && $when == $lastwhen) {
5211
+			return $timezones;
5212
+	} else {
5213
+			$lastwhen = $when;
5214
+	}
4922 5215
 
4923 5216
 	// Parseable datetime string?
4924
-	if (is_int($timestamp = strtotime($when)))
4925
-		$when = $timestamp;
5217
+	if (is_int($timestamp = strtotime($when))) {
5218
+			$when = $timestamp;
5219
+	}
4926 5220
 
4927 5221
 	// A Unix timestamp?
4928
-	elseif (is_numeric($when))
4929
-		$when = intval($when);
5222
+	elseif (is_numeric($when)) {
5223
+			$when = intval($when);
5224
+	}
4930 5225
 
4931 5226
 	// Invalid value? Just get current Unix timestamp.
4932
-	else
4933
-		$when = time();
5227
+	else {
5228
+			$when = time();
5229
+	}
4934 5230
 
4935 5231
 	// We'll need these too
4936 5232
 	$date_when = date_create('@' . $when);
@@ -4994,8 +5290,9 @@  discard block
 block discarded – undo
4994 5290
 	foreach ($priority_countries as $country)
4995 5291
 	{
4996 5292
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4997
-		if (!empty($country_tzids))
4998
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5293
+		if (!empty($country_tzids)) {
5294
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5295
+		}
4999 5296
 	}
5000 5297
 
5001 5298
 	// Process the preferred timezones first, then the rest.
@@ -5005,8 +5302,9 @@  discard block
 block discarded – undo
5005 5302
 	foreach ($tzids as $tzid)
5006 5303
 	{
5007 5304
 		// We don't want UTC right now
5008
-		if ($tzid == 'UTC')
5009
-			continue;
5305
+		if ($tzid == 'UTC') {
5306
+					continue;
5307
+		}
5010 5308
 
5011 5309
 		$tz = timezone_open($tzid);
5012 5310
 
@@ -5021,12 +5319,14 @@  discard block
 block discarded – undo
5021 5319
 		$tzgeo = timezone_location_get($tz);
5022 5320
 
5023 5321
 		// Don't overwrite our preferred tzids
5024
-		if (empty($zones[$tzkey]['tzid']))
5025
-			$zones[$tzkey]['tzid'] = $tzid;
5322
+		if (empty($zones[$tzkey]['tzid'])) {
5323
+					$zones[$tzkey]['tzid'] = $tzid;
5324
+		}
5026 5325
 
5027 5326
 		// A time zone from a prioritized country?
5028
-		if (in_array($tzid, $priority_tzids))
5029
-			$priority_zones[$tzkey] = true;
5327
+		if (in_array($tzid, $priority_tzids)) {
5328
+					$priority_zones[$tzkey] = true;
5329
+		}
5030 5330
 
5031 5331
 		// Keep track of the location and offset for this tzid
5032 5332
 		$tzid_parts = explode('/', $tzid);
@@ -5047,15 +5347,17 @@  discard block
 block discarded – undo
5047 5347
 
5048 5348
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5049 5349
 
5050
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5051
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5052
-		else
5053
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5350
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5351
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5352
+		} else {
5353
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5354
+		}
5054 5355
 
5055
-		if (isset($priority_zones[$tzkey]))
5056
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5057
-		else
5058
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5356
+		if (isset($priority_zones[$tzkey])) {
5357
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5358
+		} else {
5359
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5360
+		}
5059 5361
 	}
5060 5362
 
5061 5363
 	$timezones = array_merge(
@@ -5109,9 +5411,9 @@  discard block
 block discarded – undo
5109 5411
 			'Indian/Kerguelen' => 'TFT',
5110 5412
 		);
5111 5413
 
5112
-		if (!empty($missing_tz_abbrs[$tzid]))
5113
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5114
-		else
5414
+		if (!empty($missing_tz_abbrs[$tzid])) {
5415
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5416
+		} else
5115 5417
 		{
5116 5418
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5117 5419
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5139,8 +5441,9 @@  discard block
 block discarded – undo
5139 5441
  */
5140 5442
 function inet_ptod($ip_address)
5141 5443
 {
5142
-	if (!isValidIP($ip_address))
5143
-		return $ip_address;
5444
+	if (!isValidIP($ip_address)) {
5445
+			return $ip_address;
5446
+	}
5144 5447
 
5145 5448
 	$bin = inet_pton($ip_address);
5146 5449
 	return $bin;
@@ -5152,13 +5455,15 @@  discard block
 block discarded – undo
5152 5455
  */
5153 5456
 function inet_dtop($bin)
5154 5457
 {
5155
-	if(empty($bin))
5156
-		return '';
5458
+	if(empty($bin)) {
5459
+			return '';
5460
+	}
5157 5461
 
5158 5462
 	global $db_type;
5159 5463
 
5160
-	if ($db_type == 'postgresql')
5161
-		return $bin;
5464
+	if ($db_type == 'postgresql') {
5465
+			return $bin;
5466
+	}
5162 5467
 
5163 5468
 	$ip_address = inet_ntop($bin);
5164 5469
 
@@ -5183,26 +5488,32 @@  discard block
 block discarded – undo
5183 5488
  */
5184 5489
 function _safe_serialize($value)
5185 5490
 {
5186
-	if(is_null($value))
5187
-		return 'N;';
5491
+	if(is_null($value)) {
5492
+			return 'N;';
5493
+	}
5188 5494
 
5189
-	if(is_bool($value))
5190
-		return 'b:'. (int) $value .';';
5495
+	if(is_bool($value)) {
5496
+			return 'b:'. (int) $value .';';
5497
+	}
5191 5498
 
5192
-	if(is_int($value))
5193
-		return 'i:'. $value .';';
5499
+	if(is_int($value)) {
5500
+			return 'i:'. $value .';';
5501
+	}
5194 5502
 
5195
-	if(is_float($value))
5196
-		return 'd:'. str_replace(',', '.', $value) .';';
5503
+	if(is_float($value)) {
5504
+			return 'd:'. str_replace(',', '.', $value) .';';
5505
+	}
5197 5506
 
5198
-	if(is_string($value))
5199
-		return 's:'. strlen($value) .':"'. $value .'";';
5507
+	if(is_string($value)) {
5508
+			return 's:'. strlen($value) .':"'. $value .'";';
5509
+	}
5200 5510
 
5201 5511
 	if(is_array($value))
5202 5512
 	{
5203 5513
 		$out = '';
5204
-		foreach($value as $k => $v)
5205
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5514
+		foreach($value as $k => $v) {
5515
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5516
+		}
5206 5517
 
5207 5518
 		return 'a:'. count($value) .':{'. $out .'}';
5208 5519
 	}
@@ -5228,8 +5539,9 @@  discard block
 block discarded – undo
5228 5539
 
5229 5540
 	$out = _safe_serialize($value);
5230 5541
 
5231
-	if (isset($mbIntEnc))
5232
-		mb_internal_encoding($mbIntEnc);
5542
+	if (isset($mbIntEnc)) {
5543
+			mb_internal_encoding($mbIntEnc);
5544
+	}
5233 5545
 
5234 5546
 	return $out;
5235 5547
 }
@@ -5246,8 +5558,9 @@  discard block
 block discarded – undo
5246 5558
 function _safe_unserialize($str)
5247 5559
 {
5248 5560
 	// Input  is not a string.
5249
-	if(empty($str) || !is_string($str))
5250
-		return false;
5561
+	if(empty($str) || !is_string($str)) {
5562
+			return false;
5563
+	}
5251 5564
 
5252 5565
 	$stack = array();
5253 5566
 	$expected = array();
@@ -5263,43 +5576,38 @@  discard block
 block discarded – undo
5263 5576
 	while($state != 1)
5264 5577
 	{
5265 5578
 		$type = isset($str[0]) ? $str[0] : '';
5266
-		if($type == '}')
5267
-			$str = substr($str, 1);
5268
-
5269
-		else if($type == 'N' && $str[1] == ';')
5579
+		if($type == '}') {
5580
+					$str = substr($str, 1);
5581
+		} else if($type == 'N' && $str[1] == ';')
5270 5582
 		{
5271 5583
 			$value = null;
5272 5584
 			$str = substr($str, 2);
5273
-		}
5274
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5585
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5275 5586
 		{
5276 5587
 			$value = $matches[1] == '1' ? true : false;
5277 5588
 			$str = substr($str, 4);
5278
-		}
5279
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5589
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5280 5590
 		{
5281 5591
 			$value = (int)$matches[1];
5282 5592
 			$str = $matches[2];
5283
-		}
5284
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5593
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5285 5594
 		{
5286 5595
 			$value = (float)$matches[1];
5287 5596
 			$str = $matches[3];
5288
-		}
5289
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5597
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5290 5598
 		{
5291 5599
 			$value = substr($matches[2], 0, (int)$matches[1]);
5292 5600
 			$str = substr($matches[2], (int)$matches[1] + 2);
5293
-		}
5294
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5601
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5295 5602
 		{
5296 5603
 			$expectedLength = (int)$matches[1];
5297 5604
 			$str = $matches[2];
5298 5605
 		}
5299 5606
 
5300 5607
 		// Object or unknown/malformed type.
5301
-		else
5302
-			return false;
5608
+		else {
5609
+					return false;
5610
+		}
5303 5611
 
5304 5612
 		switch($state)
5305 5613
 		{
@@ -5327,8 +5635,9 @@  discard block
 block discarded – undo
5327 5635
 				if($type == '}')
5328 5636
 				{
5329 5637
 					// Array size is less than expected.
5330
-					if(count($list) < end($expected))
5331
-						return false;
5638
+					if(count($list) < end($expected)) {
5639
+											return false;
5640
+					}
5332 5641
 
5333 5642
 					unset($list);
5334 5643
 					$list = &$stack[count($stack)-1];
@@ -5337,8 +5646,9 @@  discard block
 block discarded – undo
5337 5646
 					// Go to terminal state if we're at the end of the root array.
5338 5647
 					array_pop($expected);
5339 5648
 
5340
-					if(count($expected) == 0)
5341
-						$state = 1;
5649
+					if(count($expected) == 0) {
5650
+											$state = 1;
5651
+					}
5342 5652
 
5343 5653
 					break;
5344 5654
 				}
@@ -5346,8 +5656,9 @@  discard block
 block discarded – undo
5346 5656
 				if($type == 'i' || $type == 's')
5347 5657
 				{
5348 5658
 					// Array size exceeds expected length.
5349
-					if(count($list) >= end($expected))
5350
-						return false;
5659
+					if(count($list) >= end($expected)) {
5660
+											return false;
5661
+					}
5351 5662
 
5352 5663
 					$key = $value;
5353 5664
 					$state = 3;
@@ -5381,8 +5692,9 @@  discard block
 block discarded – undo
5381 5692
 	}
5382 5693
 
5383 5694
 	// Trailing data in input.
5384
-	if(!empty($str))
5385
-		return false;
5695
+	if(!empty($str)) {
5696
+			return false;
5697
+	}
5386 5698
 
5387 5699
 	return $data;
5388 5700
 }
@@ -5405,8 +5717,9 @@  discard block
 block discarded – undo
5405 5717
 
5406 5718
 	$out = _safe_unserialize($str);
5407 5719
 
5408
-	if (isset($mbIntEnc))
5409
-		mb_internal_encoding($mbIntEnc);
5720
+	if (isset($mbIntEnc)) {
5721
+			mb_internal_encoding($mbIntEnc);
5722
+	}
5410 5723
 
5411 5724
 	return $out;
5412 5725
 }
@@ -5421,12 +5734,14 @@  discard block
 block discarded – undo
5421 5734
 function smf_chmod($file, $value = 0)
5422 5735
 {
5423 5736
 	// No file? no checks!
5424
-	if (empty($file))
5425
-		return false;
5737
+	if (empty($file)) {
5738
+			return false;
5739
+	}
5426 5740
 
5427 5741
 	// Already writable?
5428
-	if (is_writable($file))
5429
-		return true;
5742
+	if (is_writable($file)) {
5743
+			return true;
5744
+	}
5430 5745
 
5431 5746
 	// Do we have a file or a dir?
5432 5747
 	$isDir = is_dir($file);
@@ -5442,10 +5757,9 @@  discard block
 block discarded – undo
5442 5757
 		{
5443 5758
 			$isWritable = true;
5444 5759
 			break;
5760
+		} else {
5761
+					@chmod($file, $val);
5445 5762
 		}
5446
-
5447
-		else
5448
-			@chmod($file, $val);
5449 5763
 	}
5450 5764
 
5451 5765
 	return $isWritable;
@@ -5464,8 +5778,9 @@  discard block
 block discarded – undo
5464 5778
 	global $txt;
5465 5779
 
5466 5780
 	// Come on...
5467
-	if (empty($json) || !is_string($json))
5468
-		return array();
5781
+	if (empty($json) || !is_string($json)) {
5782
+			return array();
5783
+	}
5469 5784
 
5470 5785
 	$returnArray = @json_decode($json, $returnAsArray);
5471 5786
 
@@ -5503,11 +5818,11 @@  discard block
 block discarded – undo
5503 5818
 		$jsonDebug = $jsonDebug[0];
5504 5819
 		loadLanguage('Errors');
5505 5820
 
5506
-		if (!empty($jsonDebug))
5507
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5508
-
5509
-		else
5510
-			log_error($txt['json_'. $jsonError], 'critical');
5821
+		if (!empty($jsonDebug)) {
5822
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5823
+		} else {
5824
+					log_error($txt['json_'. $jsonError], 'critical');
5825
+		}
5511 5826
 
5512 5827
 		// Everyone expects an array.
5513 5828
 		return array();
@@ -5537,8 +5852,9 @@  discard block
 block discarded – undo
5537 5852
 	global $db_show_debug, $modSettings;
5538 5853
 
5539 5854
 	// Defensive programming anyone?
5540
-	if (empty($data))
5541
-		return false;
5855
+	if (empty($data)) {
5856
+			return false;
5857
+	}
5542 5858
 
5543 5859
 	// Don't need extra stuff...
5544 5860
 	$db_show_debug = false;
@@ -5546,11 +5862,11 @@  discard block
 block discarded – undo
5546 5862
 	// Kill anything else.
5547 5863
 	ob_end_clean();
5548 5864
 
5549
-	if (!empty($modSettings['CompressedOutput']))
5550
-		@ob_start('ob_gzhandler');
5551
-
5552
-	else
5553
-		ob_start();
5865
+	if (!empty($modSettings['CompressedOutput'])) {
5866
+			@ob_start('ob_gzhandler');
5867
+	} else {
5868
+			ob_start();
5869
+	}
5554 5870
 
5555 5871
 	// Set the header.
5556 5872
 	header($type);
@@ -5582,8 +5898,9 @@  discard block
 block discarded – undo
5582 5898
 	static $done = false;
5583 5899
 
5584 5900
 	// If we don't need to do anything, don't
5585
-	if (!$update && $done)
5586
-		return;
5901
+	if (!$update && $done) {
5902
+			return;
5903
+	}
5587 5904
 
5588 5905
 	// Should we get a new copy of the official list of TLDs?
5589 5906
 	if ($update)
@@ -5604,10 +5921,11 @@  discard block
 block discarded – undo
5604 5921
 		// Clean $tlds and convert it to an array
5605 5922
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5606 5923
 			$line = trim($line);
5607
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5608
-				return false;
5609
-			else
5610
-				return true;
5924
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5925
+							return false;
5926
+			} else {
5927
+							return true;
5928
+			}
5611 5929
 		});
5612 5930
 
5613 5931
 		// Convert Punycode to Unicode
@@ -5661,8 +5979,9 @@  discard block
 block discarded – undo
5661 5979
 						$idx += $digit * $w;
5662 5980
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5663 5981
 
5664
-						if ($digit < $t)
5665
-							break;
5982
+						if ($digit < $t) {
5983
+													break;
5984
+						}
5666 5985
 
5667 5986
 						$w = (int) ($w * ($base - $t));
5668 5987
 					}
@@ -5671,8 +5990,9 @@  discard block
 block discarded – undo
5671 5990
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5672 5991
 					$delta += intval($delta / ($deco_len + 1));
5673 5992
 
5674
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5675
-						$delta = intval($delta / ($base - $tmin));
5993
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5994
+											$delta = intval($delta / ($base - $tmin));
5995
+					}
5676 5996
 
5677 5997
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5678 5998
 					$is_first = false;
@@ -5681,8 +6001,9 @@  discard block
 block discarded – undo
5681 6001
 
5682 6002
 					if ($deco_len > 0)
5683 6003
 					{
5684
-						for ($i = $deco_len; $i > $idx; $i--)
5685
-							$decoded[$i] = $decoded[($i - 1)];
6004
+						for ($i = $deco_len; $i > $idx; $i--) {
6005
+													$decoded[$i] = $decoded[($i - 1)];
6006
+						}
5686 6007
 					}
5687 6008
 					$decoded[$idx++] = $char;
5688 6009
 				}
@@ -5690,24 +6011,29 @@  discard block
 block discarded – undo
5690 6011
 				foreach ($decoded as $k => $v)
5691 6012
 				{
5692 6013
 					// 7bit are transferred literally
5693
-					if ($v < 128)
5694
-						$output .= chr($v);
6014
+					if ($v < 128) {
6015
+											$output .= chr($v);
6016
+					}
5695 6017
 
5696 6018
 					// 2 bytes
5697
-					elseif ($v < (1 << 11))
5698
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6019
+					elseif ($v < (1 << 11)) {
6020
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6021
+					}
5699 6022
 
5700 6023
 					// 3 bytes
5701
-					elseif ($v < (1 << 16))
5702
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6024
+					elseif ($v < (1 << 16)) {
6025
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6026
+					}
5703 6027
 
5704 6028
 					// 4 bytes
5705
-					elseif ($v < (1 << 21))
5706
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6029
+					elseif ($v < (1 << 21)) {
6030
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6031
+					}
5707 6032
 
5708 6033
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5709
-					else
5710
-						$output .= $safe_char;
6034
+					else {
6035
+											$output .= $safe_char;
6036
+					}
5711 6037
 				}
5712 6038
 
5713 6039
 				$output_parts[] = $output;
@@ -5802,8 +6128,7 @@  discard block
 block discarded – undo
5802 6128
 
5803 6129
 		$strlen = 'mb_strlen';
5804 6130
 		$substr = 'mb_substr';
5805
-	}
5806
-	else
6131
+	} else
5807 6132
 	{
5808 6133
 		$strlen = $smcFunc['strlen'];
5809 6134
 		$substr = $smcFunc['substr'];
@@ -5817,20 +6142,21 @@  discard block
 block discarded – undo
5817 6142
 
5818 6143
 		$first = $substr($string, 0, 1);
5819 6144
 
5820
-		if (empty($index[$first]))
5821
-			$index[$first] = array();
6145
+		if (empty($index[$first])) {
6146
+					$index[$first] = array();
6147
+		}
5822 6148
 
5823 6149
 		if ($strlen($string) > 1)
5824 6150
 		{
5825 6151
 			// Sanity check on recursion
5826
-			if ($depth > 99)
5827
-				$index[$first][$substr($string, 1)] = '';
5828
-
5829
-			else
5830
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6152
+			if ($depth > 99) {
6153
+							$index[$first][$substr($string, 1)] = '';
6154
+			} else {
6155
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6156
+			}
6157
+		} else {
6158
+					$index[$first][''] = '';
5831 6159
 		}
5832
-		else
5833
-			$index[$first][''] = '';
5834 6160
 
5835 6161
 		$depth--;
5836 6162
 		return $index;
@@ -5853,9 +6179,9 @@  discard block
 block discarded – undo
5853 6179
 			$key_regex = preg_quote($key, $delim);
5854 6180
 			$new_key = $key;
5855 6181
 
5856
-			if (empty($value))
5857
-				$sub_regex = '';
5858
-			else
6182
+			if (empty($value)) {
6183
+							$sub_regex = '';
6184
+			} else
5859 6185
 			{
5860 6186
 				$sub_regex = $index_to_regex($value, $delim);
5861 6187
 
@@ -5863,22 +6189,22 @@  discard block
 block discarded – undo
5863 6189
 				{
5864 6190
 					$new_key_array = explode('(?'.'>', $sub_regex);
5865 6191
 					$new_key .= $new_key_array[0];
6192
+				} else {
6193
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5866 6194
 				}
5867
-				else
5868
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5869 6195
 			}
5870 6196
 
5871
-			if ($depth > 1)
5872
-				$regex[$new_key] = $key_regex . $sub_regex;
5873
-			else
6197
+			if ($depth > 1) {
6198
+							$regex[$new_key] = $key_regex . $sub_regex;
6199
+			} else
5874 6200
 			{
5875 6201
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5876 6202
 				{
5877 6203
 					$regex[$new_key] = $key_regex . $sub_regex;
5878 6204
 					unset($index[$key]);
6205
+				} else {
6206
+									break;
5879 6207
 				}
5880
-				else
5881
-					break;
5882 6208
 			}
5883 6209
 		}
5884 6210
 
@@ -5887,10 +6213,11 @@  discard block
 block discarded – undo
5887 6213
 			$l1 = $strlen($k1);
5888 6214
 			$l2 = $strlen($k2);
5889 6215
 
5890
-			if ($l1 == $l2)
5891
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5892
-			else
5893
-				return $l1 > $l2 ? -1 : 1;
6216
+			if ($l1 == $l2) {
6217
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6218
+			} else {
6219
+							return $l1 > $l2 ? -1 : 1;
6220
+			}
5894 6221
 		});
5895 6222
 
5896 6223
 		$depth--;
@@ -5901,15 +6228,18 @@  discard block
 block discarded – undo
5901 6228
 	$index = array();
5902 6229
 	$regexes = array();
5903 6230
 
5904
-	foreach ($strings as $string)
5905
-		$index = $add_string_to_index($string, $index);
6231
+	foreach ($strings as $string) {
6232
+			$index = $add_string_to_index($string, $index);
6233
+	}
5906 6234
 
5907
-	while (!empty($index))
5908
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6235
+	while (!empty($index)) {
6236
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6237
+	}
5909 6238
 
5910 6239
 	// Restore PHP's internal character encoding to whatever it was originally
5911
-	if (!empty($current_encoding))
5912
-		mb_internal_encoding($current_encoding);
6240
+	if (!empty($current_encoding)) {
6241
+			mb_internal_encoding($current_encoding);
6242
+	}
5913 6243
 
5914 6244
 	return $regexes;
5915 6245
 }
Please login to merge, or discard this patch.
Sources/Subscriptions-PayPal.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -402,7 +402,7 @@
 block discarded – undo
402 402
 	 * A private function to find out the subscription details.
403 403
 	 *
404 404
 	 * @access private
405
-	 * @return boolean|void False on failure, otherwise just sets $_POST['item_number']
405
+	 * @return false|null False on failure, otherwise just sets $_POST['item_number']
406 406
 	 */
407 407
 	private function _findSubscription()
408 408
 	{
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -236,7 +236,7 @@
 block discarded – undo
236 236
 			$header = 'POST /cgi-bin/webscr HTTP/1.1' . "\r\n";
237 237
 			$header .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
238 238
 			$header .= 'Host: www.' . (!empty($modSettings['paidsubs_test']) ? 'sandbox.' : '') . 'paypal.com' . "\r\n";
239
-			$header .= 'Content-Length: ' . strlen ($requestString) . "\r\n";
239
+			$header .= 'Content-Length: ' . strlen($requestString) . "\r\n";
240 240
 			$header .= 'Connection: close' . "\r\n\r\n";
241 241
 
242 242
 			// Open the connection.
Please login to merge, or discard this patch.
Braces   +83 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
 // This won't be dedicated without this - this must exist in each gateway!
15 15
 // SMF Payment Gateway: paypal
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Class for returning available form data for this gateway
@@ -118,8 +119,7 @@  discard block
 block discarded – undo
118 119
 		{
119 120
 			$return_data['hidden']['p3'] = 1;
120 121
 			$return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1));
121
-		}
122
-		else
122
+		} else
123 123
 		{
124 124
 			preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match);
125 125
 			$unit = $match[1];
@@ -130,14 +130,15 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 
132 132
 		// If it's repeatable do some javascript to respect this idea.
133
-		if (!empty($sub_data['repeatable']))
134
-			$return_data['javascript'] = '
133
+		if (!empty($sub_data['repeatable'])) {
134
+					$return_data['javascript'] = '
135 135
 				document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();" class="input_check">' . $txt['paid_make_recurring'] . '</label><br>\');
136 136
 
137 137
 				function switchPaypalRecur()
138 138
 				{
139 139
 					document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick";
140 140
 				}';
141
+		}
141 142
 
142 143
 		return $return_data;
143 144
 	}
@@ -160,20 +161,24 @@  discard block
 block discarded – undo
160 161
 		global $modSettings;
161 162
 
162 163
 		// Has the user set up an email address?
163
-		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email'])))
164
-			return false;
164
+		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) {
165
+					return false;
166
+		}
165 167
 		// Check the correct transaction types are even here.
166
-		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email'])))
167
-			return false;
168
+		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) {
169
+					return false;
170
+		}
168 171
 		// Correct email address?
169
-		if (!isset($_POST['business']))
170
-			$_POST['business'] = $_POST['receiver_email'];
172
+		if (!isset($_POST['business'])) {
173
+					$_POST['business'] = $_POST['receiver_email'];
174
+		}
171 175
 
172 176
 		// Are we testing?
173
-		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
174
-			return false;
175
-		elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails']))))
176
-			return false;
177
+		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
178
+					return false;
179
+		} elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) {
180
+					return false;
181
+		}
177 182
 		return true;
178 183
 	}
179 184
 
@@ -192,15 +197,17 @@  discard block
 block discarded – undo
192 197
 		global $modSettings, $txt;
193 198
 
194 199
 		// Put this to some default value.
195
-		if (!isset($_POST['txn_type']))
196
-			$_POST['txn_type'] = '';
200
+		if (!isset($_POST['txn_type'])) {
201
+					$_POST['txn_type'] = '';
202
+		}
197 203
 
198 204
 		// Build the request string - starting with the minimum requirement.
199 205
 		$requestString = 'cmd=_notify-validate';
200 206
 
201 207
 		// Now my dear, add all the posted bits in the order we got them
202
-		foreach ($_POST as $k => $v)
203
-			$requestString .= '&' . $k . '=' . urlencode($v);
208
+		foreach ($_POST as $k => $v) {
209
+					$requestString .= '&' . $k . '=' . urlencode($v);
210
+		}
204 211
 
205 212
 		// Can we use curl?
206 213
 		if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr'))
@@ -240,14 +247,16 @@  discard block
 block discarded – undo
240 247
 			$header .= 'Connection: close' . "\r\n\r\n";
241 248
 
242 249
 			// Open the connection.
243
-			if (!empty($modSettings['paidsubs_test']))
244
-				$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
245
-			else
246
-				$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
250
+			if (!empty($modSettings['paidsubs_test'])) {
251
+							$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
252
+			} else {
253
+							$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
254
+			}
247 255
 
248 256
 			// Did it work?
249
-			if (!$fp)
250
-				generateSubscriptionError($txt['paypal_could_not_connect']);
257
+			if (!$fp) {
258
+							generateSubscriptionError($txt['paypal_could_not_connect']);
259
+			}
251 260
 
252 261
 			// Put the data to the port.
253 262
 			fputs($fp, $header . $requestString);
@@ -256,8 +265,9 @@  discard block
 block discarded – undo
256 265
 			while (!feof($fp))
257 266
 			{
258 267
 				$this->return_data = fgets($fp, 1024);
259
-				if (strcmp(trim($this->return_data), 'VERIFIED') === 0)
260
-					break;
268
+				if (strcmp(trim($this->return_data), 'VERIFIED') === 0) {
269
+									break;
270
+				}
261 271
 			}
262 272
 
263 273
 			// Clean up.
@@ -265,28 +275,34 @@  discard block
 block discarded – undo
265 275
 		}
266 276
 
267 277
 		// If this isn't verified then give up...
268
-		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0)
269
-			exit;
278
+		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) {
279
+					exit;
280
+		}
270 281
 
271 282
 		// Check that this is intended for us.
272
-		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
273
-			exit;
283
+		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
284
+					exit;
285
+		}
274 286
 
275 287
 		// Is this a subscription - and if so is it a secondary payment that we need to process?
276 288
 		// If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding.
277
-		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false)
278
-			$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
279
-		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false))
280
-			// Calculate the subscription it relates to!
289
+		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) {
290
+					$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
291
+		}
292
+		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) {
293
+					// Calculate the subscription it relates to!
281 294
 			$this->_findSubscription();
295
+		}
282 296
 
283 297
 		// Verify the currency!
284
-		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code']))
285
-			exit;
298
+		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) {
299
+					exit;
300
+		}
286 301
 
287 302
 		// Can't exist if it doesn't contain anything.
288
-		if (empty($_POST['item_number']))
289
-			exit;
303
+		if (empty($_POST['item_number'])) {
304
+					exit;
305
+		}
290 306
 
291 307
 		// Return the id_sub and id_member
292 308
 		return explode('+', $_POST['item_number']);
@@ -299,10 +315,11 @@  discard block
 block discarded – undo
299 315
 	 */
300 316
 	public function isRefund()
301 317
 	{
302
-		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed'))
303
-			return true;
304
-		else
305
-			return false;
318
+		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) {
319
+					return true;
320
+		} else {
321
+					return false;
322
+		}
306 323
 	}
307 324
 
308 325
 	/**
@@ -312,10 +329,11 @@  discard block
 block discarded – undo
312 329
 	 */
313 330
 	public function isSubscription()
314 331
 	{
315
-		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed')
316
-			return true;
317
-		else
318
-			return false;
332
+		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') {
333
+					return true;
334
+		} else {
335
+					return false;
336
+		}
319 337
 	}
320 338
 
321 339
 	/**
@@ -325,10 +343,11 @@  discard block
 block discarded – undo
325 343
 	 */
326 344
 	public function isPayment()
327 345
 	{
328
-		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept')
329
-			return true;
330
-		else
331
-			return false;
346
+		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') {
347
+					return true;
348
+		} else {
349
+					return false;
350
+		}
332 351
 	}
333 352
 
334 353
 	/**
@@ -341,10 +360,11 @@  discard block
 block discarded – undo
341 360
 		// subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment
342 361
 		// Neither require us to *do* anything as per performCancel().
343 362
 		// subscr_eot, if sent, indicates an end of payments term.
344
-		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot')
345
-			return true;
346
-		else
347
-			return false;
363
+		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') {
364
+					return true;
365
+		} else {
366
+					return false;
367
+		}
348 368
 	}
349 369
 
350 370
 	/**
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		global $smcFunc;
410 430
 
411 431
 		// Assume we have this?
412
-		if (empty($_POST['subscr_id']))
413
-			return false;
432
+		if (empty($_POST['subscr_id'])) {
433
+					return false;
434
+		}
414 435
 
415 436
 		// Do we have this in the database?
416 437
 		$request = $smcFunc['db_query']('', '
@@ -439,11 +460,12 @@  discard block
 block discarded – undo
439 460
 						'payer_email' => $_POST['payer_email'],
440 461
 					)
441 462
 				);
442
-				if ($smcFunc['db_num_rows']($request) === 0)
443
-					return false;
463
+				if ($smcFunc['db_num_rows']($request) === 0) {
464
+									return false;
465
+				}
466
+			} else {
467
+							return false;
444 468
 			}
445
-			else
446
-				return false;
447 469
 		}
448 470
 		list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request);
449 471
 		$_POST['item_number'] = $member_id . '+' . $subscription_id;
Please login to merge, or discard this patch.