Completed
Push — release-2.1 ( 35b3d8...b2efc6 )
by Mathias
09:11
created
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '
', '  ' => '  ', '[' => '[', ']' => ']')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -389,16 +409,19 @@  discard block
 block discarded – undo
389 409
 					$desired_height = $height;
390 410
 				}
391 411
 				// Scale it to the width...
392
-				elseif (empty($desired_width) && !empty($height))
393
-					$desired_width = (int) (($desired_height * $width) / $height);
412
+				elseif (empty($desired_width) && !empty($height)) {
413
+									$desired_width = (int) (($desired_height * $width) / $height);
414
+				}
394 415
 				// Scale if to the height.
395
-				elseif (!empty($width))
396
-					$desired_height = (int) (($desired_width * $height) / $width);
416
+				elseif (!empty($width)) {
417
+									$desired_height = (int) (($desired_width * $height) / $width);
418
+				}
397 419
 			}
398 420
 
399 421
 			// If the width and height are fine, just continue along...
400
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
401
-				continue;
422
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
423
+							continue;
424
+			}
402 425
 
403 426
 			// Too bad, it's too wide.  Make it as wide as the maximum.
404 427
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -418,8 +441,9 @@  discard block
 block discarded – undo
418 441
 		}
419 442
 
420 443
 		// If any img tags were actually changed...
421
-		if (!empty($replaces))
422
-			$message = strtr($message, $replaces);
444
+		if (!empty($replaces)) {
445
+					$message = strtr($message, $replaces);
446
+		}
423 447
 	}
424 448
 }
425 449
 
@@ -438,10 +462,11 @@  discard block
 block discarded – undo
438 462
 {
439 463
 	global $boardurl, $scripturl;
440 464
 
441
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
442
-		$domain_url = $match[1];
443
-	else
444
-		$domain_url = $boardurl . '/';
465
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
466
+			$domain_url = $match[1];
467
+	} else {
468
+			$domain_url = $boardurl . '/';
469
+	}
445 470
 
446 471
 	$replaces = array();
447 472
 
@@ -449,11 +474,11 @@  discard block
 block discarded – undo
449 474
 	{
450 475
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
451 476
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} elseif ($hasEqualSign) {
478
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
479
+	} else {
480
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
452 481
 	}
453
-	elseif ($hasEqualSign)
454
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
455
-	else
456
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
457 482
 
458 483
 	foreach ($matches[0] as $k => $dummy)
459 484
 	{
@@ -466,49 +491,53 @@  discard block
 block discarded – undo
466 491
 		foreach ($protocols as $protocol)
467 492
 		{
468 493
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
469
-			if ($found)
470
-				break;
494
+			if ($found) {
495
+							break;
496
+			}
471 497
 		}
472 498
 
473 499
 		if (!$found && $protocols[0] == 'http')
474 500
 		{
475
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
476
-				$replace = $domain_url . $replace;
477
-			elseif (substr($replace, 0, 1) == '?')
478
-				$replace = $scripturl . $replace;
479
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
501
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
502
+							$replace = $domain_url . $replace;
503
+			} elseif (substr($replace, 0, 1) == '?') {
504
+							$replace = $scripturl . $replace;
505
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
480 506
 			{
481 507
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
482 508
 				$this_tag = 'iurl';
483 509
 				$this_close = 'iurl';
510
+			} elseif (substr($replace, 0, 2) != '//') {
511
+							$replace = $protocols[0] . '://' . $replace;
484 512
 			}
485
-			elseif (substr($replace, 0, 2) != '//')
486
-				$replace = $protocols[0] . '://' . $replace;
487
-		}
488
-		elseif (!$found && $protocols[0] == 'ftp')
489
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
490
-		elseif (!$found)
491
-			$replace = $protocols[0] . '://' . $replace;
492
-
493
-		if ($hasEqualSign && $embeddedUrl)
494
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
495
-		elseif ($hasEqualSign)
496
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
497
-		elseif ($embeddedUrl)
498
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
499
-		else
500
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
513
+		} elseif (!$found && $protocols[0] == 'ftp') {
514
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
515
+		} elseif (!$found) {
516
+					$replace = $protocols[0] . '://' . $replace;
517
+		}
518
+
519
+		if ($hasEqualSign && $embeddedUrl) {
520
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
521
+		} elseif ($hasEqualSign) {
522
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
523
+		} elseif ($embeddedUrl) {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
525
+		} else {
526
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
527
+		}
501 528
 	}
502 529
 
503 530
 	foreach ($replaces as $k => $v)
504 531
 	{
505
-		if ($k == $v)
506
-			unset($replaces[$k]);
532
+		if ($k == $v) {
533
+					unset($replaces[$k]);
534
+		}
507 535
 	}
508 536
 
509
-	if (!empty($replaces))
510
-		$message = strtr($message, $replaces);
511
-}
537
+	if (!empty($replaces)) {
538
+			$message = strtr($message, $replaces);
539
+	}
540
+	}
512 541
 
513 542
 /**
514 543
  * This function sends an email to the specified recipient(s).
@@ -552,8 +581,9 @@  discard block
 block discarded – undo
552 581
 	}
553 582
 
554 583
 	// Nothing left? Nothing else to do
555
-	if (empty($to_array))
556
-		return true;
584
+	if (empty($to_array)) {
585
+			return true;
586
+	}
557 587
 
558 588
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
559 589
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -570,15 +600,17 @@  discard block
 block discarded – undo
570 600
 		}
571 601
 
572 602
 		// Call this function recursively for the hotmail addresses.
573
-		if (!empty($hotmail_to))
574
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		if (!empty($hotmail_to)) {
604
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
605
+		}
575 606
 
576 607
 		// The remaining addresses no longer need the fix.
577 608
 		$hotmail_fix = false;
578 609
 
579 610
 		// No other addresses left? Return instantly.
580
-		if (empty($to_array))
581
-			return $mail_result;
611
+		if (empty($to_array)) {
612
+					return $mail_result;
613
+		}
582 614
 	}
583 615
 
584 616
 	// Get rid of entities.
@@ -603,13 +635,15 @@  discard block
 block discarded – undo
603 635
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
604 636
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
605 637
 
606
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
607
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
639
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
640
+	}
608 641
 	$headers .= 'X-Mailer: SMF' . $line_break;
609 642
 
610 643
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
611
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
612
-		return false;
644
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
645
+			return false;
646
+	}
613 647
 
614 648
 	// Save the original message...
615 649
 	$orig_message = $message;
@@ -658,17 +692,19 @@  discard block
 block discarded – undo
658 692
 	}
659 693
 
660 694
 	// Are we using the mail queue, if so this is where we butt in...
661
-	if ($priority != 0)
662
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	if ($priority != 0) {
696
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
697
+	}
663 698
 
664 699
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
665 700
 	elseif (!empty($modSettings['mail_limit']))
666 701
 	{
667 702
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
668
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
669
-			$new_queue_stat = time() . '|' . 1;
670
-		else
671
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
703
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
704
+					$new_queue_stat = time() . '|' . 1;
705
+		} else {
706
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
707
+		}
672 708
 
673 709
 		updateSettings(array('mail_recent' => $new_queue_stat));
674 710
 	}
@@ -693,12 +729,13 @@  discard block
 block discarded – undo
693 729
 
694 730
 			// Wait, wait, I'm still sending here!
695 731
 			@set_time_limit(300);
696
-			if (function_exists('apache_reset_timeout'))
697
-				@apache_reset_timeout();
732
+			if (function_exists('apache_reset_timeout')) {
733
+							@apache_reset_timeout();
734
+			}
698 735
 		}
736
+	} else {
737
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
699 738
 	}
700
-	else
701
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
702 739
 
703 740
 	// Everything go smoothly?
704 741
 	return $mail_result;
@@ -724,8 +761,9 @@  discard block
 block discarded – undo
724 761
 	static $cur_insert = array();
725 762
 	static $cur_insert_len = 0;
726 763
 
727
-	if ($cur_insert_len == 0)
728
-		$cur_insert = array();
764
+	if ($cur_insert_len == 0) {
765
+			$cur_insert = array();
766
+	}
729 767
 
730 768
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
731 769
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -800,8 +838,9 @@  discard block
 block discarded – undo
800 838
 	}
801 839
 
802 840
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
803
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
804
-		return AddMailQueue(true);
841
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
842
+			return AddMailQueue(true);
843
+	}
805 844
 
806 845
 	return true;
807 846
 }
@@ -832,23 +871,26 @@  discard block
 block discarded – undo
832 871
 		'sent' => array()
833 872
 	);
834 873
 
835
-	if ($from === null)
836
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
837 876
 			'id' => $user_info['id'],
838 877
 			'name' => $user_info['name'],
839 878
 			'username' => $user_info['username']
840 879
 		);
880
+	}
841 881
 
842 882
 	// This is the one that will go in their inbox.
843 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
844 884
 	preparsecode($htmlmessage);
845 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
846
-	if ($smcFunc['strlen']($htmlsubject) > 100)
847
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
848 889
 
849 890
 	// Make sure is an array
850
-	if (!is_array($recipients))
851
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
852 894
 
853 895
 	// Integrated PMs
854 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -876,21 +918,23 @@  discard block
 block discarded – undo
876 918
 				'usernames' => array_keys($usernames),
877 919
 			)
878 920
 		);
879
-		while ($row = $smcFunc['db_fetch_assoc']($request))
880
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
881 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
882 925
 		$smcFunc['db_free_result']($request);
883 926
 
884 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
885
-		foreach ($recipients as $rec_type => $rec)
886
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
887 930
 			{
888 931
 				if (is_numeric($recipients[$rec_type][$id]))
889 932
 					continue;
933
+		}
890 934
 
891
-				if (!empty($usernames[$member]))
892
-					$recipients[$rec_type][$id] = $usernames[$member];
893
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
894 938
 				{
895 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
896 940
 					unset($recipients[$rec_type][$id]);
@@ -928,8 +972,9 @@  discard block
 block discarded – undo
928 972
 		$delete = false;
929 973
 		foreach ($criteria as $criterium)
930 974
 		{
931
-			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))
932
-				$delete = true;
975
+			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)) {
976
+							$delete = true;
977
+			}
933 978
 			// If we're adding and one criteria don't match then we stop!
934 979
 			elseif (!$row['is_or'])
935 980
 			{
@@ -937,8 +982,9 @@  discard block
 block discarded – undo
937 982
 				break;
938 983
 			}
939 984
 		}
940
-		if ($delete)
941
-			$deletes[$row['id_member']] = 1;
985
+		if ($delete) {
986
+					$deletes[$row['id_member']] = 1;
987
+		}
942 988
 	}
943 989
 	$smcFunc['db_free_result']($request);
944 990
 
@@ -953,8 +999,9 @@  discard block
 block discarded – undo
953 999
 			array(
954 1000
 			)
955 1001
 		);
956
-		while ($row = $smcFunc['db_fetch_assoc']($request))
957
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1004
+		}
958 1005
 		$smcFunc['db_free_result']($request);
959 1006
 	}
960 1007
 
@@ -962,8 +1009,9 @@  discard block
 block discarded – undo
962 1009
 	require_once($sourcedir . '/Subs-Members.php');
963 1010
 	$pmReadGroups = groupsAllowedTo('pm_read');
964 1011
 
965
-	if (empty($modSettings['permission_enable_deny']))
966
-		$pmReadGroups['denied'] = array();
1012
+	if (empty($modSettings['permission_enable_deny'])) {
1013
+			$pmReadGroups['denied'] = array();
1014
+	}
967 1015
 
968 1016
 	// Load their alert preferences
969 1017
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 	while ($row = $smcFunc['db_fetch_assoc']($request))
996 1044
 	{
997 1045
 		// Don't do anything for members to be deleted!
998
-		if (isset($deletes[$row['id_member']]))
999
-			continue;
1046
+		if (isset($deletes[$row['id_member']])) {
1047
+					continue;
1048
+		}
1000 1049
 
1001 1050
 		// Load the preferences for this member (if any)
1002 1051
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1017,8 +1066,9 @@  discard block
 block discarded – undo
1017 1066
 		{
1018 1067
 			foreach ($groups as $id)
1019 1068
 			{
1020
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1021
-					$message_limit = $message_limit_cache[$id];
1069
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1070
+									$message_limit = $message_limit_cache[$id];
1071
+				}
1022 1072
 			}
1023 1073
 
1024 1074
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1066,8 +1116,9 @@  discard block
 block discarded – undo
1066 1116
 	$smcFunc['db_free_result']($request);
1067 1117
 
1068 1118
 	// Only 'send' the message if there are any recipients left.
1069
-	if (empty($all_to))
1070
-		return $log;
1119
+	if (empty($all_to)) {
1120
+			return $log;
1121
+	}
1071 1122
 
1072 1123
 	// Insert the message itself and then grab the last insert id.
1073 1124
 	$id_pm = $smcFunc['db_insert']('',
@@ -1088,8 +1139,8 @@  discard block
 block discarded – undo
1088 1139
 	if (!empty($id_pm))
1089 1140
 	{
1090 1141
 		// If this is new we need to set it part of it's own conversation.
1091
-		if (empty($pm_head))
1092
-			$smcFunc['db_query']('', '
1142
+		if (empty($pm_head)) {
1143
+					$smcFunc['db_query']('', '
1093 1144
 				UPDATE {db_prefix}personal_messages
1094 1145
 				SET id_pm_head = {int:id_pm_head}
1095 1146
 				WHERE id_pm = {int:id_pm_head}',
@@ -1097,6 +1148,7 @@  discard block
 block discarded – undo
1097 1148
 					'id_pm_head' => $id_pm,
1098 1149
 				)
1099 1150
 			);
1151
+		}
1100 1152
 
1101 1153
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1102 1154
 		$smcFunc['db_query']('', '
@@ -1112,8 +1164,9 @@  discard block
 block discarded – undo
1112 1164
 		foreach ($all_to as $to)
1113 1165
 		{
1114 1166
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1115
-			if (!in_array($to, $recipients['bcc']))
1116
-				$to_list[] = $to;
1167
+			if (!in_array($to, $recipients['bcc'])) {
1168
+							$to_list[] = $to;
1169
+			}
1117 1170
 		}
1118 1171
 
1119 1172
 		$smcFunc['db_insert']('insert',
@@ -1131,9 +1184,9 @@  discard block
 block discarded – undo
1131 1184
 	{
1132 1185
 		censorText($message);
1133 1186
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1187
+	} else {
1188
+			$message = '';
1134 1189
 	}
1135
-	else
1136
-		$message = '';
1137 1190
 
1138 1191
 	$to_names = array();
1139 1192
 	if (count($to_list) > 1)
@@ -1146,8 +1199,9 @@  discard block
 block discarded – undo
1146 1199
 				'to_members' => $to_list,
1147 1200
 			)
1148 1201
 		);
1149
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1150
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1203
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1204
+		}
1151 1205
 		$smcFunc['db_free_result']($request);
1152 1206
 	}
1153 1207
 	$replacements = array(
@@ -1175,11 +1229,13 @@  discard block
 block discarded – undo
1175 1229
 	loadLanguage('index+PersonalMessage');
1176 1230
 
1177 1231
 	// Add one to their unread and read message counts.
1178
-	foreach ($all_to as $k => $id)
1179
-		if (isset($deletes[$id]))
1232
+	foreach ($all_to as $k => $id) {
1233
+			if (isset($deletes[$id]))
1180 1234
 			unset($all_to[$k]);
1181
-	if (!empty($all_to))
1182
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1235
+	}
1236
+	if (!empty($all_to)) {
1237
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1238
+	}
1183 1239
 
1184 1240
 	return $log;
1185 1241
 }
@@ -1209,15 +1265,17 @@  discard block
 block discarded – undo
1209 1265
 		// Let's, for now, assume there are only &#021;'ish characters.
1210 1266
 		$simple = true;
1211 1267
 
1212
-		foreach ($matches[1] as $entity)
1213
-			if ($entity > 128)
1268
+		foreach ($matches[1] as $entity) {
1269
+					if ($entity > 128)
1214 1270
 				$simple = false;
1271
+		}
1215 1272
 		unset($matches);
1216 1273
 
1217
-		if ($simple)
1218
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1274
+		if ($simple) {
1275
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1219 1276
 			{
1220 1277
 				return chr("$m[1]");
1278
+		}
1221 1279
 			}, $string);
1222 1280
 		else
1223 1281
 		{
@@ -1225,8 +1283,9 @@  discard block
 block discarded – undo
1225 1283
 			if (!$context['utf8'] && function_exists('iconv'))
1226 1284
 			{
1227 1285
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1228
-				if ($newstring)
1229
-					$string = $newstring;
1286
+				if ($newstring) {
1287
+									$string = $newstring;
1288
+				}
1230 1289
 			}
1231 1290
 
1232 1291
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1242,23 +1301,25 @@  discard block
 block discarded – undo
1242 1301
 		if (!$context['utf8'] && function_exists('iconv'))
1243 1302
 		{
1244 1303
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1245
-			if ($newstring)
1246
-				$string = $newstring;
1304
+			if ($newstring) {
1305
+							$string = $newstring;
1306
+			}
1247 1307
 		}
1248 1308
 
1249 1309
 		$entityConvert = function($m)
1250 1310
 		{
1251 1311
 			$c = $m[1];
1252
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1253
-				return $c;
1254
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1255
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1256
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1259
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1260
-			else
1261
-				return "";
1312
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1313
+							return $c;
1314
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1318
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1319
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1320
+			} else {
1321
+							return "";
1322
+			}
1262 1323
 		};
1263 1324
 
1264 1325
 		// Convert all 'special' characters to HTML entities.
@@ -1272,19 +1333,20 @@  discard block
 block discarded – undo
1272 1333
 		$string = base64_encode($string);
1273 1334
 
1274 1335
 		// Show the characterset and the transfer-encoding for header strings.
1275
-		if ($with_charset)
1276
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		if ($with_charset) {
1337
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1338
+		}
1277 1339
 
1278 1340
 		// Break it up in lines (mail body).
1279
-		else
1280
-			$string = chunk_split($string, 76, $line_break);
1341
+		else {
1342
+					$string = chunk_split($string, 76, $line_break);
1343
+		}
1281 1344
 
1282 1345
 		return array($charset, $string, 'base64');
1346
+	} else {
1347
+			return array($charset, $string, '7bit');
1348
+	}
1283 1349
 	}
1284
-
1285
-	else
1286
-		return array($charset, $string, '7bit');
1287
-}
1288 1350
 
1289 1351
 /**
1290 1352
  * Sends mail, like mail() but over SMTP.
@@ -1308,8 +1370,9 @@  discard block
 block discarded – undo
1308 1370
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1309 1371
 	{
1310 1372
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1311
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1312
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1374
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1375
+		}
1313 1376
 
1314 1377
 		if ($socket)
1315 1378
 		{
@@ -1330,8 +1393,9 @@  discard block
 block discarded – undo
1330 1393
 		// Maybe we can still save this?  The port might be wrong.
1331 1394
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1332 1395
 		{
1333
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1334
-				log_error($txt['smtp_port_ssl']);
1396
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1397
+							log_error($txt['smtp_port_ssl']);
1398
+			}
1335 1399
 		}
1336 1400
 
1337 1401
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1343,20 +1407,23 @@  discard block
 block discarded – undo
1343 1407
 	}
1344 1408
 
1345 1409
 	// Wait for a response of 220, without "-" continuer.
1346
-	if (!server_parse(null, $socket, '220'))
1347
-		return false;
1410
+	if (!server_parse(null, $socket, '220')) {
1411
+			return false;
1412
+	}
1348 1413
 
1349 1414
 	// Try and determine the servers name, fall back to the mail servers if not found
1350 1415
 	$helo = false;
1351
-	if (function_exists('gethostname') && gethostname() !== false)
1352
-		$helo = gethostname();
1353
-	elseif (function_exists('php_uname'))
1354
-		$helo = php_uname('n');
1355
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1356
-		$helo = $_SERVER['SERVER_NAME'];
1416
+	if (function_exists('gethostname') && gethostname() !== false) {
1417
+			$helo = gethostname();
1418
+	} elseif (function_exists('php_uname')) {
1419
+			$helo = php_uname('n');
1420
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1421
+			$helo = $_SERVER['SERVER_NAME'];
1422
+	}
1357 1423
 
1358
-	if (empty($helo))
1359
-		$helo = $modSettings['smtp_host'];
1424
+	if (empty($helo)) {
1425
+			$helo = $modSettings['smtp_host'];
1426
+	}
1360 1427
 
1361 1428
 	// SMTP = 1, SMTP - STARTTLS = 2
1362 1429
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1368,33 +1435,39 @@  discard block
 block discarded – undo
1368 1435
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1369 1436
 			{
1370 1437
 				// Send STARTTLS to enable encryption
1371
-				if (!server_parse('STARTTLS', $socket, '220'))
1372
-					return false;
1438
+				if (!server_parse('STARTTLS', $socket, '220')) {
1439
+									return false;
1440
+				}
1373 1441
 				// Enable the encryption
1374
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1375
-					return false;
1442
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1443
+									return false;
1444
+				}
1376 1445
 				// Send the EHLO command again
1377
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1378
-					return false;
1446
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1447
+									return false;
1448
+				}
1379 1449
 			}
1380 1450
 
1381
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1382
-				return false;
1451
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1452
+							return false;
1453
+			}
1383 1454
 			// Send the username and password, encoded.
1384
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1385
-				return false;
1455
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1456
+							return false;
1457
+			}
1386 1458
 			// The password is already encoded ;)
1387
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1388
-				return false;
1459
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1460
+							return false;
1461
+			}
1462
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1463
+					return false;
1389 1464
 		}
1390
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1391
-			return false;
1392
-	}
1393
-	else
1465
+	} else
1394 1466
 	{
1395 1467
 		// Just say "helo".
1396
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1397
-			return false;
1468
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1469
+					return false;
1470
+		}
1398 1471
 	}
1399 1472
 
1400 1473
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1407,31 +1480,38 @@  discard block
 block discarded – undo
1407 1480
 		// Reset the connection to send another email.
1408 1481
 		if ($i != 0)
1409 1482
 		{
1410
-			if (!server_parse('RSET', $socket, '250'))
1411
-				return false;
1483
+			if (!server_parse('RSET', $socket, '250')) {
1484
+							return false;
1485
+			}
1412 1486
 		}
1413 1487
 
1414 1488
 		// From, to, and then start the data...
1415
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1416
-			return false;
1417
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('DATA', $socket, '354'))
1420
-			return false;
1489
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1490
+					return false;
1491
+		}
1492
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1493
+					return false;
1494
+		}
1495
+		if (!server_parse('DATA', $socket, '354')) {
1496
+					return false;
1497
+		}
1421 1498
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1422
-		if (strlen($mail_to) > 0)
1423
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		if (strlen($mail_to) > 0) {
1500
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1501
+		}
1424 1502
 		fputs($socket, $headers . "\r\n\r\n");
1425 1503
 		fputs($socket, $message . "\r\n");
1426 1504
 
1427 1505
 		// Send a ., or in other words "end of data".
1428
-		if (!server_parse('.', $socket, '250'))
1429
-			return false;
1506
+		if (!server_parse('.', $socket, '250')) {
1507
+					return false;
1508
+		}
1430 1509
 
1431 1510
 		// Almost done, almost done... don't stop me just yet!
1432 1511
 		@set_time_limit(300);
1433
-		if (function_exists('apache_reset_timeout'))
1434
-			@apache_reset_timeout();
1512
+		if (function_exists('apache_reset_timeout')) {
1513
+					@apache_reset_timeout();
1514
+		}
1435 1515
 	}
1436 1516
 	fputs($socket, 'QUIT' . "\r\n");
1437 1517
 	fclose($socket);
@@ -1455,8 +1535,9 @@  discard block
 block discarded – undo
1455 1535
 {
1456 1536
 	global $txt;
1457 1537
 
1458
-	if ($message !== null)
1459
-		fputs($socket, $message . "\r\n");
1538
+	if ($message !== null) {
1539
+			fputs($socket, $message . "\r\n");
1540
+	}
1460 1541
 
1461 1542
 	// No response yet.
1462 1543
 	$server_response = '';
@@ -1472,8 +1553,9 @@  discard block
 block discarded – undo
1472 1553
 		$response .= $server_response;
1473 1554
 	}
1474 1555
 
1475
-	if ($code === null)
1476
-		return substr($server_response, 0, 3);
1556
+	if ($code === null) {
1557
+			return substr($server_response, 0, 3);
1558
+	}
1477 1559
 
1478 1560
 	if (substr($server_response, 0, 3) != $code)
1479 1561
 	{
@@ -1503,8 +1585,9 @@  discard block
 block discarded – undo
1503 1585
 	// Create a pspell or enchant dictionary resource
1504 1586
 	$dict = spell_init();
1505 1587
 
1506
-	if (!isset($_POST['spellstring']) || !$dict)
1507
-		die;
1588
+	if (!isset($_POST['spellstring']) || !$dict) {
1589
+			die;
1590
+	}
1508 1591
 
1509 1592
 	// Construct a bit of Javascript code.
1510 1593
 	$context['spell_js'] = '
@@ -1522,8 +1605,9 @@  discard block
 block discarded – undo
1522 1605
 		$check_word = explode('|', $alphas[$i]);
1523 1606
 
1524 1607
 		// If the word is a known word, or spelled right...
1525
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1526
-			continue;
1608
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1609
+					continue;
1610
+		}
1527 1611
 
1528 1612
 		// Find the word, and move up the "last occurrence" to here.
1529 1613
 		$found_words = true;
@@ -1537,20 +1621,23 @@  discard block
 block discarded – undo
1537 1621
 		if (!empty($suggestions))
1538 1622
 		{
1539 1623
 			// But first check they aren't going to be censored - no naughty words!
1540
-			foreach ($suggestions as $k => $word)
1541
-				if ($suggestions[$k] != censorText($word))
1624
+			foreach ($suggestions as $k => $word) {
1625
+							if ($suggestions[$k] != censorText($word))
1542 1626
 					unset($suggestions[$k]);
1627
+			}
1543 1628
 
1544
-			if (!empty($suggestions))
1545
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			if (!empty($suggestions)) {
1630
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1631
+			}
1546 1632
 		}
1547 1633
 
1548 1634
 		$context['spell_js'] .= ']),';
1549 1635
 	}
1550 1636
 
1551 1637
 	// If words were found, take off the last comma.
1552
-	if ($found_words)
1553
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	if ($found_words) {
1639
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1640
+	}
1554 1641
 
1555 1642
 	$context['spell_js'] .= '
1556 1643
 		);';
@@ -1585,11 +1672,13 @@  discard block
 block discarded – undo
1585 1672
 	global $user_info, $smcFunc;
1586 1673
 
1587 1674
 	// Can't do it if there's no topics.
1588
-	if (empty($topics))
1589
-		return;
1675
+	if (empty($topics)) {
1676
+			return;
1677
+	}
1590 1678
 	// It must be an array - it must!
1591
-	if (!is_array($topics))
1592
-		$topics = array($topics);
1679
+	if (!is_array($topics)) {
1680
+			$topics = array($topics);
1681
+	}
1593 1682
 
1594 1683
 	// Get the subject and body...
1595 1684
 	$result = $smcFunc['db_query']('', '
@@ -1637,14 +1726,15 @@  discard block
 block discarded – undo
1637 1726
 	}
1638 1727
 	$smcFunc['db_free_result']($result);
1639 1728
 
1640
-	if (!empty($task_rows))
1641
-		$smcFunc['db_insert']('',
1729
+	if (!empty($task_rows)) {
1730
+			$smcFunc['db_insert']('',
1642 1731
 			'{db_prefix}background_tasks',
1643 1732
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1644 1733
 			$task_rows,
1645 1734
 			array('id_task')
1646 1735
 		);
1647
-}
1736
+	}
1737
+	}
1648 1738
 
1649 1739
 /**
1650 1740
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1682,9 +1772,9 @@  discard block
 block discarded – undo
1682 1772
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1683 1773
 
1684 1774
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1685
-	if (!$modSettings['postmod_active'])
1686
-		$topicOptions['is_approved'] = true;
1687
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1775
+	if (!$modSettings['postmod_active']) {
1776
+			$topicOptions['is_approved'] = true;
1777
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1688 1778
 	{
1689 1779
 		$request = $smcFunc['db_query']('', '
1690 1780
 			SELECT approved
@@ -1707,8 +1797,7 @@  discard block
 block discarded – undo
1707 1797
 			$posterOptions['id'] = 0;
1708 1798
 			$posterOptions['name'] = $txt['guest_title'];
1709 1799
 			$posterOptions['email'] = '';
1710
-		}
1711
-		elseif ($posterOptions['id'] != $user_info['id'])
1800
+		} elseif ($posterOptions['id'] != $user_info['id'])
1712 1801
 		{
1713 1802
 			$request = $smcFunc['db_query']('', '
1714 1803
 				SELECT member_name, email_address
@@ -1726,12 +1815,11 @@  discard block
 block discarded – undo
1726 1815
 				$posterOptions['id'] = 0;
1727 1816
 				$posterOptions['name'] = $txt['guest_title'];
1728 1817
 				$posterOptions['email'] = '';
1818
+			} else {
1819
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1729 1820
 			}
1730
-			else
1731
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1732 1821
 			$smcFunc['db_free_result']($request);
1733
-		}
1734
-		else
1822
+		} else
1735 1823
 		{
1736 1824
 			$posterOptions['name'] = $user_info['name'];
1737 1825
 			$posterOptions['email'] = $user_info['email'];
@@ -1741,8 +1829,9 @@  discard block
 block discarded – undo
1741 1829
 	if (!empty($modSettings['enable_mentions']))
1742 1830
 	{
1743 1831
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1744
-		if (!empty($msgOptions['mentioned_members']))
1745
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		if (!empty($msgOptions['mentioned_members'])) {
1833
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1834
+		}
1746 1835
 	}
1747 1836
 
1748 1837
 	// It's do or die time: forget any user aborts!
@@ -1775,12 +1864,13 @@  discard block
 block discarded – undo
1775 1864
 	);
1776 1865
 
1777 1866
 	// Something went wrong creating the message...
1778
-	if (empty($msgOptions['id']))
1779
-		return false;
1867
+	if (empty($msgOptions['id'])) {
1868
+			return false;
1869
+	}
1780 1870
 
1781 1871
 	// Fix the attachments.
1782
-	if (!empty($msgOptions['attachments']))
1783
-		$smcFunc['db_query']('', '
1872
+	if (!empty($msgOptions['attachments'])) {
1873
+			$smcFunc['db_query']('', '
1784 1874
 			UPDATE {db_prefix}attachments
1785 1875
 			SET id_msg = {int:id_msg}
1786 1876
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1789,6 +1879,7 @@  discard block
 block discarded – undo
1789 1879
 				'id_msg' => $msgOptions['id'],
1790 1880
 			)
1791 1881
 		);
1882
+	}
1792 1883
 
1793 1884
 	// What if we want to export new posts out to a CMS?
1794 1885
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1865,20 +1956,23 @@  discard block
 block discarded – undo
1865 1956
 			'id_topic' => $topicOptions['id'],
1866 1957
 			'counter_increment' => 1,
1867 1958
 		);
1868
-		if ($msgOptions['approved'])
1869
-			$topics_columns = array(
1959
+		if ($msgOptions['approved']) {
1960
+					$topics_columns = array(
1870 1961
 				'id_member_updated = {int:poster_id}',
1871 1962
 				'id_last_msg = {int:id_msg}',
1872 1963
 				'num_replies = num_replies + {int:counter_increment}',
1873 1964
 			);
1874
-		else
1875
-			$topics_columns = array(
1965
+		} else {
1966
+					$topics_columns = array(
1876 1967
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1877 1968
 			);
1878
-		if ($topicOptions['lock_mode'] !== null)
1879
-			$topics_columns[] = 'locked = {int:locked}';
1880
-		if ($topicOptions['sticky_mode'] !== null)
1881
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1969
+		}
1970
+		if ($topicOptions['lock_mode'] !== null) {
1971
+					$topics_columns[] = 'locked = {int:locked}';
1972
+		}
1973
+		if ($topicOptions['sticky_mode'] !== null) {
1974
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1975
+		}
1882 1976
 
1883 1977
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1884 1978
 
@@ -1907,8 +2001,8 @@  discard block
 block discarded – undo
1907 2001
 	);
1908 2002
 
1909 2003
 	// Increase the number of posts and topics on the board.
1910
-	if ($msgOptions['approved'])
1911
-		$smcFunc['db_query']('', '
2004
+	if ($msgOptions['approved']) {
2005
+			$smcFunc['db_query']('', '
1912 2006
 			UPDATE {db_prefix}boards
1913 2007
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1914 2008
 			WHERE id_board = {int:id_board}',
@@ -1916,7 +2010,7 @@  discard block
 block discarded – undo
1916 2010
 				'id_board' => $topicOptions['board'],
1917 2011
 			)
1918 2012
 		);
1919
-	else
2013
+	} else
1920 2014
 	{
1921 2015
 		$smcFunc['db_query']('', '
1922 2016
 			UPDATE {db_prefix}boards
@@ -1986,8 +2080,8 @@  discard block
 block discarded – undo
1986 2080
 		}
1987 2081
 	}
1988 2082
 
1989
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1990
-		$smcFunc['db_insert']('',
2083
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2084
+			$smcFunc['db_insert']('',
1991 2085
 			'{db_prefix}background_tasks',
1992 2086
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1993 2087
 			array(
@@ -1999,19 +2093,22 @@  discard block
 block discarded – undo
1999 2093
 			),
2000 2094
 			array('id_task')
2001 2095
 		);
2096
+	}
2002 2097
 
2003 2098
 	// If there's a custom search index, it may need updating...
2004 2099
 	require_once($sourcedir . '/Search.php');
2005 2100
 	$searchAPI = findSearchAPI();
2006
-	if (is_callable(array($searchAPI, 'postCreated')))
2007
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2102
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	}
2008 2104
 
2009 2105
 	// Increase the post counter for the user that created the post.
2010 2106
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2011 2107
 	{
2012 2108
 		// Are you the one that happened to create this post?
2013
-		if ($user_info['id'] == $posterOptions['id'])
2014
-			$user_info['posts']++;
2109
+		if ($user_info['id'] == $posterOptions['id']) {
2110
+					$user_info['posts']++;
2111
+		}
2015 2112
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2016 2113
 	}
2017 2114
 
@@ -2019,19 +2116,21 @@  discard block
 block discarded – undo
2019 2116
 	$_SESSION['last_read_topic'] = 0;
2020 2117
 
2021 2118
 	// Better safe than sorry.
2022
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2023
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2120
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	}
2024 2122
 
2025 2123
 	// Update all the stats so everyone knows about this new topic and message.
2026 2124
 	updateStats('message', true, $msgOptions['id']);
2027 2125
 
2028 2126
 	// Update the last message on the board assuming it's approved AND the topic is.
2029
-	if ($msgOptions['approved'])
2030
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	if ($msgOptions['approved']) {
2128
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	}
2031 2130
 
2032 2131
 	// Queue createPost background notification
2033
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2034
-		$smcFunc['db_insert']('',
2132
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2133
+			$smcFunc['db_insert']('',
2035 2134
 			'{db_prefix}background_tasks',
2036 2135
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2037 2136
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2042,6 +2141,7 @@  discard block
 block discarded – undo
2042 2141
 			)), 0),
2043 2142
 			array('id_task')
2044 2143
 		);
2144
+	}
2045 2145
 
2046 2146
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2047 2147
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2068,14 +2168,18 @@  discard block
 block discarded – undo
2068 2168
 
2069 2169
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2070 2170
 	$messages_columns = array();
2071
-	if (isset($posterOptions['name']))
2072
-		$messages_columns['poster_name'] = $posterOptions['name'];
2073
-	if (isset($posterOptions['email']))
2074
-		$messages_columns['poster_email'] = $posterOptions['email'];
2075
-	if (isset($msgOptions['icon']))
2076
-		$messages_columns['icon'] = $msgOptions['icon'];
2077
-	if (isset($msgOptions['subject']))
2078
-		$messages_columns['subject'] = $msgOptions['subject'];
2171
+	if (isset($posterOptions['name'])) {
2172
+			$messages_columns['poster_name'] = $posterOptions['name'];
2173
+	}
2174
+	if (isset($posterOptions['email'])) {
2175
+			$messages_columns['poster_email'] = $posterOptions['email'];
2176
+	}
2177
+	if (isset($msgOptions['icon'])) {
2178
+			$messages_columns['icon'] = $msgOptions['icon'];
2179
+	}
2180
+	if (isset($msgOptions['subject'])) {
2181
+			$messages_columns['subject'] = $msgOptions['subject'];
2182
+	}
2079 2183
 	if (isset($msgOptions['body']))
2080 2184
 	{
2081 2185
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2102,8 +2206,9 @@  discard block
 block discarded – undo
2102 2206
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2103 2207
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2104 2208
 	}
2105
-	if (isset($msgOptions['smileys_enabled']))
2106
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	if (isset($msgOptions['smileys_enabled'])) {
2210
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	}
2107 2212
 
2108 2213
 	// Which columns need to be ints?
2109 2214
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2121,23 +2226,27 @@  discard block
 block discarded – undo
2121 2226
 		{
2122 2227
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2123 2228
 
2124
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2125
-				foreach ($match[1] as $i => $oldID)
2229
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2230
+							foreach ($match[1] as $i => $oldID)
2126 2231
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2232
+			}
2127 2233
 
2128
-			if (empty($modSettings['search_custom_index_config']))
2129
-				unset($msgOptions['old_body']);
2234
+			if (empty($modSettings['search_custom_index_config'])) {
2235
+							unset($msgOptions['old_body']);
2236
+			}
2130 2237
 		}
2131 2238
 
2132 2239
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2133 2240
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2134 2241
 
2135 2242
 		// Remove the poster.
2136
-		if (isset($mentions[$user_info['id']]))
2137
-			unset($mentions[$user_info['id']]);
2243
+		if (isset($mentions[$user_info['id']])) {
2244
+					unset($mentions[$user_info['id']]);
2245
+		}
2138 2246
 
2139
-		if (isset($oldmentions[$user_info['id']]))
2140
-			unset($oldmentions[$user_info['id']]);
2247
+		if (isset($oldmentions[$user_info['id']])) {
2248
+					unset($oldmentions[$user_info['id']]);
2249
+		}
2141 2250
 
2142 2251
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2143 2252
 		{
@@ -2167,8 +2276,9 @@  discard block
 block discarded – undo
2167 2276
 	}
2168 2277
 
2169 2278
 	// Nothing to do?
2170
-	if (empty($messages_columns))
2171
-		return true;
2279
+	if (empty($messages_columns)) {
2280
+			return true;
2281
+	}
2172 2282
 
2173 2283
 	// Change the post.
2174 2284
 	$smcFunc['db_query']('', '
@@ -2229,8 +2339,9 @@  discard block
 block discarded – undo
2229 2339
 	// If there's a custom search index, it needs to be modified...
2230 2340
 	require_once($sourcedir . '/Search.php');
2231 2341
 	$searchAPI = findSearchAPI();
2232
-	if (is_callable(array($searchAPI, 'postModified')))
2233
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	if (is_callable(array($searchAPI, 'postModified'))) {
2343
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	}
2234 2345
 
2235 2346
 	if (isset($msgOptions['subject']))
2236 2347
 	{
@@ -2244,14 +2355,16 @@  discard block
 block discarded – undo
2244 2355
 				'id_first_msg' => $msgOptions['id'],
2245 2356
 			)
2246 2357
 		);
2247
-		if ($smcFunc['db_num_rows']($request) == 1)
2248
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		if ($smcFunc['db_num_rows']($request) == 1) {
2359
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		}
2249 2361
 		$smcFunc['db_free_result']($request);
2250 2362
 	}
2251 2363
 
2252 2364
 	// Finally, if we are setting the approved state we need to do much more work :(
2253
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2254
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2366
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	}
2255 2368
 
2256 2369
 	return true;
2257 2370
 }
@@ -2268,11 +2381,13 @@  discard block
 block discarded – undo
2268 2381
 {
2269 2382
 	global $smcFunc;
2270 2383
 
2271
-	if (!is_array($msgs))
2272
-		$msgs = array($msgs);
2384
+	if (!is_array($msgs)) {
2385
+			$msgs = array($msgs);
2386
+	}
2273 2387
 
2274
-	if (empty($msgs))
2275
-		return false;
2388
+	if (empty($msgs)) {
2389
+			return false;
2390
+	}
2276 2391
 
2277 2392
 	// May as well start at the beginning, working out *what* we need to change.
2278 2393
 	$request = $smcFunc['db_query']('', '
@@ -2304,20 +2419,22 @@  discard block
 block discarded – undo
2304 2419
 		$topics[] = $row['id_topic'];
2305 2420
 
2306 2421
 		// Ensure our change array exists already.
2307
-		if (!isset($topic_changes[$row['id_topic']]))
2308
-			$topic_changes[$row['id_topic']] = array(
2422
+		if (!isset($topic_changes[$row['id_topic']])) {
2423
+					$topic_changes[$row['id_topic']] = array(
2309 2424
 				'id_last_msg' => $row['id_last_msg'],
2310 2425
 				'approved' => $row['topic_approved'],
2311 2426
 				'replies' => 0,
2312 2427
 				'unapproved_posts' => 0,
2313 2428
 			);
2314
-		if (!isset($board_changes[$row['id_board']]))
2315
-			$board_changes[$row['id_board']] = array(
2429
+		}
2430
+		if (!isset($board_changes[$row['id_board']])) {
2431
+					$board_changes[$row['id_board']] = array(
2316 2432
 				'posts' => 0,
2317 2433
 				'topics' => 0,
2318 2434
 				'unapproved_posts' => 0,
2319 2435
 				'unapproved_topics' => 0,
2320 2436
 			);
2437
+		}
2321 2438
 
2322 2439
 		// If it's the first message then the topic state changes!
2323 2440
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2338,14 +2455,13 @@  discard block
 block discarded – undo
2338 2455
 				'poster' => $row['id_member'],
2339 2456
 				'new_topic' => true,
2340 2457
 			);
2341
-		}
2342
-		else
2458
+		} else
2343 2459
 		{
2344 2460
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2345 2461
 
2346 2462
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2347
-			if ($row['id_msg'] > $row['id_last_msg'])
2348
-				$notification_posts[$row['id_topic']] = array(
2463
+			if ($row['id_msg'] > $row['id_last_msg']) {
2464
+							$notification_posts[$row['id_topic']] = array(
2349 2465
 					'id' => $row['id_msg'],
2350 2466
 					'body' => $row['body'],
2351 2467
 					'subject' => $row['subject'],
@@ -2356,28 +2472,33 @@  discard block
 block discarded – undo
2356 2472
 					'new_topic' => false,
2357 2473
 					'msg' => $row['id_msg'],
2358 2474
 				);
2475
+			}
2359 2476
 		}
2360 2477
 
2361 2478
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2362
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2363
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2480
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		}
2364 2482
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2365
-		elseif (!$approve)
2366
-			// Default to the first message and then we'll override in a bit ;)
2483
+		elseif (!$approve) {
2484
+					// Default to the first message and then we'll override in a bit ;)
2367 2485
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2486
+		}
2368 2487
 
2369 2488
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2489
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2372 2491
 
2373 2492
 		// Post count for the user?
2374
-		if ($row['id_member'] && empty($row['count_posts']))
2375
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		if ($row['id_member'] && empty($row['count_posts'])) {
2494
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		}
2376 2496
 	}
2377 2497
 	$smcFunc['db_free_result']($request);
2378 2498
 
2379
-	if (empty($msgs))
2380
-		return;
2499
+	if (empty($msgs)) {
2500
+			return;
2501
+	}
2381 2502
 
2382 2503
 	// Now we have the differences make the changes, first the easy one.
2383 2504
 	$smcFunc['db_query']('', '
@@ -2404,14 +2525,15 @@  discard block
 block discarded – undo
2404 2525
 				'approved' => 1,
2405 2526
 			)
2406 2527
 		);
2407
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2408
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2529
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		}
2409 2531
 		$smcFunc['db_free_result']($request);
2410 2532
 	}
2411 2533
 
2412 2534
 	// ... next the topics...
2413
-	foreach ($topic_changes as $id => $changes)
2414
-		$smcFunc['db_query']('', '
2535
+	foreach ($topic_changes as $id => $changes) {
2536
+			$smcFunc['db_query']('', '
2415 2537
 			UPDATE {db_prefix}topics
2416 2538
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2417 2539
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2424,10 +2546,11 @@  discard block
 block discarded – undo
2424 2546
 				'id_topic' => $id,
2425 2547
 			)
2426 2548
 		);
2549
+	}
2427 2550
 
2428 2551
 	// ... finally the boards...
2429
-	foreach ($board_changes as $id => $changes)
2430
-		$smcFunc['db_query']('', '
2552
+	foreach ($board_changes as $id => $changes) {
2553
+			$smcFunc['db_query']('', '
2431 2554
 			UPDATE {db_prefix}boards
2432 2555
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2433 2556
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2440,13 +2563,14 @@  discard block
 block discarded – undo
2440 2563
 				'id_board' => $id,
2441 2564
 			)
2442 2565
 		);
2566
+	}
2443 2567
 
2444 2568
 	// Finally, least importantly, notifications!
2445 2569
 	if ($approve)
2446 2570
 	{
2447 2571
 		$task_rows = array();
2448
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2449
-			$task_rows[] = array(
2572
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2573
+					$task_rows[] = array(
2450 2574
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2451 2575
 					'msgOptions' => array(
2452 2576
 						'id' => $topic['msg'],
@@ -2464,14 +2588,16 @@  discard block
 block discarded – undo
2464 2588
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2465 2589
 				)), 0
2466 2590
 			);
2591
+		}
2467 2592
 
2468
-		if ($notify)
2469
-			$smcFunc['db_insert']('',
2593
+		if ($notify) {
2594
+					$smcFunc['db_insert']('',
2470 2595
 				'{db_prefix}background_tasks',
2471 2596
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2472 2597
 				$task_rows,
2473 2598
 				array('id_task')
2474 2599
 			);
2600
+		}
2475 2601
 
2476 2602
 		$smcFunc['db_query']('', '
2477 2603
 			DELETE FROM {db_prefix}approval_queue
@@ -2487,8 +2613,9 @@  discard block
 block discarded – undo
2487 2613
 	else
2488 2614
 	{
2489 2615
 		$msgInserts = array();
2490
-		foreach ($msgs as $msg)
2491
-			$msgInserts[] = array($msg);
2616
+		foreach ($msgs as $msg) {
2617
+					$msgInserts[] = array($msg);
2618
+		}
2492 2619
 
2493 2620
 		$smcFunc['db_insert']('ignore',
2494 2621
 			'{db_prefix}approval_queue',
@@ -2502,9 +2629,10 @@  discard block
 block discarded – undo
2502 2629
 	updateLastMessages(array_keys($board_changes));
2503 2630
 
2504 2631
 	// Post count for the members?
2505
-	if (!empty($member_post_changes))
2506
-		foreach ($member_post_changes as $id_member => $count_change)
2632
+	if (!empty($member_post_changes)) {
2633
+			foreach ($member_post_changes as $id_member => $count_change)
2507 2634
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2635
+	}
2508 2636
 
2509 2637
 	return true;
2510 2638
 }
@@ -2521,11 +2649,13 @@  discard block
 block discarded – undo
2521 2649
 {
2522 2650
 	global $smcFunc;
2523 2651
 
2524
-	if (!is_array($topics))
2525
-		$topics = array($topics);
2652
+	if (!is_array($topics)) {
2653
+			$topics = array($topics);
2654
+	}
2526 2655
 
2527
-	if (empty($topics))
2528
-		return false;
2656
+	if (empty($topics)) {
2657
+			return false;
2658
+	}
2529 2659
 
2530 2660
 	$approve_type = $approve ? 0 : 1;
2531 2661
 
@@ -2541,8 +2671,9 @@  discard block
 block discarded – undo
2541 2671
 		)
2542 2672
 	);
2543 2673
 	$msgs = array();
2544
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2545
-		$msgs[] = $row['id_msg'];
2674
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2675
+			$msgs[] = $row['id_msg'];
2676
+	}
2546 2677
 	$smcFunc['db_free_result']($request);
2547 2678
 
2548 2679
 	return approvePosts($msgs, $approve);
@@ -2565,11 +2696,13 @@  discard block
 block discarded – undo
2565 2696
 	global $board_info, $board, $smcFunc;
2566 2697
 
2567 2698
 	// Please - let's be sane.
2568
-	if (empty($setboards))
2569
-		return false;
2699
+	if (empty($setboards)) {
2700
+			return false;
2701
+	}
2570 2702
 
2571
-	if (!is_array($setboards))
2572
-		$setboards = array($setboards);
2703
+	if (!is_array($setboards)) {
2704
+			$setboards = array($setboards);
2705
+	}
2573 2706
 
2574 2707
 	// If we don't know the id_msg we need to find it.
2575 2708
 	if (!$id_msg)
@@ -2587,15 +2720,16 @@  discard block
 block discarded – undo
2587 2720
 			)
2588 2721
 		);
2589 2722
 		$lastMsg = array();
2590
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2591
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2724
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		}
2592 2726
 		$smcFunc['db_free_result']($request);
2593
-	}
2594
-	else
2727
+	} else
2595 2728
 	{
2596 2729
 		// Just to note - there should only be one board passed if we are doing this.
2597
-		foreach ($setboards as $id_board)
2598
-			$lastMsg[$id_board] = $id_msg;
2730
+		foreach ($setboards as $id_board) {
2731
+					$lastMsg[$id_board] = $id_msg;
2732
+		}
2599 2733
 	}
2600 2734
 
2601 2735
 	$parent_boards = array();
@@ -2610,10 +2744,11 @@  discard block
 block discarded – undo
2610 2744
 			$lastModified[$id_board] = 0;
2611 2745
 		}
2612 2746
 
2613
-		if (!empty($board) && $id_board == $board)
2614
-			$parents = $board_info['parent_boards'];
2615
-		else
2616
-			$parents = getBoardParents($id_board);
2747
+		if (!empty($board) && $id_board == $board) {
2748
+					$parents = $board_info['parent_boards'];
2749
+		} else {
2750
+					$parents = getBoardParents($id_board);
2751
+		}
2617 2752
 
2618 2753
 		// Ignore any parents on the top child level.
2619 2754
 		// @todo Why?
@@ -2622,10 +2757,11 @@  discard block
 block discarded – undo
2622 2757
 			if ($parent['level'] != 0)
2623 2758
 			{
2624 2759
 				// If we're already doing this one as a board, is this a higher last modified?
2625
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2626
-					$lastModified[$id] = $lastModified[$id_board];
2627
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2628
-					$parent_boards[$id] = $lastModified[$id_board];
2760
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2761
+									$lastModified[$id] = $lastModified[$id_board];
2762
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2763
+									$parent_boards[$id] = $lastModified[$id_board];
2764
+				}
2629 2765
 			}
2630 2766
 		}
2631 2767
 	}
@@ -2638,23 +2774,24 @@  discard block
 block discarded – undo
2638 2774
 	// Finally, to save on queries make the changes...
2639 2775
 	foreach ($parent_boards as $id => $msg)
2640 2776
 	{
2641
-		if (!isset($parent_updates[$msg]))
2642
-			$parent_updates[$msg] = array($id);
2643
-		else
2644
-			$parent_updates[$msg][] = $id;
2777
+		if (!isset($parent_updates[$msg])) {
2778
+					$parent_updates[$msg] = array($id);
2779
+		} else {
2780
+					$parent_updates[$msg][] = $id;
2781
+		}
2645 2782
 	}
2646 2783
 
2647 2784
 	foreach ($lastMsg as $id => $msg)
2648 2785
 	{
2649
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2650
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2786
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2787
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2651 2788
 				'id' => $msg,
2652 2789
 				'updated' => $lastModified[$id],
2653 2790
 				'boards' => array($id)
2654 2791
 			);
2655
-
2656
-		else
2657
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		} else {
2793
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		}
2658 2795
 	}
2659 2796
 
2660 2797
 	// Now commit the changes!
@@ -2746,11 +2883,13 @@  discard block
 block discarded – undo
2746 2883
 	global $txt, $mbname, $scripturl, $settings;
2747 2884
 
2748 2885
 	// First things first, load up the email templates language file, if we need to.
2749
-	if ($loadLang)
2750
-		loadLanguage('EmailTemplates', $lang);
2886
+	if ($loadLang) {
2887
+			loadLanguage('EmailTemplates', $lang);
2888
+	}
2751 2889
 
2752
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2753
-		fatal_lang_error('email_no_template', 'template', array($template));
2890
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2891
+			fatal_lang_error('email_no_template', 'template', array($template));
2892
+	}
2754 2893
 
2755 2894
 	$ret = array(
2756 2895
 		'subject' => $txt[$template . '_subject'],
@@ -2800,17 +2939,18 @@  discard block
 block discarded – undo
2800 2939
 function user_info_callback($matches)
2801 2940
 {
2802 2941
 	global $user_info;
2803
-	if (empty($matches[1]))
2804
-		return '';
2942
+	if (empty($matches[1])) {
2943
+			return '';
2944
+	}
2805 2945
 
2806 2946
 	$use_ref = true;
2807 2947
 	$ref = &$user_info;
2808 2948
 
2809 2949
 	foreach (explode('.', $matches[1]) as $index)
2810 2950
 	{
2811
-		if ($use_ref && isset($ref[$index]))
2812
-			$ref = &$ref[$index];
2813
-		else
2951
+		if ($use_ref && isset($ref[$index])) {
2952
+					$ref = &$ref[$index];
2953
+		} else
2814 2954
 		{
2815 2955
 			$use_ref = false;
2816 2956
 			break;
@@ -2847,8 +2987,7 @@  discard block
 block discarded – undo
2847 2987
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2848 2988
 		{
2849 2989
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2850
-		}
2851
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2990
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2852 2991
 		{
2853 2992
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2854 2993
 		}
@@ -2858,8 +2997,7 @@  discard block
 block discarded – undo
2858 2997
 		{
2859 2998
 			$context['provider'] = 'enchant';
2860 2999
 			return $enchant_link;
2861
-		}
2862
-		else
3000
+		} else
2863 3001
 		{
2864 3002
 			// Free up any resources used...
2865 3003
 			@enchant_broker_free($context['enchant_broker']);
@@ -2880,8 +3018,9 @@  discard block
 block discarded – undo
2880 3018
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2881 3019
 
2882 3020
 		// Most people don't have anything but English installed... So we use English as a last resort.
2883
-		if (!$pspell_link)
2884
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		if (!$pspell_link) {
3022
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		}
2885 3024
 
2886 3025
 		error_reporting($old);
2887 3026
 		ob_end_clean();
@@ -2921,8 +3060,7 @@  discard block
 block discarded – undo
2921 3060
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2922 3061
 		}
2923 3062
 		return enchant_dict_check($dict, $word);
2924
-	}
2925
-	elseif ($context['provider'] == 'pspell')
3063
+	} elseif ($context['provider'] == 'pspell')
2926 3064
 	{
2927 3065
 		return pspell_check($dict, $word);
2928 3066
 	}
@@ -2958,13 +3096,11 @@  discard block
 block discarded – undo
2958 3096
 			}
2959 3097
 
2960 3098
 			return $suggestions;
2961
-		}
2962
-		else
3099
+		} else
2963 3100
 		{
2964 3101
 			return enchant_dict_suggest($dict, $word);
2965 3102
 		}
2966
-	}
2967
-	elseif ($context['provider'] == 'pspell')
3103
+	} elseif ($context['provider'] == 'pspell')
2968 3104
 	{
2969 3105
 		return pspell_suggest($dict, $word);
2970 3106
 	}
Please login to merge, or discard this patch.
Themes/default/Printpage.template.php 1 patch
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -144,11 +144,12 @@  discard block
 block discarded – undo
144 144
 				<div class="question">', $txt['poll_question'], ': <strong>', $context['poll']['question'], '</strong>';
145 145
 
146 146
 		$options = 1;
147
-		foreach ($context['poll']['options'] as $option)
148
-			echo '
147
+		foreach ($context['poll']['options'] as $option) {
148
+					echo '
149 149
 					<div class="', $option['voted_this'] ? 'voted' : '', '">', $txt['option'], ' ', $options++, ': <strong>', $option['option'], '</strong>
150 150
 						', $context['allow_poll_view'] ? $txt['votes'] . ': ' . $option['votes'] . '' : '', '
151 151
 					</div>';
152
+		}
152 153
 
153 154
 		echo '
154 155
 			</div>';
@@ -170,9 +171,10 @@  discard block
 block discarded – undo
170 171
 			echo '
171 172
 				<hr>';
172 173
 
173
-			foreach ($context['printattach'][$post['id_msg']] as $attach)
174
-				echo '
174
+			foreach ($context['printattach'][$post['id_msg']] as $attach) {
175
+							echo '
175 176
 					<img width="' . $attach['width'] . '" height="' . $attach['height'] . '" src="', $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attach['id_attach'] . '" alt="">';
177
+			}
176 178
 		}
177 179
 
178 180
 		echo '
@@ -207,12 +209,13 @@  discard block
 block discarded – undo
207 209
 		<div class="print_options">';
208 210
 
209 211
 	// Which option is set, text or text&images
210
-	if (isset($_REQUEST['images']))
211
-		echo '
212
+	if (isset($_REQUEST['images'])) {
213
+			echo '
212 214
 			<a href="', $url_text, '">', $txt['print_page_text'], '</a> | <strong><a href="', $url_images, '">', $txt['print_page_images'], '</a></strong>';
213
-	else
214
-		echo '
215
+	} else {
216
+			echo '
215 217
 			<strong><a href="', $url_text, '">', $txt['print_page_text'], '</a></strong> | <a href="', $url_images, '">', $txt['print_page_images'], '</a>';
218
+	}
216 219
 
217 220
 	echo '
218 221
 		</div><!-- .print_options -->';
Please login to merge, or discard this patch.
Themes/default/Poll.template.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 				<h3 class="catbg">', $context['page_title'], '</h3>
47 47
 			</div>';
48 48
 
49
-	if (!empty($context['poll_error']['messages']))
50
-		echo '
49
+	if (!empty($context['poll_error']['messages'])) {
50
+			echo '
51 51
 			<div class="errorbox">
52 52
 				<dl class="poll_error">
53 53
 					<dt>
@@ -58,6 +58,7 @@  discard block
 block discarded – undo
58 58
 					</dt>
59 59
 				</dl>
60 60
 			</div>';
61
+	}
61 62
 
62 63
 	echo '
63 64
 			<div>
@@ -79,8 +80,9 @@  discard block
 block discarded – undo
79 80
 								<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" size="80" maxlength="255">';
80 81
 
81 82
 		// Does this option have a vote count yet, or is it new?
82
-		if ($choice['votes'] != -1)
83
-			echo ' (', $choice['votes'], ' ', $txt['votes'], ')';
83
+		if ($choice['votes'] != -1) {
84
+					echo ' (', $choice['votes'], ' ', $txt['votes'], ')';
85
+		}
84 86
 
85 87
 		echo '
86 88
 							</dd>';
@@ -118,14 +120,15 @@  discard block
 block discarded – undo
118 120
 								<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', '>
119 121
 							</dd>';
120 122
 
121
-		if ($context['poll']['guest_vote_allowed'])
122
-			echo '
123
+		if ($context['poll']['guest_vote_allowed']) {
124
+					echo '
123 125
 							<dt>
124 126
 								<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
125 127
 							</dt>
126 128
 							<dd>
127 129
 								<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll']['guest_vote']) ? ' checked' : '', '>
128 130
 							</dd>';
131
+		}
129 132
 	}
130 133
 
131 134
 	echo '
@@ -141,12 +144,13 @@  discard block
 block discarded – undo
141 144
 					</fieldset>';
142 145
 
143 146
 	// If this is an edit, we can allow them to reset the vote counts.
144
-	if ($context['is_edit'])
145
-		echo '
147
+	if ($context['is_edit']) {
148
+			echo '
146 149
 					<fieldset id="poll_reset">
147 150
 						<legend>', $txt['reset_votes'], '</legend>
148 151
 						<input type="checkbox" name="resetVoteCount" value="on"> ' . $txt['reset_votes_check'] . '
149 152
 					</fieldset>';
153
+	}
150 154
 	echo '
151 155
 					<input type="submit" name="post" value="', $txt['save'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
152 156
 				</div><!-- .roundframe -->
Please login to merge, or discard this patch.
Themes/default/Stats.template.php 1 patch
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -44,10 +44,11 @@  discard block
 block discarded – undo
44 44
 				<dt>', $txt['users_online_today'], ':</dt>
45 45
 				<dd>', $context['online_today'], '</dd>';
46 46
 
47
-	if (!empty($modSettings['hitStats']))
48
-		echo '
47
+	if (!empty($modSettings['hitStats'])) {
48
+			echo '
49 49
 				<dt>', $txt['num_hits'], ':</dt>
50 50
 				<dd>', $context['num_hits'], '</dd>';
51
+	}
51 52
 
52 53
 	echo '
53 54
 			</dl>
@@ -71,17 +72,19 @@  discard block
 block discarded – undo
71 72
 				<dt>', $txt['gender_stats'], ':</dt>
72 73
 				<dd>';
73 74
 
74
-		foreach ($context['gender'] as $g => $n)
75
-			echo $g, ': ', $n, '<br>';
75
+		foreach ($context['gender'] as $g => $n) {
76
+					echo $g, ': ', $n, '<br>';
77
+		}
76 78
 
77 79
 		echo '
78 80
 				</dd>';
79 81
 	}
80 82
 
81
-	if (!empty($modSettings['hitStats']))
82
-		echo '
83
+	if (!empty($modSettings['hitStats'])) {
84
+			echo '
83 85
 				<dt>', $txt['average_hits'], ':</dt>
84 86
 				<dd>', $context['average_hits'], '</dd>';
87
+	}
85 88
 
86 89
 	echo '
87 90
 			</dl>';
@@ -105,14 +108,15 @@  discard block
 block discarded – undo
105 108
 					</dt>
106 109
 					<dd class="statsbar">';
107 110
 
108
-			if (!empty($item['percent']))
109
-				echo '
111
+			if (!empty($item['percent'])) {
112
+							echo '
110 113
 						<div class="bar" style="width: ', $item['percent'], '%;">
111 114
 							<span class="righttext">', $item['num'], '</span>
112 115
 						</div>';
113
-			else
114
-				echo '
116
+			} else {
117
+							echo '
115 118
 						<div class="bar empty"><span class="righttext">', $item['num'], '</span></div>';
119
+			}
116 120
 
117 121
 			echo '
118 122
 					</dd>';
@@ -144,9 +148,10 @@  discard block
 block discarded – undo
144 148
 					<th>', $txt['stats_new_members'], '</th>
145 149
 					<th>', $txt['most_online'], '</th>';
146 150
 
147
-		if (!empty($modSettings['hitStats']))
148
-			echo '
151
+		if (!empty($modSettings['hitStats'])) {
152
+					echo '
149 153
 					<th>', $txt['page_views'], '</th>';
154
+		}
150 155
 
151 156
 		echo '
152 157
 				</tr>
@@ -165,9 +170,10 @@  discard block
 block discarded – undo
165 170
 					<th>', $year['new_members'], '</th>
166 171
 					<th>', $year['most_members_online'], '</th>';
167 172
 
168
-			if (!empty($modSettings['hitStats']))
169
-				echo '
173
+			if (!empty($modSettings['hitStats'])) {
174
+							echo '
170 175
 					<th>', $year['hits'], '</th>';
176
+			}
171 177
 
172 178
 			echo '
173 179
 				</tr>';
@@ -184,9 +190,10 @@  discard block
 block discarded – undo
184 190
 					<th>', $month['new_members'], '</th>
185 191
 					<th>', $month['most_members_online'], '</th>';
186 192
 
187
-				if (!empty($modSettings['hitStats']))
188
-					echo '
193
+				if (!empty($modSettings['hitStats'])) {
194
+									echo '
189 195
 					<th>', $month['hits'], '</th>';
196
+				}
190 197
 
191 198
 				echo '
192 199
 				</tr>';
@@ -203,9 +210,10 @@  discard block
 block discarded – undo
203 210
 					<td>', $day['new_members'], '</td>
204 211
 					<td>', $day['most_members_online'], '</td>';
205 212
 
206
-						if (!empty($modSettings['hitStats']))
207
-							echo '
213
+						if (!empty($modSettings['hitStats'])) {
214
+													echo '
208 215
 					<td>', $day['hits'], '</td>';
216
+						}
209 217
 
210 218
 						echo '
211 219
 				</tr>';
Please login to merge, or discard this patch.
Themes/default/ManageNews.template.php 1 patch
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -18,9 +18,10 @@  discard block
 block discarded – undo
18 18
 	global $context, $txt, $scripturl;
19 19
 
20 20
 	// Are we done sending the newsletter?
21
-	if (!empty($context['newsletter_sent']))
22
-		echo '
21
+	if (!empty($context['newsletter_sent'])) {
22
+			echo '
23 23
 	<div class="infobox">', $txt['admin_news_newsletter_' . $context['newsletter_sent']], '</div>';
24
+	}
24 25
 
25 26
 	echo '
26 27
 	<div id="admincenter">
@@ -39,9 +40,10 @@  discard block
 block discarded – undo
39 40
 					</dt>
40 41
 					<dd>';
41 42
 
42
-	foreach ($context['groups'] as $group)
43
-		echo '
43
+	foreach ($context['groups'] as $group) {
44
+			echo '
44 45
 						<label for="groups_', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups_', $group['id'], '" value="', $group['id'], '" checked> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br>';
46
+	}
45 47
 
46 48
 	echo '
47 49
 						<br>
@@ -82,9 +84,10 @@  discard block
 block discarded – undo
82 84
 						</dt>
83 85
 						<dd>';
84 86
 
85
-	foreach ($context['groups'] as $group)
86
-		echo '
87
+	foreach ($context['groups'] as $group) {
88
+			echo '
87 89
 							<label for="exclude_groups_', $group['id'], '"><input type="checkbox" name="exclude_groups[', $group['id'], ']" id="exclude_groups_', $group['id'], '" value="', $group['id'], '"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br>';
90
+	}
88 91
 
89 92
 	echo '
90 93
 							<br>
@@ -230,9 +233,10 @@  discard block
 block discarded – undo
230 233
 				<div id="bbcBox_message"></div>';
231 234
 
232 235
 	// What about smileys?
233
-	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
234
-		echo '
236
+	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) {
237
+			echo '
235 238
 				<div id="smileyBox_message"></div>';
239
+	}
236 240
 
237 241
 	// Show BBC buttons, smileys and textbox.
238 242
 	echo '
@@ -253,9 +257,10 @@  discard block
 block discarded – undo
253 257
 			<input type="hidden" name="email_force" value="', $context['email_force'], '">
254 258
 			<input type="hidden" name="total_emails" value="', $context['total_emails'], '">';
255 259
 
256
-	foreach ($context['recipients'] as $key => $values)
257
-		echo '
260
+	foreach ($context['recipients'] as $key => $values) {
261
+			echo '
258 262
 			<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '">';
263
+	}
259 264
 
260 265
 	echo '
261 266
 			<script>';
@@ -413,9 +418,10 @@  discard block
 block discarded – undo
413 418
 				<input type="hidden" name="parse_html" value="', $context['parse_html'], '">';
414 419
 
415 420
 	// All the things we must remember!
416
-	foreach ($context['recipients'] as $key => $values)
417
-		echo '
421
+	foreach ($context['recipients'] as $key => $values) {
422
+			echo '
418 423
 				<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '">';
424
+	}
419 425
 
420 426
 	echo '
421 427
 			</div><!-- .windowbg -->
@@ -448,9 +454,10 @@  discard block
 block discarded – undo
448 454
 {
449 455
 	global $context, $txt;
450 456
 
451
-	if (!empty($context['saved_successful']))
452
-		echo '
457
+	if (!empty($context['saved_successful'])) {
458
+			echo '
453 459
 			<div class="infobox">', $txt['settings_saved'], '</div>';
460
+	}
454 461
 
455 462
 	template_show_list('news_lists');
456 463
 }
Please login to merge, or discard this patch.
Themes/default/ManageMembers.template.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 				</thead>
149 149
 				<tbody>';
150 150
 
151
-	foreach ($context['membergroups'] as $membergroup)
152
-		echo '
151
+	foreach ($context['membergroups'] as $membergroup) {
152
+			echo '
153 153
 					<tr class="windowbg">
154 154
 						<td>', $membergroup['name'], '</td>
155 155
 						<td class="centercol">
@@ -159,6 +159,7 @@  discard block
 block discarded – undo
159 159
 							', $membergroup['can_be_additional'] ? '<input type="checkbox" name="membergroups[2][]" value="' . $membergroup['id'] . '" checked>' : '', '
160 160
 						</td>
161 161
 					</tr>';
162
+	}
162 163
 
163 164
 	echo '
164 165
 					<tr class="windowbg">
@@ -185,8 +186,8 @@  discard block
 block discarded – undo
185 186
 				</thead>
186 187
 				<tbody>';
187 188
 
188
-	foreach ($context['postgroups'] as $postgroup)
189
-		echo '
189
+	foreach ($context['postgroups'] as $postgroup) {
190
+			echo '
190 191
 					<tr class="windowbg">
191 192
 						<td>
192 193
 							', $postgroup['name'], '
@@ -195,6 +196,7 @@  discard block
 block discarded – undo
195 196
 							<input type="checkbox" name="postgroups[]" value="', $postgroup['id'], '" checked>
196 197
 						</td>
197 198
 					</tr>';
199
+	}
198 200
 
199 201
 	echo '
200 202
 					<tr class="windowbg">
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,11 +38,12 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -161,14 +166,12 @@  discard block
 block discarded – undo
161 166
 				{
162 167
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
163 168
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
164
-				}
165
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
169
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
166 170
 				{
167 171
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
168 172
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
169 173
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
170
-				}
171
-				else
174
+				} else
172 175
 				{
173 176
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
174 177
 				}
@@ -219,14 +222,16 @@  discard block
 block discarded – undo
219 222
 		// Child of a child... just add it on...
220 223
 		elseif (!empty($boardIndexOptions['countChildPosts']))
221 224
 		{
222
-			if (!isset($parent_map))
223
-				$parent_map = array();
225
+			if (!isset($parent_map)) {
226
+							$parent_map = array();
227
+			}
224 228
 
225
-			if (!isset($parent_map[$row_board['id_parent']]))
226
-				foreach ($this_category as $id => $board)
229
+			if (!isset($parent_map[$row_board['id_parent']])) {
230
+							foreach ($this_category as $id => $board)
227 231
 				{
228 232
 					if (!isset($board['children'][$row_board['id_parent']]))
229 233
 						continue;
234
+			}
230 235
 
231 236
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
232 237
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -247,8 +252,9 @@  discard block
 block discarded – undo
247 252
 			continue;
248 253
 		}
249 254
 		// Found a child of a child - skip.
250
-		else
251
-			continue;
255
+		else {
256
+					continue;
257
+		}
252 258
 
253 259
 		// Prepare the subject, and make sure it's not too long.
254 260
 		censorText($row_board['subject']);
@@ -269,12 +275,13 @@  discard block
 block discarded – undo
269 275
 			'topic' => $row_board['id_topic']
270 276
 		);
271 277
 
272
-		if (!empty($settings['avatars_on_boardIndex']))
273
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
278
+		if (!empty($settings['avatars_on_boardIndex'])) {
279
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
274 280
 				'avatar' => $row_board['avatar'],
275 281
 				'email' => $row_board['email_address'],
276 282
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
277 283
 			));
284
+		}
278 285
 
279 286
 		// Provide the href and link.
280 287
 		if ($row_board['subject'] != '')
@@ -286,8 +293,7 @@  discard block
 block discarded – undo
286 293
 			link, href, subject, start (where they should go for the first unread post.),
287 294
 			and member. (which has id, name, link, href, username in it.) */
288 295
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
289
-		}
290
-		else
296
+		} else
291 297
 		{
292 298
 			$this_last_post['href'] = '';
293 299
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -295,8 +301,9 @@  discard block
 block discarded – undo
295 301
 		}
296 302
 
297 303
 		// Set the last post in the parent board.
298
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
299
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
304
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
305
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
306
+		}
300 307
 		// Just in the child...?
301 308
 		if ($isChild)
302 309
 		{
@@ -306,15 +313,17 @@  discard block
 block discarded – undo
306 313
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
307 314
 		}
308 315
 		// No last post for this board?  It's not new then, is it..?
309
-		elseif ($row_board['poster_name'] == '')
310
-			$this_category[$row_board['id_board']]['new'] = false;
316
+		elseif ($row_board['poster_name'] == '') {
317
+					$this_category[$row_board['id_board']]['new'] = false;
318
+		}
311 319
 
312 320
 		// Determine a global most recent topic.
313
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
314
-			$latest_post = array(
321
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
322
+					$latest_post = array(
315 323
 				'timestamp' => $row_board['poster_time'],
316 324
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
317 325
 			);
326
+		}
318 327
 	}
319 328
 	$smcFunc['db_free_result']($result_boards);
320 329
 
@@ -331,8 +340,9 @@  discard block
 block discarded – undo
331 340
 				if (!empty($moderators[$board['id']]))
332 341
 				{
333 342
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
334
-					foreach ($moderators[$board['id']] as $moderator)
335
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
343
+					foreach ($moderators[$board['id']] as $moderator) {
344
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
345
+					}
336 346
 				}
337 347
 				if (!empty($groups[$board['id']]))
338 348
 				{
@@ -345,16 +355,16 @@  discard block
 block discarded – undo
345 355
 				}
346 356
 			}
347 357
 		}
348
-	}
349
-	else
358
+	} else
350 359
 	{
351 360
 		foreach ($this_category as $k => $board)
352 361
 		{
353 362
 			if (!empty($moderators[$board['id']]))
354 363
 			{
355 364
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
356
-				foreach ($moderators[$board['id']] as $moderator)
357
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
365
+				foreach ($moderators[$board['id']] as $moderator) {
366
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
367
+				}
358 368
 			}
359 369
 			if (!empty($groups[$board['id']]))
360 370
 			{
@@ -368,20 +378,23 @@  discard block
 block discarded – undo
368 378
 		}
369 379
 	}
370 380
 
371
-	if ($boardIndexOptions['include_categories'])
372
-		sortCategories($categories);
373
-	else
374
-		sortBoards($this_category);
381
+	if ($boardIndexOptions['include_categories']) {
382
+			sortCategories($categories);
383
+	} else {
384
+			sortBoards($this_category);
385
+	}
375 386
 
376 387
 	// By now we should know the most recent post...if we wanna know it that is.
377
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
378
-		$context['latest_post'] = $latest_post['ref'];
388
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
389
+			$context['latest_post'] = $latest_post['ref'];
390
+	}
379 391
 
380 392
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
381
-	if ($boardIndexOptions['include_categories'])
382
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
383
-	else
384
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
393
+	if ($boardIndexOptions['include_categories']) {
394
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
395
+	} else {
396
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
397
+	}
385 398
 
386 399
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
387 400
 }
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Braces   +59 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count.
@@ -40,11 +41,11 @@  discard block
 block discarded – undo
40 41
 
41 42
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
42 43
 	{
43
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
44
-			$modSettings['enableCompressedOutput'] = 0;
45
-
46
-		else
47
-			ob_start('ob_gzhandler');
44
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
45
+					$modSettings['enableCompressedOutput'] = 0;
46
+		} else {
47
+					ob_start('ob_gzhandler');
48
+		}
48 49
 	}
49 50
 
50 51
 	if (empty($modSettings['enableCompressedOutput']))
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
 	}
77 78
 
78 79
 	// Use cache when possible.
79
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
80
-		list($file, $thumbFile) = $cache;
80
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
81
+			list($file, $thumbFile) = $cache;
82
+	}
81 83
 
82 84
 	// Get the info from the DB.
83 85
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -85,10 +87,9 @@  discard block
 block discarded – undo
85 87
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
86 88
 		$attachRequest = null;
87 89
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
88
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
89
-			$request = $attachRequest;
90
-
91
-		else
90
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
91
+					$request = $attachRequest;
92
+		} else
92 93
 		{
93 94
 			// Make sure this attachment is on this board and load its info while we are at it.
94 95
 			$request = $smcFunc['db_query']('', '
@@ -181,13 +182,15 @@  discard block
 block discarded – undo
181 182
 		}
182 183
 
183 184
 		// Cache it.
184
-		if (!empty($file) || !empty($thumbFile))
185
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
185
+		if (!empty($file) || !empty($thumbFile)) {
186
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
187
+		}
186 188
 	}
187 189
 
188 190
 	// Replace the normal file with its thumbnail if it has one!
189
-	if (!empty($showThumb) && !empty($thumbFile))
190
-		$file = $thumbFile;
191
+	if (!empty($showThumb) && !empty($thumbFile)) {
192
+			$file = $thumbFile;
193
+	}
191 194
 
192 195
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
193 196
 	if (!file_exists($file['filePath']))
@@ -237,8 +240,8 @@  discard block
 block discarded – undo
237 240
 	}
238 241
 
239 242
 	// Update the download counter (unless it's a thumbnail or resuming an incomplete download).
240
-	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0)
241
-		$smcFunc['db_query']('', '
243
+	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) {
244
+			$smcFunc['db_query']('', '
242 245
 			UPDATE {db_prefix}attachments
243 246
 			SET downloads = downloads + 1
244 247
 			WHERE id_attach = {int:id_attach}',
@@ -246,12 +249,14 @@  discard block
 block discarded – undo
246 249
 				'id_attach' => $attachId,
247 250
 			)
248 251
 		);
252
+	}
249 253
 
250 254
 	// Send the attachment headers.
251 255
 	header('Pragma: ');
252 256
 
253
-	if (!isBrowser('gecko'))
254
-		header('Content-Transfer-Encoding: binary');
257
+	if (!isBrowser('gecko')) {
258
+			header('Content-Transfer-Encoding: binary');
259
+	}
255 260
 
256 261
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
257 262
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -260,18 +265,19 @@  discard block
 block discarded – undo
260 265
 	header('ETag: ' . $eTag);
261 266
 
262 267
 	// Make sure the mime type warrants an inline display.
263
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
264
-		unset($_REQUEST['image']);
268
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
269
+			unset($_REQUEST['image']);
270
+	}
265 271
 
266 272
 	// Does this have a mime type?
267
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
268
-		header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
269
-
270
-	else
273
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
274
+			header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
275
+	} else
271 276
 	{
272 277
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
273
-		if (isset($_REQUEST['image']))
274
-			unset($_REQUEST['image']);
278
+		if (isset($_REQUEST['image'])) {
279
+					unset($_REQUEST['image']);
280
+		}
275 281
 	}
276 282
 
277 283
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -279,24 +285,22 @@  discard block
 block discarded – undo
279 285
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
280 286
 
281 287
 	// Different browsers like different standards...
282
-	if (isBrowser('firefox'))
283
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
284
-
285
-	elseif (isBrowser('opera'))
286
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
287
-
288
-	elseif (isBrowser('ie'))
289
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
290
-
291
-	else
292
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
288
+	if (isBrowser('firefox')) {
289
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
290
+	} elseif (isBrowser('opera')) {
291
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
292
+	} elseif (isBrowser('ie')) {
293
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
294
+	} else {
295
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
296
+	}
293 297
 
294 298
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
295
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
296
-		header('Cache-Control: no-cache');
297
-
298
-	else
299
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
299
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
300
+			header('Cache-Control: no-cache');
301
+	} else {
302
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
303
+	}
300 304
 
301 305
 	// Multipart and resuming support
302 306
 	if (isset($_SERVER['HTTP_RANGE']))
@@ -304,9 +308,9 @@  discard block
 block discarded – undo
304 308
 		header("HTTP/1.1 206 Partial Content");
305 309
 		header("Content-Length: $new_length");
306 310
 		header("Content-Range: bytes $range-$range_end/$size");
311
+	} else {
312
+			header("Content-Length: " . $size);
307 313
 	}
308
-	else
309
-		header("Content-Length: " . $size);
310 314
 
311 315
 
312 316
 	// Try to buy some time...
@@ -315,8 +319,9 @@  discard block
 block discarded – undo
315 319
 	// For multipart/resumable downloads, send the requested chunk(s) of the file
316 320
 	if (isset($_SERVER['HTTP_RANGE']))
317 321
 	{
318
-		while (@ob_get_level() > 0)
319
-			@ob_end_clean();
322
+		while (@ob_get_level() > 0) {
323
+					@ob_end_clean();
324
+		}
320 325
 
321 326
 		// 40 kilobytes is a good-ish amount
322 327
 		$chunksize = 40 * 1024;
@@ -340,8 +345,9 @@  discard block
 block discarded – undo
340 345
 	elseif ($size > 4194304)
341 346
 	{
342 347
 		// Forcibly end any output buffering going on.
343
-		while (@ob_get_level() > 0)
344
-			@ob_end_clean();
348
+		while (@ob_get_level() > 0) {
349
+					@ob_end_clean();
350
+		}
345 351
 
346 352
 		$fp = fopen($file['filePath'], 'rb');
347 353
 		while (!feof($fp))
@@ -353,8 +359,9 @@  discard block
 block discarded – undo
353 359
 	}
354 360
 
355 361
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
356
-	elseif (@readfile($file['filePath']) === null)
357
-		echo file_get_contents($file['filePath']);
362
+	elseif (@readfile($file['filePath']) === null) {
363
+			echo file_get_contents($file['filePath']);
364
+	}
358 365
 
359 366
 	die();
360 367
 }
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +703 added lines, -527 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,26 +1238,29 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196 1260
 
1197
-			if ($row['field_length'])
1198
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1261
+			if ($row['field_length']) {
1262
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			}
1199 1264
 
1200 1265
 			// Any masks?
1201 1266
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1204,36 +1269,34 @@  discard block
 block discarded – undo
1204 1269
 				$valueReference = un_htmlspecialchars($value);
1205 1270
 
1206 1271
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1207
-				if (empty($value) && !is_numeric($value))
1208
-					$value = '';
1272
+				if (empty($value) && !is_numeric($value)) {
1273
+									$value = '';
1274
+				}
1209 1275
 
1210 1276
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1211 1277
 				{
1212
-					if ($returnErrors)
1213
-						$errors[] = 'custom_field_nohtml_fail';
1214
-
1215
-					else
1216
-						$value = '';
1217
-				}
1218
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1278
+					if ($returnErrors) {
1279
+											$errors[] = 'custom_field_nohtml_fail';
1280
+					} else {
1281
+											$value = '';
1282
+					}
1283
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1219 1284
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_mail_fail';
1222
-
1223
-					else
1224
-						$value = '';
1225
-				}
1226
-				elseif ($row['mask'] == 'number')
1285
+					if ($returnErrors) {
1286
+											$errors[] = 'custom_field_mail_fail';
1287
+					} else {
1288
+											$value = '';
1289
+					}
1290
+				} elseif ($row['mask'] == 'number')
1227 1291
 				{
1228 1292
 					$value = (int) $value;
1229
-				}
1230
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1293
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1231 1294
 				{
1232
-					if ($returnErrors)
1233
-						$errors[] = 'custom_field_regex_fail';
1234
-
1235
-					else
1236
-						$value = '';
1295
+					if ($returnErrors) {
1296
+											$errors[] = 'custom_field_regex_fail';
1297
+					} else {
1298
+											$value = '';
1299
+					}
1237 1300
 				}
1238 1301
 
1239 1302
 				unset($valueReference);
@@ -1261,8 +1324,9 @@  discard block
 block discarded – undo
1261 1324
 
1262 1325
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1263 1326
 
1264
-	if (!empty($hook_errors) && is_array($hook_errors))
1265
-		$errors = array_merge($errors, $hook_errors);
1327
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1328
+			$errors = array_merge($errors, $hook_errors);
1329
+	}
1266 1330
 
1267 1331
 	// Make those changes!
1268 1332
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1280,9 +1344,10 @@  discard block
 block discarded – undo
1280 1344
 		}
1281 1345
 	}
1282 1346
 
1283
-	if ($returnErrors)
1284
-		return $errors;
1285
-}
1347
+	if ($returnErrors) {
1348
+			return $errors;
1349
+	}
1350
+	}
1286 1351
 
1287 1352
 /**
1288 1353
  * Show all the users buddies, as well as a add/delete interface.
@@ -1294,8 +1359,9 @@  discard block
 block discarded – undo
1294 1359
 	global $context, $txt, $modSettings;
1295 1360
 
1296 1361
 	// Do a quick check to ensure people aren't getting here illegally!
1297
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1298
-		fatal_lang_error('no_access', false);
1362
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1363
+			fatal_lang_error('no_access', false);
1364
+	}
1299 1365
 
1300 1366
 	// Can we email the user direct?
1301 1367
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1325,9 +1391,10 @@  discard block
 block discarded – undo
1325 1391
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1326 1392
 	$call = call_helper($subActions[$context['list_area']][0], true);
1327 1393
 
1328
-	if (!empty($call))
1329
-		call_user_func($call, $memID);
1330
-}
1394
+	if (!empty($call)) {
1395
+			call_user_func($call, $memID);
1396
+	}
1397
+	}
1331 1398
 
1332 1399
 /**
1333 1400
  * Show all the users buddies, as well as a add/delete interface.
@@ -1341,9 +1408,10 @@  discard block
 block discarded – undo
1341 1408
 
1342 1409
 	// For making changes!
1343 1410
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1344
-	foreach ($buddiesArray as $k => $dummy)
1345
-		if ($dummy == '')
1411
+	foreach ($buddiesArray as $k => $dummy) {
1412
+			if ($dummy == '')
1346 1413
 			unset($buddiesArray[$k]);
1414
+	}
1347 1415
 
1348 1416
 	// Removing a buddy?
1349 1417
 	if (isset($_GET['remove']))
@@ -1355,10 +1423,11 @@  discard block
 block discarded – undo
1355 1423
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1356 1424
 
1357 1425
 		// Heh, I'm lazy, do it the easy way...
1358
-		foreach ($buddiesArray as $key => $buddy)
1359
-			if ($buddy == (int) $_GET['remove'])
1426
+		foreach ($buddiesArray as $key => $buddy) {
1427
+					if ($buddy == (int) $_GET['remove'])
1360 1428
 			{
1361 1429
 				unset($buddiesArray[$key]);
1430
+		}
1362 1431
 				$_SESSION['prf-save'] = true;
1363 1432
 			}
1364 1433
 
@@ -1368,8 +1437,7 @@  discard block
 block discarded – undo
1368 1437
 
1369 1438
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1370 1439
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1371
-	}
1372
-	elseif (isset($_POST['new_buddy']))
1440
+	} elseif (isset($_POST['new_buddy']))
1373 1441
 	{
1374 1442
 		checkSession();
1375 1443
 
@@ -1382,8 +1450,9 @@  discard block
 block discarded – undo
1382 1450
 		{
1383 1451
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1384 1452
 
1385
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1386
-				unset($new_buddies[$k]);
1453
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1454
+							unset($new_buddies[$k]);
1455
+			}
1387 1456
 		}
1388 1457
 
1389 1458
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1403,16 +1472,18 @@  discard block
 block discarded – undo
1403 1472
 				)
1404 1473
 			);
1405 1474
 
1406
-			if ($smcFunc['db_num_rows']($request) != 0)
1407
-				$_SESSION['prf-save'] = true;
1475
+			if ($smcFunc['db_num_rows']($request) != 0) {
1476
+							$_SESSION['prf-save'] = true;
1477
+			}
1408 1478
 
1409 1479
 			// Add the new member to the buddies array.
1410 1480
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1411 1481
 			{
1412
-				if (in_array($row['id_member'], $buddiesArray))
1413
-					continue;
1414
-				else
1415
-					$buddiesArray[] = (int) $row['id_member'];
1482
+				if (in_array($row['id_member'], $buddiesArray)) {
1483
+									continue;
1484
+				} else {
1485
+									$buddiesArray[] = (int) $row['id_member'];
1486
+				}
1416 1487
 			}
1417 1488
 			$smcFunc['db_free_result']($request);
1418 1489
 
@@ -1442,18 +1513,20 @@  discard block
 block discarded – undo
1442 1513
 
1443 1514
 	$context['custom_pf'] = array();
1444 1515
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1445
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1446
-		if (!isset($disabled_fields[$row['col_name']]))
1516
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1517
+			if (!isset($disabled_fields[$row['col_name']]))
1447 1518
 			$context['custom_pf'][$row['col_name']] = array(
1448 1519
 				'label' => $row['field_name'],
1449 1520
 				'type' => $row['field_type'],
1450 1521
 				'bbc' => !empty($row['bbc']),
1451 1522
 				'enclose' => $row['enclose'],
1452 1523
 			);
1524
+	}
1453 1525
 
1454 1526
 	// Gotta disable the gender option.
1455
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1456
-		unset($context['custom_pf']['cust_gender']);
1527
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1528
+			unset($context['custom_pf']['cust_gender']);
1529
+	}
1457 1530
 
1458 1531
 	$smcFunc['db_free_result']($request);
1459 1532
 
@@ -1470,8 +1543,9 @@  discard block
 block discarded – undo
1470 1543
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1471 1544
 			)
1472 1545
 		);
1473
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1474
-			$buddies[] = $row['id_member'];
1546
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1547
+					$buddies[] = $row['id_member'];
1548
+		}
1475 1549
 		$smcFunc['db_free_result']($result);
1476 1550
 	}
1477 1551
 
@@ -1499,30 +1573,32 @@  discard block
 block discarded – undo
1499 1573
 					continue;
1500 1574
 				}
1501 1575
 
1502
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1503
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1504
-
1505
-				elseif ($column['type'] == 'check')
1506
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1576
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1577
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1578
+				} elseif ($column['type'] == 'check') {
1579
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1580
+				}
1507 1581
 
1508 1582
 				// Enclosing the user input within some other text?
1509
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1510
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1583
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1584
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1511 1585
 						'{SCRIPTURL}' => $scripturl,
1512 1586
 						'{IMAGES_URL}' => $settings['images_url'],
1513 1587
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1514 1588
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1515 1589
 					));
1590
+				}
1516 1591
 			}
1517 1592
 		}
1518 1593
 	}
1519 1594
 
1520 1595
 	if (isset($_SESSION['prf-save']))
1521 1596
 	{
1522
-		if ($_SESSION['prf-save'] === true)
1523
-			$context['saved_successful'] = true;
1524
-		else
1525
-			$context['saved_failed'] = $_SESSION['prf-save'];
1597
+		if ($_SESSION['prf-save'] === true) {
1598
+					$context['saved_successful'] = true;
1599
+		} else {
1600
+					$context['saved_failed'] = $_SESSION['prf-save'];
1601
+		}
1526 1602
 
1527 1603
 		unset($_SESSION['prf-save']);
1528 1604
 	}
@@ -1542,9 +1618,10 @@  discard block
 block discarded – undo
1542 1618
 
1543 1619
 	// For making changes!
1544 1620
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1545
-	foreach ($ignoreArray as $k => $dummy)
1546
-		if ($dummy == '')
1621
+	foreach ($ignoreArray as $k => $dummy) {
1622
+			if ($dummy == '')
1547 1623
 			unset($ignoreArray[$k]);
1624
+	}
1548 1625
 
1549 1626
 	// Removing a member from the ignore list?
1550 1627
 	if (isset($_GET['remove']))
@@ -1554,10 +1631,11 @@  discard block
 block discarded – undo
1554 1631
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1555 1632
 
1556 1633
 		// Heh, I'm lazy, do it the easy way...
1557
-		foreach ($ignoreArray as $key => $id_remove)
1558
-			if ($id_remove == (int) $_GET['remove'])
1634
+		foreach ($ignoreArray as $key => $id_remove) {
1635
+					if ($id_remove == (int) $_GET['remove'])
1559 1636
 			{
1560 1637
 				unset($ignoreArray[$key]);
1638
+		}
1561 1639
 				$_SESSION['prf-save'] = true;
1562 1640
 			}
1563 1641
 
@@ -1567,8 +1645,7 @@  discard block
 block discarded – undo
1567 1645
 
1568 1646
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1569 1647
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1570
-	}
1571
-	elseif (isset($_POST['new_ignore']))
1648
+	} elseif (isset($_POST['new_ignore']))
1572 1649
 	{
1573 1650
 		checkSession();
1574 1651
 		// Prepare the string for extraction...
@@ -1580,8 +1657,9 @@  discard block
 block discarded – undo
1580 1657
 		{
1581 1658
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1582 1659
 
1583
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1584
-				unset($new_entries[$k]);
1660
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1661
+							unset($new_entries[$k]);
1662
+			}
1585 1663
 		}
1586 1664
 
1587 1665
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1599,16 +1677,18 @@  discard block
 block discarded – undo
1599 1677
 				)
1600 1678
 			);
1601 1679
 
1602
-			if ($smcFunc['db_num_rows']($request) != 0)
1603
-				$_SESSION['prf-save'] = true;
1680
+			if ($smcFunc['db_num_rows']($request) != 0) {
1681
+							$_SESSION['prf-save'] = true;
1682
+			}
1604 1683
 
1605 1684
 			// Add the new member to the buddies array.
1606 1685
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1607 1686
 			{
1608
-				if (in_array($row['id_member'], $ignoreArray))
1609
-					continue;
1610
-				else
1611
-					$ignoreArray[] = (int) $row['id_member'];
1687
+				if (in_array($row['id_member'], $ignoreArray)) {
1688
+									continue;
1689
+				} else {
1690
+									$ignoreArray[] = (int) $row['id_member'];
1691
+				}
1612 1692
 			}
1613 1693
 			$smcFunc['db_free_result']($request);
1614 1694
 
@@ -1637,8 +1717,9 @@  discard block
 block discarded – undo
1637 1717
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1638 1718
 			)
1639 1719
 		);
1640
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1641
-			$ignored[] = $row['id_member'];
1720
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1721
+					$ignored[] = $row['id_member'];
1722
+		}
1642 1723
 		$smcFunc['db_free_result']($result);
1643 1724
 	}
1644 1725
 
@@ -1657,10 +1738,11 @@  discard block
 block discarded – undo
1657 1738
 
1658 1739
 	if (isset($_SESSION['prf-save']))
1659 1740
 	{
1660
-		if ($_SESSION['prf-save'] === true)
1661
-			$context['saved_successful'] = true;
1662
-		else
1663
-			$context['saved_failed'] = $_SESSION['prf-save'];
1741
+		if ($_SESSION['prf-save'] === true) {
1742
+					$context['saved_successful'] = true;
1743
+		} else {
1744
+					$context['saved_failed'] = $_SESSION['prf-save'];
1745
+		}
1664 1746
 
1665 1747
 		unset($_SESSION['prf-save']);
1666 1748
 	}
@@ -1676,8 +1758,9 @@  discard block
 block discarded – undo
1676 1758
 	global $context, $txt;
1677 1759
 
1678 1760
 	loadThemeOptions($memID);
1679
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1680
-		loadCustomFields($memID, 'account');
1761
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1762
+			loadCustomFields($memID, 'account');
1763
+	}
1681 1764
 
1682 1765
 	$context['sub_template'] = 'edit_options';
1683 1766
 	$context['page_desc'] = $txt['account_info'];
@@ -1704,8 +1787,9 @@  discard block
 block discarded – undo
1704 1787
 	global $context, $txt;
1705 1788
 
1706 1789
 	loadThemeOptions($memID);
1707
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1708
-		loadCustomFields($memID, 'forumprofile');
1790
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1791
+			loadCustomFields($memID, 'forumprofile');
1792
+	}
1709 1793
 
1710 1794
 	$context['sub_template'] = 'edit_options';
1711 1795
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1738,18 +1822,21 @@  discard block
 block discarded – undo
1738 1822
 	$dirs = array();
1739 1823
 	$files = array();
1740 1824
 
1741
-	if (!$dir)
1742
-		return array();
1825
+	if (!$dir) {
1826
+			return array();
1827
+	}
1743 1828
 
1744 1829
 	while ($line = $dir->read())
1745 1830
 	{
1746
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1747
-			continue;
1831
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1832
+					continue;
1833
+		}
1748 1834
 
1749
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1750
-			$dirs[] = $line;
1751
-		else
1752
-			$files[] = $line;
1835
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1836
+					$dirs[] = $line;
1837
+		} else {
1838
+					$files[] = $line;
1839
+		}
1753 1840
 	}
1754 1841
 	$dir->close();
1755 1842
 
@@ -1770,14 +1857,15 @@  discard block
 block discarded – undo
1770 1857
 	foreach ($dirs as $line)
1771 1858
 	{
1772 1859
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1773
-		if (!empty($tmp))
1774
-			$result[] = array(
1860
+		if (!empty($tmp)) {
1861
+					$result[] = array(
1775 1862
 				'filename' => $smcFunc['htmlspecialchars']($line),
1776 1863
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1777 1864
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1778 1865
 				'is_dir' => true,
1779 1866
 				'files' => $tmp
1780 1867
 		);
1868
+		}
1781 1869
 		unset($tmp);
1782 1870
 	}
1783 1871
 
@@ -1787,8 +1875,9 @@  discard block
 block discarded – undo
1787 1875
 		$extension = substr(strrchr($line, '.'), 1);
1788 1876
 
1789 1877
 		// Make sure it is an image.
1790
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1791
-			continue;
1878
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1879
+					continue;
1880
+		}
1792 1881
 
1793 1882
 		$result[] = array(
1794 1883
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1796,8 +1885,9 @@  discard block
 block discarded – undo
1796 1885
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1797 1886
 			'is_dir' => false
1798 1887
 		);
1799
-		if ($level == 1)
1800
-			$context['avatar_list'][] = $directory . '/' . $line;
1888
+		if ($level == 1) {
1889
+					$context['avatar_list'][] = $directory . '/' . $line;
1890
+		}
1801 1891
 	}
1802 1892
 
1803 1893
 	return $result;
@@ -1816,8 +1906,9 @@  discard block
 block discarded – undo
1816 1906
 	loadSubTemplate('options');
1817 1907
 
1818 1908
 	loadThemeOptions($memID);
1819
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1820
-		loadCustomFields($memID, 'theme');
1909
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1910
+			loadCustomFields($memID, 'theme');
1911
+	}
1821 1912
 
1822 1913
 	$context['sub_template'] = 'edit_options';
1823 1914
 	$context['page_desc'] = $txt['theme_info'];
@@ -1871,16 +1962,19 @@  discard block
 block discarded – undo
1871 1962
 {
1872 1963
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1873 1964
 
1874
-	if (!isset($context['token_check']))
1875
-		$context['token_check'] = 'profile-nt' . $memID;
1965
+	if (!isset($context['token_check'])) {
1966
+			$context['token_check'] = 'profile-nt' . $memID;
1967
+	}
1876 1968
 
1877 1969
 	is_not_guest();
1878
-	if (!$context['user']['is_owner'])
1879
-		isAllowedTo('profile_extra_any');
1970
+	if (!$context['user']['is_owner']) {
1971
+			isAllowedTo('profile_extra_any');
1972
+	}
1880 1973
 
1881 1974
 	// Set the post action if we're coming from the profile...
1882
-	if (!isset($context['action']))
1883
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1975
+	if (!isset($context['action'])) {
1976
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1977
+	}
1884 1978
 
1885 1979
 	// What options are set
1886 1980
 	loadThemeOptions($memID);
@@ -1967,28 +2061,34 @@  discard block
 block discarded – undo
1967 2061
 	);
1968 2062
 
1969 2063
 	// There are certain things that are disabled at the group level.
1970
-	if (empty($modSettings['cal_enabled']))
1971
-		unset($alert_types['calendar']);
2064
+	if (empty($modSettings['cal_enabled'])) {
2065
+			unset($alert_types['calendar']);
2066
+	}
1972 2067
 
1973 2068
 	// Disable paid subscriptions at group level if they're disabled
1974
-	if (empty($modSettings['paid_enabled']))
1975
-		unset($alert_types['paidsubs']);
2069
+	if (empty($modSettings['paid_enabled'])) {
2070
+			unset($alert_types['paidsubs']);
2071
+	}
1976 2072
 
1977 2073
 	// Disable membergroup requests at group level if they're disabled
1978
-	if (empty($modSettings['show_group_membership']))
1979
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2074
+	if (empty($modSettings['show_group_membership'])) {
2075
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2076
+	}
1980 2077
 
1981 2078
 	// Disable mentions if they're disabled
1982
-	if (empty($modSettings['enable_mentions']))
1983
-		unset($alert_types['msg']['msg_mention']);
2079
+	if (empty($modSettings['enable_mentions'])) {
2080
+			unset($alert_types['msg']['msg_mention']);
2081
+	}
1984 2082
 
1985 2083
 	// Disable likes if they're disabled
1986
-	if (empty($modSettings['enable_likes']))
1987
-		unset($alert_types['msg']['msg_like']);
2084
+	if (empty($modSettings['enable_likes'])) {
2085
+			unset($alert_types['msg']['msg_like']);
2086
+	}
1988 2087
 
1989 2088
 	// Disable buddy requests if they're disabled
1990
-	if (empty($modSettings['enable_buddylist']))
1991
-		unset($alert_types['members']['buddy_request']);
2089
+	if (empty($modSettings['enable_buddylist'])) {
2090
+			unset($alert_types['members']['buddy_request']);
2091
+	}
1992 2092
 
1993 2093
 	// Now, now, we could pass this through global but we should really get into the habit of
1994 2094
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2016,15 +2116,17 @@  discard block
 block discarded – undo
2016 2116
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2017 2117
 		}
2018 2118
 
2019
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2020
-			unset($alert_types['members']['request_group']);
2119
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2120
+					unset($alert_types['members']['request_group']);
2121
+		}
2021 2122
 
2022 2123
 		foreach ($alert_types as $group => $items)
2023 2124
 		{
2024 2125
 			foreach ($items as $alert_key => $alert_value)
2025 2126
 			{
2026
-				if (!isset($alert_value['permission']))
2027
-					continue;
2127
+				if (!isset($alert_value['permission'])) {
2128
+									continue;
2129
+				}
2028 2130
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2029 2131
 				{
2030 2132
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2032,12 +2134,14 @@  discard block
 block discarded – undo
2032 2134
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2033 2135
 				}
2034 2136
 
2035
-				if (!$perms_cache[$alert_value['permission']['name']])
2036
-					unset ($alert_types[$group][$alert_key]);
2137
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2138
+									unset ($alert_types[$group][$alert_key]);
2139
+				}
2037 2140
 			}
2038 2141
 
2039
-			if (empty($alert_types[$group]))
2040
-				unset ($alert_types[$group]);
2142
+			if (empty($alert_types[$group])) {
2143
+							unset ($alert_types[$group]);
2144
+			}
2041 2145
 		}
2042 2146
 	}
2043 2147
 
@@ -2069,9 +2173,9 @@  discard block
 block discarded – undo
2069 2173
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2070 2174
 						break;
2071 2175
 					case 'select':
2072
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2073
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2074
-						else
2176
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2177
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2178
+						} else
2075 2179
 						{
2076 2180
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2077 2181
 							$keys = array_keys($this_option['opts']);
@@ -2091,23 +2195,28 @@  discard block
 block discarded – undo
2091 2195
 				$this_value = 0;
2092 2196
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2093 2197
 				{
2094
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2095
-						$this_value |= $bitvalue;
2198
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2199
+											$this_value |= $bitvalue;
2200
+					}
2201
+				}
2202
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2203
+									$update_prefs[$item_key] = $this_value;
2096 2204
 				}
2097
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2098
-					$update_prefs[$item_key] = $this_value;
2099 2205
 			}
2100 2206
 		}
2101 2207
 
2102
-		if (!empty($_POST['opt_alert_timeout']))
2103
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2208
+		if (!empty($_POST['opt_alert_timeout'])) {
2209
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2210
+		}
2104 2211
 
2105
-		if (!empty($_POST['notify_announcements']))
2106
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2212
+		if (!empty($_POST['notify_announcements'])) {
2213
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2214
+		}
2107 2215
 
2108 2216
 		setNotifyPrefs((int) $memID, $update_prefs);
2109
-		foreach ($update_prefs as $pref => $value)
2110
-			$context['alert_prefs'][$pref] = $value;
2217
+		foreach ($update_prefs as $pref => $value) {
2218
+					$context['alert_prefs'][$pref] = $value;
2219
+		}
2111 2220
 
2112 2221
 		makeNotificationChanges($memID);
2113 2222
 
@@ -2137,8 +2246,9 @@  discard block
 block discarded – undo
2137 2246
 
2138 2247
 	// Now we're all set up.
2139 2248
 	is_not_guest();
2140
-	if (!$context['user']['is_owner'])
2141
-		fatal_error('no_access');
2249
+	if (!$context['user']['is_owner']) {
2250
+			fatal_error('no_access');
2251
+	}
2142 2252
 
2143 2253
 	checkSession('get');
2144 2254
 
@@ -2170,8 +2280,9 @@  discard block
 block discarded – undo
2170 2280
 {
2171 2281
 	global $smcFunc;
2172 2282
 
2173
-	if (empty($toMark) || empty($memID))
2174
-		return false;
2283
+	if (empty($toMark) || empty($memID)) {
2284
+			return false;
2285
+	}
2175 2286
 
2176 2287
 	$toMark = (array) $toMark;
2177 2288
 
@@ -2205,8 +2316,9 @@  discard block
 block discarded – undo
2205 2316
 {
2206 2317
 	global $smcFunc;
2207 2318
 
2208
-	if (empty($toDelete))
2209
-		return false;
2319
+	if (empty($toDelete)) {
2320
+			return false;
2321
+	}
2210 2322
 
2211 2323
 	$toDelete = (array) $toDelete;
2212 2324
 
@@ -2241,8 +2353,9 @@  discard block
 block discarded – undo
2241 2353
 {
2242 2354
 	global $smcFunc;
2243 2355
 
2244
-	if (empty($memID))
2245
-		return false;
2356
+	if (empty($memID)) {
2357
+			return false;
2358
+	}
2246 2359
 
2247 2360
 	$request = $smcFunc['db_query']('', '
2248 2361
 		SELECT id_alert
@@ -2319,8 +2432,9 @@  discard block
 block discarded – undo
2319 2432
 					{
2320 2433
 						$link = $topic['link'];
2321 2434
 
2322
-						if ($topic['new'])
2323
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2435
+						if ($topic['new']) {
2436
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2437
+						}
2324 2438
 
2325 2439
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2326 2440
 
@@ -2471,8 +2585,9 @@  discard block
 block discarded – undo
2471 2585
 					{
2472 2586
 						$link = $board['link'];
2473 2587
 
2474
-						if ($board['new'])
2475
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2588
+						if ($board['new']) {
2589
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2590
+						}
2476 2591
 
2477 2592
 						return $link;
2478 2593
 					},
@@ -2672,8 +2787,8 @@  discard block
 block discarded – undo
2672 2787
 		)
2673 2788
 	);
2674 2789
 	$notification_boards = array();
2675
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2676
-		$notification_boards[] = array(
2790
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2791
+			$notification_boards[] = array(
2677 2792
 			'id' => $row['id_board'],
2678 2793
 			'name' => $row['name'],
2679 2794
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2681,6 +2796,7 @@  discard block
 block discarded – undo
2681 2796
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2682 2797
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2683 2798
 		);
2799
+	}
2684 2800
 	$smcFunc['db_free_result']($request);
2685 2801
 
2686 2802
 	return $notification_boards;
@@ -2695,17 +2811,18 @@  discard block
 block discarded – undo
2695 2811
 {
2696 2812
 	global $context, $options, $cur_profile, $smcFunc;
2697 2813
 
2698
-	if (isset($_POST['default_options']))
2699
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2814
+	if (isset($_POST['default_options'])) {
2815
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2816
+	}
2700 2817
 
2701 2818
 	if ($context['user']['is_owner'])
2702 2819
 	{
2703 2820
 		$context['member']['options'] = $options;
2704
-		if (isset($_POST['options']) && is_array($_POST['options']))
2705
-			foreach ($_POST['options'] as $k => $v)
2821
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2822
+					foreach ($_POST['options'] as $k => $v)
2706 2823
 				$context['member']['options'][$k] = $v;
2707
-	}
2708
-	else
2824
+		}
2825
+	} else
2709 2826
 	{
2710 2827
 		$request = $smcFunc['db_query']('', '
2711 2828
 			SELECT id_member, variable, value
@@ -2726,8 +2843,9 @@  discard block
 block discarded – undo
2726 2843
 				continue;
2727 2844
 			}
2728 2845
 
2729
-			if (isset($_POST['options'][$row['variable']]))
2730
-				$row['value'] = $_POST['options'][$row['variable']];
2846
+			if (isset($_POST['options'][$row['variable']])) {
2847
+							$row['value'] = $_POST['options'][$row['variable']];
2848
+			}
2731 2849
 			$context['member']['options'][$row['variable']] = $row['value'];
2732 2850
 		}
2733 2851
 		$smcFunc['db_free_result']($request);
@@ -2735,8 +2853,9 @@  discard block
 block discarded – undo
2735 2853
 		// Load up the default theme options for any missing.
2736 2854
 		foreach ($temp as $k => $v)
2737 2855
 		{
2738
-			if (!isset($context['member']['options'][$k]))
2739
-				$context['member']['options'][$k] = $v;
2856
+			if (!isset($context['member']['options'][$k])) {
2857
+							$context['member']['options'][$k] = $v;
2858
+			}
2740 2859
 		}
2741 2860
 	}
2742 2861
 }
@@ -2751,8 +2870,9 @@  discard block
 block discarded – undo
2751 2870
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2752 2871
 
2753 2872
 	// Have the admins enabled this option?
2754
-	if (empty($modSettings['allow_ignore_boards']))
2755
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2873
+	if (empty($modSettings['allow_ignore_boards'])) {
2874
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2875
+	}
2756 2876
 
2757 2877
 	// Find all the boards this user is allowed to see.
2758 2878
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2772,12 +2892,13 @@  discard block
 block discarded – undo
2772 2892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2773 2893
 	{
2774 2894
 		// This category hasn't been set up yet..
2775
-		if (!isset($context['categories'][$row['id_cat']]))
2776
-			$context['categories'][$row['id_cat']] = array(
2895
+		if (!isset($context['categories'][$row['id_cat']])) {
2896
+					$context['categories'][$row['id_cat']] = array(
2777 2897
 				'id' => $row['id_cat'],
2778 2898
 				'name' => $row['cat_name'],
2779 2899
 				'boards' => array()
2780 2900
 			);
2901
+		}
2781 2902
 
2782 2903
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2783 2904
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2807,18 +2928,20 @@  discard block
 block discarded – undo
2807 2928
 	}
2808 2929
 
2809 2930
 	$max_boards = ceil(count($temp_boards) / 2);
2810
-	if ($max_boards == 1)
2811
-		$max_boards = 2;
2931
+	if ($max_boards == 1) {
2932
+			$max_boards = 2;
2933
+	}
2812 2934
 
2813 2935
 	// Now, alternate them so they can be shown left and right ;).
2814 2936
 	$context['board_columns'] = array();
2815 2937
 	for ($i = 0; $i < $max_boards; $i++)
2816 2938
 	{
2817 2939
 		$context['board_columns'][] = $temp_boards[$i];
2818
-		if (isset($temp_boards[$i + $max_boards]))
2819
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2820
-		else
2821
-			$context['board_columns'][] = array();
2940
+		if (isset($temp_boards[$i + $max_boards])) {
2941
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2942
+		} else {
2943
+					$context['board_columns'][] = array();
2944
+		}
2822 2945
 	}
2823 2946
 
2824 2947
 	loadThemeOptions($memID);
@@ -2887,8 +3010,9 @@  discard block
 block discarded – undo
2887 3010
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2888 3011
 	{
2889 3012
 		// We should skip the administrator group if they don't have the admin_forum permission!
2890
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2891
-			continue;
3013
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3014
+					continue;
3015
+		}
2892 3016
 
2893 3017
 		$context['member_groups'][$row['id_group']] = array(
2894 3018
 			'id' => $row['id_group'],
@@ -2934,16 +3058,17 @@  discard block
 block discarded – undo
2934 3058
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2935 3059
 	// Warning message for signature image limits?
2936 3060
 	$context['signature_warning'] = '';
2937
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2938
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2939
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2940
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3061
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3062
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3063
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3064
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3065
+	}
2941 3066
 
2942 3067
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2943 3068
 
2944
-	if (empty($context['do_preview']))
2945
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2946
-	else
3069
+	if (empty($context['do_preview'])) {
3070
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3071
+	} else
2947 3072
 	{
2948 3073
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2949 3074
 		$validation = profileValidateSignature($signature);
@@ -2953,8 +3078,9 @@  discard block
 block discarded – undo
2953 3078
 			$context['post_errors'] = array();
2954 3079
 		}
2955 3080
 		$context['post_errors'][] = 'signature_not_yet_saved';
2956
-		if ($validation !== true && $validation !== false)
2957
-			$context['post_errors'][] = $validation;
3081
+		if ($validation !== true && $validation !== false) {
3082
+					$context['post_errors'][] = $validation;
3083
+		}
2958 3084
 
2959 3085
 		censorText($context['member']['signature']);
2960 3086
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2964,8 +3090,9 @@  discard block
 block discarded – undo
2964 3090
 	}
2965 3091
 
2966 3092
 	// Load the spell checker?
2967
-	if ($context['show_spellchecking'])
2968
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3093
+	if ($context['show_spellchecking']) {
3094
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3095
+	}
2969 3096
 
2970 3097
 	return true;
2971 3098
 }
@@ -2999,8 +3126,7 @@  discard block
 block discarded – undo
2999 3126
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3000 3127
 		);
3001 3128
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3002
-	}
3003
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3129
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3004 3130
 	{
3005 3131
 		$context['member']['avatar'] += array(
3006 3132
 			'choice' => 'upload',
@@ -3010,33 +3136,34 @@  discard block
 block discarded – undo
3010 3136
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
3011 3137
 	}
3012 3138
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3013
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3014
-		$context['member']['avatar'] += array(
3139
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3140
+			$context['member']['avatar'] += array(
3015 3141
 			'choice' => 'external',
3016 3142
 			'server_pic' => 'blank.png',
3017 3143
 			'external' => $cur_profile['avatar_original']
3018 3144
 		);
3019
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3020
-		$context['member']['avatar'] += array(
3145
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3146
+			$context['member']['avatar'] += array(
3021 3147
 			'choice' => 'server_stored',
3022 3148
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3023 3149
 			'external' => 'http://'
3024 3150
 		);
3025
-	else
3026
-		$context['member']['avatar'] += array(
3151
+	} else {
3152
+			$context['member']['avatar'] += array(
3027 3153
 			'choice' => 'none',
3028 3154
 			'server_pic' => 'blank.png',
3029 3155
 			'external' => 'http://'
3030 3156
 		);
3157
+	}
3031 3158
 
3032 3159
 	// Get a list of all the avatars.
3033 3160
 	if ($context['member']['avatar']['allow_server_stored'])
3034 3161
 	{
3035 3162
 		$context['avatar_list'] = array();
3036 3163
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3164
+	} else {
3165
+			$context['avatars'] = array();
3037 3166
 	}
3038
-	else
3039
-		$context['avatars'] = array();
3040 3167
 
3041 3168
 	// Second level selected avatar...
3042 3169
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3065,19 +3192,22 @@  discard block
 block discarded – undo
3065 3192
 			)
3066 3193
 		);
3067 3194
 		$protected_groups = array(1);
3068
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3069
-			$protected_groups[] = $row['id_group'];
3195
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3196
+					$protected_groups[] = $row['id_group'];
3197
+		}
3070 3198
 		$smcFunc['db_free_result']($request);
3071 3199
 
3072 3200
 		$protected_groups = array_unique($protected_groups);
3073 3201
 	}
3074 3202
 
3075 3203
 	// The account page allows the change of your id_group - but not to a protected group!
3076
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3077
-		$value = (int) $value;
3204
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3205
+			$value = (int) $value;
3206
+	}
3078 3207
 	// ... otherwise it's the old group sir.
3079
-	else
3080
-		$value = $old_profile['id_group'];
3208
+	else {
3209
+			$value = $old_profile['id_group'];
3210
+	}
3081 3211
 
3082 3212
 	// Find the additional membergroups (if any)
3083 3213
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3086,16 +3216,18 @@  discard block
 block discarded – undo
3086 3216
 		foreach ($_POST['additional_groups'] as $group_id)
3087 3217
 		{
3088 3218
 			$group_id = (int) $group_id;
3089
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3090
-				$additional_groups[] = $group_id;
3219
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3220
+							$additional_groups[] = $group_id;
3221
+			}
3091 3222
 		}
3092 3223
 
3093 3224
 		// Put the protected groups back in there if you don't have permission to take them away.
3094 3225
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3095 3226
 		foreach ($old_additional_groups as $group_id)
3096 3227
 		{
3097
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3098
-				$additional_groups[] = $group_id;
3228
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3229
+							$additional_groups[] = $group_id;
3230
+			}
3099 3231
 		}
3100 3232
 
3101 3233
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3127,18 +3259,20 @@  discard block
 block discarded – undo
3127 3259
 			list ($another) = $smcFunc['db_fetch_row']($request);
3128 3260
 			$smcFunc['db_free_result']($request);
3129 3261
 
3130
-			if (empty($another))
3131
-				fatal_lang_error('at_least_one_admin', 'critical');
3262
+			if (empty($another)) {
3263
+							fatal_lang_error('at_least_one_admin', 'critical');
3264
+			}
3132 3265
 		}
3133 3266
 	}
3134 3267
 
3135 3268
 	// If we are changing group status, update permission cache as necessary.
3136 3269
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3137 3270
 	{
3138
-		if ($context['user']['is_owner'])
3139
-			$_SESSION['mc']['time'] = 0;
3140
-		else
3141
-			updateSettings(array('settings_updated' => time()));
3271
+		if ($context['user']['is_owner']) {
3272
+					$_SESSION['mc']['time'] = 0;
3273
+		} else {
3274
+					updateSettings(array('settings_updated' => time()));
3275
+		}
3142 3276
 	}
3143 3277
 
3144 3278
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3159,8 +3293,9 @@  discard block
 block discarded – undo
3159 3293
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3160 3294
 
3161 3295
 	$memID = $context['id_member'];
3162
-	if (empty($memID) && !empty($context['password_auth_failed']))
3163
-		return false;
3296
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3297
+			return false;
3298
+	}
3164 3299
 
3165 3300
 	require_once($sourcedir . '/ManageAttachments.php');
3166 3301
 
@@ -3171,8 +3306,9 @@  discard block
 block discarded – undo
3171 3306
 	$downloadedExternalAvatar = false;
3172 3307
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3173 3308
 	{
3174
-		if (!is_writable($uploadDir))
3175
-			fatal_lang_error('attachments_no_write', 'critical');
3309
+		if (!is_writable($uploadDir)) {
3310
+					fatal_lang_error('attachments_no_write', 'critical');
3311
+		}
3176 3312
 
3177 3313
 		require_once($sourcedir . '/Subs-Package.php');
3178 3314
 
@@ -3216,19 +3352,18 @@  discard block
 block discarded – undo
3216 3352
 
3217 3353
 		// Get rid of their old avatar. (if uploaded.)
3218 3354
 		removeAttachments(array('id_member' => $memID));
3219
-	}
3220
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3355
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3221 3356
 	{
3222 3357
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3223
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3224
-			$profile_vars['avatar'] = 'gravatar://';
3225
-		else
3226
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3358
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3359
+					$profile_vars['avatar'] = 'gravatar://';
3360
+		} else {
3361
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3362
+		}
3227 3363
 
3228 3364
 		// Get rid of their old avatar. (if uploaded.)
3229 3365
 		removeAttachments(array('id_member' => $memID));
3230
-	}
3231
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3366
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3232 3367
 	{
3233 3368
 		// We need these clean...
3234 3369
 		$cur_profile['id_attach'] = 0;
@@ -3240,11 +3375,13 @@  discard block
 block discarded – undo
3240 3375
 
3241 3376
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3242 3377
 
3243
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3244
-			$profile_vars['avatar'] = '';
3378
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3379
+					$profile_vars['avatar'] = '';
3380
+		}
3245 3381
 		// Trying to make us do something we'll regret?
3246
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3247
-			return 'bad_avatar_invalid_url';
3382
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3383
+					return 'bad_avatar_invalid_url';
3384
+		}
3248 3385
 		// Should we check dimensions?
3249 3386
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3250 3387
 		{
@@ -3254,9 +3391,9 @@  discard block
 block discarded – undo
3254 3391
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3255 3392
 			{
3256 3393
 				// Houston, we have a problem. The avatar is too large!!
3257
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3258
-					return 'bad_avatar_too_large';
3259
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3394
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3395
+									return 'bad_avatar_too_large';
3396
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3260 3397
 				{
3261 3398
 					// @todo remove this if appropriate
3262 3399
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3266,26 +3403,27 @@  discard block
 block discarded – undo
3266 3403
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3267 3404
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3268 3405
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3406
+					} else {
3407
+											return 'bad_avatar';
3269 3408
 					}
3270
-					else
3271
-						return 'bad_avatar';
3272 3409
 				}
3273 3410
 			}
3274 3411
 		}
3275
-	}
3276
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3412
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3277 3413
 	{
3278 3414
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3279 3415
 		{
3280 3416
 			// Get the dimensions of the image.
3281 3417
 			if (!$downloadedExternalAvatar)
3282 3418
 			{
3283
-				if (!is_writable($uploadDir))
3284
-					fatal_lang_error('attachments_no_write', 'critical');
3419
+				if (!is_writable($uploadDir)) {
3420
+									fatal_lang_error('attachments_no_write', 'critical');
3421
+				}
3285 3422
 
3286 3423
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3287
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3288
-					fatal_lang_error('attach_timeout', 'critical');
3424
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3425
+									fatal_lang_error('attach_timeout', 'critical');
3426
+				}
3289 3427
 
3290 3428
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3291 3429
 			}
@@ -3398,17 +3536,19 @@  discard block
 block discarded – undo
3398 3536
 			$profile_vars['avatar'] = '';
3399 3537
 
3400 3538
 			// Delete any temporary file.
3401
-			if (file_exists($_FILES['attachment']['tmp_name']))
3402
-				@unlink($_FILES['attachment']['tmp_name']);
3539
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3540
+							@unlink($_FILES['attachment']['tmp_name']);
3541
+			}
3403 3542
 		}
3404 3543
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3405
-		else
3544
+		else {
3545
+					$profile_vars['avatar'] = '';
3546
+		}
3547
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3548
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3549
+	} else {
3406 3550
 			$profile_vars['avatar'] = '';
3407 3551
 	}
3408
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3409
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3410
-	else
3411
-		$profile_vars['avatar'] = '';
3412 3552
 
3413 3553
 	// Setup the profile variables so it shows things right on display!
3414 3554
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3456,9 +3596,9 @@  discard block
 block discarded – undo
3456 3596
 		$smiley_parsed = $unparsed_signature;
3457 3597
 		parsesmileys($smiley_parsed);
3458 3598
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3459
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3460
-			return 'signature_allow_smileys';
3461
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3599
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3600
+					return 'signature_allow_smileys';
3601
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3462 3602
 		{
3463 3603
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3464 3604
 			return 'signature_max_smileys';
@@ -3471,14 +3611,15 @@  discard block
 block discarded – undo
3471 3611
 			{
3472 3612
 				$limit_broke = 0;
3473 3613
 				// Attempt to allow all sizes of abuse, so to speak.
3474
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3475
-					$limit_broke = $sig_limits[7] . 'px';
3476
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3477
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3478
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3479
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3480
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3481
-					$limit_broke = 'large';
3614
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3615
+									$limit_broke = $sig_limits[7] . 'px';
3616
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3617
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3618
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3619
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3620
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3621
+									$limit_broke = 'large';
3622
+				}
3482 3623
 
3483 3624
 				if ($limit_broke)
3484 3625
 				{
@@ -3520,24 +3661,26 @@  discard block
 block discarded – undo
3520 3661
 					$width = -1; $height = -1;
3521 3662
 
3522 3663
 					// Does it have predefined restraints? Width first.
3523
-					if ($matches[6][$key])
3524
-						$matches[2][$key] = $matches[6][$key];
3664
+					if ($matches[6][$key]) {
3665
+											$matches[2][$key] = $matches[6][$key];
3666
+					}
3525 3667
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3526 3668
 					{
3527 3669
 						$width = $sig_limits[5];
3528 3670
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3671
+					} elseif ($matches[2][$key]) {
3672
+											$width = $matches[2][$key];
3529 3673
 					}
3530
-					elseif ($matches[2][$key])
3531
-						$width = $matches[2][$key];
3532 3674
 					// ... and height.
3533 3675
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3534 3676
 					{
3535 3677
 						$height = $sig_limits[6];
3536
-						if ($width != -1)
3537
-							$width = $width * ($height / $matches[4][$key]);
3678
+						if ($width != -1) {
3679
+													$width = $width * ($height / $matches[4][$key]);
3680
+						}
3681
+					} elseif ($matches[4][$key]) {
3682
+											$height = $matches[4][$key];
3538 3683
 					}
3539
-					elseif ($matches[4][$key])
3540
-						$height = $matches[4][$key];
3541 3684
 
3542 3685
 					// If the dimensions are still not fixed - we need to check the actual image.
3543 3686
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3555,21 +3698,24 @@  discard block
 block discarded – undo
3555 3698
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3556 3699
 							{
3557 3700
 								$height = $sig_limits[6];
3558
-								if ($width == -1)
3559
-									$width = $sizes[0];
3701
+								if ($width == -1) {
3702
+																	$width = $sizes[0];
3703
+								}
3560 3704
 								$width = $width * ($height / $sizes[1]);
3705
+							} elseif ($width != -1) {
3706
+															$height = $sizes[1];
3561 3707
 							}
3562
-							elseif ($width != -1)
3563
-								$height = $sizes[1];
3564 3708
 						}
3565 3709
 					}
3566 3710
 
3567 3711
 					// Did we come up with some changes? If so remake the string.
3568
-					if ($width != -1 || $height != -1)
3569
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3712
+					if ($width != -1 || $height != -1) {
3713
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3714
+					}
3715
+				}
3716
+				if (!empty($replaces)) {
3717
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3570 3718
 				}
3571
-				if (!empty($replaces))
3572
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3573 3719
 			}
3574 3720
 		}
3575 3721
 
@@ -3613,10 +3759,12 @@  discard block
 block discarded – undo
3613 3759
 	$email = strtr($email, array('&#039;' => '\''));
3614 3760
 
3615 3761
 	// Check the name and email for validity.
3616
-	if (trim($email) == '')
3617
-		return 'no_email';
3618
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3619
-		return 'bad_email';
3762
+	if (trim($email) == '') {
3763
+			return 'no_email';
3764
+	}
3765
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3766
+			return 'bad_email';
3767
+	}
3620 3768
 
3621 3769
 	// Email addresses should be and stay unique.
3622 3770
 	$request = $smcFunc['db_query']('', '
@@ -3631,8 +3779,9 @@  discard block
 block discarded – undo
3631 3779
 		)
3632 3780
 	);
3633 3781
 
3634
-	if ($smcFunc['db_num_rows']($request) > 0)
3635
-		return 'email_taken';
3782
+	if ($smcFunc['db_num_rows']($request) > 0) {
3783
+			return 'email_taken';
3784
+	}
3636 3785
 	$smcFunc['db_free_result']($request);
3637 3786
 
3638 3787
 	return true;
@@ -3645,8 +3794,9 @@  discard block
 block discarded – undo
3645 3794
 {
3646 3795
 	global $modSettings, $context, $cur_profile;
3647 3796
 
3648
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3649
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3797
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3798
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3799
+	}
3650 3800
 
3651 3801
 	loadUserSettings();
3652 3802
 	writeLog();
@@ -3662,8 +3812,9 @@  discard block
 block discarded – undo
3662 3812
 	require_once($sourcedir . '/Subs-Post.php');
3663 3813
 
3664 3814
 	// Shouldn't happen but just in case.
3665
-	if (empty($profile_vars['email_address']))
3666
-		return;
3815
+	if (empty($profile_vars['email_address'])) {
3816
+			return;
3817
+	}
3667 3818
 
3668 3819
 	$replacements = array(
3669 3820
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3686,8 +3837,9 @@  discard block
 block discarded – undo
3686 3837
 	$_SESSION['log_time'] = 0;
3687 3838
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3688 3839
 
3689
-	if (isset($_COOKIE[$cookiename]))
3690
-		$_COOKIE[$cookiename] = '';
3840
+	if (isset($_COOKIE[$cookiename])) {
3841
+			$_COOKIE[$cookiename] = '';
3842
+	}
3691 3843
 
3692 3844
 	loadUserSettings();
3693 3845
 
@@ -3720,11 +3872,13 @@  discard block
 block discarded – undo
3720 3872
 	$groups[] = $curMember['id_group'];
3721 3873
 
3722 3874
 	// Ensure the query doesn't croak!
3723
-	if (empty($groups))
3724
-		$groups = array(0);
3875
+	if (empty($groups)) {
3876
+			$groups = array(0);
3877
+	}
3725 3878
 	// Just to be sure...
3726
-	foreach ($groups as $k => $v)
3727
-		$groups[$k] = (int) $v;
3879
+	foreach ($groups as $k => $v) {
3880
+			$groups[$k] = (int) $v;
3881
+	}
3728 3882
 
3729 3883
 	// Get all the membergroups they can join.
3730 3884
 	$request = $smcFunc['db_query']('', '
@@ -3754,12 +3908,14 @@  discard block
 block discarded – undo
3754 3908
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3755 3909
 	{
3756 3910
 		// Can they edit their primary group?
3757
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3758
-			$context['can_edit_primary'] = true;
3911
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3912
+					$context['can_edit_primary'] = true;
3913
+		}
3759 3914
 
3760 3915
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3761
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3762
-			continue;
3916
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3917
+					continue;
3918
+		}
3763 3919
 
3764 3920
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3765 3921
 			'id' => $row['id_group'],
@@ -3788,13 +3944,15 @@  discard block
 block discarded – undo
3788 3944
 	);
3789 3945
 
3790 3946
 	// No changing primary one unless you have enough groups!
3791
-	if (count($context['groups']['member']) < 2)
3792
-		$context['can_edit_primary'] = false;
3947
+	if (count($context['groups']['member']) < 2) {
3948
+			$context['can_edit_primary'] = false;
3949
+	}
3793 3950
 
3794 3951
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3795
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3796
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3797
-}
3952
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3953
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3954
+	}
3955
+	}
3798 3956
 
3799 3957
 /**
3800 3958
  * This function actually makes all the group changes
@@ -3809,10 +3967,12 @@  discard block
 block discarded – undo
3809 3967
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3810 3968
 
3811 3969
 	// Let's be extra cautious...
3812
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3813
-		isAllowedTo('manage_membergroups');
3814
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3815
-		fatal_lang_error('no_access', false);
3970
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3971
+			isAllowedTo('manage_membergroups');
3972
+	}
3973
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3974
+			fatal_lang_error('no_access', false);
3975
+	}
3816 3976
 
3817 3977
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3818 3978
 
@@ -3831,8 +3991,9 @@  discard block
 block discarded – undo
3831 3991
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3832 3992
 
3833 3993
 	// Sanity check!!
3834
-	if ($group_id == 1)
3835
-		isAllowedTo('admin_forum');
3994
+	if ($group_id == 1) {
3995
+			isAllowedTo('admin_forum');
3996
+	}
3836 3997
 	// Protected groups too!
3837 3998
 	else
3838 3999
 	{
@@ -3849,8 +4010,9 @@  discard block
 block discarded – undo
3849 4010
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3850 4011
 		$smcFunc['db_free_result']($request);
3851 4012
 
3852
-		if ($is_protected == 1)
3853
-			isAllowedTo('admin_forum');
4013
+		if ($is_protected == 1) {
4014
+					isAllowedTo('admin_forum');
4015
+		}
3854 4016
 	}
3855 4017
 
3856 4018
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3872,36 +4034,43 @@  discard block
 block discarded – undo
3872 4034
 			$group_name = $row['group_name'];
3873 4035
 
3874 4036
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3875
-			if ($changeType == 'request' && $row['group_type'] != 2)
3876
-				fatal_lang_error('no_access', false);
4037
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4038
+							fatal_lang_error('no_access', false);
4039
+			}
3877 4040
 			// What about leaving a requestable group we are not a member of?
3878
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3879
-				fatal_lang_error('no_access', false);
3880
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3881
-				fatal_lang_error('no_access', false);
4041
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4042
+							fatal_lang_error('no_access', false);
4043
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4044
+							fatal_lang_error('no_access', false);
4045
+			}
3882 4046
 
3883 4047
 			// We can't change the primary group if this is hidden!
3884
-			if ($row['hidden'] == 2)
3885
-				$canChangePrimary = false;
4048
+			if ($row['hidden'] == 2) {
4049
+							$canChangePrimary = false;
4050
+			}
3886 4051
 		}
3887 4052
 
3888 4053
 		// If this is their old primary, can we change it?
3889
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3890
-			$canChangePrimary = 1;
4054
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4055
+					$canChangePrimary = 1;
4056
+		}
3891 4057
 
3892 4058
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3893
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3894
-			$canChangePrimary = false;
4059
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4060
+					$canChangePrimary = false;
4061
+		}
3895 4062
 
3896 4063
 		// If this is the one we are acting on, can we even act?
3897
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3898
-			$canChangePrimary = false;
4064
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4065
+					$canChangePrimary = false;
4066
+		}
3899 4067
 	}
3900 4068
 	$smcFunc['db_free_result']($request);
3901 4069
 
3902 4070
 	// Didn't find the target?
3903
-	if (!$foundTarget)
3904
-		fatal_lang_error('no_access', false);
4071
+	if (!$foundTarget) {
4072
+			fatal_lang_error('no_access', false);
4073
+	}
3905 4074
 
3906 4075
 	// Final security check, don't allow users to promote themselves to admin.
3907 4076
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3921,8 +4090,9 @@  discard block
 block discarded – undo
3921 4090
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3922 4091
 		$smcFunc['db_free_result']($request);
3923 4092
 
3924
-		if ($disallow)
3925
-			isAllowedTo('admin_forum');
4093
+		if ($disallow) {
4094
+					isAllowedTo('admin_forum');
4095
+		}
3926 4096
 	}
3927 4097
 
3928 4098
 	// If we're requesting, add the note then return.
@@ -3940,8 +4110,9 @@  discard block
 block discarded – undo
3940 4110
 				'status_open' => 0,
3941 4111
 			)
3942 4112
 		);
3943
-		if ($smcFunc['db_num_rows']($request) != 0)
3944
-			fatal_lang_error('profile_error_already_requested_group');
4113
+		if ($smcFunc['db_num_rows']($request) != 0) {
4114
+					fatal_lang_error('profile_error_already_requested_group');
4115
+		}
3945 4116
 		$smcFunc['db_free_result']($request);
3946 4117
 
3947 4118
 		// Log the request.
@@ -3975,10 +4146,11 @@  discard block
 block discarded – undo
3975 4146
 		// Are we leaving?
3976 4147
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3977 4148
 		{
3978
-			if ($old_profile['id_group'] == $group_id)
3979
-				$newPrimary = 0;
3980
-			else
3981
-				unset($addGroups[$group_id]);
4149
+			if ($old_profile['id_group'] == $group_id) {
4150
+							$newPrimary = 0;
4151
+			} else {
4152
+							unset($addGroups[$group_id]);
4153
+			}
3982 4154
 		}
3983 4155
 		// ... if not, must be joining.
3984 4156
 		else
@@ -3986,36 +4158,42 @@  discard block
 block discarded – undo
3986 4158
 			// Can we change the primary, and do we want to?
3987 4159
 			if ($canChangePrimary)
3988 4160
 			{
3989
-				if ($old_profile['id_group'] != 0)
3990
-					$addGroups[$old_profile['id_group']] = -1;
4161
+				if ($old_profile['id_group'] != 0) {
4162
+									$addGroups[$old_profile['id_group']] = -1;
4163
+				}
3991 4164
 				$newPrimary = $group_id;
3992 4165
 			}
3993 4166
 			// Otherwise it's an additional group...
3994
-			else
3995
-				$addGroups[$group_id] = -1;
4167
+			else {
4168
+							$addGroups[$group_id] = -1;
4169
+			}
3996 4170
 		}
3997 4171
 	}
3998 4172
 	// Finally, we must be setting the primary.
3999 4173
 	elseif ($canChangePrimary)
4000 4174
 	{
4001
-		if ($old_profile['id_group'] != 0)
4002
-			$addGroups[$old_profile['id_group']] = -1;
4003
-		if (isset($addGroups[$group_id]))
4004
-			unset($addGroups[$group_id]);
4175
+		if ($old_profile['id_group'] != 0) {
4176
+					$addGroups[$old_profile['id_group']] = -1;
4177
+		}
4178
+		if (isset($addGroups[$group_id])) {
4179
+					unset($addGroups[$group_id]);
4180
+		}
4005 4181
 		$newPrimary = $group_id;
4006 4182
 	}
4007 4183
 
4008 4184
 	// Finally, we can make the changes!
4009
-	foreach ($addGroups as $id => $dummy)
4010
-		if (empty($id))
4185
+	foreach ($addGroups as $id => $dummy) {
4186
+			if (empty($id))
4011 4187
 			unset($addGroups[$id]);
4188
+	}
4012 4189
 	$addGroups = implode(',', array_flip($addGroups));
4013 4190
 
4014 4191
 	// Ensure that we don't cache permissions if the group is changing.
4015
-	if ($context['user']['is_owner'])
4016
-		$_SESSION['mc']['time'] = 0;
4017
-	else
4018
-		updateSettings(array('settings_updated' => time()));
4192
+	if ($context['user']['is_owner']) {
4193
+			$_SESSION['mc']['time'] = 0;
4194
+	} else {
4195
+			updateSettings(array('settings_updated' => time()));
4196
+	}
4019 4197
 
4020 4198
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4021 4199
 
@@ -4038,8 +4216,9 @@  discard block
 block discarded – undo
4038 4216
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4039 4217
 	{
4040 4218
 		// Check to ensure we're forcing SSL for authentication
4041
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4042
-			fatal_lang_error('login_ssl_required');
4219
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4220
+					fatal_lang_error('login_ssl_required');
4221
+		}
4043 4222
 
4044 4223
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4045 4224
 		// we do not want too much AJAX to confuse them.
@@ -4076,8 +4255,7 @@  discard block
 block discarded – undo
4076 4255
 				$context['sub_template'] = 'tfasetup_backup';
4077 4256
 
4078 4257
 				return;
4079
-			}
4080
-			else
4258
+			} else
4081 4259
 			{
4082 4260
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4083 4261
 				$context['tfa_error'] = !$valid_code;
@@ -4085,8 +4263,7 @@  discard block
 block discarded – undo
4085 4263
 				$context['tfa_pass_value'] = $_POST['passwd'];
4086 4264
 				$context['tfa_value'] = $_POST['tfa_code'];
4087 4265
 			}
4088
-		}
4089
-		else
4266
+		} else
4090 4267
 		{
4091 4268
 			$totp = new \TOTP\Auth();
4092 4269
 			$secret = $totp->generateCode();
@@ -4096,17 +4273,16 @@  discard block
 block discarded – undo
4096 4273
 		}
4097 4274
 
4098 4275
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4099
-	}
4100
-	elseif (isset($_REQUEST['disable']))
4276
+	} elseif (isset($_REQUEST['disable']))
4101 4277
 	{
4102 4278
 		updateMemberData($memID, array(
4103 4279
 			'tfa_secret' => '',
4104 4280
 			'tfa_backup' => '',
4105 4281
 		));
4106 4282
 		redirectexit('action=profile;area=account;u=' . $memID);
4283
+	} else {
4284
+			redirectexit('action=profile;area=account;u=' . $memID);
4285
+	}
4107 4286
 	}
4108
-	else
4109
-		redirectexit('action=profile;area=account;u=' . $memID);
4110
-}
4111 4287
 
4112 4288
 ?>
4113 4289
\ No newline at end of file
Please login to merge, or discard this patch.