Completed
Push — release-2.1 ( e07574...f1e1b9 )
by
unknown
11s
created
Sources/Subs-Editor.php 1 patch
Braces   +412 added lines, -309 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -381,8 +395,7 @@  discard block
 block discarded – undo
381 395
 
382 396
 			// Put the tags back into the body.
383 397
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
384
-		}
385
-		else
398
+		} else
386 399
 		{
387 400
 			// Just get rid of this evil tag.
388 401
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -395,8 +408,9 @@  discard block
 block discarded – undo
395 408
 		// Find the position of this again.
396 409
 		$start_pos = strpos($text, $matches[0]);
397 410
 		$end_pos = false;
398
-		if ($start_pos === false)
399
-			break;
411
+		if ($start_pos === false) {
412
+					break;
413
+		}
400 414
 
401 415
 		// This must have an end tag - and we must find the right one.
402 416
 		$lower_text = strtolower($text);
@@ -429,8 +443,9 @@  discard block
 block discarded – undo
429 443
 				break;
430 444
 			}
431 445
 		}
432
-		if ($end_pos === false)
433
-			break;
446
+		if ($end_pos === false) {
447
+					break;
448
+		}
434 449
 
435 450
 		// Now work out what the attributes are.
436 451
 		$attribs = fetchTagAttributes($matches[1]);
@@ -444,11 +459,11 @@  discard block
 block discarded – undo
444 459
 				$v = (int) trim($v);
445 460
 				$v = empty($v) ? 1 : $v;
446 461
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
462
+			} elseif ($s == 'face') {
463
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
464
+			} elseif ($s == 'color') {
465
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
447 466
 			}
448
-			elseif ($s == 'face')
449
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
450
-			elseif ($s == 'color')
451
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
452 467
 		}
453 468
 
454 469
 		// As before add in our tags.
@@ -456,8 +471,9 @@  discard block
 block discarded – undo
456 471
 		foreach ($tags as $tag)
457 472
 		{
458 473
 			$before .= $tag[0];
459
-			if (isset($tag[1]))
460
-				$after = $tag[1] . $after;
474
+			if (isset($tag[1])) {
475
+							$after = $tag[1] . $after;
476
+			}
461 477
 		}
462 478
 
463 479
 		// Remove the tag so it's never checked again.
@@ -468,8 +484,9 @@  discard block
 block discarded – undo
468 484
 	}
469 485
 
470 486
 	// Almost there, just a little more time.
471
-	if (connection_aborted() && $context['server']['is_apache'])
472
-		@apache_reset_timeout();
487
+	if (connection_aborted() && $context['server']['is_apache']) {
488
+			@apache_reset_timeout();
489
+	}
473 490
 
474 491
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
475 492
 	{
@@ -525,12 +542,13 @@  discard block
 block discarded – undo
525 542
 						{
526 543
 							$inList = true;
527 544
 
528
-							if ($tag === 'ol')
529
-								$listType = 'decimal';
530
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
531
-								$listType = $listTypeMapping[$match[1]];
532
-							else
533
-								$listType = null;
545
+							if ($tag === 'ol') {
546
+															$listType = 'decimal';
547
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
548
+															$listType = $listTypeMapping[$match[1]];
549
+							} else {
550
+															$listType = null;
551
+							}
534 552
 
535 553
 							$listDepth++;
536 554
 
@@ -594,9 +612,7 @@  discard block
 block discarded – undo
594 612
 							$parts[$i + 1] = '';
595 613
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
596 614
 							$parts[$i + 3] = '';
597
-						}
598
-
599
-						else
615
+						} else
600 616
 						{
601 617
 							// We're in a list item.
602 618
 							if ($listDepth > 0)
@@ -633,9 +649,7 @@  discard block
 block discarded – undo
633 649
 							$parts[$i + 1] = '';
634 650
 							$parts[$i + 2] = '';
635 651
 							$parts[$i + 3] = '';
636
-						}
637
-
638
-						else
652
+						} else
639 653
 						{
640 654
 							// Remove the trailing breaks from the list item.
641 655
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -673,8 +687,9 @@  discard block
 block discarded – undo
673 687
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
674 688
 		}
675 689
 
676
-		for ($i = $listDepth; $i > 0; $i--)
677
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
690
+		for ($i = $listDepth; $i > 0; $i--) {
691
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		}
678 693
 
679 694
 	}
680 695
 
@@ -683,8 +698,9 @@  discard block
 block discarded – undo
683 698
 	{
684 699
 		// Find the position of the image.
685 700
 		$start_pos = strpos($text, $matches[0]);
686
-		if ($start_pos === false)
687
-			break;
701
+		if ($start_pos === false) {
702
+					break;
703
+		}
688 704
 		$end_pos = $start_pos + strlen($matches[0]);
689 705
 
690 706
 		$params = '';
@@ -693,12 +709,13 @@  discard block
 block discarded – undo
693 709
 		$attrs = fetchTagAttributes($matches[1]);
694 710
 		foreach ($attrs as $attrib => $value)
695 711
 		{
696
-			if (in_array($attrib, array('width', 'height')))
697
-				$params .= ' ' . $attrib . '=' . (int) $value;
698
-			elseif ($attrib == 'alt' && trim($value) != '')
699
-				$params .= ' alt=' . trim($value);
700
-			elseif ($attrib == 'src')
701
-				$src = trim($value);
712
+			if (in_array($attrib, array('width', 'height'))) {
713
+							$params .= ' ' . $attrib . '=' . (int) $value;
714
+			} elseif ($attrib == 'alt' && trim($value) != '') {
715
+							$params .= ' alt=' . trim($value);
716
+			} elseif ($attrib == 'src') {
717
+							$src = trim($value);
718
+			}
702 719
 		}
703 720
 
704 721
 		$tag = '';
@@ -709,10 +726,11 @@  discard block
 block discarded – undo
709 726
 			{
710 727
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
711 728
 
712
-				if (substr($src, 0, 1) === '/')
713
-					$src = $baseURL . $src;
714
-				else
715
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				if (substr($src, 0, 1) === '/') {
730
+									$src = $baseURL . $src;
731
+				} else {
732
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
733
+				}
716 734
 			}
717 735
 
718 736
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -890,20 +908,23 @@  discard block
 block discarded – undo
890 908
 		},
891 909
 	);
892 910
 
893
-	foreach ($tags as $tag => $replace)
894
-		$text = preg_replace_callback($tag, $replace, $text);
911
+	foreach ($tags as $tag => $replace) {
912
+			$text = preg_replace_callback($tag, $replace, $text);
913
+	}
895 914
 
896 915
 	// Please give us just a little more time.
897
-	if (connection_aborted() && $context['server']['is_apache'])
898
-		@apache_reset_timeout();
916
+	if (connection_aborted() && $context['server']['is_apache']) {
917
+			@apache_reset_timeout();
918
+	}
899 919
 
900 920
 	// What about URL's - the pain in the ass of the tag world.
901 921
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
902 922
 	{
903 923
 		// Find the position of the URL.
904 924
 		$start_pos = strpos($text, $matches[0]);
905
-		if ($start_pos === false)
906
-			break;
925
+		if ($start_pos === false) {
926
+					break;
927
+		}
907 928
 		$end_pos = $start_pos + strlen($matches[0]);
908 929
 
909 930
 		$tag_type = 'url';
@@ -917,8 +938,9 @@  discard block
 block discarded – undo
917 938
 				$href = trim($value);
918 939
 
919 940
 				// Are we dealing with an FTP link?
920
-				if (preg_match('~^ftps?://~', $href) === 1)
921
-					$tag_type = 'ftp';
941
+				if (preg_match('~^ftps?://~', $href) === 1) {
942
+									$tag_type = 'ftp';
943
+				}
922 944
 
923 945
 				// Or is this a link to an email address?
924 946
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -932,28 +954,31 @@  discard block
 block discarded – undo
932 954
 				{
933 955
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
934 956
 
935
-					if (substr($href, 0, 1) === '/')
936
-						$href = $baseURL . $href;
937
-					else
938
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					if (substr($href, 0, 1) === '/') {
958
+											$href = $baseURL . $href;
959
+					} else {
960
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
961
+					}
939 962
 				}
940 963
 			}
941 964
 
942 965
 			// External URL?
943 966
 			if ($attrib == 'target' && $tag_type == 'url')
944 967
 			{
945
-				if (trim($value) == '_blank')
946
-					$tag_type == 'iurl';
968
+				if (trim($value) == '_blank') {
969
+									$tag_type == 'iurl';
970
+				}
947 971
 			}
948 972
 		}
949 973
 
950 974
 		$tag = '';
951 975
 		if ($href != '')
952 976
 		{
953
-			if ($matches[2] == $href)
954
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
955
-			else
956
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			if ($matches[2] == $href) {
978
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
979
+			} else {
980
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
981
+			}
957 982
 		}
958 983
 
959 984
 		// Replace the tag
@@ -992,17 +1017,18 @@  discard block
 block discarded – undo
992 1017
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
993 1018
 		if ($text[$i] == '=')
994 1019
 		{
995
-			if ($tag_state == 0)
996
-				$tag_state = 1;
997
-			elseif ($tag_state == 2)
998
-				$value .= '=';
1020
+			if ($tag_state == 0) {
1021
+							$tag_state = 1;
1022
+			} elseif ($tag_state == 2) {
1023
+							$value .= '=';
1024
+			}
999 1025
 		}
1000 1026
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1001 1027
 		elseif ($text[$i] == ' ')
1002 1028
 		{
1003
-			if ($tag_state == 2)
1004
-				$value .= ' ';
1005
-			elseif ($tag_state == 1)
1029
+			if ($tag_state == 2) {
1030
+							$value .= ' ';
1031
+			} elseif ($tag_state == 1)
1006 1032
 			{
1007 1033
 				$attribs[$key] = $value;
1008 1034
 				$key = $value = '';
@@ -1013,24 +1039,27 @@  discard block
 block discarded – undo
1013 1039
 		elseif ($text[$i] == '"')
1014 1040
 		{
1015 1041
 			// Must be either going into or out of a string.
1016
-			if ($tag_state == 1)
1017
-				$tag_state = 2;
1018
-			else
1019
-				$tag_state = 1;
1042
+			if ($tag_state == 1) {
1043
+							$tag_state = 2;
1044
+			} else {
1045
+							$tag_state = 1;
1046
+			}
1020 1047
 		}
1021 1048
 		// Otherwise it's fine.
1022 1049
 		else
1023 1050
 		{
1024
-			if ($tag_state == 0)
1025
-				$key .= $text[$i];
1026
-			else
1027
-				$value .= $text[$i];
1051
+			if ($tag_state == 0) {
1052
+							$key .= $text[$i];
1053
+			} else {
1054
+							$value .= $text[$i];
1055
+			}
1028 1056
 		}
1029 1057
 	}
1030 1058
 
1031 1059
 	// Anything left?
1032
-	if ($key != '' && $value != '')
1033
-		$attribs[$key] = $value;
1060
+	if ($key != '' && $value != '') {
1061
+			$attribs[$key] = $value;
1062
+	}
1034 1063
 
1035 1064
 	return $attribs;
1036 1065
 }
@@ -1046,15 +1075,17 @@  discard block
 block discarded – undo
1046 1075
 	global $modSettings;
1047 1076
 
1048 1077
 	// Don't care about the texts that are too short.
1049
-	if (strlen($text) < 3)
1050
-		return $text;
1078
+	if (strlen($text) < 3) {
1079
+			return $text;
1080
+	}
1051 1081
 
1052 1082
 	// A list of tags that's disabled by the admin.
1053 1083
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1054 1084
 
1055 1085
 	// Add flash if it's disabled as embedded tag.
1056
-	if (empty($modSettings['enableEmbeddedFlash']))
1057
-		$disabled['flash'] = true;
1086
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1087
+			$disabled['flash'] = true;
1088
+	}
1058 1089
 
1059 1090
 	// Get a list of all the tags that are not disabled.
1060 1091
 	$all_tags = parse_bbc(false);
@@ -1062,10 +1093,12 @@  discard block
 block discarded – undo
1062 1093
 	$self_closing_tags = array();
1063 1094
 	foreach ($all_tags as $tag)
1064 1095
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1096
+		if (!isset($disabled[$tag['tag']])) {
1097
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1098
+		}
1099
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1100
+					$self_closing_tags[] = $tag['tag'];
1101
+		}
1069 1102
 	}
1070 1103
 
1071 1104
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1125,19 @@  discard block
 block discarded – undo
1092 1125
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1126
 
1094 1127
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1128
+				if ($isClosingTag && $insideTag === $tagName) {
1129
+									$insideTag = null;
1130
+				}
1097 1131
 
1098 1132
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1133
+				elseif (!$isClosingTag && $insideTag === null) {
1134
+									$insideTag = $tagName;
1135
+				}
1101 1136
 
1102 1137
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1138
+				else {
1139
+									unset($matches[$i]);
1140
+				}
1105 1141
 			}
1106 1142
 
1107 1143
 			// The next one is gonna be the other one.
@@ -1109,8 +1145,9 @@  discard block
 block discarded – undo
1109 1145
 		}
1110 1146
 
1111 1147
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1148
+		if ($insideTag !== null) {
1149
+					$matches[] = '[/' . $insideTag . ']';
1150
+		}
1114 1151
 
1115 1152
 		// And a complete text string again.
1116 1153
 		$text = implode('', $matches);
@@ -1119,8 +1156,9 @@  discard block
 block discarded – undo
1119 1156
 	// Quickly remove any tags which are back to back.
1120 1157
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1158
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1159
+	while (strlen($text) !== $lastlen) {
1160
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1161
+	}
1124 1162
 
1125 1163
 	// Need to sort the tags my name length.
1126 1164
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1195,9 @@  discard block
 block discarded – undo
1157 1195
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1196
 
1159 1197
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1198
+			if ($tag === '') {
1199
+							continue;
1200
+			}
1162 1201
 
1163 1202
 			// Special case: inside [code] blocks any code is left untouched.
1164 1203
 			elseif ($tag === 'code')
@@ -1169,8 +1208,9 @@  discard block
 block discarded – undo
1169 1208
 					$inCode = false;
1170 1209
 
1171 1210
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1211
+					if (!empty($inlineElements)) {
1212
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1213
+					}
1174 1214
 				}
1175 1215
 
1176 1216
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1239,9 @@  discard block
 block discarded – undo
1199 1239
 					$inNoBbc = false;
1200 1240
 
1201 1241
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1242
+					if (!empty($inlineElements)) {
1243
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1244
+					}
1204 1245
 				}
1205 1246
 
1206 1247
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1261,9 @@  discard block
 block discarded – undo
1220 1261
 			}
1221 1262
 
1222 1263
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1264
+			elseif ($inCode || $inNoBbc) {
1265
+							continue;
1266
+			}
1225 1267
 
1226 1268
 			// We're dealing with an opening tag.
1227 1269
 			if ($isOpeningTag)
@@ -1262,8 +1304,9 @@  discard block
 block discarded – undo
1262 1304
 							if ($parts[$j + 3] === $tag)
1263 1305
 							{
1264 1306
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1307
+								if ($parts[$j + 2] === '') {
1308
+																	$curLevel++;
1309
+								}
1267 1310
 
1268 1311
 								// A closing tag, decrease the level.
1269 1312
 								else
@@ -1286,13 +1329,15 @@  discard block
 block discarded – undo
1286 1329
 					{
1287 1330
 						if ($isCompetingTag)
1288 1331
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1332
+							if (!isset($competingElements[$tag])) {
1333
+															$competingElements[$tag] = array();
1334
+							}
1291 1335
 
1292 1336
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1337
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1338
+							if (count($competingElements[$tag]) > 1) {
1339
+															$parts[$i] .= '[/' . $tag . ']';
1340
+							}
1296 1341
 						}
1297 1342
 
1298 1343
 						$inlineElements[$elementContent] = $tag;
@@ -1313,15 +1358,17 @@  discard block
 block discarded – undo
1313 1358
 						$addClosingTags = array();
1314 1359
 						while ($element = array_pop($blockElements))
1315 1360
 						{
1316
-							if ($element === $tag)
1317
-								break;
1361
+							if ($element === $tag) {
1362
+															break;
1363
+							}
1318 1364
 
1319 1365
 							// Still a block tag was open not equal to this tag.
1320 1366
 							$addClosingTags[] = $element['type'];
1321 1367
 						}
1322 1368
 
1323
-						if (!empty($addClosingTags))
1324
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						if (!empty($addClosingTags)) {
1370
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1371
+						}
1325 1372
 
1326 1373
 						// Apparently the closing tag was not found on the stack.
1327 1374
 						if (!is_string($element) || $element !== $tag)
@@ -1331,8 +1378,7 @@  discard block
 block discarded – undo
1331 1378
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1332 1379
 							continue;
1333 1380
 						}
1334
-					}
1335
-					else
1381
+					} else
1336 1382
 					{
1337 1383
 						// Get rid of this closing tag!
1338 1384
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1361,53 +1407,62 @@  discard block
 block discarded – undo
1361 1407
 							unset($inlineElements[$tagContentToBeClosed]);
1362 1408
 
1363 1409
 							// Was this the tag we were looking for?
1364
-							if ($tagToBeClosed === $tag)
1365
-								break;
1410
+							if ($tagToBeClosed === $tag) {
1411
+															break;
1412
+							}
1366 1413
 
1367 1414
 							// Nope, close it and look further!
1368
-							else
1369
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							else {
1416
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1417
+							}
1370 1418
 						}
1371 1419
 
1372 1420
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1373 1421
 						{
1374 1422
 							array_pop($competingElements[$tag]);
1375 1423
 
1376
-							if (count($competingElements[$tag]) > 0)
1377
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							if (count($competingElements[$tag]) > 0) {
1425
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1426
+							}
1378 1427
 						}
1379 1428
 					}
1380 1429
 
1381 1430
 					// Unexpected closing tag, ex-ter-mi-nate.
1382
-					else
1383
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					else {
1432
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1433
+					}
1384 1434
 				}
1385 1435
 			}
1386 1436
 		}
1387 1437
 
1388 1438
 		// Close the code tags.
1389
-		if ($inCode)
1390
-			$parts[$i] .= '[/code]';
1439
+		if ($inCode) {
1440
+					$parts[$i] .= '[/code]';
1441
+		}
1391 1442
 
1392 1443
 		// The same for nobbc tags.
1393
-		elseif ($inNoBbc)
1394
-			$parts[$i] .= '[/nobbc]';
1444
+		elseif ($inNoBbc) {
1445
+					$parts[$i] .= '[/nobbc]';
1446
+		}
1395 1447
 
1396 1448
 		// Still inline tags left unclosed? Close them now, better late than never.
1397
-		elseif (!empty($inlineElements))
1398
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		elseif (!empty($inlineElements)) {
1450
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1451
+		}
1399 1452
 
1400 1453
 		// Now close the block elements.
1401
-		if (!empty($blockElements))
1402
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		if (!empty($blockElements)) {
1455
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1456
+		}
1403 1457
 
1404 1458
 		$text = implode('', $parts);
1405 1459
 	}
1406 1460
 
1407 1461
 	// Final clean up of back to back tags.
1408 1462
 	$lastlen = 0;
1409
-	while (strlen($text) !== $lastlen)
1410
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	while (strlen($text) !== $lastlen) {
1464
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1465
+	}
1411 1466
 
1412 1467
 	return $text;
1413 1468
 }
@@ -1436,22 +1491,25 @@  discard block
 block discarded – undo
1436 1491
 	$context['template_layers'] = array();
1437 1492
 	// Lets make sure we aren't going to output anything nasty.
1438 1493
 	@ob_end_clean();
1439
-	if (!empty($modSettings['enableCompressedOutput']))
1440
-		@ob_start('ob_gzhandler');
1441
-	else
1442
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1443 1499
 
1444 1500
 	// If we don't have any locale better avoid broken js
1445
-	if (empty($txt['lang_locale']))
1446
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1447 1504
 
1448 1505
 	$file_data = '(function ($) {
1449 1506
 	\'use strict\';
1450 1507
 
1451 1508
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1452
-	foreach ($editortxt as $key => $val)
1453
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1454 1511
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1512
+	}
1455 1513
 
1456 1514
 	$file_data .= '
1457 1515
 		dateFormat: "day.month.year"
@@ -1519,8 +1577,9 @@  discard block
 block discarded – undo
1519 1577
 				)
1520 1578
 			);
1521 1579
 			$icon_data = array();
1522
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1523
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1524 1583
 			$smcFunc['db_free_result']($request);
1525 1584
 
1526 1585
 			$icons = array();
@@ -1535,9 +1594,9 @@  discard block
 block discarded – undo
1535 1594
 			}
1536 1595
 
1537 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1538 1599
 		}
1539
-		else
1540
-			$icons = $temp;
1541 1600
 	}
1542 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1543 1602
 
@@ -1579,8 +1638,9 @@  discard block
 block discarded – undo
1579 1638
 	{
1580 1639
 		// Some general stuff.
1581 1640
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1582
-		if (!empty($context['drafts_autosave']))
1583
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1641
+		if (!empty($context['drafts_autosave'])) {
1642
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1643
+		}
1584 1644
 
1585 1645
 		// This really has some WYSIWYG stuff.
1586 1646
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1598,8 +1658,9 @@  discard block
 block discarded – undo
1598 1658
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1599 1659
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1600 1660
 		// editor language file
1601
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1602
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1661
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1662
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1663
+		}
1603 1664
 
1604 1665
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1605 1666
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1608,11 +1669,12 @@  discard block
 block discarded – undo
1608 1669
 			loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck');
1609 1670
 
1610 1671
 			// Some hidden information is needed in order to make the spell checking work.
1611
-			if (!isset($_REQUEST['xml']))
1612
-				$context['insert_after_template'] .= '
1672
+			if (!isset($_REQUEST['xml'])) {
1673
+							$context['insert_after_template'] .= '
1613 1674
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1614 1675
 			<input type="hidden" name="spellstring" value="">
1615 1676
 		</form>';
1677
+			}
1616 1678
 		}
1617 1679
 	}
1618 1680
 
@@ -1804,10 +1866,12 @@  discard block
 block discarded – undo
1804 1866
 
1805 1867
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1806 1868
 		$disabled_tags = array();
1807
-		if (!empty($modSettings['disabledBBC']))
1808
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1809
-		if (empty($modSettings['enableEmbeddedFlash']))
1810
-			$disabled_tags[] = 'flash';
1869
+		if (!empty($modSettings['disabledBBC'])) {
1870
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1871
+		}
1872
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1873
+					$disabled_tags[] = 'flash';
1874
+		}
1811 1875
 
1812 1876
 		foreach ($disabled_tags as $tag)
1813 1877
 		{
@@ -1819,9 +1883,10 @@  discard block
 block discarded – undo
1819 1883
 				$context['disabled_tags']['orderedlist'] = true;
1820 1884
 			}
1821 1885
 
1822
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1823
-				if ($tag === $thisTag)
1886
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1887
+							if ($tag === $thisTag)
1824 1888
 					$context['disabled_tags'][$tagNameBBC] = true;
1889
+			}
1825 1890
 
1826 1891
 			$context['disabled_tags'][$tag] = true;
1827 1892
 		}
@@ -1832,8 +1897,9 @@  discard block
 block discarded – undo
1832 1897
 
1833 1898
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1834 1899
 		{
1835
-			if (!isset($context['bbc_toolbar'][$row]))
1836
-				$context['bbc_toolbar'][$row] = array();
1900
+			if (!isset($context['bbc_toolbar'][$row])) {
1901
+							$context['bbc_toolbar'][$row] = array();
1902
+			}
1837 1903
 
1838 1904
 			$tagsRow = array();
1839 1905
 
@@ -1869,20 +1935,21 @@  discard block
 block discarded – undo
1869 1935
 
1870 1936
 					$context['bbcodes_handlers'] .= '
1871 1937
 						});';
1872
-				}
1873
-				else
1938
+				} else
1874 1939
 				{
1875 1940
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1876 1941
 					$tagsRow = array();
1877 1942
 				}
1878 1943
 			}
1879 1944
 
1880
-			if (!empty($tagsRow))
1881
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1945
+			if (!empty($tagsRow)) {
1946
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1947
+			}
1882 1948
 		}
1883 1949
 
1884
-		if (!empty($bbcodes_styles))
1885
-			addInlineCss($bbcodes_styles);
1950
+		if (!empty($bbcodes_styles)) {
1951
+					addInlineCss($bbcodes_styles);
1952
+		}
1886 1953
 	}
1887 1954
 
1888 1955
 	// Initialize smiley array... if not loaded before.
@@ -1894,8 +1961,8 @@  discard block
 block discarded – undo
1894 1961
 		);
1895 1962
 
1896 1963
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1897
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1898
-			$context['smileys']['postform'][] = array(
1964
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1965
+					$context['smileys']['postform'][] = array(
1899 1966
 				'smileys' => array(
1900 1967
 					array(
1901 1968
 						'code' => ':)',
@@ -1981,7 +2048,7 @@  discard block
 block discarded – undo
1981 2048
 				),
1982 2049
 				'isLast' => true,
1983 2050
 			);
1984
-		elseif ($user_info['smiley_set'] != 'none')
2051
+		} elseif ($user_info['smiley_set'] != 'none')
1985 2052
 		{
1986 2053
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1987 2054
 			{
@@ -2004,17 +2071,19 @@  discard block
 block discarded – undo
2004 2071
 
2005 2072
 				foreach ($context['smileys'] as $section => $smileyRows)
2006 2073
 				{
2007
-					foreach ($smileyRows as $rowIndex => $smileys)
2008
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2074
+					foreach ($smileyRows as $rowIndex => $smileys) {
2075
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2076
+					}
2009 2077
 
2010
-					if (!empty($smileyRows))
2011
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2078
+					if (!empty($smileyRows)) {
2079
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2080
+					}
2012 2081
 				}
2013 2082
 
2014 2083
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2084
+			} else {
2085
+							$context['smileys'] = $temp;
2015 2086
 			}
2016
-			else
2017
-				$context['smileys'] = $temp;
2018 2087
 		}
2019 2088
 	}
2020 2089
 
@@ -2030,12 +2099,15 @@  discard block
 block discarded – undo
2030 2099
 		'plugins' => 'undo' . (empty($modSettings['disabledBBC']) || strpos($modSettings['disabledBBC'], 'youtube') === false ? ',autoyoutube' : ''),
2031 2100
 		'bbcodeTrim' => true,
2032 2101
 	);
2033
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2034
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2035
-	if (!empty($context['right_to_left']))
2036
-		$sce_options['rtl'] = true;
2037
-	if ($editorOptions['id'] != 'quickReply')
2038
-		$sce_options['autofocus'] = true;
2102
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2103
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2104
+	}
2105
+	if (!empty($context['right_to_left'])) {
2106
+			$sce_options['rtl'] = true;
2107
+	}
2108
+	if ($editorOptions['id'] != 'quickReply') {
2109
+			$sce_options['autofocus'] = true;
2110
+	}
2039 2111
 
2040 2112
 	$sce_options['emoticons'] = array();
2041 2113
 	$sce_options['emoticonsEnabled'] = false;
@@ -2051,10 +2123,11 @@  discard block
 block discarded – undo
2051 2123
 			$countLocations--;
2052 2124
 
2053 2125
 			unset($smiley_location);
2054
-			if ($location == 'postform')
2055
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2056
-			elseif ($location == 'popup')
2057
-				$smiley_location = &$sce_options['emoticons']['popup'];
2126
+			if ($location == 'postform') {
2127
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2128
+			} elseif ($location == 'popup') {
2129
+							$smiley_location = &$sce_options['emoticons']['popup'];
2130
+			}
2058 2131
 
2059 2132
 			$numRows = count($smileyRows);
2060 2133
 
@@ -2062,11 +2135,13 @@  discard block
 block discarded – undo
2062 2135
 			$emptyPlaceholder = 0;
2063 2136
 			foreach ($smileyRows as $smileyRow)
2064 2137
 			{
2065
-				foreach ($smileyRow['smileys'] as $smiley)
2066
-					$smiley_location[$smiley['code']] = $settings['smileys_url'] . '/' . $smiley['filename'];
2138
+				foreach ($smileyRow['smileys'] as $smiley) {
2139
+									$smiley_location[$smiley['code']] = $settings['smileys_url'] . '/' . $smiley['filename'];
2140
+				}
2067 2141
 
2068
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2069
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2142
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2143
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2144
+				}
2070 2145
 			}
2071 2146
 		}
2072 2147
 	}
@@ -2081,8 +2156,9 @@  discard block
 block discarded – undo
2081 2156
 
2082 2157
 			$count_tags--;
2083 2158
 
2084
-			if (!empty($count_tags))
2085
-				$sce_options['toolbar'] .= '||';
2159
+			if (!empty($count_tags)) {
2160
+							$sce_options['toolbar'] .= '||';
2161
+			}
2086 2162
 		}
2087 2163
 	}
2088 2164
 
@@ -2110,8 +2186,9 @@  discard block
 block discarded – undo
2110 2186
 		loadTemplate('GenericControls');
2111 2187
 
2112 2188
 		// Some javascript ma'am?
2113
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2114
-			loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2189
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2190
+					loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2191
+		}
2115 2192
 
2116 2193
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2117 2194
 
@@ -2124,8 +2201,8 @@  discard block
 block discarded – undo
2124 2201
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2125 2202
 
2126 2203
 	// Log this into our collection.
2127
-	if ($isNew)
2128
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2204
+	if ($isNew) {
2205
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2129 2206
 			'id' => $verificationOptions['id'],
2130 2207
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2131 2208
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2136,13 +2213,15 @@  discard block
 block discarded – undo
2136 2213
 			'questions' => array(),
2137 2214
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2138 2215
 		);
2216
+	}
2139 2217
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2140 2218
 
2141 2219
 	// Is there actually going to be anything?
2142
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2143
-		return false;
2144
-	elseif (!$isNew && !$do_test)
2145
-		return true;
2220
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2221
+			return false;
2222
+	} elseif (!$isNew && !$do_test) {
2223
+			return true;
2224
+	}
2146 2225
 
2147 2226
 	// Sanitize reCAPTCHA fields?
2148 2227
 	if ($thisVerification['can_recaptcha'])
@@ -2155,11 +2234,12 @@  discard block
 block discarded – undo
2155 2234
 	}
2156 2235
 
2157 2236
 	// Add javascript for the object.
2158
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2159
-		$context['insert_after_template'] .= '
2237
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2238
+			$context['insert_after_template'] .= '
2160 2239
 			<script>
2161 2240
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2162 2241
 			</script>';
2242
+	}
2163 2243
 
2164 2244
 	// If we want questions do we have a cache of all the IDs?
2165 2245
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2182,8 +2262,9 @@  discard block
 block discarded – undo
2182 2262
 				unset ($row['id_question']);
2183 2263
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2184 2264
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2185
-				foreach ($row['answers'] as $k => $v)
2186
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2265
+				foreach ($row['answers'] as $k => $v) {
2266
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2267
+				}
2187 2268
 
2188 2269
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2189 2270
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2194,35 +2275,42 @@  discard block
 block discarded – undo
2194 2275
 		}
2195 2276
 	}
2196 2277
 
2197
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2198
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2278
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2279
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2280
+	}
2199 2281
 
2200 2282
 	// Do we need to refresh the verification?
2201
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2202
-		$force_refresh = true;
2203
-	else
2204
-		$force_refresh = false;
2283
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2284
+			$force_refresh = true;
2285
+	} else {
2286
+			$force_refresh = false;
2287
+	}
2205 2288
 
2206 2289
 	// This can also force a fresh, although unlikely.
2207
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2208
-		$force_refresh = true;
2290
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2291
+			$force_refresh = true;
2292
+	}
2209 2293
 
2210 2294
 	$verification_errors = array();
2211 2295
 	// Start with any testing.
2212 2296
 	if ($do_test)
2213 2297
 	{
2214 2298
 		// This cannot happen!
2215
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2216
-			fatal_lang_error('no_access', false);
2299
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2300
+					fatal_lang_error('no_access', false);
2301
+		}
2217 2302
 		// ... nor this!
2218
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2219
-			fatal_lang_error('no_access', false);
2303
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2304
+					fatal_lang_error('no_access', false);
2305
+		}
2220 2306
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2221
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2222
-			fatal_lang_error('no_access', false);
2307
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2308
+					fatal_lang_error('no_access', false);
2309
+		}
2223 2310
 		// While we're here, did the user do something bad?
2224
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2225
-			$verification_errors[] = 'wrong_verification_answer';
2311
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2312
+					$verification_errors[] = 'wrong_verification_answer';
2313
+		}
2226 2314
 
2227 2315
 		if ($thisVerification['can_recaptcha'])
2228 2316
 		{
@@ -2233,22 +2321,25 @@  discard block
 block discarded – undo
2233 2321
 			{
2234 2322
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2235 2323
 
2236
-				if (!$resp->isSuccess())
2237
-					$verification_errors[] = 'wrong_verification_code';
2324
+				if (!$resp->isSuccess()) {
2325
+									$verification_errors[] = 'wrong_verification_code';
2326
+				}
2327
+			} else {
2328
+							$verification_errors[] = 'wrong_verification_code';
2238 2329
 			}
2239
-			else
2240
-				$verification_errors[] = 'wrong_verification_code';
2241 2330
 		}
2242
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2243
-			$verification_errors[] = 'wrong_verification_code';
2331
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2332
+					$verification_errors[] = 'wrong_verification_code';
2333
+		}
2244 2334
 		if ($thisVerification['number_questions'])
2245 2335
 		{
2246 2336
 			$incorrectQuestions = array();
2247 2337
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2248 2338
 			{
2249 2339
 				// We don't have this question any more, thus no answers.
2250
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2251
-					continue;
2340
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2341
+									continue;
2342
+				}
2252 2343
 				// This is quite complex. We have our question but it might have multiple answers.
2253 2344
 				// First, did they actually answer this question?
2254 2345
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2260,24 +2351,28 @@  discard block
 block discarded – undo
2260 2351
 				else
2261 2352
 				{
2262 2353
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2263
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2264
-						$incorrectQuestions[] = $q;
2354
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2355
+											$incorrectQuestions[] = $q;
2356
+					}
2265 2357
 				}
2266 2358
 			}
2267 2359
 
2268
-			if (!empty($incorrectQuestions))
2269
-				$verification_errors[] = 'wrong_verification_answer';
2360
+			if (!empty($incorrectQuestions)) {
2361
+							$verification_errors[] = 'wrong_verification_answer';
2362
+			}
2270 2363
 		}
2271 2364
 	}
2272 2365
 
2273 2366
 	// Any errors means we refresh potentially.
2274 2367
 	if (!empty($verification_errors))
2275 2368
 	{
2276
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2277
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2369
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2370
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2371
+		}
2278 2372
 		// Too many errors?
2279
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2280
-			$force_refresh = true;
2373
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2374
+					$force_refresh = true;
2375
+		}
2281 2376
 
2282 2377
 		// Keep a track of these.
2283 2378
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2310,8 +2405,9 @@  discard block
 block discarded – undo
2310 2405
 			// Are we overriding the range?
2311 2406
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2312 2407
 
2313
-			for ($i = 0; $i < 6; $i++)
2314
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2408
+			for ($i = 0; $i < 6; $i++) {
2409
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2410
+			}
2315 2411
 		}
2316 2412
 
2317 2413
 		// Getting some new questions?
@@ -2319,8 +2415,9 @@  discard block
 block discarded – undo
2319 2415
 		{
2320 2416
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2321 2417
 			$possible_langs = array();
2322
-			if (isset($_SESSION['language']))
2323
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2418
+			if (isset($_SESSION['language'])) {
2419
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2420
+			}
2324 2421
 			if (!empty($user_info['language']));
2325 2422
 			$possible_langs[] = $user_info['language'];
2326 2423
 			$possible_langs[] = $language;
@@ -2339,8 +2436,7 @@  discard block
 block discarded – undo
2339 2436
 				}
2340 2437
 			}
2341 2438
 		}
2342
-	}
2343
-	else
2439
+	} else
2344 2440
 	{
2345 2441
 		// Same questions as before.
2346 2442
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2350,8 +2446,9 @@  discard block
 block discarded – undo
2350 2446
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2351 2447
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2352 2448
 	{
2353
-		if (!isset($context['html_headers']))
2354
-			$context['html_headers'] = '';
2449
+		if (!isset($context['html_headers'])) {
2450
+					$context['html_headers'] = '';
2451
+		}
2355 2452
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2356 2453
 	}
2357 2454
 
@@ -2377,11 +2474,13 @@  discard block
 block discarded – undo
2377 2474
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2378 2475
 
2379 2476
 	// Return errors if we have them.
2380
-	if (!empty($verification_errors))
2381
-		return $verification_errors;
2477
+	if (!empty($verification_errors)) {
2478
+			return $verification_errors;
2479
+	}
2382 2480
 	// If we had a test that one, make a note.
2383
-	elseif ($do_test)
2384
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2481
+	elseif ($do_test) {
2482
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2483
+	}
2385 2484
 
2386 2485
 	// Say that everything went well chaps.
2387 2486
 	return true;
@@ -2406,8 +2505,9 @@  discard block
 block discarded – undo
2406 2505
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2407 2506
 
2408 2507
 	// If we're just checking the callback function is registered return true or false.
2409
-	if ($checkRegistered != null)
2410
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2508
+	if ($checkRegistered != null) {
2509
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2510
+	}
2411 2511
 
2412 2512
 	checkSession('get');
2413 2513
 	loadTemplate('Xml');
@@ -2558,24 +2658,27 @@  discard block
 block discarded – undo
2558 2658
 		foreach ($possible_versions as $ver)
2559 2659
 		{
2560 2660
 			$ver = trim($ver);
2561
-			if (strpos($ver, 'SMF') === 0)
2562
-				$versions[] = $ver;
2661
+			if (strpos($ver, 'SMF') === 0) {
2662
+							$versions[] = $ver;
2663
+			}
2563 2664
 		}
2564 2665
 	}
2565 2666
 	$smcFunc['db_free_result']($request);
2566 2667
 
2567 2668
 	// Just in case we don't have ANYthing.
2568
-	if (empty($versions))
2569
-		$versions = array('SMF 2.0');
2669
+	if (empty($versions)) {
2670
+			$versions = array('SMF 2.0');
2671
+	}
2570 2672
 
2571
-	foreach ($versions as $id => $version)
2572
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2673
+	foreach ($versions as $id => $version) {
2674
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2573 2675
 			$xml_data['items']['children'][] = array(
2574 2676
 				'attributes' => array(
2575 2677
 					'id' => $id,
2576 2678
 				),
2577 2679
 				'value' => $version,
2578 2680
 			);
2681
+	}
2579 2682
 
2580 2683
 	return $xml_data;
2581 2684
 }
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +901 added lines, -661 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 	// Override the language file?
467
-	if (isset($_GET['lang_file']))
468
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+	if (isset($_GET['lang_file'])) {
493
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+	}
471 497
 
472 498
 	// Make sure it exists, if it doesn't reset it.
473 499
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,12 +502,14 @@  discard block
 block discarded – undo
476 502
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+		}
481 508
 
482 509
 		// For backup we load the english at first -> second language overwrite the english one
483
-		if (count($incontext['detected_languages']) > 1)
484
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
510
+		if (count($incontext['detected_languages']) > 1) {
511
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
512
+		}
485 513
 	}
486 514
 
487 515
 	// And now include the actual language file itself.
@@ -498,8 +526,9 @@  discard block
 block discarded – undo
498 526
 	global $upgradeurl, $upcontext, $command_line;
499 527
 
500 528
 	// Command line users can't be redirected.
501
-	if ($command_line)
502
-		upgradeExit(true);
529
+	if ($command_line) {
530
+			upgradeExit(true);
531
+	}
503 532
 
504 533
 	// Are we providing the core info?
505 534
 	if ($addForm)
@@ -525,12 +554,14 @@  discard block
 block discarded – undo
525 554
 	define('SMF', 1);
526 555
 
527 556
 	// Start the session.
528
-	if (@ini_get('session.save_handler') == 'user')
529
-		@ini_set('session.save_handler', 'files');
557
+	if (@ini_get('session.save_handler') == 'user') {
558
+			@ini_set('session.save_handler', 'files');
559
+	}
530 560
 	@session_start();
531 561
 
532
-	if (empty($smcFunc))
533
-		$smcFunc = array();
562
+	if (empty($smcFunc)) {
563
+			$smcFunc = array();
564
+	}
534 565
 
535 566
 	// We need this for authentication and some upgrade code
536 567
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -557,24 +588,27 @@  discard block
 block discarded – undo
557 588
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
558 589
 
559 590
 		// Make the connection...
560
-		if (empty($db_connection))
561
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
562
-		else
563
-			// If we've returned here, ping/reconnect to be safe
591
+		if (empty($db_connection)) {
592
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
593
+		} else {
594
+					// If we've returned here, ping/reconnect to be safe
564 595
 			$smcFunc['db_ping']($db_connection);
596
+		}
565 597
 
566 598
 		// Oh dear god!!
567
-		if ($db_connection === null)
568
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
599
+		if ($db_connection === null) {
600
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
601
+		}
569 602
 
570
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
571
-			$smcFunc['db_query']('', '
603
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
604
+					$smcFunc['db_query']('', '
572 605
 			SET NAMES {string:db_character_set}',
573 606
 			array(
574 607
 				'db_error_skip' => true,
575 608
 				'db_character_set' => $db_character_set,
576 609
 			)
577 610
 		);
611
+		}
578 612
 
579 613
 		// Load the modSettings data...
580 614
 		$request = $smcFunc['db_query']('', '
@@ -585,11 +619,11 @@  discard block
 block discarded – undo
585 619
 			)
586 620
 		);
587 621
 		$modSettings = array();
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$modSettings[$row['variable']] = $row['value'];
622
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+					$modSettings[$row['variable']] = $row['value'];
624
+		}
590 625
 		$smcFunc['db_free_result']($request);
591
-	}
592
-	else
626
+	} else
593 627
 	{
594 628
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
595 629
 	}
@@ -603,9 +637,10 @@  discard block
 block discarded – undo
603 637
 		cleanRequest();
604 638
 	}
605 639
 
606
-	if (!isset($_GET['substep']))
607
-		$_GET['substep'] = 0;
608
-}
640
+	if (!isset($_GET['substep'])) {
641
+			$_GET['substep'] = 0;
642
+	}
643
+	}
609 644
 
610 645
 function initialize_inputs()
611 646
 {
@@ -635,8 +670,9 @@  discard block
 block discarded – undo
635 670
 		$dh = opendir(dirname(__FILE__));
636 671
 		while ($file = readdir($dh))
637 672
 		{
638
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
639
-				@unlink(dirname(__FILE__) . '/' . $file);
673
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
674
+							@unlink(dirname(__FILE__) . '/' . $file);
675
+			}
640 676
 		}
641 677
 		closedir($dh);
642 678
 
@@ -665,8 +701,9 @@  discard block
 block discarded – undo
665 701
 	$temp = 'upgrade_php?step';
666 702
 	while (strlen($temp) > 4)
667 703
 	{
668
-		if (isset($_GET[$temp]))
669
-			unset($_GET[$temp]);
704
+		if (isset($_GET[$temp])) {
705
+					unset($_GET[$temp]);
706
+		}
670 707
 		$temp = substr($temp, 1);
671 708
 	}
672 709
 
@@ -693,32 +730,39 @@  discard block
 block discarded – undo
693 730
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
694 731
 
695 732
 	// Need legacy scripts?
696
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
697
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
698
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
699
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
700
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
701
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
733
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
734
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
735
+	}
736
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
737
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
738
+	}
739
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
740
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
741
+	}
702 742
 
703 743
 	// We don't need "-utf8" files anymore...
704 744
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
705 745
 
706 746
 	// This needs to exist!
707
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
708
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
709
-	else
710
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
747
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
748
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
749
+	} else {
750
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
751
+	}
711 752
 
712
-	if (!$check)
713
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
753
+	if (!$check) {
754
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
714 755
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
756
+	}
715 757
 
716 758
 	// Do they meet the install requirements?
717
-	if (!php_version_check())
718
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
759
+	if (!php_version_check()) {
760
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
761
+	}
719 762
 
720
-	if (!db_version_check())
721
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
763
+	if (!db_version_check()) {
764
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
765
+	}
722 766
 
723 767
 	// Do some checks to make sure they have proper privileges
724 768
 	db_extend('packages');
@@ -733,14 +777,16 @@  discard block
 block discarded – undo
733 777
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
734 778
 
735 779
 	// Sorry... we need CREATE, ALTER and DROP
736
-	if (!$create || !$alter || !$drop)
737
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
780
+	if (!$create || !$alter || !$drop) {
781
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
782
+	}
738 783
 
739 784
 	// Do a quick version spot check.
740 785
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
741 786
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
742
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
743
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
787
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
788
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
789
+	}
744 790
 
745 791
 	// What absolutely needs to be writable?
746 792
 	$writable_files = array(
@@ -749,12 +795,13 @@  discard block
 block discarded – undo
749 795
 	);
750 796
 
751 797
 	// Only check for minified writable files if we have it enabled or not set.
752
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
753
-		$writable_files += array(
798
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
799
+			$writable_files += array(
754 800
 			$modSettings['theme_dir'] . '/css/minified.css',
755 801
 			$modSettings['theme_dir'] . '/scripts/minified.js',
756 802
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
757 803
 		);
804
+	}
758 805
 
759 806
 	// Do we need to add this setting?
760 807
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -766,12 +813,13 @@  discard block
 block discarded – undo
766 813
 	quickFileWritable($custom_av_dir);
767 814
 
768 815
 	// Are we good now?
769
-	if (!is_writable($custom_av_dir))
770
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
771
-	elseif ($need_settings_update)
816
+	if (!is_writable($custom_av_dir)) {
817
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
818
+	} elseif ($need_settings_update)
772 819
 	{
773
-		if (!function_exists('cache_put_data'))
774
-			require_once($sourcedir . '/Load.php');
820
+		if (!function_exists('cache_put_data')) {
821
+					require_once($sourcedir . '/Load.php');
822
+		}
775 823
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
776 824
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
777 825
 	}
@@ -780,28 +828,33 @@  discard block
 block discarded – undo
780 828
 
781 829
 	// Check the cache directory.
782 830
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
783
-	if (!file_exists($cachedir_temp))
784
-		@mkdir($cachedir_temp);
785
-	if (!file_exists($cachedir_temp))
786
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
787
-
788
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
789
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
790
-	elseif (!isset($_GET['skiplang']))
831
+	if (!file_exists($cachedir_temp)) {
832
+			@mkdir($cachedir_temp);
833
+	}
834
+	if (!file_exists($cachedir_temp)) {
835
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
836
+	}
837
+
838
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
839
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
840
+	} elseif (!isset($_GET['skiplang']))
791 841
 	{
792 842
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
793 843
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
794 844
 
795
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
796
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
845
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
846
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
847
+		}
797 848
 	}
798 849
 
799
-	if (!makeFilesWritable($writable_files))
800
-		return false;
850
+	if (!makeFilesWritable($writable_files)) {
851
+			return false;
852
+	}
801 853
 
802 854
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
803
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
804
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
855
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
856
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
857
+	}
805 858
 
806 859
 	// Upgrade the agreement.
807 860
 	elseif (isset($modSettings['agreement']))
@@ -812,8 +865,8 @@  discard block
 block discarded – undo
812 865
 	}
813 866
 
814 867
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
815
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
816
-		$upcontext['warning'] = '
868
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
869
+			$upcontext['warning'] = '
817 870
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
818 871
 			<ul>
819 872
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -821,19 +874,23 @@  discard block
 block discarded – undo
821 874
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
822 875
 			</ul>
823 876
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
877
+	}
824 878
 
825 879
 	// Confirm mbstring is loaded...
826
-	if (!extension_loaded('mbstring'))
827
-		return throw_error($txt['install_no_mbstring']);
880
+	if (!extension_loaded('mbstring')) {
881
+			return throw_error($txt['install_no_mbstring']);
882
+	}
828 883
 
829 884
 	// Check for https stream support.
830 885
 	$supported_streams = stream_get_wrappers();
831
-	if (!in_array('https', $supported_streams))
832
-		$upcontext['custom_warning'] = $txt['install_no_https'];
886
+	if (!in_array('https', $supported_streams)) {
887
+			$upcontext['custom_warning'] = $txt['install_no_https'];
888
+	}
833 889
 
834 890
 	// Either we're logged in or we're going to present the login.
835
-	if (checkLogin())
836
-		return true;
891
+	if (checkLogin()) {
892
+			return true;
893
+	}
837 894
 
838 895
 	$upcontext += createToken('login');
839 896
 
@@ -847,15 +904,17 @@  discard block
 block discarded – undo
847 904
 	global $smcFunc, $db_type, $support_js;
848 905
 
849 906
 	// Don't bother if the security is disabled.
850
-	if ($disable_security)
851
-		return true;
907
+	if ($disable_security) {
908
+			return true;
909
+	}
852 910
 
853 911
 	// Are we trying to login?
854 912
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
855 913
 	{
856 914
 		// If we've disabled security pick a suitable name!
857
-		if (empty($_POST['user']))
858
-			$_POST['user'] = 'Administrator';
915
+		if (empty($_POST['user'])) {
916
+					$_POST['user'] = 'Administrator';
917
+		}
859 918
 
860 919
 		// Before 2.0 these column names were different!
861 920
 		$oldDB = false;
@@ -870,16 +929,17 @@  discard block
 block discarded – undo
870 929
 					'db_error_skip' => true,
871 930
 				)
872 931
 			);
873
-			if ($smcFunc['db_num_rows']($request) != 0)
874
-				$oldDB = true;
932
+			if ($smcFunc['db_num_rows']($request) != 0) {
933
+							$oldDB = true;
934
+			}
875 935
 			$smcFunc['db_free_result']($request);
876 936
 		}
877 937
 
878 938
 		// Get what we believe to be their details.
879 939
 		if (!$disable_security)
880 940
 		{
881
-			if ($oldDB)
882
-				$request = $smcFunc['db_query']('', '
941
+			if ($oldDB) {
942
+							$request = $smcFunc['db_query']('', '
883 943
 					SELECT id_member, memberName AS member_name, passwd, id_group,
884 944
 					additionalGroups AS additional_groups, lngfile
885 945
 					FROM {db_prefix}members
@@ -889,8 +949,8 @@  discard block
 block discarded – undo
889 949
 						'db_error_skip' => true,
890 950
 					)
891 951
 				);
892
-			else
893
-				$request = $smcFunc['db_query']('', '
952
+			} else {
953
+							$request = $smcFunc['db_query']('', '
894 954
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
895 955
 					FROM {db_prefix}members
896 956
 					WHERE member_name = {string:member_name}',
@@ -899,6 +959,7 @@  discard block
 block discarded – undo
899 959
 						'db_error_skip' => true,
900 960
 					)
901 961
 				);
962
+			}
902 963
 			if ($smcFunc['db_num_rows']($request) != 0)
903 964
 			{
904 965
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -906,16 +967,17 @@  discard block
 block discarded – undo
906 967
 				$groups = explode(',', $addGroups);
907 968
 				$groups[] = $id_group;
908 969
 
909
-				foreach ($groups as $k => $v)
910
-					$groups[$k] = (int) $v;
970
+				foreach ($groups as $k => $v) {
971
+									$groups[$k] = (int) $v;
972
+				}
911 973
 
912 974
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
913 975
 
914 976
 				// We don't use "-utf8" anymore...
915 977
 				$user_language = str_ireplace('-utf8', '', $user_language);
978
+			} else {
979
+							$upcontext['username_incorrect'] = true;
916 980
 			}
917
-			else
918
-				$upcontext['username_incorrect'] = true;
919 981
 			$smcFunc['db_free_result']($request);
920 982
 		}
921 983
 		$upcontext['username'] = $_POST['user'];
@@ -925,13 +987,14 @@  discard block
 block discarded – undo
925 987
 		{
926 988
 			$upcontext['upgrade_status']['js'] = 1;
927 989
 			$support_js = 1;
990
+		} else {
991
+					$support_js = 0;
928 992
 		}
929
-		else
930
-			$support_js = 0;
931 993
 
932 994
 		// Note down the version we are coming from.
933
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
934
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
995
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
996
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
997
+		}
935 998
 
936 999
 		// Didn't get anywhere?
937 1000
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -965,15 +1028,15 @@  discard block
 block discarded – undo
965 1028
 							'db_error_skip' => true,
966 1029
 						)
967 1030
 					);
968
-					if ($smcFunc['db_num_rows']($request) == 0)
969
-						return throw_error('You need to be an admin to perform an upgrade!');
1031
+					if ($smcFunc['db_num_rows']($request) == 0) {
1032
+											return throw_error('You need to be an admin to perform an upgrade!');
1033
+					}
970 1034
 					$smcFunc['db_free_result']($request);
971 1035
 				}
972 1036
 
973 1037
 				$upcontext['user']['id'] = $id_member;
974 1038
 				$upcontext['user']['name'] = $name;
975
-			}
976
-			else
1039
+			} else
977 1040
 			{
978 1041
 				$upcontext['user']['id'] = 1;
979 1042
 				$upcontext['user']['name'] = 'Administrator';
@@ -989,11 +1052,11 @@  discard block
 block discarded – undo
989 1052
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
990 1053
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
991 1054
 
992
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
993
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
994
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
995
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
996
-				else
1055
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1056
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1057
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1058
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1059
+				} else
997 1060
 				{
998 1061
 					// Set this as the new language.
999 1062
 					$upcontext['language'] = $user_language;
@@ -1037,8 +1100,9 @@  discard block
 block discarded – undo
1037 1100
 	unset($member_columns);
1038 1101
 
1039 1102
 	// If we've not submitted then we're done.
1040
-	if (empty($_POST['upcont']))
1041
-		return false;
1103
+	if (empty($_POST['upcont'])) {
1104
+			return false;
1105
+	}
1042 1106
 
1043 1107
 	// Firstly, if they're enabling SM stat collection just do it.
1044 1108
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1058,16 +1122,17 @@  discard block
 block discarded – undo
1058 1122
 				fwrite($fp, $out);
1059 1123
 
1060 1124
 				$return_data = '';
1061
-				while (!feof($fp))
1062
-					$return_data .= fgets($fp, 128);
1125
+				while (!feof($fp)) {
1126
+									$return_data .= fgets($fp, 128);
1127
+				}
1063 1128
 
1064 1129
 				fclose($fp);
1065 1130
 
1066 1131
 				// Get the unique site ID.
1067 1132
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1068 1133
 
1069
-				if (!empty($ID[1]))
1070
-					$smcFunc['db_insert']('replace',
1134
+				if (!empty($ID[1])) {
1135
+									$smcFunc['db_insert']('replace',
1071 1136
 						$db_prefix . 'settings',
1072 1137
 						array('variable' => 'string', 'value' => 'string'),
1073 1138
 						array(
@@ -1076,9 +1141,9 @@  discard block
 block discarded – undo
1076 1141
 						),
1077 1142
 						array('variable')
1078 1143
 					);
1144
+				}
1079 1145
 			}
1080
-		}
1081
-		else
1146
+		} else
1082 1147
 		{
1083 1148
 			$smcFunc['db_insert']('replace',
1084 1149
 				$db_prefix . 'settings',
@@ -1089,8 +1154,8 @@  discard block
 block discarded – undo
1089 1154
 		}
1090 1155
 	}
1091 1156
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1092
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1093
-		$smcFunc['db_query']('', '
1157
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1158
+			$smcFunc['db_query']('', '
1094 1159
 			DELETE FROM {db_prefix}settings
1095 1160
 			WHERE variable = {string:enable_sm_stats}',
1096 1161
 			array(
@@ -1098,6 +1163,7 @@  discard block
 block discarded – undo
1098 1163
 				'db_error_skip' => true,
1099 1164
 			)
1100 1165
 		);
1166
+	}
1101 1167
 
1102 1168
 	// Deleting old karma stuff?
1103 1169
 	if (!empty($_POST['delete_karma']))
@@ -1112,20 +1178,22 @@  discard block
 block discarded – undo
1112 1178
 		);
1113 1179
 
1114 1180
 		// Cleaning up old karma member settings.
1115
-		if ($upcontext['karma_installed']['good'])
1116
-			$smcFunc['db_query']('', '
1181
+		if ($upcontext['karma_installed']['good']) {
1182
+					$smcFunc['db_query']('', '
1117 1183
 				ALTER TABLE {db_prefix}members
1118 1184
 				DROP karma_good',
1119 1185
 				array()
1120 1186
 			);
1187
+		}
1121 1188
 
1122 1189
 		// Does karma bad was enable?
1123
-		if ($upcontext['karma_installed']['bad'])
1124
-			$smcFunc['db_query']('', '
1190
+		if ($upcontext['karma_installed']['bad']) {
1191
+					$smcFunc['db_query']('', '
1125 1192
 				ALTER TABLE {db_prefix}members
1126 1193
 				DROP karma_bad',
1127 1194
 				array()
1128 1195
 			);
1196
+		}
1129 1197
 
1130 1198
 		// Cleaning up old karma permissions.
1131 1199
 		$smcFunc['db_query']('', '
@@ -1143,32 +1211,37 @@  discard block
 block discarded – undo
1143 1211
 	}
1144 1212
 
1145 1213
 	// Emptying the error log?
1146
-	if (!empty($_POST['empty_error']))
1147
-		$smcFunc['db_query']('truncate_table', '
1214
+	if (!empty($_POST['empty_error'])) {
1215
+			$smcFunc['db_query']('truncate_table', '
1148 1216
 			TRUNCATE {db_prefix}log_errors',
1149 1217
 			array(
1150 1218
 			)
1151 1219
 		);
1220
+	}
1152 1221
 
1153 1222
 	$changes = array();
1154 1223
 
1155 1224
 	// Add proxy settings.
1156
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1157
-		$changes += array(
1225
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1226
+			$changes += array(
1158 1227
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1159 1228
 			'image_proxy_maxsize' => 5190,
1160 1229
 			'image_proxy_enabled' => 0,
1161 1230
 		);
1231
+	}
1162 1232
 
1163 1233
 	// If $boardurl reflects https, set force_ssl
1164
-	if (!function_exists('cache_put_data'))
1165
-		require_once($sourcedir . '/Load.php');
1166
-	if (stripos($boardurl, 'https://') !== false)
1167
-		updateSettings(array('force_ssl' => '1'));
1234
+	if (!function_exists('cache_put_data')) {
1235
+			require_once($sourcedir . '/Load.php');
1236
+	}
1237
+	if (stripos($boardurl, 'https://') !== false) {
1238
+			updateSettings(array('force_ssl' => '1'));
1239
+	}
1168 1240
 
1169 1241
 	// If we're overriding the language follow it through.
1170
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1171
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1242
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1243
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1244
+	}
1172 1245
 
1173 1246
 	if (!empty($_POST['maint']))
1174 1247
 	{
@@ -1180,26 +1253,29 @@  discard block
 block discarded – undo
1180 1253
 		{
1181 1254
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1182 1255
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1183
-		}
1184
-		else
1256
+		} else
1185 1257
 		{
1186 1258
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1187 1259
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1188 1260
 		}
1189 1261
 	}
1190 1262
 
1191
-	if ($command_line)
1192
-		echo ' * Updating Settings.php...';
1263
+	if ($command_line) {
1264
+			echo ' * Updating Settings.php...';
1265
+	}
1193 1266
 
1194 1267
 	// Fix some old paths.
1195
-	if (substr($boarddir, 0, 1) == '.')
1196
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1268
+	if (substr($boarddir, 0, 1) == '.') {
1269
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1270
+	}
1197 1271
 
1198
-	if (substr($sourcedir, 0, 1) == '.')
1199
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1272
+	if (substr($sourcedir, 0, 1) == '.') {
1273
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1274
+	}
1200 1275
 
1201
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1202
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1276
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1277
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1278
+	}
1203 1279
 
1204 1280
 	// If they have a "host:port" setup for the host, split that into separate values
1205 1281
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1210,32 +1286,36 @@  discard block
 block discarded – undo
1210 1286
 		$changes['db_server'] = '\'' . $db_server . '\'';
1211 1287
 
1212 1288
 		// Only set this if we're not using the default port
1213
-		if ($db_port != ini_get('mysqli.default_port'))
1214
-			$changes['db_port'] = (int) $db_port;
1215
-	}
1216
-	elseif (!empty($db_port))
1289
+		if ($db_port != ini_get('mysqli.default_port')) {
1290
+					$changes['db_port'] = (int) $db_port;
1291
+		}
1292
+	} elseif (!empty($db_port))
1217 1293
 	{
1218 1294
 		// If db_port is set and is the same as the default, set it to ''
1219 1295
 		if ($db_type == 'mysql')
1220 1296
 		{
1221
-			if ($db_port == ini_get('mysqli.default_port'))
1222
-				$changes['db_port'] = '\'\'';
1223
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1224
-				$changes['db_port'] = '\'\'';
1297
+			if ($db_port == ini_get('mysqli.default_port')) {
1298
+							$changes['db_port'] = '\'\'';
1299
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1300
+							$changes['db_port'] = '\'\'';
1301
+			}
1225 1302
 		}
1226 1303
 	}
1227 1304
 
1228 1305
 	// Maybe we haven't had this option yet?
1229
-	if (empty($packagesdir))
1230
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1306
+	if (empty($packagesdir)) {
1307
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1308
+	}
1231 1309
 
1232 1310
 	// Add support for $tasksdir var.
1233
-	if (empty($tasksdir))
1234
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1311
+	if (empty($tasksdir)) {
1312
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1313
+	}
1235 1314
 
1236 1315
 	// Make sure we fix the language as well.
1237
-	if (stristr($language, '-utf8'))
1238
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1316
+	if (stristr($language, '-utf8')) {
1317
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1318
+	}
1239 1319
 
1240 1320
 	// @todo Maybe change the cookie name if going to 1.1, too?
1241 1321
 
@@ -1246,8 +1326,9 @@  discard block
 block discarded – undo
1246 1326
 	// Tell Settings.php to store db_last_error.php in the cache
1247 1327
 	move_db_last_error_to_cachedir();
1248 1328
 
1249
-	if ($command_line)
1250
-		echo ' Successful.' . "\n";
1329
+	if ($command_line) {
1330
+			echo ' Successful.' . "\n";
1331
+	}
1251 1332
 
1252 1333
 	// Are we doing debug?
1253 1334
 	if (isset($_POST['debug']))
@@ -1257,8 +1338,9 @@  discard block
 block discarded – undo
1257 1338
 	}
1258 1339
 
1259 1340
 	// If we're not backing up then jump one.
1260
-	if (empty($_POST['backup']))
1261
-		$upcontext['current_step']++;
1341
+	if (empty($_POST['backup'])) {
1342
+			$upcontext['current_step']++;
1343
+	}
1262 1344
 
1263 1345
 	// If we've got here then let's proceed to the next step!
1264 1346
 	return true;
@@ -1273,8 +1355,9 @@  discard block
 block discarded – undo
1273 1355
 	$upcontext['page_title'] = $txt['backup_database'];
1274 1356
 
1275 1357
 	// Done it already - js wise?
1276
-	if (!empty($_POST['backup_done']))
1277
-		return true;
1358
+	if (!empty($_POST['backup_done'])) {
1359
+			return true;
1360
+	}
1278 1361
 
1279 1362
 	// Some useful stuff here.
1280 1363
 	db_extend();
@@ -1288,9 +1371,10 @@  discard block
 block discarded – undo
1288 1371
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1289 1372
 
1290 1373
 	$table_names = array();
1291
-	foreach ($tables as $table)
1292
-		if (substr($table, 0, 7) !== 'backup_')
1374
+	foreach ($tables as $table) {
1375
+			if (substr($table, 0, 7) !== 'backup_')
1293 1376
 			$table_names[] = $table;
1377
+	}
1294 1378
 
1295 1379
 	$upcontext['table_count'] = count($table_names);
1296 1380
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1300,12 +1384,14 @@  discard block
 block discarded – undo
1300 1384
 	$file_steps = $upcontext['table_count'];
1301 1385
 
1302 1386
 	// What ones have we already done?
1303
-	foreach ($table_names as $id => $table)
1304
-		if ($id < $_GET['substep'])
1387
+	foreach ($table_names as $id => $table) {
1388
+			if ($id < $_GET['substep'])
1305 1389
 			$upcontext['previous_tables'][] = $table;
1390
+	}
1306 1391
 
1307
-	if ($command_line)
1308
-		echo 'Backing Up Tables.';
1392
+	if ($command_line) {
1393
+			echo 'Backing Up Tables.';
1394
+	}
1309 1395
 
1310 1396
 	// If we don't support javascript we backup here.
1311 1397
 	if (!$support_js || isset($_GET['xml']))
@@ -1324,8 +1410,9 @@  discard block
 block discarded – undo
1324 1410
 			backupTable($table_names[$substep]);
1325 1411
 
1326 1412
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1327
-			if (isset($_GET['xml']))
1328
-				return upgradeExit();
1413
+			if (isset($_GET['xml'])) {
1414
+							return upgradeExit();
1415
+			}
1329 1416
 		}
1330 1417
 
1331 1418
 		if ($command_line)
@@ -1358,9 +1445,10 @@  discard block
 block discarded – undo
1358 1445
 
1359 1446
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1360 1447
 
1361
-	if ($command_line)
1362
-		echo ' done.';
1363
-}
1448
+	if ($command_line) {
1449
+			echo ' done.';
1450
+	}
1451
+	}
1364 1452
 
1365 1453
 // Step 2: Everything.
1366 1454
 function DatabaseChanges()
@@ -1369,8 +1457,9 @@  discard block
 block discarded – undo
1369 1457
 	global $upcontext, $support_js, $db_type;
1370 1458
 
1371 1459
 	// Have we just completed this?
1372
-	if (!empty($_POST['database_done']))
1373
-		return true;
1460
+	if (!empty($_POST['database_done'])) {
1461
+			return true;
1462
+	}
1374 1463
 
1375 1464
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1376 1465
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1385,15 +1474,16 @@  discard block
 block discarded – undo
1385 1474
 	);
1386 1475
 
1387 1476
 	// How many files are there in total?
1388
-	if (isset($_GET['filecount']))
1389
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1390
-	else
1477
+	if (isset($_GET['filecount'])) {
1478
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1479
+	} else
1391 1480
 	{
1392 1481
 		$upcontext['file_count'] = 0;
1393 1482
 		foreach ($files as $file)
1394 1483
 		{
1395
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1396
-				$upcontext['file_count']++;
1484
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1485
+							$upcontext['file_count']++;
1486
+			}
1397 1487
 		}
1398 1488
 	}
1399 1489
 
@@ -1403,9 +1493,9 @@  discard block
 block discarded – undo
1403 1493
 	$upcontext['cur_file_num'] = 0;
1404 1494
 	foreach ($files as $file)
1405 1495
 	{
1406
-		if ($did_not_do)
1407
-			$did_not_do--;
1408
-		else
1496
+		if ($did_not_do) {
1497
+					$did_not_do--;
1498
+		} else
1409 1499
 		{
1410 1500
 			$upcontext['cur_file_num']++;
1411 1501
 			$upcontext['cur_file_name'] = $file[0];
@@ -1432,12 +1522,13 @@  discard block
 block discarded – undo
1432 1522
 					// Flag to move on to the next.
1433 1523
 					$upcontext['completed_step'] = true;
1434 1524
 					// Did we complete the whole file?
1435
-					if ($nextFile)
1436
-						$upcontext['current_debug_item_num'] = -1;
1525
+					if ($nextFile) {
1526
+											$upcontext['current_debug_item_num'] = -1;
1527
+					}
1437 1528
 					return upgradeExit();
1529
+				} elseif ($support_js) {
1530
+									break;
1438 1531
 				}
1439
-				elseif ($support_js)
1440
-					break;
1441 1532
 			}
1442 1533
 			// Set the progress bar to be right as if we had - even if we hadn't...
1443 1534
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1463,8 +1554,9 @@  discard block
 block discarded – undo
1463 1554
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1464 1555
 
1465 1556
 	// Now it's nice to have some of the basic SMF source files.
1466
-	if (!isset($_GET['ssi']) && !$command_line)
1467
-		redirectLocation('&ssi=1');
1557
+	if (!isset($_GET['ssi']) && !$command_line) {
1558
+			redirectLocation('&ssi=1');
1559
+	}
1468 1560
 
1469 1561
 	$upcontext['sub_template'] = 'upgrade_complete';
1470 1562
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1480,14 +1572,16 @@  discard block
 block discarded – undo
1480 1572
 	// Are we in maintenance mode?
1481 1573
 	if (isset($upcontext['user']['main']))
1482 1574
 	{
1483
-		if ($command_line)
1484
-			echo ' * ';
1575
+		if ($command_line) {
1576
+					echo ' * ';
1577
+		}
1485 1578
 		$upcontext['removed_maintenance'] = true;
1486 1579
 		$changes['maintenance'] = $upcontext['user']['main'];
1487 1580
 	}
1488 1581
 	// Otherwise if somehow we are in 2 let's go to 1.
1489
-	elseif (!empty($maintenance) && $maintenance == 2)
1490
-		$changes['maintenance'] = 1;
1582
+	elseif (!empty($maintenance) && $maintenance == 2) {
1583
+			$changes['maintenance'] = 1;
1584
+	}
1491 1585
 
1492 1586
 	// Wipe this out...
1493 1587
 	$upcontext['user'] = array();
@@ -1502,9 +1596,9 @@  discard block
 block discarded – undo
1502 1596
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1503 1597
 
1504 1598
 	// Now is the perfect time to fetch the SM files.
1505
-	if ($command_line)
1506
-		cli_scheduled_fetchSMfiles();
1507
-	else
1599
+	if ($command_line) {
1600
+			cli_scheduled_fetchSMfiles();
1601
+	} else
1508 1602
 	{
1509 1603
 		require_once($sourcedir . '/ScheduledTasks.php');
1510 1604
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1512,8 +1606,9 @@  discard block
 block discarded – undo
1512 1606
 	}
1513 1607
 
1514 1608
 	// Log what we've done.
1515
-	if (empty($user_info['id']))
1516
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1609
+	if (empty($user_info['id'])) {
1610
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1611
+	}
1517 1612
 
1518 1613
 	// Log the action manually, so CLI still works.
1519 1614
 	$smcFunc['db_insert']('',
@@ -1532,8 +1627,9 @@  discard block
 block discarded – undo
1532 1627
 
1533 1628
 	// Save the current database version.
1534 1629
 	$server_version = $smcFunc['db_server_info']();
1535
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1536
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1630
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1631
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1632
+	}
1537 1633
 
1538 1634
 	if ($command_line)
1539 1635
 	{
@@ -1545,8 +1641,9 @@  discard block
 block discarded – undo
1545 1641
 
1546 1642
 	// Make sure it says we're done.
1547 1643
 	$upcontext['overall_percent'] = 100;
1548
-	if (isset($upcontext['step_progress']))
1549
-		unset($upcontext['step_progress']);
1644
+	if (isset($upcontext['step_progress'])) {
1645
+			unset($upcontext['step_progress']);
1646
+	}
1550 1647
 
1551 1648
 	$_GET['substep'] = 0;
1552 1649
 	return false;
@@ -1557,8 +1654,9 @@  discard block
 block discarded – undo
1557 1654
 {
1558 1655
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1559 1656
 
1560
-	if (empty($modSettings['time_format']))
1561
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1657
+	if (empty($modSettings['time_format'])) {
1658
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1659
+	}
1562 1660
 
1563 1661
 	// What files do we want to get
1564 1662
 	$request = $smcFunc['db_query']('', '
@@ -1592,8 +1690,9 @@  discard block
 block discarded – undo
1592 1690
 		$file_data = fetch_web_data($url);
1593 1691
 
1594 1692
 		// If we got an error - give up - the site might be down.
1595
-		if ($file_data === false)
1596
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1693
+		if ($file_data === false) {
1694
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1695
+		}
1597 1696
 
1598 1697
 		// Save the file to the database.
1599 1698
 		$smcFunc['db_query']('substring', '
@@ -1635,8 +1734,9 @@  discard block
 block discarded – undo
1635 1734
 	$themeData = array();
1636 1735
 	foreach ($values as $variable => $value)
1637 1736
 	{
1638
-		if (!isset($value) || $value === null)
1639
-			$value = 0;
1737
+		if (!isset($value) || $value === null) {
1738
+					$value = 0;
1739
+		}
1640 1740
 
1641 1741
 		$themeData[] = array(0, 1, $variable, $value);
1642 1742
 	}
@@ -1665,8 +1765,9 @@  discard block
 block discarded – undo
1665 1765
 
1666 1766
 	foreach ($values as $variable => $value)
1667 1767
 	{
1668
-		if (empty($modSettings[$value[0]]))
1669
-			continue;
1768
+		if (empty($modSettings[$value[0]])) {
1769
+					continue;
1770
+		}
1670 1771
 
1671 1772
 		$smcFunc['db_query']('', '
1672 1773
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1752,19 +1853,21 @@  discard block
 block discarded – undo
1752 1853
 	set_error_handler(
1753 1854
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1754 1855
 		{
1755
-			if ($support_js)
1756
-				return true;
1757
-			else
1758
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1856
+			if ($support_js) {
1857
+							return true;
1858
+			} else {
1859
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1860
+			}
1759 1861
 		}
1760 1862
 	);
1761 1863
 
1762 1864
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1763 1865
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1764
-	if ($db_type == 'mysql')
1765
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1766
-	else
1767
-		$db_collation = '';
1866
+	if ($db_type == 'mysql') {
1867
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1868
+	} else {
1869
+			$db_collation = '';
1870
+	}
1768 1871
 
1769 1872
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1770 1873
 
@@ -1776,8 +1879,9 @@  discard block
 block discarded – undo
1776 1879
 	$last_step = '';
1777 1880
 
1778 1881
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1779
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1780
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1882
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1883
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1884
+	}
1781 1885
 
1782 1886
 	// Count the total number of steps within this file - for progress.
1783 1887
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1797,15 +1901,18 @@  discard block
 block discarded – undo
1797 1901
 		$do_current = $substep >= $_GET['substep'];
1798 1902
 
1799 1903
 		// Get rid of any comments in the beginning of the line...
1800
-		if (substr(trim($line), 0, 2) === '/*')
1801
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1904
+		if (substr(trim($line), 0, 2) === '/*') {
1905
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1906
+		}
1802 1907
 
1803 1908
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1804
-		if ($is_debug && !$support_js && $command_line)
1805
-			flush();
1909
+		if ($is_debug && !$support_js && $command_line) {
1910
+					flush();
1911
+		}
1806 1912
 
1807
-		if (trim($line) === '')
1808
-			continue;
1913
+		if (trim($line) === '') {
1914
+					continue;
1915
+		}
1809 1916
 
1810 1917
 		if (trim(substr($line, 0, 3)) === '---')
1811 1918
 		{
@@ -1815,8 +1922,9 @@  discard block
 block discarded – undo
1815 1922
 			if (trim($current_data) != '' && $type !== '}')
1816 1923
 			{
1817 1924
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1818
-				if ($command_line)
1819
-					echo $upcontext['error_message'];
1925
+				if ($command_line) {
1926
+									echo $upcontext['error_message'];
1927
+				}
1820 1928
 			}
1821 1929
 
1822 1930
 			if ($type == ' ')
@@ -1834,17 +1942,18 @@  discard block
 block discarded – undo
1834 1942
 				if ($do_current)
1835 1943
 				{
1836 1944
 					$upcontext['actioned_items'][] = $last_step;
1837
-					if ($command_line)
1838
-						echo ' * ';
1945
+					if ($command_line) {
1946
+											echo ' * ';
1947
+					}
1839 1948
 				}
1840
-			}
1841
-			elseif ($type == '#')
1949
+			} elseif ($type == '#')
1842 1950
 			{
1843 1951
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1844 1952
 
1845 1953
 				$upcontext['current_debug_item_num']++;
1846
-				if (trim($line) != '---#')
1847
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1954
+				if (trim($line) != '---#') {
1955
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1956
+				}
1848 1957
 
1849 1958
 				// Have we already done something?
1850 1959
 				if (isset($_GET['xml']) && $done_something)
@@ -1855,34 +1964,36 @@  discard block
 block discarded – undo
1855 1964
 
1856 1965
 				if ($do_current)
1857 1966
 				{
1858
-					if (trim($line) == '---#' && $command_line)
1859
-						echo ' done.', $endl;
1860
-					elseif ($command_line)
1861
-						echo ' +++ ', rtrim(substr($line, 4));
1862
-					elseif (trim($line) != '---#')
1967
+					if (trim($line) == '---#' && $command_line) {
1968
+											echo ' done.', $endl;
1969
+					} elseif ($command_line) {
1970
+											echo ' +++ ', rtrim(substr($line, 4));
1971
+					} elseif (trim($line) != '---#')
1863 1972
 					{
1864
-						if ($is_debug)
1865
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1973
+						if ($is_debug) {
1974
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1975
+						}
1866 1976
 					}
1867 1977
 				}
1868 1978
 
1869 1979
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1870 1980
 				{
1871
-					if ($command_line)
1872
-						echo ' * ';
1873
-					else
1874
-						$upcontext['actioned_items'][] = $last_step;
1981
+					if ($command_line) {
1982
+											echo ' * ';
1983
+					} else {
1984
+											$upcontext['actioned_items'][] = $last_step;
1985
+					}
1875 1986
 				}
1876 1987
 
1877 1988
 				// Small step - only if we're actually doing stuff.
1878
-				if ($do_current)
1879
-					nextSubstep(++$substep);
1880
-				else
1881
-					$substep++;
1882
-			}
1883
-			elseif ($type == '{')
1884
-				$current_type = 'code';
1885
-			elseif ($type == '}')
1989
+				if ($do_current) {
1990
+									nextSubstep(++$substep);
1991
+				} else {
1992
+									$substep++;
1993
+				}
1994
+			} elseif ($type == '{') {
1995
+							$current_type = 'code';
1996
+			} elseif ($type == '}')
1886 1997
 			{
1887 1998
 				$current_type = 'sql';
1888 1999
 
@@ -1895,8 +2006,9 @@  discard block
 block discarded – undo
1895 2006
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1896 2007
 				{
1897 2008
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1898
-					if ($command_line)
1899
-						echo $upcontext['error_message'];
2009
+					if ($command_line) {
2010
+											echo $upcontext['error_message'];
2011
+					}
1900 2012
 				}
1901 2013
 
1902 2014
 				// Done with code!
@@ -1976,8 +2088,9 @@  discard block
 block discarded – undo
1976 2088
 	$db_unbuffered = false;
1977 2089
 
1978 2090
 	// Failure?!
1979
-	if ($result !== false)
1980
-		return $result;
2091
+	if ($result !== false) {
2092
+			return $result;
2093
+	}
1981 2094
 
1982 2095
 	$db_error_message = $smcFunc['db_error']($db_connection);
1983 2096
 	// If MySQL we do something more clever.
@@ -2005,54 +2118,61 @@  discard block
 block discarded – undo
2005 2118
 			{
2006 2119
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2007 2120
 				$result = mysqli_query($db_connection, $string);
2008
-				if ($result !== false)
2009
-					return $result;
2121
+				if ($result !== false) {
2122
+									return $result;
2123
+				}
2010 2124
 			}
2011
-		}
2012
-		elseif ($mysqli_errno == 2013)
2125
+		} elseif ($mysqli_errno == 2013)
2013 2126
 		{
2014 2127
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2015 2128
 			mysqli_select_db($db_connection, $db_name);
2016 2129
 			if ($db_connection)
2017 2130
 			{
2018 2131
 				$result = mysqli_query($db_connection, $string);
2019
-				if ($result !== false)
2020
-					return $result;
2132
+				if ($result !== false) {
2133
+									return $result;
2134
+				}
2021 2135
 			}
2022 2136
 		}
2023 2137
 		// Duplicate column name... should be okay ;).
2024
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2025
-			return false;
2138
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2139
+					return false;
2140
+		}
2026 2141
 		// Duplicate insert... make sure it's the proper type of query ;).
2027
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2028
-			return false;
2142
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2143
+					return false;
2144
+		}
2029 2145
 		// Creating an index on a non-existent column.
2030
-		elseif ($mysqli_errno == 1072)
2031
-			return false;
2032
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2033
-			return false;
2146
+		elseif ($mysqli_errno == 1072) {
2147
+					return false;
2148
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2149
+					return false;
2150
+		}
2034 2151
 	}
2035 2152
 	// If a table already exists don't go potty.
2036 2153
 	else
2037 2154
 	{
2038 2155
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2039 2156
 		{
2040
-			if (strpos($db_error_message, 'exist') !== false)
2041
-				return true;
2042
-		}
2043
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2157
+			if (strpos($db_error_message, 'exist') !== false) {
2158
+							return true;
2159
+			}
2160
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2044 2161
 		{
2045
-			if (strpos($db_error_message, 'duplicate') !== false)
2046
-				return true;
2162
+			if (strpos($db_error_message, 'duplicate') !== false) {
2163
+							return true;
2164
+			}
2047 2165
 		}
2048 2166
 	}
2049 2167
 
2050 2168
 	// Get the query string so we pass everything.
2051 2169
 	$query_string = '';
2052
-	foreach ($_GET as $k => $v)
2053
-		$query_string .= ';' . $k . '=' . $v;
2054
-	if (strlen($query_string) != 0)
2055
-		$query_string = '?' . substr($query_string, 1);
2170
+	foreach ($_GET as $k => $v) {
2171
+			$query_string .= ';' . $k . '=' . $v;
2172
+	}
2173
+	if (strlen($query_string) != 0) {
2174
+			$query_string = '?' . substr($query_string, 1);
2175
+	}
2056 2176
 
2057 2177
 	if ($command_line)
2058 2178
 	{
@@ -2107,16 +2227,18 @@  discard block
 block discarded – undo
2107 2227
 			{
2108 2228
 				$found |= 1;
2109 2229
 				// Do some checks on the data if we have it set.
2110
-				if (isset($change['col_type']))
2111
-					$found &= $change['col_type'] === $column['type'];
2112
-				if (isset($change['null_allowed']))
2113
-					$found &= $column['null'] == $change['null_allowed'];
2114
-				if (isset($change['default']))
2115
-					$found &= $change['default'] === $column['default'];
2230
+				if (isset($change['col_type'])) {
2231
+									$found &= $change['col_type'] === $column['type'];
2232
+				}
2233
+				if (isset($change['null_allowed'])) {
2234
+									$found &= $column['null'] == $change['null_allowed'];
2235
+				}
2236
+				if (isset($change['default'])) {
2237
+									$found &= $change['default'] === $column['default'];
2238
+				}
2116 2239
 			}
2117 2240
 		}
2118
-	}
2119
-	elseif ($change['type'] === 'index')
2241
+	} elseif ($change['type'] === 'index')
2120 2242
 	{
2121 2243
 		$request = upgrade_query('
2122 2244
 			SHOW INDEX
@@ -2125,9 +2247,10 @@  discard block
 block discarded – undo
2125 2247
 		{
2126 2248
 			$cur_index = array();
2127 2249
 
2128
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2129
-				if ($row['Key_name'] === $change['name'])
2250
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2251
+							if ($row['Key_name'] === $change['name'])
2130 2252
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2253
+			}
2131 2254
 
2132 2255
 			ksort($cur_index, SORT_NUMERIC);
2133 2256
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2137,14 +2260,17 @@  discard block
 block discarded – undo
2137 2260
 	}
2138 2261
 
2139 2262
 	// If we're trying to add and it's added, we're done.
2140
-	if ($found && in_array($change['method'], array('add', 'change')))
2141
-		return true;
2263
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2264
+			return true;
2265
+	}
2142 2266
 	// Otherwise if we're removing and it wasn't found we're also done.
2143
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2144
-		return true;
2267
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2268
+			return true;
2269
+	}
2145 2270
 	// Otherwise is it just a test?
2146
-	elseif ($is_test)
2147
-		return false;
2271
+	elseif ($is_test) {
2272
+			return false;
2273
+	}
2148 2274
 
2149 2275
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2150 2276
 	$running = false;
@@ -2155,8 +2281,9 @@  discard block
 block discarded – undo
2155 2281
 			SHOW FULL PROCESSLIST');
2156 2282
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2283
 		{
2158
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2159
-				$found = true;
2284
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2285
+							$found = true;
2286
+			}
2160 2287
 		}
2161 2288
 
2162 2289
 		// Can't find it? Then we need to run it fools!
@@ -2168,8 +2295,9 @@  discard block
 block discarded – undo
2168 2295
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2169 2296
 				' . $change['text'], true) !== false;
2170 2297
 
2171
-			if (!$success)
2172
-				return false;
2298
+			if (!$success) {
2299
+							return false;
2300
+			}
2173 2301
 
2174 2302
 			// Return
2175 2303
 			$running = true;
@@ -2211,8 +2339,9 @@  discard block
 block discarded – undo
2211 2339
 			'db_error_skip' => true,
2212 2340
 		)
2213 2341
 	);
2214
-	if ($smcFunc['db_num_rows']($request) === 0)
2215
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2342
+	if ($smcFunc['db_num_rows']($request) === 0) {
2343
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2344
+	}
2216 2345
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2217 2346
 	$smcFunc['db_free_result']($request);
2218 2347
 
@@ -2234,18 +2363,19 @@  discard block
 block discarded – undo
2234 2363
 			)
2235 2364
 		);
2236 2365
 		// No results? Just forget it all together.
2237
-		if ($smcFunc['db_num_rows']($request) === 0)
2238
-			unset($table_row['Collation']);
2239
-		else
2240
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2366
+		if ($smcFunc['db_num_rows']($request) === 0) {
2367
+					unset($table_row['Collation']);
2368
+		} else {
2369
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2370
+		}
2241 2371
 		$smcFunc['db_free_result']($request);
2242 2372
 	}
2243 2373
 
2244 2374
 	if ($column_fix)
2245 2375
 	{
2246 2376
 		// Make sure there are no NULL's left.
2247
-		if ($null_fix)
2248
-			$smcFunc['db_query']('', '
2377
+		if ($null_fix) {
2378
+					$smcFunc['db_query']('', '
2249 2379
 				UPDATE {db_prefix}' . $change['table'] . '
2250 2380
 				SET ' . $change['column'] . ' = {string:default}
2251 2381
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2254,6 +2384,7 @@  discard block
 block discarded – undo
2254 2384
 					'db_error_skip' => true,
2255 2385
 				)
2256 2386
 			);
2387
+		}
2257 2388
 
2258 2389
 		// Do the actual alteration.
2259 2390
 		$smcFunc['db_query']('', '
@@ -2282,8 +2413,9 @@  discard block
 block discarded – undo
2282 2413
 	}
2283 2414
 
2284 2415
 	// Not a column we need to check on?
2285
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2286
-		return;
2416
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2417
+			return;
2418
+	}
2287 2419
 
2288 2420
 	// Break it up you (six|seven).
2289 2421
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2302,13 +2434,13 @@  discard block
 block discarded – undo
2302 2434
 				'new_name' => $temp[2],
2303 2435
 		));
2304 2436
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2305
-		if ($smcFunc['db_num_rows'] != 1)
2306
-			return;
2437
+		if ($smcFunc['db_num_rows'] != 1) {
2438
+					return;
2439
+		}
2307 2440
 
2308 2441
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2309 2442
 		$smcFunc['db_free_result']($request);
2310
-	}
2311
-	else
2443
+	} else
2312 2444
 	{
2313 2445
 		// Do this the old fashion, sure method way.
2314 2446
 		$request = $smcFunc['db_query']('', '
@@ -2319,21 +2451,24 @@  discard block
 block discarded – undo
2319 2451
 		));
2320 2452
 		// Mayday!
2321 2453
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2322
-		if ($smcFunc['db_num_rows'] == 0)
2323
-			return;
2454
+		if ($smcFunc['db_num_rows'] == 0) {
2455
+					return;
2456
+		}
2324 2457
 
2325 2458
 		// Oh where, oh where has my little field gone. Oh where can it be...
2326
-		while ($row = $smcFunc['db_query']($request))
2327
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2459
+		while ($row = $smcFunc['db_query']($request)) {
2460
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2328 2461
 			{
2329 2462
 				$current_type = $row['Type'];
2463
+		}
2330 2464
 				break;
2331 2465
 			}
2332 2466
 	}
2333 2467
 
2334 2468
 	// If this doesn't match, the column may of been altered for a reason.
2335
-	if (trim($current_type) != trim($temp[3]))
2336
-		$temp[3] = $current_type;
2469
+	if (trim($current_type) != trim($temp[3])) {
2470
+			$temp[3] = $current_type;
2471
+	}
2337 2472
 
2338 2473
 	// Piece this back together.
2339 2474
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2345,8 +2480,9 @@  discard block
 block discarded – undo
2345 2480
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2346 2481
 	global $step_progress, $is_debug, $upcontext;
2347 2482
 
2348
-	if ($_GET['substep'] < $substep)
2349
-		$_GET['substep'] = $substep;
2483
+	if ($_GET['substep'] < $substep) {
2484
+			$_GET['substep'] = $substep;
2485
+	}
2350 2486
 
2351 2487
 	if ($command_line)
2352 2488
 	{
@@ -2359,29 +2495,33 @@  discard block
 block discarded – undo
2359 2495
 	}
2360 2496
 
2361 2497
 	@set_time_limit(300);
2362
-	if (function_exists('apache_reset_timeout'))
2363
-		@apache_reset_timeout();
2498
+	if (function_exists('apache_reset_timeout')) {
2499
+			@apache_reset_timeout();
2500
+	}
2364 2501
 
2365
-	if (time() - $start_time <= $timeLimitThreshold)
2366
-		return;
2502
+	if (time() - $start_time <= $timeLimitThreshold) {
2503
+			return;
2504
+	}
2367 2505
 
2368 2506
 	// Do we have some custom step progress stuff?
2369 2507
 	if (!empty($step_progress))
2370 2508
 	{
2371 2509
 		$upcontext['substep_progress'] = 0;
2372 2510
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2373
-		if ($step_progress['current'] > $step_progress['total'])
2374
-			$upcontext['substep_progress'] = 99.9;
2375
-		else
2376
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2511
+		if ($step_progress['current'] > $step_progress['total']) {
2512
+					$upcontext['substep_progress'] = 99.9;
2513
+		} else {
2514
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2515
+		}
2377 2516
 
2378 2517
 		// Make it nicely rounded.
2379 2518
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2380 2519
 	}
2381 2520
 
2382 2521
 	// If this is XML we just exit right away!
2383
-	if (isset($_GET['xml']))
2384
-		return upgradeExit();
2522
+	if (isset($_GET['xml'])) {
2523
+			return upgradeExit();
2524
+	}
2385 2525
 
2386 2526
 	// We're going to pause after this!
2387 2527
 	$upcontext['pause'] = true;
@@ -2389,13 +2529,15 @@  discard block
 block discarded – undo
2389 2529
 	$upcontext['query_string'] = '';
2390 2530
 	foreach ($_GET as $k => $v)
2391 2531
 	{
2392
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2393
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2532
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2533
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2534
+		}
2394 2535
 	}
2395 2536
 
2396 2537
 	// Custom warning?
2397
-	if (!empty($custom_warning))
2398
-		$upcontext['custom_warning'] = $custom_warning;
2538
+	if (!empty($custom_warning)) {
2539
+			$upcontext['custom_warning'] = $custom_warning;
2540
+	}
2399 2541
 
2400 2542
 	upgradeExit();
2401 2543
 }
@@ -2410,25 +2552,26 @@  discard block
 block discarded – undo
2410 2552
 	ob_implicit_flush(true);
2411 2553
 	@set_time_limit(600);
2412 2554
 
2413
-	if (!isset($_SERVER['argv']))
2414
-		$_SERVER['argv'] = array();
2555
+	if (!isset($_SERVER['argv'])) {
2556
+			$_SERVER['argv'] = array();
2557
+	}
2415 2558
 	$_GET['maint'] = 1;
2416 2559
 
2417 2560
 	foreach ($_SERVER['argv'] as $i => $arg)
2418 2561
 	{
2419
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2420
-			$_GET['lang'] = $match[1];
2421
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2422
-			continue;
2423
-		elseif ($arg == '--no-maintenance')
2424
-			$_GET['maint'] = 0;
2425
-		elseif ($arg == '--debug')
2426
-			$is_debug = true;
2427
-		elseif ($arg == '--backup')
2428
-			$_POST['backup'] = 1;
2429
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2430
-			$_GET['conv'] = 1;
2431
-		elseif ($i != 0)
2562
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2563
+					$_GET['lang'] = $match[1];
2564
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2565
+					continue;
2566
+		} elseif ($arg == '--no-maintenance') {
2567
+					$_GET['maint'] = 0;
2568
+		} elseif ($arg == '--debug') {
2569
+					$is_debug = true;
2570
+		} elseif ($arg == '--backup') {
2571
+					$_POST['backup'] = 1;
2572
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2573
+					$_GET['conv'] = 1;
2574
+		} elseif ($i != 0)
2432 2575
 		{
2433 2576
 			echo 'SMF Command-line Upgrader
2434 2577
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2442,10 +2585,12 @@  discard block
 block discarded – undo
2442 2585
 		}
2443 2586
 	}
2444 2587
 
2445
-	if (!php_version_check())
2446
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2447
-	if (!db_version_check())
2448
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2588
+	if (!php_version_check()) {
2589
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2590
+	}
2591
+	if (!db_version_check()) {
2592
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2593
+	}
2449 2594
 
2450 2595
 	// Do some checks to make sure they have proper privileges
2451 2596
 	db_extend('packages');
@@ -2460,34 +2605,39 @@  discard block
 block discarded – undo
2460 2605
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2461 2606
 
2462 2607
 	// Sorry... we need CREATE, ALTER and DROP
2463
-	if (!$create || !$alter || !$drop)
2464
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2608
+	if (!$create || !$alter || !$drop) {
2609
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2610
+	}
2465 2611
 
2466 2612
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2467 2613
 		&& @file_exists($sourcedir . '/QueryString.php')
2468 2614
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2469
-	if (!$check && !isset($modSettings['smfVersion']))
2470
-		print_error('Error: Some files are missing or out-of-date.', true);
2615
+	if (!$check && !isset($modSettings['smfVersion'])) {
2616
+			print_error('Error: Some files are missing or out-of-date.', true);
2617
+	}
2471 2618
 
2472 2619
 	// Do a quick version spot check.
2473 2620
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2474 2621
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2475
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2476
-		print_error('Error: Some files have not yet been updated properly.');
2622
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2623
+			print_error('Error: Some files have not yet been updated properly.');
2624
+	}
2477 2625
 
2478 2626
 	// Make sure Settings.php is writable.
2479 2627
 	quickFileWritable($boarddir . '/Settings.php');
2480
-	if (!is_writable($boarddir . '/Settings.php'))
2481
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2628
+	if (!is_writable($boarddir . '/Settings.php')) {
2629
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2630
+	}
2482 2631
 
2483 2632
 	// Make sure Settings_bak.php is writable.
2484 2633
 	quickFileWritable($boarddir . '/Settings_bak.php');
2485
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2486
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2634
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2635
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2636
+	}
2487 2637
 
2488
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2489
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2490
-	elseif (isset($modSettings['agreement']))
2638
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2639
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2640
+	} elseif (isset($modSettings['agreement']))
2491 2641
 	{
2492 2642
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2493 2643
 		fwrite($fp, $modSettings['agreement']);
@@ -2497,36 +2647,42 @@  discard block
 block discarded – undo
2497 2647
 	// Make sure Themes is writable.
2498 2648
 	quickFileWritable($modSettings['theme_dir']);
2499 2649
 
2500
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2501
-		print_error('Error: Unable to obtain write access to "Themes".');
2650
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2651
+			print_error('Error: Unable to obtain write access to "Themes".');
2652
+	}
2502 2653
 
2503 2654
 	// Make sure cache directory exists and is writable!
2504 2655
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2505
-	if (!file_exists($cachedir_temp))
2506
-		@mkdir($cachedir_temp);
2656
+	if (!file_exists($cachedir_temp)) {
2657
+			@mkdir($cachedir_temp);
2658
+	}
2507 2659
 
2508 2660
 	// Make sure the cache temp dir is writable.
2509 2661
 	quickFileWritable($cachedir_temp);
2510 2662
 
2511
-	if (!is_writable($cachedir_temp))
2512
-		print_error('Error: Unable to obtain write access to "cache".', true);
2663
+	if (!is_writable($cachedir_temp)) {
2664
+			print_error('Error: Unable to obtain write access to "cache".', true);
2665
+	}
2513 2666
 
2514 2667
 	// Make sure db_last_error.php is writable.
2515 2668
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2516
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2517
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2669
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2670
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2671
+	}
2518 2672
 
2519
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2520
-		print_error('Error: Unable to find language files!', true);
2521
-	else
2673
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2674
+			print_error('Error: Unable to find language files!', true);
2675
+	} else
2522 2676
 	{
2523 2677
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2524 2678
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2525 2679
 
2526
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2527
-			print_error('Error: Language files out of date.', true);
2528
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2529
-			print_error('Error: Install language is missing for selected language.', true);
2680
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2681
+					print_error('Error: Language files out of date.', true);
2682
+		}
2683
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2684
+					print_error('Error: Install language is missing for selected language.', true);
2685
+		}
2530 2686
 
2531 2687
 		// Otherwise include it!
2532 2688
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2546,8 +2702,9 @@  discard block
 block discarded – undo
2546 2702
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2547 2703
 
2548 2704
 	// Done it already?
2549
-	if (!empty($_POST['utf8_done']))
2550
-		return true;
2705
+	if (!empty($_POST['utf8_done'])) {
2706
+			return true;
2707
+	}
2551 2708
 
2552 2709
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2553 2710
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2560,8 +2717,7 @@  discard block
 block discarded – undo
2560 2717
 		);
2561 2718
 
2562 2719
 		return true;
2563
-	}
2564
-	else
2720
+	} else
2565 2721
 	{
2566 2722
 		$upcontext['page_title'] = $txt['converting_utf8'];
2567 2723
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2605,8 +2761,9 @@  discard block
 block discarded – undo
2605 2761
 			)
2606 2762
 		);
2607 2763
 		$db_charsets = array();
2608
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2609
-			$db_charsets[] = $row['Charset'];
2764
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2765
+					$db_charsets[] = $row['Charset'];
2766
+		}
2610 2767
 
2611 2768
 		$smcFunc['db_free_result']($request);
2612 2769
 
@@ -2642,13 +2799,15 @@  discard block
 block discarded – undo
2642 2799
 		// If there's a fulltext index, we need to drop it first...
2643 2800
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2644 2801
 		{
2645
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2646
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2802
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2803
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2647 2804
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2805
+			}
2648 2806
 			$smcFunc['db_free_result']($request);
2649 2807
 
2650
-			if (isset($upcontext['fulltext_index']))
2651
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2808
+			if (isset($upcontext['fulltext_index'])) {
2809
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2810
+			}
2652 2811
 		}
2653 2812
 
2654 2813
 		// Drop it and make a note...
@@ -2838,8 +2997,9 @@  discard block
 block discarded – undo
2838 2997
 			$replace = '%field%';
2839 2998
 
2840 2999
 			// Build a huge REPLACE statement...
2841
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2842
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3000
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3001
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3002
+			}
2843 3003
 		}
2844 3004
 
2845 3005
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2849,9 +3009,10 @@  discard block
 block discarded – undo
2849 3009
 		$upcontext['table_count'] = count($queryTables);
2850 3010
 
2851 3011
 		// What ones have we already done?
2852
-		foreach ($queryTables as $id => $table)
2853
-			if ($id < $_GET['substep'])
3012
+		foreach ($queryTables as $id => $table) {
3013
+					if ($id < $_GET['substep'])
2854 3014
 				$upcontext['previous_tables'][] = $table;
3015
+		}
2855 3016
 
2856 3017
 		$upcontext['cur_table_num'] = $_GET['substep'];
2857 3018
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2888,8 +3049,9 @@  discard block
 block discarded – undo
2888 3049
 			nextSubstep($substep);
2889 3050
 
2890 3051
 			// Just to make sure it doesn't time out.
2891
-			if (function_exists('apache_reset_timeout'))
2892
-				@apache_reset_timeout();
3052
+			if (function_exists('apache_reset_timeout')) {
3053
+							@apache_reset_timeout();
3054
+			}
2893 3055
 
2894 3056
 			$table_charsets = array();
2895 3057
 
@@ -2912,8 +3074,9 @@  discard block
 block discarded – undo
2912 3074
 
2913 3075
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2914 3076
 						if ($charset != 'utf8') {
2915
-							if (!isset($table_charsets[$charset]))
2916
-								$table_charsets[$charset] = array();
3077
+							if (!isset($table_charsets[$charset])) {
3078
+															$table_charsets[$charset] = array();
3079
+							}
2917 3080
 
2918 3081
 							$table_charsets[$charset][] = $column_info;
2919 3082
 						}
@@ -2954,10 +3117,11 @@  discard block
 block discarded – undo
2954 3117
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2955 3118
 				{
2956 3119
 					$update = '';
2957
-					foreach ($table_charsets as $charset => $columns)
2958
-						foreach ($columns as $column)
3120
+					foreach ($table_charsets as $charset => $columns) {
3121
+											foreach ($columns as $column)
2959 3122
 							$update .= '
2960 3123
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3124
+					}
2961 3125
 
2962 3126
 					$smcFunc['db_query']('', '
2963 3127
 						UPDATE {raw:table_name}
@@ -2982,8 +3146,9 @@  discard block
 block discarded – undo
2982 3146
 			// Now do the actual conversion (if still needed).
2983 3147
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2984 3148
 			{
2985
-				if ($command_line)
2986
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3149
+				if ($command_line) {
3150
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3151
+				}
2987 3152
 
2988 3153
 				$smcFunc['db_query']('', '
2989 3154
 					ALTER TABLE {raw:table_name}
@@ -2993,12 +3158,14 @@  discard block
 block discarded – undo
2993 3158
 					)
2994 3159
 				);
2995 3160
 
2996
-				if ($command_line)
2997
-					echo " done.\n";
3161
+				if ($command_line) {
3162
+									echo " done.\n";
3163
+				}
2998 3164
 			}
2999 3165
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3000
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3001
-				return upgradeExit();
3166
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3167
+							return upgradeExit();
3168
+			}
3002 3169
 		}
3003 3170
 
3004 3171
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3027,8 +3194,8 @@  discard block
 block discarded – undo
3027 3194
 		);
3028 3195
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3029 3196
 		{
3030
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3031
-				$smcFunc['db_query']('', '
3197
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3198
+							$smcFunc['db_query']('', '
3032 3199
 					UPDATE {db_prefix}log_actions
3033 3200
 					SET extra = {string:extra}
3034 3201
 					WHERE id_action = {int:current_action}',
@@ -3037,6 +3204,7 @@  discard block
 block discarded – undo
3037 3204
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3038 3205
 					)
3039 3206
 				);
3207
+			}
3040 3208
 		}
3041 3209
 		$smcFunc['db_free_result']($request);
3042 3210
 
@@ -3058,15 +3226,17 @@  discard block
 block discarded – undo
3058 3226
 	// First thing's first - did we already do this?
3059 3227
 	if (!empty($modSettings['json_done']))
3060 3228
 	{
3061
-		if ($command_line)
3062
-			return DeleteUpgrade();
3063
-		else
3064
-			return true;
3229
+		if ($command_line) {
3230
+					return DeleteUpgrade();
3231
+		} else {
3232
+					return true;
3233
+		}
3065 3234
 	}
3066 3235
 
3067 3236
 	// Done it already - js wise?
3068
-	if (!empty($_POST['json_done']))
3069
-		return true;
3237
+	if (!empty($_POST['json_done'])) {
3238
+			return true;
3239
+	}
3070 3240
 
3071 3241
 	// List of tables affected by this function
3072 3242
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3098,12 +3268,14 @@  discard block
 block discarded – undo
3098 3268
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3099 3269
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3100 3270
 
3101
-	foreach ($keys as $id => $table)
3102
-		if ($id < $_GET['substep'])
3271
+	foreach ($keys as $id => $table) {
3272
+			if ($id < $_GET['substep'])
3103 3273
 			$upcontext['previous_tables'][] = $table;
3274
+	}
3104 3275
 
3105
-	if ($command_line)
3106
-		echo 'Converting data from serialize() to json_encode().';
3276
+	if ($command_line) {
3277
+			echo 'Converting data from serialize() to json_encode().';
3278
+	}
3107 3279
 
3108 3280
 	if (!$support_js || isset($_GET['xml']))
3109 3281
 	{
@@ -3143,8 +3315,9 @@  discard block
 block discarded – undo
3143 3315
 
3144 3316
 				// Loop through and fix these...
3145 3317
 				$new_settings = array();
3146
-				if ($command_line)
3147
-					echo "\n" . 'Fixing some settings...';
3318
+				if ($command_line) {
3319
+									echo "\n" . 'Fixing some settings...';
3320
+				}
3148 3321
 
3149 3322
 				foreach ($serialized_settings as $var)
3150 3323
 				{
@@ -3152,22 +3325,24 @@  discard block
 block discarded – undo
3152 3325
 					{
3153 3326
 						// Attempt to unserialize the setting
3154 3327
 						$temp = @safe_unserialize($modSettings[$var]);
3155
-						if (!$temp && $command_line)
3156
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3157
-						elseif ($temp !== false)
3158
-							$new_settings[$var] = json_encode($temp);
3328
+						if (!$temp && $command_line) {
3329
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3330
+						} elseif ($temp !== false) {
3331
+													$new_settings[$var] = json_encode($temp);
3332
+						}
3159 3333
 					}
3160 3334
 				}
3161 3335
 
3162 3336
 				// Update everything at once
3163
-				if (!function_exists('cache_put_data'))
3164
-					require_once($sourcedir . '/Load.php');
3337
+				if (!function_exists('cache_put_data')) {
3338
+									require_once($sourcedir . '/Load.php');
3339
+				}
3165 3340
 				updateSettings($new_settings, true);
3166 3341
 
3167
-				if ($command_line)
3168
-					echo ' done.';
3169
-			}
3170
-			elseif ($table == 'themes')
3342
+				if ($command_line) {
3343
+									echo ' done.';
3344
+				}
3345
+			} elseif ($table == 'themes')
3171 3346
 			{
3172 3347
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3173 3348
 				$query = $smcFunc['db_query']('', '
@@ -3186,10 +3361,11 @@  discard block
 block discarded – undo
3186 3361
 
3187 3362
 						if ($command_line)
3188 3363
 						{
3189
-							if ($temp === false)
3190
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3191
-							else
3192
-								echo "\n" . 'Fixing admin preferences...';
3364
+							if ($temp === false) {
3365
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3366
+							} else {
3367
+															echo "\n" . 'Fixing admin preferences...';
3368
+							}
3193 3369
 						}
3194 3370
 
3195 3371
 						if ($temp !== false)
@@ -3211,15 +3387,15 @@  discard block
 block discarded – undo
3211 3387
 								)
3212 3388
 							);
3213 3389
 
3214
-							if ($command_line)
3215
-								echo ' done.';
3390
+							if ($command_line) {
3391
+															echo ' done.';
3392
+							}
3216 3393
 						}
3217 3394
 					}
3218 3395
 
3219 3396
 					$smcFunc['db_free_result']($query);
3220 3397
 				}
3221
-			}
3222
-			else
3398
+			} else
3223 3399
 			{
3224 3400
 				// First item is always the key...
3225 3401
 				$key = $info[0];
@@ -3230,8 +3406,7 @@  discard block
 block discarded – undo
3230 3406
 				{
3231 3407
 					$col_select = $info[1];
3232 3408
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3233
-				}
3234
-				else
3409
+				} else
3235 3410
 				{
3236 3411
 					$col_select = implode(', ', $info);
3237 3412
 				}
@@ -3264,8 +3439,7 @@  discard block
 block discarded – undo
3264 3439
 								if ($temp === false && $command_line)
3265 3440
 								{
3266 3441
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3267
-								}
3268
-								else
3442
+								} else
3269 3443
 								{
3270 3444
 									$row[$col] = json_encode($temp);
3271 3445
 
@@ -3290,16 +3464,18 @@  discard block
 block discarded – undo
3290 3464
 						}
3291 3465
 					}
3292 3466
 
3293
-					if ($command_line)
3294
-						echo ' done.';
3467
+					if ($command_line) {
3468
+											echo ' done.';
3469
+					}
3295 3470
 
3296 3471
 					// Free up some memory...
3297 3472
 					$smcFunc['db_free_result']($query);
3298 3473
 				}
3299 3474
 			}
3300 3475
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3301
-			if (isset($_GET['xml']))
3302
-				return upgradeExit();
3476
+			if (isset($_GET['xml'])) {
3477
+							return upgradeExit();
3478
+			}
3303 3479
 		}
3304 3480
 
3305 3481
 		if ($command_line)
@@ -3314,8 +3490,9 @@  discard block
 block discarded – undo
3314 3490
 
3315 3491
 		$_GET['substep'] = 0;
3316 3492
 		// Make sure we move on!
3317
-		if ($command_line)
3318
-			return DeleteUpgrade();
3493
+		if ($command_line) {
3494
+					return DeleteUpgrade();
3495
+		}
3319 3496
 
3320 3497
 		return true;
3321 3498
 	}
@@ -3372,14 +3549,16 @@  discard block
 block discarded – undo
3372 3549
 	global $upcontext, $txt, $settings;
3373 3550
 
3374 3551
 	// Don't call me twice!
3375
-	if (!empty($upcontext['chmod_called']))
3376
-		return;
3552
+	if (!empty($upcontext['chmod_called'])) {
3553
+			return;
3554
+	}
3377 3555
 
3378 3556
 	$upcontext['chmod_called'] = true;
3379 3557
 
3380 3558
 	// Nothing?
3381
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3382
-		return;
3559
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3560
+			return;
3561
+	}
3383 3562
 
3384 3563
 	// Was it a problem with Windows?
3385 3564
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3411,11 +3590,12 @@  discard block
 block discarded – undo
3411 3590
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3412 3591
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3413 3592
 
3414
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3415
-		echo '
3593
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3594
+			echo '
3416 3595
 					content.write(\'<hr>\n\t\t\t\');
3417 3596
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3418 3597
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3598
+	}
3419 3599
 
3420 3600
 	echo '
3421 3601
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3423,17 +3603,19 @@  discard block
 block discarded – undo
3423 3603
 				}
3424 3604
 			</script>';
3425 3605
 
3426
-	if (!empty($upcontext['chmod']['ftp_error']))
3427
-		echo '
3606
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3607
+			echo '
3428 3608
 			<div class="error_message red">
3429 3609
 				', $txt['upgrade_ftp_error'], '<br><br>
3430 3610
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3431 3611
 			</div>
3432 3612
 			<br>';
3613
+	}
3433 3614
 
3434
-	if (empty($upcontext['chmod_in_form']))
3435
-		echo '
3615
+	if (empty($upcontext['chmod_in_form'])) {
3616
+			echo '
3436 3617
 	<form action="', $upcontext['form_url'], '" method="post">';
3618
+	}
3437 3619
 
3438 3620
 	echo '
3439 3621
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3468,10 +3650,11 @@  discard block
 block discarded – undo
3468 3650
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3469 3651
 	</div>';
3470 3652
 
3471
-	if (empty($upcontext['chmod_in_form']))
3472
-		echo '
3653
+	if (empty($upcontext['chmod_in_form'])) {
3654
+			echo '
3473 3655
 	</form>';
3474
-}
3656
+	}
3657
+	}
3475 3658
 
3476 3659
 function template_upgrade_above()
3477 3660
 {
@@ -3531,9 +3714,10 @@  discard block
 block discarded – undo
3531 3714
 				<h2>', $txt['upgrade_progress'], '</h2>
3532 3715
 				<ul>';
3533 3716
 
3534
-	foreach ($upcontext['steps'] as $num => $step)
3535
-		echo '
3717
+	foreach ($upcontext['steps'] as $num => $step) {
3718
+			echo '
3536 3719
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3720
+	}
3537 3721
 
3538 3722
 	echo '
3539 3723
 					</ul>
@@ -3546,8 +3730,8 @@  discard block
 block discarded – undo
3546 3730
 				</div>
3547 3731
 			</div>';
3548 3732
 
3549
-	if (isset($upcontext['step_progress']))
3550
-		echo '
3733
+	if (isset($upcontext['step_progress'])) {
3734
+			echo '
3551 3735
 				<br>
3552 3736
 				<br>
3553 3737
 				<div id="progress_bar_step">
@@ -3556,6 +3740,7 @@  discard block
 block discarded – undo
3556 3740
 						<span>', $txt['upgrade_step_progress'], '</span>
3557 3741
 					</div>
3558 3742
 				</div>';
3743
+	}
3559 3744
 
3560 3745
 	echo '
3561 3746
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3586,32 +3771,36 @@  discard block
 block discarded – undo
3586 3771
 {
3587 3772
 	global $upcontext, $txt;
3588 3773
 
3589
-	if (!empty($upcontext['pause']))
3590
-		echo '
3774
+	if (!empty($upcontext['pause'])) {
3775
+			echo '
3591 3776
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3592 3777
 
3593 3778
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3594 3779
 								<h3>
3595 3780
 									', $txt['upgrade_paused_overload'], '
3596 3781
 								</h3>';
3782
+	}
3597 3783
 
3598
-	if (!empty($upcontext['custom_warning']))
3599
-		echo '
3784
+	if (!empty($upcontext['custom_warning'])) {
3785
+			echo '
3600 3786
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3601 3787
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3602 3788
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3603 3789
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3604 3790
 								</div>';
3791
+	}
3605 3792
 
3606 3793
 	echo '
3607 3794
 								<div class="righttext" style="margin: 1ex;">';
3608 3795
 
3609
-	if (!empty($upcontext['continue']))
3610
-		echo '
3796
+	if (!empty($upcontext['continue'])) {
3797
+			echo '
3611 3798
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3612
-	if (!empty($upcontext['skip']))
3613
-		echo '
3799
+	}
3800
+	if (!empty($upcontext['skip'])) {
3801
+			echo '
3614 3802
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3803
+	}
3615 3804
 
3616 3805
 	echo '
3617 3806
 								</div>
@@ -3661,11 +3850,12 @@  discard block
 block discarded – undo
3661 3850
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3662 3851
 	<smf>';
3663 3852
 
3664
-	if (!empty($upcontext['get_data']))
3665
-		foreach ($upcontext['get_data'] as $k => $v)
3853
+	if (!empty($upcontext['get_data'])) {
3854
+			foreach ($upcontext['get_data'] as $k => $v)
3666 3855
 			echo '
3667 3856
 		<get key="', $k, '">', $v, '</get>';
3668
-}
3857
+	}
3858
+	}
3669 3859
 
3670 3860
 function template_xml_below()
3671 3861
 {
@@ -3706,8 +3896,8 @@  discard block
 block discarded – undo
3706 3896
 	template_chmod();
3707 3897
 
3708 3898
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3709
-	if ($upcontext['is_large_forum'])
3710
-		echo '
3899
+	if ($upcontext['is_large_forum']) {
3900
+			echo '
3711 3901
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3712 3902
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3713 3903
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3715,10 +3905,11 @@  discard block
 block discarded – undo
3715 3905
 				', $txt['upgrade_warning_lots_data'], '
3716 3906
 			</div>
3717 3907
 		</div>';
3908
+	}
3718 3909
 
3719 3910
 	// A warning message?
3720
-	if (!empty($upcontext['warning']))
3721
-		echo '
3911
+	if (!empty($upcontext['warning'])) {
3912
+			echo '
3722 3913
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3723 3914
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3724 3915
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3726,6 +3917,7 @@  discard block
 block discarded – undo
3726 3917
 				', $upcontext['warning'], '
3727 3918
 			</div>
3728 3919
 		</div>';
3920
+	}
3729 3921
 
3730 3922
 	// Paths are incorrect?
3731 3923
 	echo '
@@ -3741,20 +3933,22 @@  discard block
 block discarded – undo
3741 3933
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3742 3934
 	{
3743 3935
 		$ago = time() - $upcontext['started'];
3744
-		if ($ago < 60)
3745
-			$ago = $ago . ' seconds';
3746
-		elseif ($ago < 3600)
3747
-			$ago = (int) ($ago / 60) . ' minutes';
3748
-		else
3749
-			$ago = (int) ($ago / 3600) . ' hours';
3936
+		if ($ago < 60) {
3937
+					$ago = $ago . ' seconds';
3938
+		} elseif ($ago < 3600) {
3939
+					$ago = (int) ($ago / 60) . ' minutes';
3940
+		} else {
3941
+					$ago = (int) ($ago / 3600) . ' hours';
3942
+		}
3750 3943
 
3751 3944
 		$active = time() - $upcontext['updated'];
3752
-		if ($active < 60)
3753
-			$updated = $active . ' seconds';
3754
-		elseif ($active < 3600)
3755
-			$updated = (int) ($active / 60) . ' minutes';
3756
-		else
3757
-			$updated = (int) ($active / 3600) . ' hours';
3945
+		if ($active < 60) {
3946
+					$updated = $active . ' seconds';
3947
+		} elseif ($active < 3600) {
3948
+					$updated = (int) ($active / 60) . ' minutes';
3949
+		} else {
3950
+					$updated = (int) ($active / 3600) . ' hours';
3951
+		}
3758 3952
 
3759 3953
 		echo '
3760 3954
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3763,16 +3957,18 @@  discard block
 block discarded – undo
3763 3957
 			<div style="padding-left: 6ex;">
3764 3958
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3765 3959
 
3766
-		if ($active < 600)
3767
-			echo '
3960
+		if ($active < 600) {
3961
+					echo '
3768 3962
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3963
+		}
3769 3964
 
3770
-		if ($active > $upcontext['inactive_timeout'])
3771
-			echo '
3965
+		if ($active > $upcontext['inactive_timeout']) {
3966
+					echo '
3772 3967
 				<br><br>',$txt['upgrade_run'], '';
3773
-		else
3774
-			echo '
3968
+		} else {
3969
+					echo '
3775 3970
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3971
+		}
3776 3972
 
3777 3973
 		echo '
3778 3974
 			</div>
@@ -3788,9 +3984,10 @@  discard block
 block discarded – undo
3788 3984
 					<td>
3789 3985
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3790 3986
 
3791
-	if (!empty($upcontext['username_incorrect']))
3792
-		echo '
3987
+	if (!empty($upcontext['username_incorrect'])) {
3988
+			echo '
3793 3989
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3990
+	}
3794 3991
 
3795 3992
 	echo '
3796 3993
 					</td>
@@ -3801,9 +3998,10 @@  discard block
 block discarded – undo
3801 3998
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3802 3999
 						<input type="hidden" name="hash_passwrd" value="">';
3803 4000
 
3804
-	if (!empty($upcontext['password_failed']))
3805
-		echo '
4001
+	if (!empty($upcontext['password_failed'])) {
4002
+			echo '
3806 4003
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
4004
+	}
3807 4005
 
3808 4006
 	echo '
3809 4007
 					</td>
@@ -3874,8 +4072,8 @@  discard block
 block discarded – undo
3874 4072
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3875 4073
 
3876 4074
 	// Warning message?
3877
-	if (!empty($upcontext['upgrade_options_warning']))
3878
-		echo '
4075
+	if (!empty($upcontext['upgrade_options_warning'])) {
4076
+			echo '
3879 4077
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3880 4078
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3881 4079
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3883,6 +4081,7 @@  discard block
 block discarded – undo
3883 4081
 				', $upcontext['upgrade_options_warning'], '
3884 4082
 			</div>
3885 4083
 		</div>';
4084
+	}
3886 4085
 
3887 4086
 	echo '
3888 4087
 				<table>
@@ -3925,8 +4124,8 @@  discard block
 block discarded – undo
3925 4124
 						</td>
3926 4125
 					</tr>';
3927 4126
 
3928
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3929
-		echo '
4127
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4128
+			echo '
3930 4129
 					<tr valign="top">
3931 4130
 						<td width="2%">
3932 4131
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3935,6 +4134,7 @@  discard block
 block discarded – undo
3935 4134
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3936 4135
 						</td>
3937 4136
 					</tr>';
4137
+	}
3938 4138
 
3939 4139
 	echo '
3940 4140
 					<tr valign="top">
@@ -3972,10 +4172,11 @@  discard block
 block discarded – undo
3972 4172
 			</div>';
3973 4173
 
3974 4174
 	// Dont any tables so far?
3975
-	if (!empty($upcontext['previous_tables']))
3976
-		foreach ($upcontext['previous_tables'] as $table)
4175
+	if (!empty($upcontext['previous_tables'])) {
4176
+			foreach ($upcontext['previous_tables'] as $table)
3977 4177
 			echo '
3978 4178
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4179
+	}
3979 4180
 
3980 4181
 	echo '
3981 4182
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4012,12 +4213,13 @@  discard block
 block discarded – undo
4012 4213
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4013 4214
 
4014 4215
 		// If debug flood the screen.
4015
-		if ($is_debug)
4016
-			echo '
4216
+		if ($is_debug) {
4217
+					echo '
4017 4218
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4018 4219
 
4019 4220
 				if (document.getElementById(\'debug_section\').scrollHeight)
4020 4221
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4222
+		}
4021 4223
 
4022 4224
 		echo '
4023 4225
 				// Get the next update...
@@ -4050,8 +4252,9 @@  discard block
 block discarded – undo
4050 4252
 {
4051 4253
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4052 4254
 
4053
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4054
-		$is_debug = true;
4255
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4256
+			$is_debug = true;
4257
+	}
4055 4258
 
4056 4259
 	echo '
4057 4260
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4066,8 +4269,9 @@  discard block
 block discarded – undo
4066 4269
 	{
4067 4270
 		foreach ($upcontext['actioned_items'] as $num => $item)
4068 4271
 		{
4069
-			if ($num != 0)
4070
-				echo ' Successful!';
4272
+			if ($num != 0) {
4273
+							echo ' Successful!';
4274
+			}
4071 4275
 			echo '<br>' . $item;
4072 4276
 		}
4073 4277
 		if (!empty($upcontext['changes_complete']))
@@ -4080,28 +4284,32 @@  discard block
 block discarded – undo
4080 4284
 				$seconds = intval($active % 60);
4081 4285
 
4082 4286
 				$totalTime = '';
4083
-				if ($hours > 0)
4084
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4085
-				if ($minutes > 0)
4086
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4087
-				if ($seconds > 0)
4088
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4287
+				if ($hours > 0) {
4288
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4289
+				}
4290
+				if ($minutes > 0) {
4291
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4292
+				}
4293
+				if ($seconds > 0) {
4294
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4295
+				}
4089 4296
 			}
4090 4297
 
4091
-			if ($is_debug && !empty($totalTime))
4092
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4093
-			else
4094
-				echo ' Successful!<br><br>';
4298
+			if ($is_debug && !empty($totalTime)) {
4299
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4300
+			} else {
4301
+							echo ' Successful!<br><br>';
4302
+			}
4095 4303
 
4096 4304
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4097 4305
 		}
4098
-	}
4099
-	else
4306
+	} else
4100 4307
 	{
4101 4308
 		// Tell them how many files we have in total.
4102
-		if ($upcontext['file_count'] > 1)
4103
-			echo '
4309
+		if ($upcontext['file_count'] > 1) {
4310
+					echo '
4104 4311
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4312
+		}
4105 4313
 
4106 4314
 		echo '
4107 4315
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4117,19 +4325,23 @@  discard block
 block discarded – undo
4117 4325
 				$seconds = intval($active % 60);
4118 4326
 
4119 4327
 				$totalTime = '';
4120
-				if ($hours > 0)
4121
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4122
-				if ($minutes > 0)
4123
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4124
-				if ($seconds > 0)
4125
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4328
+				if ($hours > 0) {
4329
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4330
+				}
4331
+				if ($minutes > 0) {
4332
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4333
+				}
4334
+				if ($seconds > 0) {
4335
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4336
+				}
4126 4337
 			}
4127 4338
 
4128 4339
 			echo '
4129 4340
 			<br><span id="upgradeCompleted">';
4130 4341
 
4131
-			if (!empty($totalTime))
4132
-				echo 'Completed in ', $totalTime, '<br>';
4342
+			if (!empty($totalTime)) {
4343
+							echo 'Completed in ', $totalTime, '<br>';
4344
+			}
4133 4345
 
4134 4346
 			echo '</span>
4135 4347
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4166,9 +4378,10 @@  discard block
 block discarded – undo
4166 4378
 			var getData = "";
4167 4379
 			var debugItems = ', $upcontext['debug_items'], ';';
4168 4380
 
4169
-		if ($is_debug)
4170
-			echo '
4381
+		if ($is_debug) {
4382
+					echo '
4171 4383
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4384
+		}
4172 4385
 
4173 4386
 		echo '
4174 4387
 			function getNextItem()
@@ -4208,9 +4421,10 @@  discard block
 block discarded – undo
4208 4421
 						document.getElementById("error_block").style.display = "";
4209 4422
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4210 4423
 
4211
-	if ($is_debug)
4212
-		echo '
4424
+	if ($is_debug) {
4425
+			echo '
4213 4426
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4427
+	}
4214 4428
 
4215 4429
 	echo '
4216 4430
 					}
@@ -4231,9 +4445,10 @@  discard block
 block discarded – undo
4231 4445
 						document.getElementById("error_block").style.display = "";
4232 4446
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4233 4447
 
4234
-	if ($is_debug)
4235
-		echo '
4448
+	if ($is_debug) {
4449
+			echo '
4236 4450
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4451
+	}
4237 4452
 
4238 4453
 	echo '
4239 4454
 					}
@@ -4292,8 +4507,8 @@  discard block
 block discarded – undo
4292 4507
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4293 4508
 				{';
4294 4509
 
4295
-		if ($is_debug)
4296
-			echo '
4510
+		if ($is_debug) {
4511
+					echo '
4297 4512
 					document.getElementById(\'debug_section\').style.display = "none";
4298 4513
 
4299 4514
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4311,6 +4526,7 @@  discard block
 block discarded – undo
4311 4526
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4312 4527
 
4313 4528
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4529
+		}
4314 4530
 
4315 4531
 		echo '
4316 4532
 
@@ -4318,9 +4534,10 @@  discard block
 block discarded – undo
4318 4534
 					document.getElementById(\'contbutt\').disabled = 0;
4319 4535
 					document.getElementById(\'database_done\').value = 1;';
4320 4536
 
4321
-		if ($upcontext['file_count'] > 1)
4322
-			echo '
4537
+		if ($upcontext['file_count'] > 1) {
4538
+					echo '
4323 4539
 					document.getElementById(\'info1\').style.display = "none";';
4540
+		}
4324 4541
 
4325 4542
 		echo '
4326 4543
 					document.getElementById(\'info2\').style.display = "none";
@@ -4333,9 +4550,10 @@  discard block
 block discarded – undo
4333 4550
 					lastItem = 0;
4334 4551
 					prevFile = curFile;';
4335 4552
 
4336
-		if ($is_debug)
4337
-			echo '
4553
+		if ($is_debug) {
4554
+					echo '
4338 4555
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4556
+		}
4339 4557
 
4340 4558
 		echo '
4341 4559
 					getNextItem();
@@ -4343,8 +4561,8 @@  discard block
 block discarded – undo
4343 4561
 				}';
4344 4562
 
4345 4563
 		// If debug scroll the screen.
4346
-		if ($is_debug)
4347
-			echo '
4564
+		if ($is_debug) {
4565
+					echo '
4348 4566
 				if (iLastSubStepProgress == -1)
4349 4567
 				{
4350 4568
 					// Give it consistent dots.
@@ -4363,6 +4581,7 @@  discard block
 block discarded – undo
4363 4581
 
4364 4582
 				if (document.getElementById(\'debug_section\').scrollHeight)
4365 4583
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4584
+		}
4366 4585
 
4367 4586
 		echo '
4368 4587
 				// Update the page.
@@ -4423,9 +4642,10 @@  discard block
 block discarded – undo
4423 4642
 			}';
4424 4643
 
4425 4644
 		// Start things off assuming we've not errored.
4426
-		if (empty($upcontext['error_message']))
4427
-			echo '
4645
+		if (empty($upcontext['error_message'])) {
4646
+					echo '
4428 4647
 			getNextItem();';
4648
+		}
4429 4649
 
4430 4650
 		echo '
4431 4651
 		//# sourceURL=dynamicScript-dbch.js
@@ -4443,18 +4663,21 @@  discard block
 block discarded – undo
4443 4663
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4444 4664
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4445 4665
 
4446
-	if (!empty($upcontext['error_message']))
4447
-		echo '
4666
+	if (!empty($upcontext['error_message'])) {
4667
+			echo '
4448 4668
 	<error>', $upcontext['error_message'], '</error>';
4669
+	}
4449 4670
 
4450
-	if (!empty($upcontext['error_string']))
4451
-		echo '
4671
+	if (!empty($upcontext['error_string'])) {
4672
+			echo '
4452 4673
 	<sql>', $upcontext['error_string'], '</sql>';
4674
+	}
4453 4675
 
4454
-	if ($is_debug)
4455
-		echo '
4676
+	if ($is_debug) {
4677
+			echo '
4456 4678
 	<curtime>', time(), '</curtime>';
4457
-}
4679
+	}
4680
+	}
4458 4681
 
4459 4682
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4460 4683
 function template_convert_utf8()
@@ -4473,18 +4696,20 @@  discard block
 block discarded – undo
4473 4696
 			</div>';
4474 4697
 
4475 4698
 	// Done any tables so far?
4476
-	if (!empty($upcontext['previous_tables']))
4477
-		foreach ($upcontext['previous_tables'] as $table)
4699
+	if (!empty($upcontext['previous_tables'])) {
4700
+			foreach ($upcontext['previous_tables'] as $table)
4478 4701
 			echo '
4479 4702
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4703
+	}
4480 4704
 
4481 4705
 	echo '
4482 4706
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4483 4707
 
4484 4708
 	// If we dropped their index, let's let them know
4485
-	if ($upcontext['dropping_index'])
4486
-		echo '
4709
+	if ($upcontext['dropping_index']) {
4710
+			echo '
4487 4711
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4712
+	}
4488 4713
 
4489 4714
 	// Completion notification
4490 4715
 	echo '
@@ -4521,12 +4746,13 @@  discard block
 block discarded – undo
4521 4746
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4522 4747
 
4523 4748
 		// If debug flood the screen.
4524
-		if ($is_debug)
4525
-			echo '
4749
+		if ($is_debug) {
4750
+					echo '
4526 4751
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4527 4752
 
4528 4753
 				if (document.getElementById(\'debug_section\').scrollHeight)
4529 4754
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4755
+		}
4530 4756
 
4531 4757
 		echo '
4532 4758
 				// Get the next update...
@@ -4574,19 +4800,21 @@  discard block
 block discarded – undo
4574 4800
 			</div>';
4575 4801
 
4576 4802
 	// Dont any tables so far?
4577
-	if (!empty($upcontext['previous_tables']))
4578
-		foreach ($upcontext['previous_tables'] as $table)
4803
+	if (!empty($upcontext['previous_tables'])) {
4804
+			foreach ($upcontext['previous_tables'] as $table)
4579 4805
 			echo '
4580 4806
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4807
+	}
4581 4808
 
4582 4809
 	echo '
4583 4810
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4584 4811
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4585 4812
 
4586 4813
 	// Try to make sure substep was reset.
4587
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4588
-		echo '
4814
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4815
+			echo '
4589 4816
 			<input type="hidden" name="substep" id="substep" value="0">';
4817
+	}
4590 4818
 
4591 4819
 	// Continue please!
4592 4820
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4619,12 +4847,13 @@  discard block
 block discarded – undo
4619 4847
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4620 4848
 
4621 4849
 		// If debug flood the screen.
4622
-		if ($is_debug)
4623
-			echo '
4850
+		if ($is_debug) {
4851
+					echo '
4624 4852
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4625 4853
 
4626 4854
 				if (document.getElementById(\'debug_section\').scrollHeight)
4627 4855
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4856
+		}
4628 4857
 
4629 4858
 		echo '
4630 4859
 				// Get the next update...
@@ -4660,8 +4889,8 @@  discard block
 block discarded – undo
4660 4889
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4661 4890
 	<form action="', $boardurl, '/index.php">';
4662 4891
 
4663
-	if (!empty($upcontext['can_delete_script']))
4664
-		echo '
4892
+	if (!empty($upcontext['can_delete_script'])) {
4893
+			echo '
4665 4894
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4666 4895
 			<script>
4667 4896
 				function doTheDelete(theCheck)
@@ -4673,6 +4902,7 @@  discard block
 block discarded – undo
4673 4902
 				}
4674 4903
 			</script>
4675 4904
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4905
+	}
4676 4906
 
4677 4907
 	$active = time() - $upcontext['started'];
4678 4908
 	$hours = floor($active / 3600);
@@ -4682,16 +4912,20 @@  discard block
 block discarded – undo
4682 4912
 	if ($is_debug)
4683 4913
 	{
4684 4914
 		$totalTime = '';
4685
-		if ($hours > 0)
4686
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4687
-		if ($minutes > 0)
4688
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4689
-		if ($seconds > 0)
4690
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4915
+		if ($hours > 0) {
4916
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4917
+		}
4918
+		if ($minutes > 0) {
4919
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4920
+		}
4921
+		if ($seconds > 0) {
4922
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4923
+		}
4691 4924
 	}
4692 4925
 
4693
-	if ($is_debug && !empty($totalTime))
4694
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4926
+	if ($is_debug && !empty($totalTime)) {
4927
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4928
+	}
4695 4929
 
4696 4930
 	echo '<br>
4697 4931
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4718,8 +4952,9 @@  discard block
 block discarded – undo
4718 4952
 
4719 4953
 	$current_substep = $_GET['substep'];
4720 4954
 
4721
-	if (empty($_GET['a']))
4722
-		$_GET['a'] = 0;
4955
+	if (empty($_GET['a'])) {
4956
+			$_GET['a'] = 0;
4957
+	}
4723 4958
 	$step_progress['name'] = 'Converting ips';
4724 4959
 	$step_progress['current'] = $_GET['a'];
4725 4960
 
@@ -4762,16 +4997,19 @@  discard block
 block discarded – undo
4762 4997
 				'empty' => '',
4763 4998
 				'limit' => $limit,
4764 4999
 		));
4765
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4766
-			$arIp[] = $row[$oldCol];
5000
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5001
+					$arIp[] = $row[$oldCol];
5002
+		}
4767 5003
 		$smcFunc['db_free_result']($request);
4768 5004
 
4769 5005
 		// Special case, null ip could keep us in a loop.
4770
-		if (is_null($arIp[0]))
4771
-			unset($arIp[0]);
5006
+		if (is_null($arIp[0])) {
5007
+					unset($arIp[0]);
5008
+		}
4772 5009
 
4773
-		if (empty($arIp))
4774
-			$is_done = true;
5010
+		if (empty($arIp)) {
5011
+					$is_done = true;
5012
+		}
4775 5013
 
4776 5014
 		$updates = array();
4777 5015
 		$cases = array();
@@ -4780,16 +5018,18 @@  discard block
 block discarded – undo
4780 5018
 		{
4781 5019
 			$arIp[$i] = trim($arIp[$i]);
4782 5020
 
4783
-			if (empty($arIp[$i]))
4784
-				continue;
5021
+			if (empty($arIp[$i])) {
5022
+							continue;
5023
+			}
4785 5024
 
4786 5025
 			$updates['ip' . $i] = $arIp[$i];
4787 5026
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4788 5027
 
4789 5028
 			if ($setSize > 0 && $i % $setSize === 0)
4790 5029
 			{
4791
-				if (count($updates) == 1)
4792
-					continue;
5030
+				if (count($updates) == 1) {
5031
+									continue;
5032
+				}
4793 5033
 
4794 5034
 				$updates['whereSet'] = array_values($updates);
4795 5035
 				$smcFunc['db_query']('', '
@@ -4823,8 +5063,7 @@  discard block
 block discarded – undo
4823 5063
 							'ip' => $ip
4824 5064
 					));
4825 5065
 				}
4826
-			}
4827
-			else
5066
+			} else
4828 5067
 			{
4829 5068
 				$updates['whereSet'] = array_values($updates);
4830 5069
 				$smcFunc['db_query']('', '
@@ -4838,9 +5077,9 @@  discard block
 block discarded – undo
4838 5077
 					$updates
4839 5078
 				);
4840 5079
 			}
5080
+		} else {
5081
+					$is_done = true;
4841 5082
 		}
4842
-		else
4843
-			$is_done = true;
4844 5083
 
4845 5084
 		$_GET['a'] += $limit;
4846 5085
 		$step_progress['current'] = $_GET['a'];
@@ -4866,10 +5105,11 @@  discard block
 block discarded – undo
4866 5105
 
4867 5106
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4868 5107
 
4869
-	if (isset($columns[$column]))
4870
-		return $columns[$column];
4871
-	else
4872
-		return null;
4873
-}
5108
+	if (isset($columns[$column])) {
5109
+			return $columns[$column];
5110
+	} else {
5111
+			return null;
5112
+	}
5113
+	}
4874 5114
 
4875 5115
 ?>
4876 5116
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageSettings.php 1 patch
Braces   +276 added lines, -201 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
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -206,16 +207,18 @@  discard block
 block discarded – undo
206 207
 	{
207 208
 		$all_zones = timezone_identifiers_list();
208 209
 		// Make sure we set the value to the same as the printed value.
209
-		foreach ($all_zones as $zone)
210
-			$config_vars['default_timezone'][2][$zone] = $zone;
210
+		foreach ($all_zones as $zone) {
211
+					$config_vars['default_timezone'][2][$zone] = $zone;
212
+		}
213
+	} else {
214
+			unset($config_vars['default_timezone']);
211 215
 	}
212
-	else
213
-		unset($config_vars['default_timezone']);
214 216
 
215 217
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
216 218
 
217
-	if ($return_config)
218
-		return $config_vars;
219
+	if ($return_config) {
220
+			return $config_vars;
221
+	}
219 222
 
220 223
 	// Saving?
221 224
 	if (isset($_GET['save']))
@@ -223,8 +226,9 @@  discard block
 block discarded – undo
223 226
 		checkSession();
224 227
 
225 228
 		// Prevent absurd boundaries here - make it a day tops.
226
-		if (isset($_POST['lastActive']))
227
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
229
+		if (isset($_POST['lastActive'])) {
230
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
231
+		}
228 232
 
229 233
 		call_integration_hook('integrate_save_basic_settings');
230 234
 
@@ -232,8 +236,9 @@  discard block
 block discarded – undo
232 236
 		$_SESSION['adm-save'] = true;
233 237
 
234 238
 		// Do a bit of housekeeping
235
-		if (empty($_POST['minimize_files']))
236
-			deleteAllMinified();
239
+		if (empty($_POST['minimize_files'])) {
240
+					deleteAllMinified();
241
+		}
237 242
 
238 243
 		writeLog();
239 244
 		redirectexit('action=admin;area=featuresettings;sa=basic');
@@ -273,8 +278,9 @@  discard block
 block discarded – undo
273 278
 
274 279
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
275 280
 
276
-	if ($return_config)
277
-		return $config_vars;
281
+	if ($return_config) {
282
+			return $config_vars;
283
+	}
278 284
 
279 285
 	// Setup the template.
280 286
 	require_once($sourcedir . '/ManageServer.php');
@@ -291,13 +297,15 @@  discard block
 block discarded – undo
291 297
 
292 298
 		// Clean up the tags.
293 299
 		$bbcTags = array();
294
-		foreach (parse_bbc(false) as $tag)
295
-			$bbcTags[] = $tag['tag'];
300
+		foreach (parse_bbc(false) as $tag) {
301
+					$bbcTags[] = $tag['tag'];
302
+		}
296 303
 
297
-		if (!isset($_POST['disabledBBC_enabledTags']))
298
-			$_POST['disabledBBC_enabledTags'] = array();
299
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
300
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
304
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
305
+					$_POST['disabledBBC_enabledTags'] = array();
306
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
307
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
308
+		}
301 309
 		// Work out what is actually disabled!
302 310
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
303 311
 
@@ -341,8 +349,9 @@  discard block
 block discarded – undo
341 349
 
342 350
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
343 351
 
344
-	if ($return_config)
345
-		return $config_vars;
352
+	if ($return_config) {
353
+			return $config_vars;
354
+	}
346 355
 
347 356
 	// Saving?
348 357
 	if (isset($_GET['save']))
@@ -382,8 +391,9 @@  discard block
 block discarded – undo
382 391
 
383 392
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
384 393
 
385
-	if ($return_config)
386
-		return $config_vars;
394
+	if ($return_config) {
395
+			return $config_vars;
396
+	}
387 397
 
388 398
 	// Saving?
389 399
 	if (isset($_GET['save']))
@@ -421,8 +431,9 @@  discard block
 block discarded – undo
421 431
 
422 432
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
423 433
 
424
-	if ($return_config)
425
-		return $config_vars;
434
+	if ($return_config) {
435
+			return $config_vars;
436
+	}
426 437
 
427 438
 	// Saving?
428 439
 	if (isset($_GET['save']))
@@ -466,8 +477,8 @@  discard block
 block discarded – undo
466 477
 			'enable' => array('check', 'warning_enable'),
467 478
 	);
468 479
 
469
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
470
-		$config_vars += array(
480
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
481
+			$config_vars += array(
471 482
 			'',
472 483
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
473 484
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -476,15 +487,18 @@  discard block
 block discarded – undo
476 487
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
477 488
 				array('permissions', 'view_warning'),
478 489
 		);
490
+	}
479 491
 
480 492
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
481 493
 
482
-	if ($return_config)
483
-		return $config_vars;
494
+	if ($return_config) {
495
+			return $config_vars;
496
+	}
484 497
 
485 498
 	// Cannot use moderation if post moderation is not enabled.
486
-	if (!$modSettings['postmod_active'])
487
-		unset($config_vars['moderate']);
499
+	if (!$modSettings['postmod_active']) {
500
+			unset($config_vars['moderate']);
501
+	}
488 502
 
489 503
 	// Will need the utility functions from here.
490 504
 	require_once($sourcedir . '/ManageServer.php');
@@ -509,16 +523,16 @@  discard block
 block discarded – undo
509 523
 				'warning_watch' => 10,
510 524
 				'warning_mute' => 60,
511 525
 			);
512
-			if ($modSettings['postmod_active'])
513
-				$vars['warning_moderate'] = 35;
526
+			if ($modSettings['postmod_active']) {
527
+							$vars['warning_moderate'] = 35;
528
+			}
514 529
 
515 530
 			foreach ($vars as $var => $value)
516 531
 			{
517 532
 				$config_vars[] = array('int', $var);
518 533
 				$_POST[$var] = $value;
519 534
 			}
520
-		}
521
-		else
535
+		} else
522 536
 		{
523 537
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
524 538
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -606,8 +620,9 @@  discard block
 block discarded – undo
606 620
 
607 621
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
608 622
 
609
-	if ($return_config)
610
-		return $config_vars;
623
+	if ($return_config) {
624
+			return $config_vars;
625
+	}
611 626
 
612 627
 	// You need to be an admin to edit settings!
613 628
 	isAllowedTo('admin_forum');
@@ -641,8 +656,9 @@  discard block
 block discarded – undo
641 656
 
642 657
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
643 658
 	{
644
-		if (empty($context['settings_insert_above']))
645
-			$context['settings_insert_above'] = '';
659
+		if (empty($context['settings_insert_above'])) {
660
+					$context['settings_insert_above'] = '';
661
+		}
646 662
 
647 663
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
648 664
 	}
@@ -685,8 +701,9 @@  discard block
 block discarded – undo
685 701
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
686 702
 
687 703
 		// Hack in guest requiring verification!
688
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
689
-			$_POST['posts_require_captcha'] = -1;
704
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
705
+					$_POST['posts_require_captcha'] = -1;
706
+		}
690 707
 
691 708
 		$save_vars = $config_vars;
692 709
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -703,14 +720,16 @@  discard block
 block discarded – undo
703 720
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
704 721
 		{
705 722
 			// If we had some questions for this language before, but don't now, delete everything from that language.
706
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
707
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
723
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
724
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
725
+			}
708 726
 
709 727
 			// Now step through and see if any existing questions no longer exist.
710
-			if (!empty($context['qa_by_lang'][$lang_id]))
711
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
728
+			if (!empty($context['qa_by_lang'][$lang_id])) {
729
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
712 730
 					if (empty($_POST['question'][$lang_id][$q_id]))
713 731
 						$changes['delete'][] = $q_id;
732
+			}
714 733
 
715 734
 			// Now let's see if there are new questions or ones that need updating.
716 735
 			if (isset($_POST['question'][$lang_id]))
@@ -719,14 +738,16 @@  discard block
 block discarded – undo
719 738
 				{
720 739
 					// Ignore junky ids.
721 740
 					$q_id = (int) $q_id;
722
-					if ($q_id <= 0)
723
-						continue;
741
+					if ($q_id <= 0) {
742
+											continue;
743
+					}
724 744
 
725 745
 					// Check the question isn't empty (because they want to delete it?)
726 746
 					if (empty($question) || trim($question) == '')
727 747
 					{
728
-						if (isset($context['question_answers'][$q_id]))
729
-							$changes['delete'][] = $q_id;
748
+						if (isset($context['question_answers'][$q_id])) {
749
+													$changes['delete'][] = $q_id;
750
+						}
730 751
 						continue;
731 752
 					}
732 753
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -734,19 +755,22 @@  discard block
 block discarded – undo
734 755
 					// Get the answers. Firstly check there actually might be some.
735 756
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
736 757
 					{
737
-						if (isset($context['question_answers'][$q_id]))
738
-							$changes['delete'][] = $q_id;
758
+						if (isset($context['question_answers'][$q_id])) {
759
+													$changes['delete'][] = $q_id;
760
+						}
739 761
 						continue;
740 762
 					}
741 763
 					// Now get them and check that they might be viable.
742 764
 					$answers = array();
743
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
744
-						if (!empty($answer) && trim($answer) !== '')
765
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
766
+											if (!empty($answer) && trim($answer) !== '')
745 767
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
768
+					}
746 769
 					if (empty($answers))
747 770
 					{
748
-						if (isset($context['question_answers'][$q_id]))
749
-							$changes['delete'][] = $q_id;
771
+						if (isset($context['question_answers'][$q_id])) {
772
+													$changes['delete'][] = $q_id;
773
+						}
750 774
 						continue;
751 775
 					}
752 776
 					$answers = $smcFunc['json_encode']($answers);
@@ -756,16 +780,17 @@  discard block
 block discarded – undo
756 780
 					{
757 781
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
758 782
 						$changes['insert'][] = array($lang_id, $question, $answers);
759
-					}
760
-					else
783
+					} else
761 784
 					{
762 785
 						// It's an existing question. Let's see what's changed, if anything.
763
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
764
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
786
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
787
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
788
+						}
765 789
 					}
766 790
 
767
-					if (!isset($qs_per_lang[$lang_id]))
768
-						$qs_per_lang[$lang_id] = 0;
791
+					if (!isset($qs_per_lang[$lang_id])) {
792
+											$qs_per_lang[$lang_id] = 0;
793
+					}
769 794
 					$qs_per_lang[$lang_id]++;
770 795
 				}
771 796
 			}
@@ -815,8 +840,9 @@  discard block
 block discarded – undo
815 840
 
816 841
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
817 842
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
818
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
819
-			$_POST['qa_verification_number'] = $count_questions;
843
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
844
+					$_POST['qa_verification_number'] = $count_questions;
845
+		}
820 846
 
821 847
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
822 848
 
@@ -831,24 +857,27 @@  discard block
 block discarded – undo
831 857
 
832 858
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
833 859
 	$_SESSION['visual_verification_code'] = '';
834
-	for ($i = 0; $i < 6; $i++)
835
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
860
+	for ($i = 0; $i < 6; $i++) {
861
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
862
+	}
836 863
 
837 864
 	// Some javascript for CAPTCHA.
838 865
 	$context['settings_post_javascript'] = '';
839
-	if ($context['use_graphic_library'])
840
-		$context['settings_post_javascript'] .= '
866
+	if ($context['use_graphic_library']) {
867
+			$context['settings_post_javascript'] .= '
841 868
 		function refreshImages()
842 869
 		{
843 870
 			var imageType = document.getElementById(\'visual_verification_type\').value;
844 871
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
845 872
 		}';
873
+	}
846 874
 
847 875
 	// Show the image itself, or text saying we can't.
848
-	if ($context['use_graphic_library'])
849
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
850
-	else
851
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
876
+	if ($context['use_graphic_library']) {
877
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
878
+	} else {
879
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
880
+	}
852 881
 
853 882
 	// Hack for PM spam settings.
854 883
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -858,9 +887,10 @@  discard block
 block discarded – undo
858 887
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
859 888
 
860 889
 	// Some minor javascript for the guest post setting.
861
-	if ($modSettings['posts_require_captcha'])
862
-		$context['settings_post_javascript'] .= '
890
+	if ($modSettings['posts_require_captcha']) {
891
+			$context['settings_post_javascript'] .= '
863 892
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
893
+	}
864 894
 
865 895
 	// And everything else.
866 896
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -907,8 +937,9 @@  discard block
 block discarded – undo
907 937
 
908 938
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
909 939
 
910
-	if ($return_config)
911
-		return $config_vars;
940
+	if ($return_config) {
941
+			return $config_vars;
942
+	}
912 943
 
913 944
 	// Setup the template.
914 945
 	$context['page_title'] = $txt['signature_settings'];
@@ -963,8 +994,9 @@  discard block
 block discarded – undo
963 994
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
964 995
 
965 996
 				// Max characters...
966
-				if (!empty($sig_limits[1]))
967
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
997
+				if (!empty($sig_limits[1])) {
998
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
999
+				}
968 1000
 				// Max lines...
969 1001
 				if (!empty($sig_limits[2]))
970 1002
 				{
@@ -974,8 +1006,9 @@  discard block
 block discarded – undo
974 1006
 						if ($sig[$i] == "\n")
975 1007
 						{
976 1008
 							$count++;
977
-							if ($count >= $sig_limits[2])
978
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1009
+							if ($count >= $sig_limits[2]) {
1010
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1011
+							}
979 1012
 						}
980 1013
 					}
981 1014
 				}
@@ -986,17 +1019,19 @@  discard block
 block discarded – undo
986 1019
 					{
987 1020
 						$limit_broke = 0;
988 1021
 						// Attempt to allow all sizes of abuse, so to speak.
989
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
990
-							$limit_broke = $sig_limits[7] . 'px';
991
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
992
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
993
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
994
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
995
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
996
-							$limit_broke = 'large';
997
-
998
-						if ($limit_broke)
999
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1022
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1023
+													$limit_broke = $sig_limits[7] . 'px';
1024
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1025
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1026
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1027
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1028
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1029
+													$limit_broke = 'large';
1030
+						}
1031
+
1032
+						if ($limit_broke) {
1033
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1034
+						}
1000 1035
 					}
1001 1036
 				}
1002 1037
 
@@ -1052,32 +1087,34 @@  discard block
 block discarded – undo
1052 1087
 											$img_offset = false;
1053 1088
 										}
1054 1089
 									}
1090
+								} else {
1091
+																	$replaces[$image] = '';
1055 1092
 								}
1056
-								else
1057
-									$replaces[$image] = '';
1058 1093
 
1059 1094
 								continue;
1060 1095
 							}
1061 1096
 
1062 1097
 							// Does it have predefined restraints? Width first.
1063
-							if ($matches[6][$key])
1064
-								$matches[2][$key] = $matches[6][$key];
1098
+							if ($matches[6][$key]) {
1099
+															$matches[2][$key] = $matches[6][$key];
1100
+							}
1065 1101
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1066 1102
 							{
1067 1103
 								$width = $sig_limits[5];
1068 1104
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1105
+							} elseif ($matches[2][$key]) {
1106
+															$width = $matches[2][$key];
1069 1107
 							}
1070
-							elseif ($matches[2][$key])
1071
-								$width = $matches[2][$key];
1072 1108
 							// ... and height.
1073 1109
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1074 1110
 							{
1075 1111
 								$height = $sig_limits[6];
1076
-								if ($width != -1)
1077
-									$width = $width * ($height / $matches[4][$key]);
1112
+								if ($width != -1) {
1113
+																	$width = $width * ($height / $matches[4][$key]);
1114
+								}
1115
+							} elseif ($matches[4][$key]) {
1116
+															$height = $matches[4][$key];
1078 1117
 							}
1079
-							elseif ($matches[4][$key])
1080
-								$height = $matches[4][$key];
1081 1118
 
1082 1119
 							// If the dimensions are still not fixed - we need to check the actual image.
1083 1120
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1095,12 +1132,13 @@  discard block
 block discarded – undo
1095 1132
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1096 1133
 									{
1097 1134
 										$height = $sig_limits[6];
1098
-										if ($width == -1)
1099
-											$width = $sizes[0];
1135
+										if ($width == -1) {
1136
+																					$width = $sizes[0];
1137
+										}
1100 1138
 										$width = $width * ($height / $sizes[1]);
1139
+									} elseif ($width != -1) {
1140
+																			$height = $sizes[1];
1101 1141
 									}
1102
-									elseif ($width != -1)
1103
-										$height = $sizes[1];
1104 1142
 								}
1105 1143
 							}
1106 1144
 
@@ -1113,8 +1151,9 @@  discard block
 block discarded – undo
1113 1151
 							// Record that we got one.
1114 1152
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1115 1153
 						}
1116
-						if (!empty($replaces))
1117
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1154
+						if (!empty($replaces)) {
1155
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1156
+						}
1118 1157
 					}
1119 1158
 				}
1120 1159
 				// Try to fix disabled tags.
@@ -1126,18 +1165,20 @@  discard block
 block discarded – undo
1126 1165
 
1127 1166
 				$sig = strtr($sig, array("\n" => '<br>'));
1128 1167
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1129
-				if ($sig != $row['signature'])
1130
-					$changes[$row['id_member']] = $sig;
1168
+				if ($sig != $row['signature']) {
1169
+									$changes[$row['id_member']] = $sig;
1170
+				}
1171
+			}
1172
+			if ($smcFunc['db_num_rows']($request) == 0) {
1173
+							$done = true;
1131 1174
 			}
1132
-			if ($smcFunc['db_num_rows']($request) == 0)
1133
-				$done = true;
1134 1175
 			$smcFunc['db_free_result']($request);
1135 1176
 
1136 1177
 			// Do we need to delete what we have?
1137 1178
 			if (!empty($changes))
1138 1179
 			{
1139
-				foreach ($changes as $id => $sig)
1140
-					$smcFunc['db_query']('', '
1180
+				foreach ($changes as $id => $sig) {
1181
+									$smcFunc['db_query']('', '
1141 1182
 						UPDATE {db_prefix}members
1142 1183
 						SET signature = {string:signature}
1143 1184
 						WHERE id_member = {int:id_member}',
@@ -1146,11 +1187,13 @@  discard block
 block discarded – undo
1146 1187
 							'signature' => $sig,
1147 1188
 						)
1148 1189
 					);
1190
+				}
1149 1191
 			}
1150 1192
 
1151 1193
 			$_GET['step'] += 50;
1152
-			if (!$done)
1153
-				pauseSignatureApplySettings();
1194
+			if (!$done) {
1195
+							pauseSignatureApplySettings();
1196
+			}
1154 1197
 		}
1155 1198
 		$settings_applied = true;
1156 1199
 	}
@@ -1168,8 +1211,9 @@  discard block
 block discarded – undo
1168 1211
 	);
1169 1212
 
1170 1213
 	// Temporarily make each setting a modSetting!
1171
-	foreach ($context['signature_settings'] as $key => $value)
1172
-		$modSettings['signature_' . $key] = $value;
1214
+	foreach ($context['signature_settings'] as $key => $value) {
1215
+			$modSettings['signature_' . $key] = $value;
1216
+	}
1173 1217
 
1174 1218
 	// Make sure we check the right tags!
1175 1219
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1181,23 +1225,26 @@  discard block
 block discarded – undo
1181 1225
 
1182 1226
 		// Clean up the tag stuff!
1183 1227
 		$bbcTags = array();
1184
-		foreach (parse_bbc(false) as $tag)
1185
-			$bbcTags[] = $tag['tag'];
1228
+		foreach (parse_bbc(false) as $tag) {
1229
+					$bbcTags[] = $tag['tag'];
1230
+		}
1186 1231
 
1187
-		if (!isset($_POST['signature_bbc_enabledTags']))
1188
-			$_POST['signature_bbc_enabledTags'] = array();
1189
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1190
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1232
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1233
+					$_POST['signature_bbc_enabledTags'] = array();
1234
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1235
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1236
+		}
1191 1237
 
1192 1238
 		$sig_limits = array();
1193 1239
 		foreach ($context['signature_settings'] as $key => $value)
1194 1240
 		{
1195
-			if ($key == 'allow_smileys')
1196
-				continue;
1197
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1198
-				$sig_limits[] = -1;
1199
-			else
1200
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1241
+			if ($key == 'allow_smileys') {
1242
+							continue;
1243
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1244
+							$sig_limits[] = -1;
1245
+			} else {
1246
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1247
+			}
1201 1248
 		}
1202 1249
 
1203 1250
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1230,12 +1277,14 @@  discard block
 block discarded – undo
1230 1277
 
1231 1278
 	// Try get more time...
1232 1279
 	@set_time_limit(600);
1233
-	if (function_exists('apache_reset_timeout'))
1234
-		@apache_reset_timeout();
1280
+	if (function_exists('apache_reset_timeout')) {
1281
+			@apache_reset_timeout();
1282
+	}
1235 1283
 
1236 1284
 	// Have we exhausted all the time we allowed?
1237
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1238
-		return;
1285
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1286
+			return;
1287
+	}
1239 1288
 
1240 1289
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1241 1290
 	$context['page_title'] = $txt['not_done_title'];
@@ -1281,9 +1330,10 @@  discard block
 block discarded – undo
1281 1330
 		$disable_fields = array_flip($standard_fields);
1282 1331
 		if (!empty($_POST['active']))
1283 1332
 		{
1284
-			foreach ($_POST['active'] as $value)
1285
-				if (isset($disable_fields[$value]))
1333
+			foreach ($_POST['active'] as $value) {
1334
+							if (isset($disable_fields[$value]))
1286 1335
 					unset($disable_fields[$value]);
1336
+			}
1287 1337
 		}
1288 1338
 		// What we have left!
1289 1339
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1292,16 +1342,18 @@  discard block
 block discarded – undo
1292 1342
 		$reg_fields = array();
1293 1343
 		if (!empty($_POST['reg']))
1294 1344
 		{
1295
-			foreach ($_POST['reg'] as $value)
1296
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1345
+			foreach ($_POST['reg'] as $value) {
1346
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1297 1347
 					$reg_fields[] = $value;
1348
+			}
1298 1349
 		}
1299 1350
 		// What we have left!
1300 1351
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1301 1352
 
1302 1353
 		$_SESSION['adm-save'] = true;
1303
-		if (!empty($changes))
1304
-			updateSettings($changes);
1354
+		if (!empty($changes)) {
1355
+					updateSettings($changes);
1356
+		}
1305 1357
 	}
1306 1358
 
1307 1359
 	createToken('admin-scp');
@@ -1404,11 +1456,13 @@  discard block
 block discarded – undo
1404 1456
 					{
1405 1457
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1406 1458
 
1407
-						if ($rowData['field_order'] > 1)
1408
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1459
+						if ($rowData['field_order'] > 1) {
1460
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1461
+						}
1409 1462
 
1410
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1411
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1463
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1464
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1465
+						}
1412 1466
 
1413 1467
 						$return .= '</p>';
1414 1468
 
@@ -1546,16 +1600,16 @@  discard block
 block discarded – undo
1546 1600
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1547 1601
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1548 1602
 
1549
-		foreach ($standard_fields as $field)
1550
-			$list[] = array(
1603
+		foreach ($standard_fields as $field) {
1604
+					$list[] = array(
1551 1605
 				'id' => $field,
1552 1606
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1553 1607
 				'disabled' => in_array($field, $disabled_fields),
1554 1608
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1555 1609
 				'can_show_register' => !in_array($field, $fields_no_registration),
1556 1610
 			);
1557
-	}
1558
-	else
1611
+		}
1612
+	} else
1559 1613
 	{
1560 1614
 		// Load all the fields.
1561 1615
 		$request = $smcFunc['db_query']('', '
@@ -1569,8 +1623,9 @@  discard block
 block discarded – undo
1569 1623
 				'items_per_page' => $items_per_page,
1570 1624
 			)
1571 1625
 		);
1572
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1573
-			$list[] = $row;
1626
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1627
+					$list[] = $row;
1628
+		}
1574 1629
 		$smcFunc['db_free_result']($request);
1575 1630
 	}
1576 1631
 
@@ -1636,9 +1691,9 @@  discard block
 block discarded – undo
1636 1691
 		$context['field'] = array();
1637 1692
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1638 1693
 		{
1639
-			if ($row['field_type'] == 'textarea')
1640
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1641
-			else
1694
+			if ($row['field_type'] == 'textarea') {
1695
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1696
+			} else
1642 1697
 			{
1643 1698
 				$rows = 3;
1644 1699
 				$cols = 30;
@@ -1674,8 +1729,8 @@  discard block
 block discarded – undo
1674 1729
 	}
1675 1730
 
1676 1731
 	// Setup the default values as needed.
1677
-	if (empty($context['field']))
1678
-		$context['field'] = array(
1732
+	if (empty($context['field'])) {
1733
+			$context['field'] = array(
1679 1734
 			'name' => '',
1680 1735
 			'col_name' => '???',
1681 1736
 			'desc' => '',
@@ -1700,6 +1755,7 @@  discard block
 block discarded – undo
1700 1755
 			'enclose' => '',
1701 1756
 			'placement' => 0,
1702 1757
 		);
1758
+	}
1703 1759
 
1704 1760
 	// Are we moving it?
1705 1761
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1708,8 +1764,10 @@  discard block
 block discarded – undo
1708 1764
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1709 1765
 
1710 1766
 		// Is this a valid position?
1711
-		if ($new_order <= 0 || $new_order > $order_count)
1712
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1767
+		if ($new_order <= 0 || $new_order > $order_count) {
1768
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1769
+		}
1770
+		// @todo implement an error handler
1713 1771
 
1714 1772
 		// All good, proceed.
1715 1773
 		$smcFunc['db_query']('','
@@ -1740,12 +1798,14 @@  discard block
 block discarded – undo
1740 1798
 		validateToken('admin-ecp');
1741 1799
 
1742 1800
 		// Everyone needs a name - even the (bracket) unknown...
1743
-		if (trim($_POST['field_name']) == '')
1744
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1801
+		if (trim($_POST['field_name']) == '') {
1802
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1803
+		}
1745 1804
 
1746 1805
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1747
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1748
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1806
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1807
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1808
+		}
1749 1809
 
1750 1810
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1751 1811
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1762,8 +1822,9 @@  discard block
 block discarded – undo
1762 1822
 
1763 1823
 		// Some masking stuff...
1764 1824
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1765
-		if ($mask == 'regex' && isset($_POST['regex']))
1766
-			$mask .= $_POST['regex'];
1825
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1826
+					$mask .= $_POST['regex'];
1827
+		}
1767 1828
 
1768 1829
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1769 1830
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1782,8 +1843,9 @@  discard block
 block discarded – undo
1782 1843
 				$v = strtr($v, array(',' => ''));
1783 1844
 
1784 1845
 				// Nada, zip, etc...
1785
-				if (trim($v) == '')
1786
-					continue;
1846
+				if (trim($v) == '') {
1847
+									continue;
1848
+				}
1787 1849
 
1788 1850
 				// Otherwise, save it boy.
1789 1851
 				$field_options .= $v . ',';
@@ -1791,15 +1853,17 @@  discard block
 block discarded – undo
1791 1853
 				$newOptions[$k] = $v;
1792 1854
 
1793 1855
 				// Is it default?
1794
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1795
-					$default = $v;
1856
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1857
+									$default = $v;
1858
+				}
1796 1859
 			}
1797 1860
 			$field_options = substr($field_options, 0, -1);
1798 1861
 		}
1799 1862
 
1800 1863
 		// Text area has default has dimensions
1801
-		if ($_POST['field_type'] == 'textarea')
1802
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1864
+		if ($_POST['field_type'] == 'textarea') {
1865
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1866
+		}
1803 1867
 
1804 1868
 		// Come up with the unique name?
1805 1869
 		if (empty($context['fid']))
@@ -1808,32 +1872,36 @@  discard block
 block discarded – undo
1808 1872
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1809 1873
 
1810 1874
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1811
-			if (isset($matches[1]))
1812
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1813
-			else
1814
-				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1875
+			if (isset($matches[1])) {
1876
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1877
+			} else {
1878
+							$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1879
+			}
1815 1880
 
1816 1881
 			// Make sure this is unique.
1817 1882
 			$current_fields = array();
1818 1883
 			$request = $smcFunc['db_query']('', '
1819 1884
 				SELECT id_field, col_name
1820 1885
 				FROM {db_prefix}custom_fields');
1821
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1822
-				$current_fields[$row['id_field']] = $row['col_name'];
1886
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1887
+							$current_fields[$row['id_field']] = $row['col_name'];
1888
+			}
1823 1889
 			$smcFunc['db_free_result']($request);
1824 1890
 
1825 1891
 			$unique = false;
1826 1892
 			for ($i = 0; !$unique && $i < 9; $i ++)
1827 1893
 			{
1828
-				if (!in_array($col_name, $current_fields))
1829
-					$unique = true;
1830
-				else
1831
-					$col_name = $initial_col_name . $i;
1894
+				if (!in_array($col_name, $current_fields)) {
1895
+									$unique = true;
1896
+				} else {
1897
+									$col_name = $initial_col_name . $i;
1898
+				}
1832 1899
 			}
1833 1900
 
1834 1901
 			// Still not a unique column name? Leave it up to the user, then.
1835
-			if (!$unique)
1836
-				fatal_lang_error('custom_option_not_unique');
1902
+			if (!$unique) {
1903
+							fatal_lang_error('custom_option_not_unique');
1904
+			}
1837 1905
 		}
1838 1906
 		// Work out what to do with the user data otherwise...
1839 1907
 		else
@@ -1861,8 +1929,9 @@  discard block
 block discarded – undo
1861 1929
 				// Work out what's changed!
1862 1930
 				foreach ($context['field']['options'] as $k => $option)
1863 1931
 				{
1864
-					if (trim($option) == '')
1865
-						continue;
1932
+					if (trim($option) == '') {
1933
+											continue;
1934
+					}
1866 1935
 
1867 1936
 					// Still exists?
1868 1937
 					if (in_array($option, $newOptions))
@@ -1876,8 +1945,8 @@  discard block
 block discarded – undo
1876 1945
 				foreach ($optionChanges as $k => $option)
1877 1946
 				{
1878 1947
 					// Just been renamed?
1879
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1880
-						$smcFunc['db_query']('', '
1948
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1949
+											$smcFunc['db_query']('', '
1881 1950
 							UPDATE {db_prefix}themes
1882 1951
 							SET value = {string:new_value}
1883 1952
 							WHERE variable = {string:current_column}
@@ -1890,6 +1959,7 @@  discard block
 block discarded – undo
1890 1959
 								'old_value' => $option,
1891 1960
 							)
1892 1961
 						);
1962
+					}
1893 1963
 				}
1894 1964
 			}
1895 1965
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1932,8 +2002,8 @@  discard block
 block discarded – undo
1932 2002
 			);
1933 2003
 
1934 2004
 			// Just clean up any old selects - these are a pain!
1935
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1936
-				$smcFunc['db_query']('', '
2005
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
2006
+							$smcFunc['db_query']('', '
1937 2007
 					DELETE FROM {db_prefix}themes
1938 2008
 					WHERE variable = {string:current_column}
1939 2009
 						AND value NOT IN ({array_string:new_option_values})
@@ -1944,8 +2014,8 @@  discard block
 block discarded – undo
1944 2014
 						'current_column' => $context['field']['col_name'],
1945 2015
 					)
1946 2016
 				);
1947
-		}
1948
-		else
2017
+			}
2018
+		} else
1949 2019
 		{
1950 2020
 			// Gotta figure it out the order.
1951 2021
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2120,11 +2190,13 @@  discard block
 block discarded – undo
2120 2190
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2121 2191
 
2122 2192
 	$prune_toggle_dt = array();
2123
-	foreach ($prune_toggle as $item)
2124
-		$prune_toggle_dt[] = 'setting_' . $item;
2193
+	foreach ($prune_toggle as $item) {
2194
+			$prune_toggle_dt[] = 'setting_' . $item;
2195
+	}
2125 2196
 
2126
-	if ($return_config)
2127
-		return $config_vars;
2197
+	if ($return_config) {
2198
+			return $config_vars;
2199
+	}
2128 2200
 
2129 2201
 	addInlineJavaScript('
2130 2202
 	function togglePruned()
@@ -2162,15 +2234,16 @@  discard block
 block discarded – undo
2162 2234
 			$vals = array();
2163 2235
 			foreach ($config_vars as $index => $dummy)
2164 2236
 			{
2165
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2166
-					continue;
2237
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2238
+									continue;
2239
+				}
2167 2240
 
2168 2241
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2169 2242
 			}
2170 2243
 			$_POST['pruningOptions'] = implode(',', $vals);
2244
+		} else {
2245
+					$_POST['pruningOptions'] = '';
2171 2246
 		}
2172
-		else
2173
-			$_POST['pruningOptions'] = '';
2174 2247
 
2175 2248
 		saveDBSettings($savevar);
2176 2249
 		$_SESSION['adm-save'] = true;
@@ -2182,10 +2255,11 @@  discard block
 block discarded – undo
2182 2255
 	$context['sub_template'] = 'show_settings';
2183 2256
 
2184 2257
 	// Get the actual values
2185
-	if (!empty($modSettings['pruningOptions']))
2186
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2187
-	else
2188
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2258
+	if (!empty($modSettings['pruningOptions'])) {
2259
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2260
+	} else {
2261
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2262
+	}
2189 2263
 
2190 2264
 	prepareDBSettingContext($config_vars);
2191 2265
 }
@@ -2207,8 +2281,9 @@  discard block
 block discarded – undo
2207 2281
 	// Make it even easier to add new settings.
2208 2282
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2209 2283
 
2210
-	if ($return_config)
2211
-		return $config_vars;
2284
+	if ($return_config) {
2285
+			return $config_vars;
2286
+	}
2212 2287
 
2213 2288
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2214 2289
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +280 added lines, -203 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -519,15 +544,17 @@  discard block
 block discarded – undo
519 544
 
520 545
 		// Store this useful data!
521 546
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
547
+		if ($row['id_topic']) {
548
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
549
+		} else {
550
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
551
+		}
526 552
 	}
527 553
 	$smcFunc['db_free_result']($request);
528 554
 
529
-	if (empty($boards))
530
-		return true;
555
+	if (empty($boards)) {
556
+			return true;
557
+	}
531 558
 
532 559
 	// Just get the board names.
533 560
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +566,14 @@  discard block
 block discarded – undo
539 566
 		)
540 567
 	);
541 568
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
569
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
570
+			$boards[$row['id_board']] = $row['name'];
571
+	}
544 572
 	$smcFunc['db_free_result']($request);
545 573
 
546
-	if (empty($boards))
547
-		return true;
574
+	if (empty($boards)) {
575
+			return true;
576
+	}
548 577
 
549 578
 	// Get the actual topics...
550 579
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +593,57 @@  discard block
 block discarded – undo
564 593
 	$types = array();
565 594
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 595
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
596
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
597
+					$types[$row['note_type']][$row['id_board']] = array(
569 598
 				'lines' => array(),
570 599
 				'name' => $row['board_name'],
571 600
 				'id' => $row['id_board'],
572 601
 			);
602
+		}
573 603
 
574 604
 		if ($row['note_type'] == 'reply')
575 605
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
606
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
607
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
608
+			} else {
609
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 610
 					'id' => $row['id_topic'],
581 611
 					'subject' => un_htmlspecialchars($row['subject']),
582 612
 					'count' => 1,
583 613
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
614
+			}
615
+		} elseif ($row['note_type'] == 'topic')
586 616
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
617
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
618
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 619
 					'id' => $row['id_topic'],
590 620
 					'subject' => un_htmlspecialchars($row['subject']),
591 621
 				);
592
-		}
593
-		else
622
+			}
623
+		} else
594 624
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
625
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
626
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 627
 					'id' => $row['id_topic'],
598 628
 					'subject' => un_htmlspecialchars($row['subject']),
599 629
 					'starter' => $row['id_member_started'],
600 630
 				);
631
+			}
601 632
 		}
602 633
 
603 634
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
635
+		if (!empty($notify['topics'][$row['id_topic']])) {
636
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
637
+		}
638
+		if (!empty($notify['boards'][$row['id_board']])) {
639
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
640
+		}
608 641
 	}
609 642
 	$smcFunc['db_free_result']($request);
610 643
 
611
-	if (empty($types))
612
-		return true;
644
+	if (empty($types)) {
645
+			return true;
646
+	}
613 647
 
614 648
 	// Let's load all the languages into a cache thingy.
615 649
 	$langtxt = array();
@@ -650,8 +684,9 @@  discard block
 block discarded – undo
650 684
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 685
 
652 686
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
687
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
688
+					continue;
689
+		}
655 690
 
656 691
 		// Right character set!
657 692
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +702,43 @@  discard block
 block discarded – undo
667 702
 		if (isset($types['topic']))
668 703
 		{
669 704
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
705
+			foreach ($types['topic'] as $id => $board) {
706
+							foreach ($board['lines'] as $topic)
672 707
 					if (in_array($mid, $topic['members']))
673 708
 					{
674 709
 						if (!$titled)
675 710
 						{
676 711
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
712
+			}
677 713
 							$titled = true;
678 714
 						}
679 715
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 716
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
717
+			if ($titled) {
718
+							$email['body'] .= "\n";
719
+			}
683 720
 		}
684 721
 
685 722
 		// What about replies?
686 723
 		if (isset($types['reply']))
687 724
 		{
688 725
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
726
+			foreach ($types['reply'] as $id => $board) {
727
+							foreach ($board['lines'] as $topic)
691 728
 					if (in_array($mid, $topic['members']))
692 729
 					{
693 730
 						if (!$titled)
694 731
 						{
695 732
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
733
+			}
696 734
 							$titled = true;
697 735
 						}
698 736
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 737
 					}
700 738
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
739
+			if ($titled) {
740
+							$email['body'] .= "\n";
741
+			}
703 742
 		}
704 743
 
705 744
 		// Finally, moderation actions!
@@ -708,24 +747,27 @@  discard block
 block discarded – undo
708 747
 			$titled = false;
709 748
 			foreach ($types as $note_type => $type)
710 749
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
750
+				if ($note_type == 'topic' || $note_type == 'reply') {
751
+									continue;
752
+				}
713 753
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
754
+				foreach ($type as $id => $board) {
755
+									foreach ($board['lines'] as $topic)
716 756
 						if (in_array($mid, $topic['members']))
717 757
 						{
718 758
 							if (!$titled)
719 759
 							{
720 760
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
761
+				}
721 762
 								$titled = true;
722 763
 							}
723 764
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 765
 						}
725 766
 			}
726 767
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
768
+		if ($titled) {
769
+					$email['body'] .= "\n";
770
+		}
729 771
 
730 772
 		// Then just say our goodbyes!
731 773
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +795,7 @@  discard block
 block discarded – undo
753 795
 				'not_daily' => 0,
754 796
 			)
755 797
 		);
756
-	}
757
-	else
798
+	} else
758 799
 	{
759 800
 		// Clear any only weekly ones, and stop us from sending daily again.
760 801
 		$smcFunc['db_query']('', '
@@ -816,16 +857,19 @@  discard block
 block discarded – undo
816 857
 	global $modSettings, $smcFunc, $sourcedir;
817 858
 
818 859
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
860
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
861
+			return false;
862
+	}
821 863
 
822 864
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
865
+	if (!$number) {
866
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
867
+	}
825 868
 
826 869
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
870
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
871
+			return false;
872
+	}
829 873
 
830 874
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 875
 	if (!$override_limit)
@@ -842,8 +886,9 @@  discard block
 block discarded – undo
842 886
 				'last_send' => $modSettings['mail_next_send'],
843 887
 			)
844 888
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
889
+		if ($smcFunc['db_affected_rows']() == 0) {
890
+					return false;
891
+		}
847 892
 		$modSettings['mail_next_send'] = time() + $delay;
848 893
 	}
849 894
 
@@ -864,8 +909,9 @@  discard block
 block discarded – undo
864 909
 			$mn += $number;
865 910
 		}
866 911
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
912
+		else {
913
+					return false;
914
+		}
869 915
 
870 916
 		// Reflect that we're about to send some, do it now to be safe.
871 917
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +946,15 @@  discard block
 block discarded – undo
900 946
 	$smcFunc['db_free_result']($request);
901 947
 
902 948
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
949
+	if (!empty($ids)) {
950
+			$smcFunc['db_query']('', '
905 951
 			DELETE FROM {db_prefix}mail_queue
906 952
 			WHERE id_mail IN ({array_int:mail_list})',
907 953
 			array(
908 954
 				'mail_list' => $ids,
909 955
 			)
910 956
 		);
957
+	}
911 958
 
912 959
 	// Don't believe we have any left?
913 960
 	if (count($ids) < $number)
@@ -925,11 +972,13 @@  discard block
 block discarded – undo
925 972
 		);
926 973
 	}
927 974
 
928
-	if (empty($ids))
929
-		return false;
975
+	if (empty($ids)) {
976
+			return false;
977
+	}
930 978
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
979
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
980
+			require_once($sourcedir . '/Subs-Post.php');
981
+	}
933 982
 
934 983
 	// Send each email, yea!
935 984
 	$failed_emails = array();
@@ -949,15 +998,17 @@  discard block
 block discarded – undo
949 998
 
950 999
 			// Try to stop a timeout, this would be bad...
951 1000
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1001
+			if (function_exists('apache_reset_timeout')) {
1002
+							@apache_reset_timeout();
1003
+			}
1004
+		} else {
1005
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1006
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1007
 
958 1008
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1009
+		if (!$result) {
1010
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1011
+		}
961 1012
 	}
962 1013
 
963 1014
 	// Any emails that didn't send?
@@ -972,8 +1023,8 @@  discard block
 block discarded – undo
972 1023
 		);
973 1024
 
974 1025
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1026
+		if ($modSettings['mail_failed_attempts'] > 5) {
1027
+					$smcFunc['db_query']('', '
977 1028
 				UPDATE {db_prefix}settings
978 1029
 				SET value = {string:next_mail_send}
979 1030
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1033,7 @@  discard block
 block discarded – undo
982 1033
 					'next_mail_send' => time() + 60,
983 1034
 					'last_send' => $modSettings['mail_next_send'],
984 1035
 			));
1036
+		}
985 1037
 
986 1038
 		// Add our email back to the queue, manually.
987 1039
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1046,8 @@  discard block
 block discarded – undo
994 1046
 		return false;
995 1047
 	}
996 1048
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1049
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1050
+			$smcFunc['db_query']('', '
999 1051
 			UPDATE {db_prefix}settings
1000 1052
 			SET value = {string:zero}
1001 1053
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1055,7 @@  discard block
 block discarded – undo
1003 1055
 				'zero' => '0',
1004 1056
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1057
 		));
1058
+	}
1006 1059
 
1007 1060
 	// Had something to send...
1008 1061
 	return true;
@@ -1019,16 +1072,18 @@  discard block
 block discarded – undo
1019 1072
 	global $modSettings, $smcFunc;
1020 1073
 
1021 1074
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1075
+	if (!is_array($tasks)) {
1076
+			$tasks = array($tasks);
1077
+	}
1024 1078
 
1025 1079
 	// Actually have something passed?
1026 1080
 	if (!empty($tasks))
1027 1081
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1082
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1083
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1084
+		} else {
1085
+					$task_query = ' AND task IN ({array_string:tasks})';
1086
+		}
1032 1087
 	}
1033 1088
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1089
 
@@ -1049,20 +1104,22 @@  discard block
 block discarded – undo
1049 1104
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1105
 
1051 1106
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1107
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1108
+					$tasks[$row['id_task']] = $next_time;
1109
+		} else {
1110
+					$next_time = $row['next_time'];
1111
+		}
1056 1112
 
1057 1113
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1114
+		if ($next_time < $nextTaskTime) {
1115
+					$nextTaskTime = $next_time;
1116
+		}
1060 1117
 	}
1061 1118
 	$smcFunc['db_free_result']($request);
1062 1119
 
1063 1120
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1121
+	foreach ($tasks as $id => $time) {
1122
+			$smcFunc['db_query']('', '
1066 1123
 			UPDATE {db_prefix}scheduled_tasks
1067 1124
 			SET next_time = {int:next_time}
1068 1125
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1128,13 @@  discard block
 block discarded – undo
1071 1128
 				'id_task' => $id,
1072 1129
 			)
1073 1130
 		);
1131
+	}
1074 1132
 
1075 1133
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1134
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1135
+			updateSettings(array('next_task_time' => $nextTaskTime));
1136
+	}
1137
+	}
1079 1138
 
1080 1139
 /**
1081 1140
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1147,9 @@  discard block
 block discarded – undo
1088 1147
 function next_time($regularity, $unit, $offset)
1089 1148
 {
1090 1149
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1150
+	if ($regularity == 0) {
1151
+			$regularity = 2;
1152
+	}
1093 1153
 
1094 1154
 	$curMin = date('i', time());
1095 1155
 
@@ -1099,15 +1159,16 @@  discard block
 block discarded – undo
1099 1159
 		$off = date('i', $offset);
1100 1160
 
1101 1161
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1162
+		if ($off == $curMin) {
1163
+					$next_time = time() + $regularity;
1164
+		} else
1105 1165
 		{
1106 1166
 			// Make sure that the offset is always in the past.
1107 1167
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1168
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1169
+			while ($off <= $curMin) {
1170
+							$off += $regularity;
1171
+			}
1111 1172
 
1112 1173
 			// Now we know when the time should be!
1113 1174
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1188,13 @@  discard block
 block discarded – undo
1127 1188
 		// Default we'll jump in hours.
1128 1189
 		$applyOffset = 3600;
1129 1190
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1191
+		if ($unit == 'd') {
1192
+					$applyOffset = 86400;
1193
+		}
1132 1194
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1195
+		if ($unit == 'w') {
1196
+					$applyOffset = 604800;
1197
+		}
1135 1198
 
1136 1199
 		$applyOffset *= $regularity;
1137 1200
 
@@ -1168,8 +1231,9 @@  discard block
 block discarded – undo
1168 1231
 		$settings[$row['variable']] = $row['value'];
1169 1232
 
1170 1233
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1234
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1235
+					$settings['default_' . $row['variable']] = $row['value'];
1236
+		}
1173 1237
 	}
1174 1238
 	$smcFunc['db_free_result']($result);
1175 1239
 
@@ -1179,12 +1243,14 @@  discard block
 block discarded – undo
1179 1243
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1244
 
1181 1245
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1246
+		if (!empty($settings['base_theme_dir'])) {
1247
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1248
+		}
1184 1249
 
1185 1250
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1251
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1252
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1253
+		}
1188 1254
 	}
1189 1255
 
1190 1256
 	// Assume we want this.
@@ -1328,8 +1394,9 @@  discard block
 block discarded – undo
1328 1394
 	// Ok should we prune the logs?
1329 1395
 	if (!empty($modSettings['pruningOptions']))
1330 1396
 	{
1331
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1332
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1397
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1398
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1399
+		}
1333 1400
 
1334 1401
 		if (!empty($modSettings['pruneErrorLog']))
1335 1402
 		{
@@ -1395,8 +1462,9 @@  discard block
 block discarded – undo
1395 1462
 				)
1396 1463
 			);
1397 1464
 
1398
-			while ($row = $smcFunc['db_fetch_row']($result))
1399
-				$reports[] = $row[0];
1465
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1466
+							$reports[] = $row[0];
1467
+			}
1400 1468
 
1401 1469
 			$smcFunc['db_free_result']($result);
1402 1470
 
@@ -1481,8 +1549,9 @@  discard block
 block discarded – undo
1481 1549
 	);
1482 1550
 
1483 1551
 	// Run Cache housekeeping
1484
-	if (!empty($cache_enable) && !empty($cacheAPI))
1485
-		$cacheAPI->housekeeping();
1552
+	if (!empty($cache_enable) && !empty($cacheAPI)) {
1553
+			$cacheAPI->housekeeping();
1554
+	}
1486 1555
 
1487 1556
 	// Prevent stale minimized CSS and JavaScript from cluttering up the theme directories
1488 1557
 	deleteAllMinified();
@@ -1565,8 +1634,9 @@  discard block
 block discarded – undo
1565 1634
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1566 1635
 
1567 1636
 		// Send the actual email.
1568
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1569
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1637
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1638
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1639
+		}
1570 1640
 
1571 1641
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1572 1642
 		{
@@ -1589,18 +1659,19 @@  discard block
 block discarded – undo
1589 1659
 	}
1590 1660
 
1591 1661
 	// Insert the alerts if any
1592
-	if (!empty($alert_rows))
1593
-		$smcFunc['db_insert']('',
1662
+	if (!empty($alert_rows)) {
1663
+			$smcFunc['db_insert']('',
1594 1664
 			'{db_prefix}user_alerts',
1595 1665
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1596 1666
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1597 1667
 			$alert_rows,
1598 1668
 			array()
1599 1669
 		);
1670
+	}
1600 1671
 
1601 1672
 	// Mark the reminder as sent.
1602
-	if (!empty($subs_reminded))
1603
-		$smcFunc['db_query']('', '
1673
+	if (!empty($subs_reminded)) {
1674
+			$smcFunc['db_query']('', '
1604 1675
 			UPDATE {db_prefix}log_subscribed
1605 1676
 			SET reminder_sent = {int:reminder_sent}
1606 1677
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1609,6 +1680,7 @@  discard block
 block discarded – undo
1609 1680
 				'reminder_sent' => 1,
1610 1681
 			)
1611 1682
 		);
1683
+	}
1612 1684
 
1613 1685
 	return true;
1614 1686
 }
@@ -1624,13 +1696,13 @@  discard block
 block discarded – undo
1624 1696
 	// We need to know where this thing is going.
1625 1697
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1626 1698
 	{
1627
-		if (!is_array($modSettings['attachmentUploadDir']))
1628
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1699
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1700
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1701
+		}
1629 1702
 
1630 1703
 		// Just use the current path for temp files.
1631 1704
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1632
-	}
1633
-	else
1705
+	} else
1634 1706
 	{
1635 1707
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1636 1708
 	}
@@ -1649,14 +1721,16 @@  discard block
 block discarded – undo
1649 1721
 
1650 1722
 		while ($file = readdir($dir))
1651 1723
 		{
1652
-			if ($file == '.' || $file == '..')
1653
-				continue;
1724
+			if ($file == '.' || $file == '..') {
1725
+							continue;
1726
+			}
1654 1727
 
1655 1728
 			if (strpos($file, 'post_tmp_') !== false)
1656 1729
 			{
1657 1730
 				// Temp file is more than 5 hours old!
1658
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1659
-					@unlink($attach_dir . '/' . $file);
1731
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1732
+									@unlink($attach_dir . '/' . $file);
1733
+				}
1660 1734
 			}
1661 1735
 		}
1662 1736
 		closedir($dir);
@@ -1689,8 +1763,9 @@  discard block
 block discarded – undo
1689 1763
 		)
1690 1764
 	);
1691 1765
 
1692
-	while ($row = $smcFunc['db_fetch_row']($request))
1693
-		$topics[] = $row[0];
1766
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1767
+			$topics[] = $row[0];
1768
+	}
1694 1769
 	$smcFunc['db_free_result']($request);
1695 1770
 
1696 1771
 	// Zap, your gone
@@ -1710,8 +1785,9 @@  discard block
 block discarded – undo
1710 1785
 {
1711 1786
 	global $smcFunc, $sourcedir, $modSettings;
1712 1787
 
1713
-	if (empty($modSettings['drafts_keep_days']))
1714
-		return true;
1788
+	if (empty($modSettings['drafts_keep_days'])) {
1789
+			return true;
1790
+	}
1715 1791
 
1716 1792
 	// init
1717 1793
 	$drafts = array();
@@ -1729,8 +1805,9 @@  discard block
 block discarded – undo
1729 1805
 		)
1730 1806
 	);
1731 1807
 
1732
-	while ($row = $smcFunc['db_fetch_row']($request))
1733
-		$drafts[] = (int) $row[0];
1808
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1809
+			$drafts[] = (int) $row[0];
1810
+	}
1734 1811
 	$smcFunc['db_free_result']($request);
1735 1812
 
1736 1813
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/ManageMaintenance.php 1 patch
Braces   +275 added lines, -204 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main dispatcher, the maintenance access point.
@@ -96,14 +97,16 @@  discard block
 block discarded – undo
96 97
 	call_integration_hook('integrate_manage_maintenance', array(&$subActions));
97 98
 
98 99
 	// Yep, sub-action time!
99
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
100
-		$subAction = $_REQUEST['sa'];
101
-	else
102
-		$subAction = 'routine';
100
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
101
+			$subAction = $_REQUEST['sa'];
102
+	} else {
103
+			$subAction = 'routine';
104
+	}
103 105
 
104 106
 	// Doing something special?
105
-	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']]))
106
-		$activity = $_REQUEST['activity'];
107
+	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) {
108
+			$activity = $_REQUEST['activity'];
109
+	}
107 110
 
108 111
 	// Set a few things.
109 112
 	$context['page_title'] = $txt['maintain_title'];
@@ -114,12 +117,14 @@  discard block
 block discarded – undo
114 117
 	call_helper($subActions[$subAction]['function']);
115 118
 
116 119
 	// Any special activity?
117
-	if (isset($activity))
118
-		call_helper($subActions[$subAction]['activities'][$activity]);
120
+	if (isset($activity)) {
121
+			call_helper($subActions[$subAction]['activities'][$activity]);
122
+	}
119 123
 
120 124
 	//converted to UTF-8? show a small maintenance info
121
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
122
-		$context['maintenance_finished'] = $txt['utf8_title'];
125
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
126
+			$context['maintenance_finished'] = $txt['utf8_title'];
127
+	}
123 128
 
124 129
 	// Create a maintenance token.  Kinda hard to do it any other way.
125 130
 	createToken('admin-maint');
@@ -141,19 +146,22 @@  discard block
 block discarded – undo
141 146
 		db_extend('packages');
142 147
 
143 148
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
144
-		foreach ($colData as $column)
145
-			if ($column['name'] == 'body')
149
+		foreach ($colData as $column) {
150
+					if ($column['name'] == 'body')
146 151
 				$body_type = $column['type'];
152
+		}
147 153
 
148 154
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
149 155
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
150 156
 	}
151 157
 
152
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
153
-		$context['maintenance_finished'] = $txt['utf8_title'];
154
-	if (isset($_GET['done']) && $_GET['done'] == 'convertentities')
155
-		$context['maintenance_finished'] = $txt['entity_convert_title'];
156
-}
158
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
159
+			$context['maintenance_finished'] = $txt['utf8_title'];
160
+	}
161
+	if (isset($_GET['done']) && $_GET['done'] == 'convertentities') {
162
+			$context['maintenance_finished'] = $txt['entity_convert_title'];
163
+	}
164
+	}
157 165
 
158 166
 /**
159 167
  * Supporting function for the routine maintenance area.
@@ -162,9 +170,10 @@  discard block
 block discarded – undo
162 170
 {
163 171
 	global $context, $txt;
164 172
 
165
-	if (isset($_GET['done']) && $_GET['done'] == 'recount')
166
-		$context['maintenance_finished'] = $txt['maintain_recount'];
167
-}
173
+	if (isset($_GET['done']) && $_GET['done'] == 'recount') {
174
+			$context['maintenance_finished'] = $txt['maintain_recount'];
175
+	}
176
+	}
168 177
 
169 178
 /**
170 179
  * Supporting function for the members maintenance area.
@@ -195,8 +204,9 @@  discard block
 block discarded – undo
195 204
 	}
196 205
 	$smcFunc['db_free_result']($result);
197 206
 
198
-	if (isset($_GET['done']) && $_GET['done'] == 'recountposts')
199
-		$context['maintenance_finished'] = $txt['maintain_recountposts'];
207
+	if (isset($_GET['done']) && $_GET['done'] == 'recountposts') {
208
+			$context['maintenance_finished'] = $txt['maintain_recountposts'];
209
+	}
200 210
 
201 211
 	loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
202 212
 }
@@ -222,11 +232,12 @@  discard block
 block discarded – undo
222 232
 	$context['categories'] = array();
223 233
 	while ($row = $smcFunc['db_fetch_assoc']($result))
224 234
 	{
225
-		if (!isset($context['categories'][$row['id_cat']]))
226
-			$context['categories'][$row['id_cat']] = array(
235
+		if (!isset($context['categories'][$row['id_cat']])) {
236
+					$context['categories'][$row['id_cat']] = array(
227 237
 				'name' => $row['cat_name'],
228 238
 				'boards' => array()
229 239
 			);
240
+		}
230 241
 
231 242
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
232 243
 			'id' => $row['id_board'],
@@ -239,11 +250,12 @@  discard block
 block discarded – undo
239 250
 	require_once($sourcedir . '/Subs-Boards.php');
240 251
 	sortCategories($context['categories']);
241 252
 
242
-	if (isset($_GET['done']) && $_GET['done'] == 'purgeold')
243
-		$context['maintenance_finished'] = $txt['maintain_old'];
244
-	elseif (isset($_GET['done']) && $_GET['done'] == 'massmove')
245
-		$context['maintenance_finished'] = $txt['move_topics_maintenance'];
246
-}
253
+	if (isset($_GET['done']) && $_GET['done'] == 'purgeold') {
254
+			$context['maintenance_finished'] = $txt['maintain_old'];
255
+	} elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') {
256
+			$context['maintenance_finished'] = $txt['move_topics_maintenance'];
257
+	}
258
+	}
247 259
 
248 260
 /**
249 261
  * Find and fix all errors on the forum.
@@ -351,15 +363,17 @@  discard block
 block discarded – undo
351 363
 	// Show me your badge!
352 364
 	isAllowedTo('admin_forum');
353 365
 
354
-	if ($db_type != 'mysql')
355
-		return;
366
+	if ($db_type != 'mysql') {
367
+			return;
368
+	}
356 369
 
357 370
 	db_extend('packages');
358 371
 
359 372
 	$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
360
-	foreach ($colData as $column)
361
-		if ($column['name'] == 'body')
373
+	foreach ($colData as $column) {
374
+			if ($column['name'] == 'body')
362 375
 			$body_type = $column['type'];
376
+	}
363 377
 
364 378
 	$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
365 379
 
@@ -369,33 +383,36 @@  discard block
 block discarded – undo
369 383
 		validateToken('admin-maint');
370 384
 
371 385
 		// Make it longer so we can do their limit.
372
-		if ($body_type == 'text')
373
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
386
+		if ($body_type == 'text') {
387
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
388
+		}
374 389
 		// Shorten the column so we can have a bit (literally per record) less space occupied
375
-		else
376
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
390
+		else {
391
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
392
+		}
377 393
 
378 394
 		// 3rd party integrations may be interested in knowning about this.
379 395
 		call_integration_hook('integrate_convert_msgbody', array($body_type));
380 396
 
381 397
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
382
-		foreach ($colData as $column)
383
-			if ($column['name'] == 'body')
398
+		foreach ($colData as $column) {
399
+					if ($column['name'] == 'body')
384 400
 				$body_type = $column['type'];
401
+		}
385 402
 
386 403
 		$context['maintenance_finished'] = $txt[$context['convert_to'] . '_title'];
387 404
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
388 405
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
389 406
 
390 407
 		return;
391
-	}
392
-	elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
408
+	} elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
393 409
 	{
394 410
 		checkSession();
395
-		if (empty($_REQUEST['start']))
396
-			validateToken('admin-maint');
397
-		else
398
-			validateToken('admin-convertMsg');
411
+		if (empty($_REQUEST['start'])) {
412
+					validateToken('admin-maint');
413
+		} else {
414
+					validateToken('admin-convertMsg');
415
+		}
399 416
 
400 417
 		$context['page_title'] = $txt['not_done_title'];
401 418
 		$context['continue_post_data'] = '';
@@ -427,8 +444,9 @@  discard block
 block discarded – undo
427 444
 					'increment' => $increment - 1,
428 445
 				)
429 446
 			);
430
-			while ($row = $smcFunc['db_fetch_assoc']($request))
431
-				$id_msg_exceeding[] = $row['id_msg'];
447
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
448
+							$id_msg_exceeding[] = $row['id_msg'];
449
+			}
432 450
 			$smcFunc['db_free_result']($request);
433 451
 
434 452
 			$_REQUEST['start'] += $increment;
@@ -457,9 +475,9 @@  discard block
 block discarded – undo
457 475
 			{
458 476
 				$query_msg = array_slice($id_msg_exceeding, 0, 100);
459 477
 				$context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding));
478
+			} else {
479
+							$query_msg = $id_msg_exceeding;
460 480
 			}
461
-			else
462
-				$query_msg = $id_msg_exceeding;
463 481
 
464 482
 			$context['exceeding_messages'] = array();
465 483
 			$request = $smcFunc['db_query']('', '
@@ -470,8 +488,9 @@  discard block
 block discarded – undo
470 488
 					'messages' => $query_msg,
471 489
 				)
472 490
 			);
473
-			while ($row = $smcFunc['db_fetch_assoc']($request))
474
-				$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
491
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
492
+							$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
493
+			}
475 494
 			$smcFunc['db_free_result']($request);
476 495
 		}
477 496
 	}
@@ -495,8 +514,9 @@  discard block
 block discarded – undo
495 514
 	isAllowedTo('admin_forum');
496 515
 
497 516
 	// Check to see if UTF-8 is currently the default character set.
498
-	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8')
499
-		fatal_lang_error('entity_convert_only_utf8');
517
+	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') {
518
+			fatal_lang_error('entity_convert_only_utf8');
519
+	}
500 520
 
501 521
 	// Some starting values.
502 522
 	$context['table'] = empty($_REQUEST['table']) ? 0 : (int) $_REQUEST['table'];
@@ -558,8 +578,9 @@  discard block
 block discarded – undo
558 578
 		// Make sure we keep stuff unique!
559 579
 		$primary_keys = array();
560 580
 
561
-		if (function_exists('apache_reset_timeout'))
562
-			@apache_reset_timeout();
581
+		if (function_exists('apache_reset_timeout')) {
582
+					@apache_reset_timeout();
583
+		}
563 584
 
564 585
 		// Get a list of text columns.
565 586
 		$columns = array();
@@ -570,9 +591,10 @@  discard block
 block discarded – undo
570 591
 				'cur_table' => $cur_table,
571 592
 			)
572 593
 		);
573
-		while ($column_info = $smcFunc['db_fetch_assoc']($request))
574
-			if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
594
+		while ($column_info = $smcFunc['db_fetch_assoc']($request)) {
595
+					if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
575 596
 				$columns[] = strtolower($column_info['Field']);
597
+		}
576 598
 
577 599
 		// Get the column with the (first) primary key.
578 600
 		$request = $smcFunc['db_query']('', '
@@ -586,8 +608,9 @@  discard block
 block discarded – undo
586 608
 		{
587 609
 			if ($row['Key_name'] === 'PRIMARY')
588 610
 			{
589
-				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns)))
590
-					$primary_key = $row['Column_name'];
611
+				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) {
612
+									$primary_key = $row['Column_name'];
613
+				}
591 614
 
592 615
 				$primary_keys[] = $row['Column_name'];
593 616
 			}
@@ -596,8 +619,9 @@  discard block
 block discarded – undo
596 619
 
597 620
 		// No primary key, no glory.
598 621
 		// Same for columns. Just to be sure we've work to do!
599
-		if (empty($primary_key) || empty($columns))
600
-			continue;
622
+		if (empty($primary_key) || empty($columns)) {
623
+					continue;
624
+		}
601 625
 
602 626
 		// Get the maximum value for the primary key.
603 627
 		$request = $smcFunc['db_query']('', '
@@ -611,8 +635,9 @@  discard block
 block discarded – undo
611 635
 		list($max_value) = $smcFunc['db_fetch_row']($request);
612 636
 		$smcFunc['db_free_result']($request);
613 637
 
614
-		if (empty($max_value))
615
-			continue;
638
+		if (empty($max_value)) {
639
+					continue;
640
+		}
616 641
 
617 642
 		while ($context['start'] <= $max_value)
618 643
 		{
@@ -636,10 +661,11 @@  discard block
 block discarded – undo
636 661
 			{
637 662
 				$insertion_variables = array();
638 663
 				$changes = array();
639
-				foreach ($row as $column_name => $column_value)
640
-					if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
664
+				foreach ($row as $column_name => $column_value) {
665
+									if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
641 666
 					{
642 667
 						$changes[] = $column_name . ' = {string:changes_' . $column_name . '}';
668
+				}
643 669
 						$insertion_variables['changes_' . $column_name] = preg_replace_callback('~&#(\d{1,5}|x[0-9a-fA-F]{1,4});~', 'fixchardb__callback', $column_value);
644 670
 					}
645 671
 
@@ -651,8 +677,8 @@  discard block
 block discarded – undo
651 677
 				}
652 678
 
653 679
 				// Update the row.
654
-				if (!empty($changes))
655
-					$smcFunc['db_query']('', '
680
+				if (!empty($changes)) {
681
+									$smcFunc['db_query']('', '
656 682
 						UPDATE {db_prefix}' . $cur_table . '
657 683
 						SET
658 684
 							' . implode(',
@@ -660,6 +686,7 @@  discard block
 block discarded – undo
660 686
 						WHERE ' . implode(' AND ', $where),
661 687
 						$insertion_variables
662 688
 					);
689
+				}
663 690
 			}
664 691
 			$smcFunc['db_free_result']($request);
665 692
 			$context['start'] += 500;
@@ -700,10 +727,11 @@  discard block
 block discarded – undo
700 727
 
701 728
 	checkSession('request');
702 729
 
703
-	if (!isset($_SESSION['optimized_tables']))
704
-		validateToken('admin-maint');
705
-	else
706
-		validateToken('admin-optimize', 'post', false);
730
+	if (!isset($_SESSION['optimized_tables'])) {
731
+			validateToken('admin-maint');
732
+	} else {
733
+			validateToken('admin-optimize', 'post', false);
734
+	}
707 735
 
708 736
 	ignore_user_abort(true);
709 737
 	db_extend();
@@ -719,13 +747,15 @@  discard block
 block discarded – undo
719 747
 	// Get a list of tables, as well as how many there are.
720 748
 	$temp_tables = $smcFunc['db_list_tables'](false, $real_prefix . '%');
721 749
 	$tables = array();
722
-	foreach ($temp_tables as $table)
723
-		$tables[] = array('table_name' => $table);
750
+	foreach ($temp_tables as $table) {
751
+			$tables[] = array('table_name' => $table);
752
+	}
724 753
 
725 754
 	// If there aren't any tables then I believe that would mean the world has exploded...
726 755
 	$context['num_tables'] = count($tables);
727
-	if ($context['num_tables'] == 0)
728
-		fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
756
+	if ($context['num_tables'] == 0) {
757
+			fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
758
+	}
729 759
 
730 760
 	$_REQUEST['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
731 761
 
@@ -736,8 +766,9 @@  discard block
 block discarded – undo
736 766
 	$_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array();
737 767
 	for ($key = $_REQUEST['start']; $context['num_tables'] - 1; $key++)
738 768
 	{
739
-		if (empty($tables[$key]))
740
-			break;
769
+		if (empty($tables[$key])) {
770
+					break;
771
+		}
741 772
 
742 773
 		// Continue?
743 774
 		if (microtime(true) - $time_start > 10)
@@ -751,8 +782,9 @@  discard block
 block discarded – undo
751 782
 			createToken('admin-optimize');
752 783
 			$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-optimize_token_var'] . '" value="' . $context['admin-optimize_token'] . '">';
753 784
 
754
-			if (function_exists('apache_reset_timeout'))
755
-				apache_reset_timeout();
785
+			if (function_exists('apache_reset_timeout')) {
786
+							apache_reset_timeout();
787
+			}
756 788
 
757 789
 			return;
758 790
 		}
@@ -760,11 +792,12 @@  discard block
 block discarded – undo
760 792
 		// Optimize the table!  We use backticks here because it might be a custom table.
761 793
 		$data_freed = $smcFunc['db_optimize_table']($tables[$key]['table_name']);
762 794
 
763
-		if ($data_freed > 0)
764
-			$_SESSION['optimized_tables'][] = array(
795
+		if ($data_freed > 0) {
796
+					$_SESSION['optimized_tables'][] = array(
765 797
 				'name' => $tables[$key]['table_name'],
766 798
 				'data_freed' => $data_freed,
767 799
 			);
800
+		}
768 801
 	}
769 802
 
770 803
 	// Number of tables, etc...
@@ -799,10 +832,11 @@  discard block
 block discarded – undo
799 832
 	checkSession('request');
800 833
 
801 834
 	// validate the request or the loop
802
-	if (!isset($_REQUEST['step']))
803
-		validateToken('admin-maint');
804
-	else
805
-		validateToken('admin-boardrecount');
835
+	if (!isset($_REQUEST['step'])) {
836
+			validateToken('admin-maint');
837
+	} else {
838
+			validateToken('admin-boardrecount');
839
+	}
806 840
 
807 841
 	$context['page_title'] = $txt['not_done_title'];
808 842
 	$context['continue_post_data'] = '';
@@ -823,8 +857,9 @@  discard block
 block discarded – undo
823 857
 	$smcFunc['db_free_result']($request);
824 858
 
825 859
 	$increment = min(max(50, ceil($max_topics / 4)), 2000);
826
-	if (empty($_REQUEST['start']))
827
-		$_REQUEST['start'] = 0;
860
+	if (empty($_REQUEST['start'])) {
861
+			$_REQUEST['start'] = 0;
862
+	}
828 863
 
829 864
 	$total_steps = 8;
830 865
 
@@ -851,8 +886,8 @@  discard block
 block discarded – undo
851 886
 					'max_id' => $_REQUEST['start'] + $increment,
852 887
 				)
853 888
 			);
854
-			while ($row = $smcFunc['db_fetch_assoc']($request))
855
-				$smcFunc['db_query']('', '
889
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
890
+							$smcFunc['db_query']('', '
856 891
 					UPDATE {db_prefix}topics
857 892
 					SET num_replies = {int:num_replies}
858 893
 					WHERE id_topic = {int:id_topic}',
@@ -861,6 +896,7 @@  discard block
 block discarded – undo
861 896
 						'id_topic' => $row['id_topic'],
862 897
 					)
863 898
 				);
899
+			}
864 900
 			$smcFunc['db_free_result']($request);
865 901
 
866 902
 			// Recount unapproved messages
@@ -879,8 +915,8 @@  discard block
 block discarded – undo
879 915
 					'max_id' => $_REQUEST['start'] + $increment,
880 916
 				)
881 917
 			);
882
-			while ($row = $smcFunc['db_fetch_assoc']($request))
883
-				$smcFunc['db_query']('', '
918
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
919
+							$smcFunc['db_query']('', '
884 920
 					UPDATE {db_prefix}topics
885 921
 					SET unapproved_posts = {int:unapproved_posts}
886 922
 					WHERE id_topic = {int:id_topic}',
@@ -889,6 +925,7 @@  discard block
 block discarded – undo
889 925
 						'id_topic' => $row['id_topic'],
890 926
 					)
891 927
 				);
928
+			}
892 929
 			$smcFunc['db_free_result']($request);
893 930
 
894 931
 			$_REQUEST['start'] += $increment;
@@ -911,8 +948,8 @@  discard block
 block discarded – undo
911 948
 	// Update the post count of each board.
912 949
 	if ($_REQUEST['step'] <= 1)
913 950
 	{
914
-		if (empty($_REQUEST['start']))
915
-			$smcFunc['db_query']('', '
951
+		if (empty($_REQUEST['start'])) {
952
+					$smcFunc['db_query']('', '
916 953
 				UPDATE {db_prefix}boards
917 954
 				SET num_posts = {int:num_posts}
918 955
 				WHERE redirect = {string:redirect}',
@@ -921,6 +958,7 @@  discard block
 block discarded – undo
921 958
 					'redirect' => '',
922 959
 				)
923 960
 			);
961
+		}
924 962
 
925 963
 		while ($_REQUEST['start'] < $max_topics)
926 964
 		{
@@ -937,8 +975,8 @@  discard block
 block discarded – undo
937 975
 					'is_approved' => 1,
938 976
 				)
939 977
 			);
940
-			while ($row = $smcFunc['db_fetch_assoc']($request))
941
-				$smcFunc['db_query']('', '
978
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
979
+							$smcFunc['db_query']('', '
942 980
 					UPDATE {db_prefix}boards
943 981
 					SET num_posts = num_posts + {int:real_num_posts}
944 982
 					WHERE id_board = {int:id_board}',
@@ -947,6 +985,7 @@  discard block
 block discarded – undo
947 985
 						'real_num_posts' => $row['real_num_posts'],
948 986
 					)
949 987
 				);
988
+			}
950 989
 			$smcFunc['db_free_result']($request);
951 990
 
952 991
 			$_REQUEST['start'] += $increment;
@@ -969,14 +1008,15 @@  discard block
 block discarded – undo
969 1008
 	// Update the topic count of each board.
970 1009
 	if ($_REQUEST['step'] <= 2)
971 1010
 	{
972
-		if (empty($_REQUEST['start']))
973
-			$smcFunc['db_query']('', '
1011
+		if (empty($_REQUEST['start'])) {
1012
+					$smcFunc['db_query']('', '
974 1013
 				UPDATE {db_prefix}boards
975 1014
 				SET num_topics = {int:num_topics}',
976 1015
 				array(
977 1016
 					'num_topics' => 0,
978 1017
 				)
979 1018
 			);
1019
+		}
980 1020
 
981 1021
 		while ($_REQUEST['start'] < $max_topics)
982 1022
 		{
@@ -993,8 +1033,8 @@  discard block
 block discarded – undo
993 1033
 					'id_topic_max' => $_REQUEST['start'] + $increment,
994 1034
 				)
995 1035
 			);
996
-			while ($row = $smcFunc['db_fetch_assoc']($request))
997
-				$smcFunc['db_query']('', '
1036
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1037
+							$smcFunc['db_query']('', '
998 1038
 					UPDATE {db_prefix}boards
999 1039
 					SET num_topics = num_topics + {int:real_num_topics}
1000 1040
 					WHERE id_board = {int:id_board}',
@@ -1003,6 +1043,7 @@  discard block
 block discarded – undo
1003 1043
 						'real_num_topics' => $row['real_num_topics'],
1004 1044
 					)
1005 1045
 				);
1046
+			}
1006 1047
 			$smcFunc['db_free_result']($request);
1007 1048
 
1008 1049
 			$_REQUEST['start'] += $increment;
@@ -1025,14 +1066,15 @@  discard block
 block discarded – undo
1025 1066
 	// Update the unapproved post count of each board.
1026 1067
 	if ($_REQUEST['step'] <= 3)
1027 1068
 	{
1028
-		if (empty($_REQUEST['start']))
1029
-			$smcFunc['db_query']('', '
1069
+		if (empty($_REQUEST['start'])) {
1070
+					$smcFunc['db_query']('', '
1030 1071
 				UPDATE {db_prefix}boards
1031 1072
 				SET unapproved_posts = {int:unapproved_posts}',
1032 1073
 				array(
1033 1074
 					'unapproved_posts' => 0,
1034 1075
 				)
1035 1076
 			);
1077
+		}
1036 1078
 
1037 1079
 		while ($_REQUEST['start'] < $max_topics)
1038 1080
 		{
@@ -1049,8 +1091,8 @@  discard block
 block discarded – undo
1049 1091
 					'is_approved' => 0,
1050 1092
 				)
1051 1093
 			);
1052
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1053
-				$smcFunc['db_query']('', '
1094
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1095
+							$smcFunc['db_query']('', '
1054 1096
 					UPDATE {db_prefix}boards
1055 1097
 					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
1056 1098
 					WHERE id_board = {int:id_board}',
@@ -1059,6 +1101,7 @@  discard block
 block discarded – undo
1059 1101
 						'unapproved_posts' => $row['real_unapproved_posts'],
1060 1102
 					)
1061 1103
 				);
1104
+			}
1062 1105
 			$smcFunc['db_free_result']($request);
1063 1106
 
1064 1107
 			$_REQUEST['start'] += $increment;
@@ -1081,14 +1124,15 @@  discard block
 block discarded – undo
1081 1124
 	// Update the unapproved topic count of each board.
1082 1125
 	if ($_REQUEST['step'] <= 4)
1083 1126
 	{
1084
-		if (empty($_REQUEST['start']))
1085
-			$smcFunc['db_query']('', '
1127
+		if (empty($_REQUEST['start'])) {
1128
+					$smcFunc['db_query']('', '
1086 1129
 				UPDATE {db_prefix}boards
1087 1130
 				SET unapproved_topics = {int:unapproved_topics}',
1088 1131
 				array(
1089 1132
 					'unapproved_topics' => 0,
1090 1133
 				)
1091 1134
 			);
1135
+		}
1092 1136
 
1093 1137
 		while ($_REQUEST['start'] < $max_topics)
1094 1138
 		{
@@ -1105,8 +1149,8 @@  discard block
 block discarded – undo
1105 1149
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1106 1150
 				)
1107 1151
 			);
1108
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1109
-				$smcFunc['db_query']('', '
1152
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1153
+							$smcFunc['db_query']('', '
1110 1154
 					UPDATE {db_prefix}boards
1111 1155
 					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
1112 1156
 					WHERE id_board = {int:id_board}',
@@ -1115,6 +1159,7 @@  discard block
 block discarded – undo
1115 1159
 						'real_unapproved_topics' => $row['real_unapproved_topics'],
1116 1160
 					)
1117 1161
 				);
1162
+			}
1118 1163
 			$smcFunc['db_free_result']($request);
1119 1164
 
1120 1165
 			$_REQUEST['start'] += $increment;
@@ -1148,8 +1193,9 @@  discard block
 block discarded – undo
1148 1193
 				'is_not_deleted' => 0,
1149 1194
 			)
1150 1195
 		);
1151
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1152
-			updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1196
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1197
+					updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1198
+		}
1153 1199
 		$smcFunc['db_free_result']($request);
1154 1200
 
1155 1201
 		$request = $smcFunc['db_query']('', '
@@ -1164,8 +1210,9 @@  discard block
 block discarded – undo
1164 1210
 				'is_not_read' => 0,
1165 1211
 			)
1166 1212
 		);
1167
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1168
-			updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1213
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1214
+					updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1215
+		}
1169 1216
 		$smcFunc['db_free_result']($request);
1170 1217
 
1171 1218
 		if (microtime(true) - $time_start > 3)
@@ -1197,12 +1244,13 @@  discard block
 block discarded – undo
1197 1244
 				)
1198 1245
 			);
1199 1246
 			$boards = array();
1200
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1201
-				$boards[$row['id_board']][] = $row['id_msg'];
1247
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1248
+							$boards[$row['id_board']][] = $row['id_msg'];
1249
+			}
1202 1250
 			$smcFunc['db_free_result']($request);
1203 1251
 
1204
-			foreach ($boards as $board_id => $messages)
1205
-				$smcFunc['db_query']('', '
1252
+			foreach ($boards as $board_id => $messages) {
1253
+							$smcFunc['db_query']('', '
1206 1254
 					UPDATE {db_prefix}messages
1207 1255
 					SET id_board = {int:id_board}
1208 1256
 					WHERE id_msg IN ({array_int:id_msg_array})',
@@ -1211,6 +1259,7 @@  discard block
 block discarded – undo
1211 1259
 						'id_board' => $board_id,
1212 1260
 					)
1213 1261
 				);
1262
+			}
1214 1263
 
1215 1264
 			$_REQUEST['start'] += $increment;
1216 1265
 
@@ -1240,8 +1289,9 @@  discard block
 block discarded – undo
1240 1289
 		)
1241 1290
 	);
1242 1291
 	$realBoardCounts = array();
1243
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1244
-		$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1292
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1293
+			$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1294
+	}
1245 1295
 	$smcFunc['db_free_result']($request);
1246 1296
 
1247 1297
 	$request = $smcFunc['db_query']('', '
@@ -1261,18 +1311,20 @@  discard block
 block discarded – undo
1261 1311
 	krsort($resort_me);
1262 1312
 
1263 1313
 	$lastModifiedMsg = array();
1264
-	foreach ($resort_me as $rows)
1265
-		foreach ($rows as $row)
1314
+	foreach ($resort_me as $rows) {
1315
+			foreach ($rows as $row)
1266 1316
 		{
1267 1317
 			// The latest message is the latest of the current board and its children.
1268 1318
 			if (isset($lastModifiedMsg[$row['id_board']]))
1269 1319
 				$curLastModifiedMsg = max($row['local_last_msg'], $lastModifiedMsg[$row['id_board']]);
1270
-			else
1271
-				$curLastModifiedMsg = $row['local_last_msg'];
1320
+	}
1321
+			else {
1322
+							$curLastModifiedMsg = $row['local_last_msg'];
1323
+			}
1272 1324
 
1273 1325
 			// If what is and what should be the latest message differ, an update is necessary.
1274
-			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated'])
1275
-				$smcFunc['db_query']('', '
1326
+			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) {
1327
+							$smcFunc['db_query']('', '
1276 1328
 					UPDATE {db_prefix}boards
1277 1329
 					SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated}
1278 1330
 					WHERE id_board = {int:id_board}',
@@ -1282,12 +1334,14 @@  discard block
 block discarded – undo
1282 1334
 						'id_board' => $row['id_board'],
1283 1335
 					)
1284 1336
 				);
1337
+			}
1285 1338
 
1286 1339
 			// Parent boards inherit the latest modified message of their children.
1287
-			if (isset($lastModifiedMsg[$row['id_parent']]))
1288
-				$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1289
-			else
1290
-				$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1340
+			if (isset($lastModifiedMsg[$row['id_parent']])) {
1341
+							$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1342
+			} else {
1343
+							$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1344
+			}
1291 1345
 		}
1292 1346
 
1293 1347
 	// Update all the basic statistics.
@@ -1359,8 +1413,9 @@  discard block
 block discarded – undo
1359 1413
 	require_once($sourcedir . '/Subs-Auth.php');
1360 1414
 	$members = findMembers($_POST['to']);
1361 1415
 
1362
-	if (empty($members))
1363
-		fatal_lang_error('reattribute_cannot_find_member');
1416
+	if (empty($members)) {
1417
+			fatal_lang_error('reattribute_cannot_find_member');
1418
+	}
1364 1419
 
1365 1420
 	$memID = array_shift($members);
1366 1421
 	$memID = $memID['id'];
@@ -1390,8 +1445,9 @@  discard block
 block discarded – undo
1390 1445
 		validateToken('admin-maint');
1391 1446
 
1392 1447
 		$groups = array();
1393
-		foreach ($_POST['groups'] as $id => $dummy)
1394
-			$groups[] = (int) $id;
1448
+		foreach ($_POST['groups'] as $id => $dummy) {
1449
+					$groups[] = (int) $id;
1450
+		}
1395 1451
 		$time_limit = (time() - ($_POST['maxdays'] * 24 * 3600));
1396 1452
 		$where_vars = array(
1397 1453
 			'time_limit' => $time_limit,
@@ -1400,9 +1456,9 @@  discard block
 block discarded – undo
1400 1456
 		{
1401 1457
 			$where = 'mem.date_registered < {int:time_limit} AND mem.is_activated = {int:is_activated}';
1402 1458
 			$where_vars['is_activated'] = 0;
1459
+		} else {
1460
+					$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1403 1461
 		}
1404
-		else
1405
-			$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1406 1462
 
1407 1463
 		// Need to get *all* groups then work out which (if any) we avoid.
1408 1464
 		$request = $smcFunc['db_query']('', '
@@ -1421,8 +1477,7 @@  discard block
 block discarded – undo
1421 1477
 				{
1422 1478
 					$where .= ' AND mem.id_post_group != {int:id_post_group_' . $row['id_group'] . '}';
1423 1479
 					$where_vars['id_post_group_' . $row['id_group']] = $row['id_group'];
1424
-				}
1425
-				else
1480
+				} else
1426 1481
 				{
1427 1482
 					$where .= ' AND mem.id_group != {int:id_group_' . $row['id_group'] . '} AND FIND_IN_SET({int:id_group_' . $row['id_group'] . '}, mem.additional_groups) = 0';
1428 1483
 					$where_vars['id_group_' . $row['id_group']] = $row['id_group'];
@@ -1449,8 +1504,9 @@  discard block
 block discarded – undo
1449 1504
 		$members = array();
1450 1505
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1451 1506
 		{
1452
-			if (!$row['is_mod'] || !in_array(3, $groups))
1453
-				$members[] = $row['id_member'];
1507
+			if (!$row['is_mod'] || !in_array(3, $groups)) {
1508
+							$members[] = $row['id_member'];
1509
+			}
1454 1510
 		}
1455 1511
 		$smcFunc['db_free_result']($request);
1456 1512
 
@@ -1497,8 +1553,9 @@  discard block
 block discarded – undo
1497 1553
 		)
1498 1554
 	);
1499 1555
 
1500
-	while ($row = $smcFunc['db_fetch_row']($request))
1501
-		$drafts[] = (int) $row[0];
1556
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1557
+			$drafts[] = (int) $row[0];
1558
+	}
1502 1559
 	$smcFunc['db_free_result']($request);
1503 1560
 
1504 1561
 	// If we have old drafts, remove them
@@ -1541,8 +1598,9 @@  discard block
 block discarded – undo
1541 1598
 	$sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']);
1542 1599
 
1543 1600
 	// No boards then this is your stop.
1544
-	if (empty($id_board_from) || empty($id_board_to))
1545
-		return;
1601
+	if (empty($id_board_from) || empty($id_board_to)) {
1602
+			return;
1603
+	}
1546 1604
 
1547 1605
 	// The big WHERE clause
1548 1606
 	$conditions = 'WHERE t.id_board = {int:id_board_from}
@@ -1590,18 +1648,20 @@  discard block
 block discarded – undo
1590 1648
 		);
1591 1649
 		list ($total_topics) = $smcFunc['db_fetch_row']($request);
1592 1650
 		$smcFunc['db_free_result']($request);
1651
+	} else {
1652
+			$total_topics = (int) $_REQUEST['totaltopics'];
1593 1653
 	}
1594
-	else
1595
-		$total_topics = (int) $_REQUEST['totaltopics'];
1596 1654
 
1597 1655
 	// Seems like we need this here.
1598 1656
 	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days;
1599 1657
 
1600
-	if ($locked)
1601
-		$context['continue_get_data'] .= ';locked';
1658
+	if ($locked) {
1659
+			$context['continue_get_data'] .= ';locked';
1660
+	}
1602 1661
 
1603
-	if ($sticky)
1604
-		$context['continue_get_data'] .= ';sticky';
1662
+	if ($sticky) {
1663
+			$context['continue_get_data'] .= ';sticky';
1664
+	}
1605 1665
 
1606 1666
 	$context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1607 1667
 
@@ -1622,8 +1682,9 @@  discard block
 block discarded – undo
1622 1682
 
1623 1683
 			// Get the ids.
1624 1684
 			$topics = array();
1625
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1626
-				$topics[] = $row['id_topic'];
1685
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1686
+							$topics[] = $row['id_topic'];
1687
+			}
1627 1688
 
1628 1689
 			// Just return if we don't have any topics left to move.
1629 1690
 			if (empty($topics))
@@ -1714,9 +1775,9 @@  discard block
 block discarded – undo
1714 1775
 		// save it so we don't do this again for this task
1715 1776
 		list ($_SESSION['total_members']) = $smcFunc['db_fetch_row']($request);
1716 1777
 		$smcFunc['db_free_result']($request);
1778
+	} else {
1779
+			validateToken('admin-recountposts');
1717 1780
 	}
1718
-	else
1719
-		validateToken('admin-recountposts');
1720 1781
 
1721 1782
 	// Lets get a group of members and determine their post count (from the boards that have post count enabled of course).
1722 1783
 	$request = $smcFunc['db_query']('', '
@@ -1762,8 +1823,9 @@  discard block
 block discarded – undo
1762 1823
 		createToken('admin-recountposts');
1763 1824
 		$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-recountposts_token_var'] . '" value="' . $context['admin-recountposts_token'] . '">';
1764 1825
 
1765
-		if (function_exists('apache_reset_timeout'))
1766
-			apache_reset_timeout();
1826
+		if (function_exists('apache_reset_timeout')) {
1827
+					apache_reset_timeout();
1828
+		}
1767 1829
 		return;
1768 1830
 	}
1769 1831
 
@@ -1849,10 +1911,9 @@  discard block
 block discarded – undo
1849 1911
 		checkSession('request');
1850 1912
 		validateToken('admin-hook', 'request');
1851 1913
 
1852
-		if ($_REQUEST['do'] == 'remove')
1853
-			remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1854
-
1855
-		else
1914
+		if ($_REQUEST['do'] == 'remove') {
1915
+					remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1916
+		} else
1856 1917
 		{
1857 1918
 			$function_remove = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '' : '!');
1858 1919
 			$function_add = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '!' : '');
@@ -1902,11 +1963,11 @@  discard block
 block discarded – undo
1902 1963
 						// Show a nice icon to indicate this is an instance.
1903 1964
 						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="' . $txt['hooks_field_function_method'] . '"></span> ' : '');
1904 1965
 
1905
-						if (!empty($data['included_file']))
1906
-							return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1907
-
1908
-						else
1909
-							return $instance . $data['real_function'];
1966
+						if (!empty($data['included_file'])) {
1967
+													return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1968
+						} else {
1969
+													return $instance . $data['real_function'];
1970
+						}
1910 1971
 					},
1911 1972
 				),
1912 1973
 				'sort' =>  array(
@@ -1971,11 +2032,12 @@  discard block
 block discarded – undo
1971 2032
 		'data' => array(
1972 2033
 			'function' => function($data) use ($txt, $scripturl, $context)
1973 2034
 			{
1974
-				if (!$data['hook_exists'])
1975
-					return '
2035
+				if (!$data['hook_exists']) {
2036
+									return '
1976 2037
 					<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $context['filter_url'] . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">
1977 2038
 						<span class="generic_icons delete" title="' . $txt['hooks_button_remove'] . '"></span>
1978 2039
 					</a>';
2040
+				}
1979 2041
 			},
1980 2042
 			'class' => 'centertext',
1981 2043
 		),
@@ -2010,10 +2072,11 @@  discard block
 block discarded – undo
2010 2072
 		{
2011 2073
 			if ($file != '.' && $file != '..')
2012 2074
 			{
2013
-				if (is_dir($dir_path . '/' . $file))
2014
-					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2015
-				else
2016
-					$files[] = array('dir' => $dir_path, 'name' => $file);
2075
+				if (is_dir($dir_path . '/' . $file)) {
2076
+									$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2077
+				} else {
2078
+									$files[] = array('dir' => $dir_path, 'name' => $file);
2079
+				}
2017 2080
 			}
2018 2081
 		}
2019 2082
 	}
@@ -2062,16 +2125,16 @@  discard block
 block discarded – undo
2062 2125
 							// I need to know if there is at least one function called in this file.
2063 2126
 							$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2064 2127
 							unset($temp_hooks[$hook][$rawFunc]);
2065
-						}
2066
-						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2128
+						} elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2067 2129
 						{
2068 2130
 							$hook_status[$hook][$hookParsedData['pureFunc']] = $hookParsedData;
2069 2131
 							$hook_status[$hook][$hookParsedData['pureFunc']]['exists'] = true;
2070 2132
 							$hook_status[$hook][$hookParsedData['pureFunc']]['in_file'] = (!empty($file['name']) ? $file['name'] : (!empty($hookParsedData['hookFile']) ? $hookParsedData['hookFile'] : ''));
2071 2133
 
2072 2134
 							// Does the hook has its own file?
2073
-							if (!empty($hookParsedData['hookFile']))
2074
-								$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2135
+							if (!empty($hookParsedData['hookFile'])) {
2136
+															$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2137
+							}
2075 2138
 
2076 2139
 							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
2077 2140
 							$temp_data['function'][$file['name']][$hookParsedData['pureFunc']] = $hookParsedData['enabled'];
@@ -2098,15 +2161,17 @@  discard block
 block discarded – undo
2098 2161
 	$sort = array();
2099 2162
 	$hooks_filters = array();
2100 2163
 
2101
-	foreach ($hooks as $hook => $functions)
2102
-		$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2164
+	foreach ($hooks as $hook => $functions) {
2165
+			$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2166
+	}
2103 2167
 
2104
-	if (!empty($hooks_filters))
2105
-		$context['insert_after_template'] .= '
2168
+	if (!empty($hooks_filters)) {
2169
+			$context['insert_after_template'] .= '
2106 2170
 		<script>
2107 2171
 			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
2108 2172
 			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>') . ';
2109 2173
 		</script>';
2174
+	}
2110 2175
 
2111 2176
 	$temp_data = array();
2112 2177
 	$id = 0;
@@ -2148,10 +2213,11 @@  discard block
 block discarded – undo
2148 2213
 
2149 2214
 	foreach ($temp_data as $data)
2150 2215
 	{
2151
-		if (++$counter < $start)
2152
-			continue;
2153
-		elseif ($counter == $start + $per_page)
2154
-			break;
2216
+		if (++$counter < $start) {
2217
+					continue;
2218
+		} elseif ($counter == $start + $per_page) {
2219
+					break;
2220
+		}
2155 2221
 
2156 2222
 		$hooks_data[] = $data;
2157 2223
 	}
@@ -2173,13 +2239,15 @@  discard block
 block discarded – undo
2173 2239
 	$hooks_count = 0;
2174 2240
 
2175 2241
 	$context['filter'] = false;
2176
-	if (isset($_GET['filter']))
2177
-		$context['filter'] = $_GET['filter'];
2242
+	if (isset($_GET['filter'])) {
2243
+			$context['filter'] = $_GET['filter'];
2244
+	}
2178 2245
 
2179 2246
 	foreach ($hooks as $hook => $functions)
2180 2247
 	{
2181
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
2182
-			$hooks_count += count($functions);
2248
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) {
2249
+					$hooks_count += count($functions);
2250
+		}
2183 2251
 	}
2184 2252
 
2185 2253
 	return $hooks_count;
@@ -2200,8 +2268,9 @@  discard block
 block discarded – undo
2200 2268
 		$integration_hooks = array();
2201 2269
 		foreach ($modSettings as $key => $value)
2202 2270
 		{
2203
-			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
2204
-				$integration_hooks[$key] = explode(',', $value);
2271
+			if (!empty($value) && substr($key, 0, 10) === 'integrate_') {
2272
+							$integration_hooks[$key] = explode(',', $value);
2273
+			}
2205 2274
 		}
2206 2275
 	}
2207 2276
 
@@ -2232,8 +2301,9 @@  discard block
 block discarded – undo
2232 2301
 	);
2233 2302
 
2234 2303
 	// Meh...
2235
-	if (empty($rawData))
2236
-		return $hookData;
2304
+	if (empty($rawData)) {
2305
+			return $hookData;
2306
+	}
2237 2307
 
2238 2308
 	// For convenience purposes only!
2239 2309
 	$modFunc = $rawData;
@@ -2244,11 +2314,11 @@  discard block
 block discarded – undo
2244 2314
 		list ($hookData['hookFile'], $modFunc) = explode('|', $modFunc);
2245 2315
 
2246 2316
 		// Does the file exists? who knows!
2247
-		if (empty($settings['theme_dir']))
2248
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2249
-
2250
-		else
2251
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2317
+		if (empty($settings['theme_dir'])) {
2318
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2319
+		} else {
2320
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2321
+		}
2252 2322
 
2253 2323
 		$hookData['fileExists'] = file_exists($hookData['absPath']);
2254 2324
 		$hookData['hookFile'] = basename($hookData['hookFile']);
@@ -2273,11 +2343,10 @@  discard block
 block discarded – undo
2273 2343
 	{
2274 2344
 		list ($hookData['class'], $hookData['method']) = explode('::', $modFunc);
2275 2345
 		$hookData['pureFunc'] = $hookData['method'];
2346
+	} else {
2347
+			$hookData['pureFunc'] = $modFunc;
2276 2348
 	}
2277 2349
 
2278
-	else
2279
-		$hookData['pureFunc'] = $modFunc;
2280
-
2281 2350
 	return $hookData;
2282 2351
 }
2283 2352
 
@@ -2294,16 +2363,18 @@  discard block
 block discarded – undo
2294 2363
  */
2295 2364
 function fixchardb__callback($matches)
2296 2365
 {
2297
-	if (!isset($matches[1]))
2298
-		return '';
2366
+	if (!isset($matches[1])) {
2367
+			return '';
2368
+	}
2299 2369
 
2300 2370
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
2301 2371
 	
2302 2372
 	// it's to big for mysql?
2303
-	if ($num > 0xFFFF)
2304
-		return $matches[0];
2305
-	else
2306
-		return fixchar__callback ($matches);
2307
-}
2373
+	if ($num > 0xFFFF) {
2374
+			return $matches[0];
2375
+	} else {
2376
+			return fixchar__callback ($matches);
2377
+	}
2378
+	}
2308 2379
 
2309 2380
 ?>
2310 2381
\ No newline at end of file
Please login to merge, or discard this patch.
proxy.php 1 patch
Braces   +35 added lines, -23 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
 	define('SMF', 'proxy');
18
+}
18 19
 
19 20
 global $proxyhousekeeping;
20 21
 
@@ -68,33 +69,38 @@  discard block
 block discarded – undo
68 69
 	 */
69 70
 	public function checkRequest()
70 71
 	{
71
-		if (!$this->enabled)
72
-			return false;
72
+		if (!$this->enabled) {
73
+					return false;
74
+		}
73 75
 
74 76
 		// Try to create the image cache directory if it doesn't exist
75
-		if (!file_exists($this->cache))
76
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
77
+		if (!file_exists($this->cache)) {
78
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
77 79
 				return false;
80
+		}
78 81
 
79 82
 		// Basic sanity check
80 83
 		$_GET['request'] = validate_iri($_GET['request']);
81 84
 
82 85
 		// We aren't going anywhere without these
83
-		if (empty($_GET['hash']) || empty($_GET['request']))
84
-			return false;
86
+		if (empty($_GET['hash']) || empty($_GET['request'])) {
87
+					return false;
88
+		}
85 89
 
86 90
 		$hash = $_GET['hash'];
87 91
 		$request = $_GET['request'];
88 92
 
89
-		if (md5($request . $this->secret) != $hash)
90
-			return false;
93
+		if (md5($request . $this->secret) != $hash) {
94
+					return false;
95
+		}
91 96
 
92 97
 		// Ensure any non-ASCII characters in the URL are encoded correctly
93 98
 		$request = iri_to_url($request);
94 99
 
95 100
 		// Attempt to cache the request if it doesn't exist
96
-		if (!$this->isCached($request))
97
-			return $this->cacheImage($request);
101
+		if (!$this->isCached($request)) {
102
+					return $this->cacheImage($request);
103
+		}
98 104
 
99 105
 		return true;
100 106
 	}
@@ -131,8 +137,9 @@  discard block
 block discarded – undo
131 137
 		if (!$cached || $time - $cached['time'] > ($this->maxDays * 86400))
132 138
 		{
133 139
 			@unlink($cached_file);
134
-			if ($this->checkRequest())
135
-				$this->serve();
140
+			if ($this->checkRequest()) {
141
+							$this->serve();
142
+			}
136 143
 			$this::redirectexit($request);
137 144
 		}
138 145
 
@@ -145,8 +152,9 @@  discard block
 block discarded – undo
145 152
 
146 153
 		// Make sure we're serving an image
147 154
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
148
-		if ($contentParts[0] != 'image')
149
-			exit;
155
+		if ($contentParts[0] != 'image') {
156
+					exit;
157
+		}
150 158
 
151 159
 		$max_age = $time - $cached['time'] + (5 * 86400);
152 160
 		header('content-type: ' . $cached['content_type']);
@@ -196,25 +204,29 @@  discard block
 block discarded – undo
196 204
 		$image = fetch_web_data($request);
197 205
 
198 206
 		// Looks like nobody was home
199
-		if (empty($image))
200
-			return -1;
207
+		if (empty($image)) {
208
+					return -1;
209
+		}
201 210
 
202 211
 		// What kind of file did they give us?
203 212
 		$finfo = finfo_open(FILEINFO_MIME_TYPE);
204 213
 		$mime_type = finfo_buffer($finfo, $image);
205 214
 
206 215
 		// SVG needs a little extra care
207
-		if ($ext == 'svg' && $mime_type == 'text/plain')
208
-			$mime_type = 'image/svg+xml';
216
+		if ($ext == 'svg' && $mime_type == 'text/plain') {
217
+					$mime_type = 'image/svg+xml';
218
+		}
209 219
 
210 220
 		// Make sure the url is returning an image
211
-		if (strpos($mime_type, 'image/') !== 0)
212
-			return -1;
221
+		if (strpos($mime_type, 'image/') !== 0) {
222
+					return -1;
223
+		}
213 224
 
214 225
 		// Validate the filesize
215 226
 		$size = strlen($image);
216
-		if ($size > ($this->maxSize * 1024))
217
-			return 0;
227
+		if ($size > ($this->maxSize * 1024)) {
228
+					return 0;
229
+		}
218 230
 
219 231
 		// Cache it for later
220 232
 		return file_put_contents($dest, json_encode(array(
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +710 added lines, -533 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
 				$value = (string) validate_iri(sanitize_iri($value));
592 610
 				return true;
593 611
 			},
@@ -602,16 +620,19 @@  discard block
 block discarded – undo
602 620
 	foreach ($profile_fields as $key => $field)
603 621
 	{
604 622
 		// Do we have permission to do this?
605
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
606
-			unset($profile_fields[$key]);
623
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
624
+					unset($profile_fields[$key]);
625
+		}
607 626
 
608 627
 		// Is it enabled?
609
-		if (isset($field['enabled']) && !$field['enabled'])
610
-			unset($profile_fields[$key]);
628
+		if (isset($field['enabled']) && !$field['enabled']) {
629
+					unset($profile_fields[$key]);
630
+		}
611 631
 
612 632
 		// Is it specifically disabled?
613
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
614
-			unset($profile_fields[$key]);
633
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
634
+					unset($profile_fields[$key]);
635
+		}
615 636
 	}
616 637
 }
617 638
 
@@ -636,9 +657,10 @@  discard block
 block discarded – undo
636 657
 	loadProfileFields(true);
637 658
 
638 659
 	// First check for any linked sets.
639
-	foreach ($profile_fields as $key => $field)
640
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
660
+	foreach ($profile_fields as $key => $field) {
661
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
641 662
 			$fields[] = $key;
663
+	}
642 664
 
643 665
 	$i = 0;
644 666
 	$last_type = '';
@@ -650,38 +672,46 @@  discard block
 block discarded – undo
650 672
 			$cur_field = &$profile_fields[$field];
651 673
 
652 674
 			// Does it have a preload and does that preload succeed?
653
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
654
-				continue;
675
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
676
+							continue;
677
+			}
655 678
 
656 679
 			// If this is anything but complex we need to do more cleaning!
657 680
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
658 681
 			{
659
-				if (!isset($cur_field['label']))
660
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
682
+				if (!isset($cur_field['label'])) {
683
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
684
+				}
661 685
 
662 686
 				// Everything has a value!
663
-				if (!isset($cur_field['value']))
664
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
687
+				if (!isset($cur_field['value'])) {
688
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
689
+				}
665 690
 
666 691
 				// Any input attributes?
667 692
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
668 693
 			}
669 694
 
670 695
 			// Was there an error with this field on posting?
671
-			if (isset($context['profile_errors'][$field]))
672
-				$cur_field['is_error'] = true;
696
+			if (isset($context['profile_errors'][$field])) {
697
+							$cur_field['is_error'] = true;
698
+			}
673 699
 
674 700
 			// Any javascript stuff?
675
-			if (!empty($cur_field['js_submit']))
676
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
677
-			if (!empty($cur_field['js']))
678
-				$context['profile_javascript'] .= $cur_field['js'];
701
+			if (!empty($cur_field['js_submit'])) {
702
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
703
+			}
704
+			if (!empty($cur_field['js'])) {
705
+							$context['profile_javascript'] .= $cur_field['js'];
706
+			}
679 707
 
680 708
 			// Any template stuff?
681
-			if (!empty($cur_field['prehtml']))
682
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
683
-			if (!empty($cur_field['posthtml']))
684
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
709
+			if (!empty($cur_field['prehtml'])) {
710
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
711
+			}
712
+			if (!empty($cur_field['posthtml'])) {
713
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
714
+			}
685 715
 
686 716
 			// Finally put it into context?
687 717
 			if ($cur_field['type'] != 'hidden')
@@ -714,12 +744,14 @@  discard block
 block discarded – undo
714 744
 	}, false);' : ''), true);
715 745
 
716 746
 	// Any onsubmit javascript?
717
-	if (!empty($context['profile_onsubmit_javascript']))
718
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
747
+	if (!empty($context['profile_onsubmit_javascript'])) {
748
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
749
+	}
719 750
 
720 751
 	// Any totally custom stuff?
721
-	if (!empty($context['profile_javascript']))
722
-		addInlineJavaScript($context['profile_javascript'], true);
752
+	if (!empty($context['profile_javascript'])) {
753
+			addInlineJavaScript($context['profile_javascript'], true);
754
+	}
723 755
 
724 756
 	// Free up some memory.
725 757
 	unset($profile_fields);
@@ -740,8 +772,9 @@  discard block
 block discarded – undo
740 772
 
741 773
 	// This allows variables to call activities when they save - by default just to reload their settings
742 774
 	$context['profile_execute_on_save'] = array();
743
-	if ($context['user']['is_owner'])
744
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
775
+	if ($context['user']['is_owner']) {
776
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
777
+	}
745 778
 
746 779
 	// Assume we log nothing.
747 780
 	$context['log_changes'] = array();
@@ -749,8 +782,9 @@  discard block
 block discarded – undo
749 782
 	// Cycle through the profile fields working out what to do!
750 783
 	foreach ($profile_fields as $key => $field)
751 784
 	{
752
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
753
-			continue;
785
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
786
+					continue;
787
+		}
754 788
 
755 789
 		// What gets updated?
756 790
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -778,12 +812,13 @@  discard block
 block discarded – undo
778 812
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
779 813
 
780 814
 		// Finally, clean up certain types.
781
-		if ($field['cast_type'] == 'int')
782
-			$_POST[$key] = (int) $_POST[$key];
783
-		elseif ($field['cast_type'] == 'float')
784
-			$_POST[$key] = (float) $_POST[$key];
785
-		elseif ($field['cast_type'] == 'check')
786
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
815
+		if ($field['cast_type'] == 'int') {
816
+					$_POST[$key] = (int) $_POST[$key];
817
+		} elseif ($field['cast_type'] == 'float') {
818
+					$_POST[$key] = (float) $_POST[$key];
819
+		} elseif ($field['cast_type'] == 'check') {
820
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
821
+		}
787 822
 
788 823
 		// If we got here we're doing OK.
789 824
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -794,11 +829,12 @@  discard block
 block discarded – undo
794 829
 			$cur_profile[$key] = $_POST[$key];
795 830
 
796 831
 			// Are we logging it?
797
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
798
-				$context['log_changes'][$key] = array(
832
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
833
+							$context['log_changes'][$key] = array(
799 834
 					'previous' => $old_profile[$key],
800 835
 					'new' => $_POST[$key],
801 836
 				);
837
+			}
802 838
 		}
803 839
 
804 840
 		// Logging group changes are a bit different...
@@ -831,10 +867,11 @@  discard block
 block discarded – undo
831 867
 				{
832 868
 					foreach ($groups as $id => $group)
833 869
 					{
834
-						if (isset($context['member_groups'][$group]))
835
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
836
-						else
837
-							unset($additional_groups[$type][$id]);
870
+						if (isset($context['member_groups'][$group])) {
871
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
872
+						} else {
873
+													unset($additional_groups[$type][$id]);
874
+						}
838 875
 					}
839 876
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
840 877
 				}
@@ -845,10 +882,11 @@  discard block
 block discarded – undo
845 882
 	}
846 883
 
847 884
 	// @todo Temporary
848
-	if ($context['user']['is_owner'])
849
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
850
-	else
851
-		$changeOther = allowedTo('profile_extra_any');
885
+	if ($context['user']['is_owner']) {
886
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
887
+	} else {
888
+			$changeOther = allowedTo('profile_extra_any');
889
+	}
852 890
 	if ($changeOther && empty($post_errors))
853 891
 	{
854 892
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -856,8 +894,9 @@  discard block
 block discarded – undo
856 894
 		{
857 895
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
858 896
 
859
-			if (!empty($custom_fields_errors))
860
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
897
+			if (!empty($custom_fields_errors)) {
898
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
899
+			}
861 900
 		}
862 901
 	}
863 902
 
@@ -883,9 +922,9 @@  discard block
 block discarded – undo
883 922
 	if ($context['user']['is_owner'])
884 923
 	{
885 924
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
925
+	} else {
926
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
886 927
 	}
887
-	else
888
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
889 928
 
890 929
 	// Arrays of all the changes - makes things easier.
891 930
 	$profile_bools = array();
@@ -896,22 +935,25 @@  discard block
 block discarded – undo
896 935
 		'ignore_boards',
897 936
 	);
898 937
 
899
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
900
-		$_POST['ignore_brd'] = array();
938
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
939
+			$_POST['ignore_brd'] = array();
940
+	}
901 941
 
902 942
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
903 943
 	if (isset($_POST['ignore_brd']))
904 944
 	{
905
-		if (!is_array($_POST['ignore_brd']))
906
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
945
+		if (!is_array($_POST['ignore_brd'])) {
946
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
947
+		}
907 948
 
908 949
 		foreach ($_POST['ignore_brd'] as $k => $d)
909 950
 		{
910 951
 			$d = (int) $d;
911
-			if ($d != 0)
912
-				$_POST['ignore_brd'][$k] = $d;
913
-			else
914
-				unset($_POST['ignore_brd'][$k]);
952
+			if ($d != 0) {
953
+							$_POST['ignore_brd'][$k] = $d;
954
+			} else {
955
+							unset($_POST['ignore_brd'][$k]);
956
+			}
915 957
 		}
916 958
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
917 959
 		unset($_POST['ignore_brd']);
@@ -924,21 +966,26 @@  discard block
 block discarded – undo
924 966
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
925 967
 		//makeAvatarChanges($memID, $post_errors);
926 968
 
927
-		if (!empty($_REQUEST['sa']))
928
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
969
+		if (!empty($_REQUEST['sa'])) {
970
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
971
+		}
929 972
 
930
-		foreach ($profile_bools as $var)
931
-			if (isset($_POST[$var]))
973
+		foreach ($profile_bools as $var) {
974
+					if (isset($_POST[$var]))
932 975
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
933
-		foreach ($profile_ints as $var)
934
-			if (isset($_POST[$var]))
976
+		}
977
+		foreach ($profile_ints as $var) {
978
+					if (isset($_POST[$var]))
935 979
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
936
-		foreach ($profile_floats as $var)
937
-			if (isset($_POST[$var]))
980
+		}
981
+		foreach ($profile_floats as $var) {
982
+					if (isset($_POST[$var]))
938 983
 				$profile_vars[$var] = (float) $_POST[$var];
939
-		foreach ($profile_strings as $var)
940
-			if (isset($_POST[$var]))
984
+		}
985
+		foreach ($profile_strings as $var) {
986
+					if (isset($_POST[$var]))
941 987
 				$profile_vars[$var] = $_POST[$var];
988
+		}
942 989
 	}
943 990
 }
944 991
 
@@ -972,8 +1019,9 @@  discard block
 block discarded – undo
972 1019
 	);
973 1020
 
974 1021
 	// Can't change reserved vars.
975
-	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))
976
-		fatal_lang_error('no_access', false);
1022
+	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)) {
1023
+			fatal_lang_error('no_access', false);
1024
+	}
977 1025
 
978 1026
 	// Don't allow any overriding of custom fields with default or non-default options.
979 1027
 	$request = $smcFunc['db_query']('', '
@@ -985,8 +1033,9 @@  discard block
 block discarded – undo
985 1033
 		)
986 1034
 	);
987 1035
 	$custom_fields = array();
988
-	while ($row = $smcFunc['db_fetch_assoc']($request))
989
-		$custom_fields[] = $row['col_name'];
1036
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1037
+			$custom_fields[] = $row['col_name'];
1038
+	}
990 1039
 	$smcFunc['db_free_result']($request);
991 1040
 
992 1041
 	// These are the theme changes...
@@ -995,33 +1044,39 @@  discard block
 block discarded – undo
995 1044
 	{
996 1045
 		foreach ($_POST['options'] as $opt => $val)
997 1046
 		{
998
-			if (in_array($opt, $custom_fields))
999
-				continue;
1047
+			if (in_array($opt, $custom_fields)) {
1048
+							continue;
1049
+			}
1000 1050
 
1001 1051
 			// These need to be controlled.
1002
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1003
-				$val = max(0, min($val, 50));
1052
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1053
+							$val = max(0, min($val, 50));
1054
+			}
1004 1055
 			// We don't set this per theme anymore.
1005
-			elseif ($opt == 'allow_no_censored')
1006
-				continue;
1056
+			elseif ($opt == 'allow_no_censored') {
1057
+							continue;
1058
+			}
1007 1059
 
1008 1060
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1009 1061
 		}
1010 1062
 	}
1011 1063
 
1012 1064
 	$erase_options = array();
1013
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1014
-		foreach ($_POST['default_options'] as $opt => $val)
1065
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1066
+			foreach ($_POST['default_options'] as $opt => $val)
1015 1067
 		{
1016 1068
 			if (in_array($opt, $custom_fields))
1017 1069
 				continue;
1070
+	}
1018 1071
 
1019 1072
 			// These need to be controlled.
1020
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1021
-				$val = max(0, min($val, 50));
1073
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1074
+							$val = max(0, min($val, 50));
1075
+			}
1022 1076
 			// Only let admins and owners change the censor.
1023
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1024
-					continue;
1077
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1078
+								continue;
1079
+			}
1025 1080
 
1026 1081
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1027 1082
 			$erase_options[] = $opt;
@@ -1057,8 +1112,9 @@  discard block
 block discarded – undo
1057 1112
 
1058 1113
 		// Admins can choose any theme, even if it's not enabled...
1059 1114
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1060
-		foreach ($themes as $t)
1061
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1115
+		foreach ($themes as $t) {
1116
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1117
+		}
1062 1118
 	}
1063 1119
 }
1064 1120
 
@@ -1077,8 +1133,9 @@  discard block
 block discarded – undo
1077 1133
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1078 1134
 	{
1079 1135
 		// Make sure only integers are deleted.
1080
-		foreach ($_POST['notify_boards'] as $index => $id)
1081
-			$_POST['notify_boards'][$index] = (int) $id;
1136
+		foreach ($_POST['notify_boards'] as $index => $id) {
1137
+					$_POST['notify_boards'][$index] = (int) $id;
1138
+		}
1082 1139
 
1083 1140
 		// id_board = 0 is reserved for topic notifications.
1084 1141
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1097,8 +1154,9 @@  discard block
 block discarded – undo
1097 1154
 	// We are editing topic notifications......
1098 1155
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1099 1156
 	{
1100
-		foreach ($_POST['notify_topics'] as $index => $id)
1101
-			$_POST['notify_topics'][$index] = (int) $id;
1157
+		foreach ($_POST['notify_topics'] as $index => $id) {
1158
+					$_POST['notify_topics'][$index] = (int) $id;
1159
+		}
1102 1160
 
1103 1161
 		// Make sure there are no zeros left.
1104 1162
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1112,16 +1170,18 @@  discard block
 block discarded – undo
1112 1170
 				'selected_member' => $memID,
1113 1171
 			)
1114 1172
 		);
1115
-		foreach ($_POST['notify_topics'] as $topic)
1116
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1173
+		foreach ($_POST['notify_topics'] as $topic) {
1174
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1175
+		}
1117 1176
 	}
1118 1177
 
1119 1178
 	// We are removing topic preferences
1120 1179
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1121 1180
 	{
1122 1181
 		$prefs = array();
1123
-		foreach ($_POST['notify_topics'] as $topic)
1124
-			$prefs[] = 'topic_notify_' . $topic;
1182
+		foreach ($_POST['notify_topics'] as $topic) {
1183
+					$prefs[] = 'topic_notify_' . $topic;
1184
+		}
1125 1185
 		deleteNotifyPrefs($memID, $prefs);
1126 1186
 	}
1127 1187
 
@@ -1129,8 +1189,9 @@  discard block
 block discarded – undo
1129 1189
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1130 1190
 	{
1131 1191
 		$prefs = array();
1132
-		foreach ($_POST['notify_boards'] as $board)
1133
-			$prefs[] = 'board_notify_' . $board;
1192
+		foreach ($_POST['notify_boards'] as $board) {
1193
+					$prefs[] = 'board_notify_' . $board;
1194
+		}
1134 1195
 		deleteNotifyPrefs($memID, $prefs);
1135 1196
 	}
1136 1197
 }
@@ -1151,8 +1212,9 @@  discard block
 block discarded – undo
1151 1212
 
1152 1213
 	$errors = array();
1153 1214
 
1154
-	if ($sanitize && isset($_POST['customfield']))
1155
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1215
+	if ($sanitize && isset($_POST['customfield'])) {
1216
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1217
+	}
1156 1218
 
1157 1219
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1158 1220
 
@@ -1178,26 +1240,29 @@  discard block
 block discarded – undo
1178 1240
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1179 1241
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1180 1242
 		*/
1181
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1182
-			continue;
1243
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1244
+					continue;
1245
+		}
1183 1246
 
1184 1247
 		// Validate the user data.
1185
-		if ($row['field_type'] == 'check')
1186
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1187
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1248
+		if ($row['field_type'] == 'check') {
1249
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1250
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1188 1251
 		{
1189 1252
 			$value = $row['default_value'];
1190
-			foreach (explode(',', $row['field_options']) as $k => $v)
1191
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1253
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1254
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1192 1255
 					$value = $v;
1256
+			}
1193 1257
 		}
1194 1258
 		// Otherwise some form of text!
1195 1259
 		else
1196 1260
 		{
1197 1261
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1198 1262
 
1199
-			if ($row['field_length'])
1200
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			if ($row['field_length']) {
1264
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1265
+			}
1201 1266
 
1202 1267
 			// Any masks?
1203 1268
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1206,36 +1271,34 @@  discard block
 block discarded – undo
1206 1271
 				$valueReference = un_htmlspecialchars($value);
1207 1272
 
1208 1273
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1209
-				if (empty($value) && !is_numeric($value))
1210
-					$value = '';
1274
+				if (empty($value) && !is_numeric($value)) {
1275
+									$value = '';
1276
+				}
1211 1277
 
1212 1278
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1213 1279
 				{
1214
-					if ($returnErrors)
1215
-						$errors[] = 'custom_field_nohtml_fail';
1216
-
1217
-					else
1218
-						$value = '';
1219
-				}
1220
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1280
+					if ($returnErrors) {
1281
+											$errors[] = 'custom_field_nohtml_fail';
1282
+					} else {
1283
+											$value = '';
1284
+					}
1285
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1221 1286
 				{
1222
-					if ($returnErrors)
1223
-						$errors[] = 'custom_field_mail_fail';
1224
-
1225
-					else
1226
-						$value = '';
1227
-				}
1228
-				elseif ($row['mask'] == 'number')
1287
+					if ($returnErrors) {
1288
+											$errors[] = 'custom_field_mail_fail';
1289
+					} else {
1290
+											$value = '';
1291
+					}
1292
+				} elseif ($row['mask'] == 'number')
1229 1293
 				{
1230 1294
 					$value = (int) $value;
1231
-				}
1232
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1295
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1233 1296
 				{
1234
-					if ($returnErrors)
1235
-						$errors[] = 'custom_field_regex_fail';
1236
-
1237
-					else
1238
-						$value = '';
1297
+					if ($returnErrors) {
1298
+											$errors[] = 'custom_field_regex_fail';
1299
+					} else {
1300
+											$value = '';
1301
+					}
1239 1302
 				}
1240 1303
 
1241 1304
 				unset($valueReference);
@@ -1259,8 +1322,7 @@  discard block
 block discarded – undo
1259 1322
 			{
1260 1323
 				$deletes = array('id_theme' => 1 , 'variable' => $row['col_name'], 'id_member' => $memID);
1261 1324
 				unset($user_profile[$memID]['options'][$row['col_name']]);
1262
-			}
1263
-			else
1325
+			} else
1264 1326
 			{
1265 1327
 				$changes[] = array(1, $row['col_name'], $value, $memID);
1266 1328
 				$user_profile[$memID]['options'][$row['col_name']] = $value;
@@ -1271,27 +1333,30 @@  discard block
 block discarded – undo
1271 1333
 
1272 1334
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize, &$deletes));
1273 1335
 
1274
-	if (!empty($hook_errors) && is_array($hook_errors))
1275
-		$errors = array_merge($errors, $hook_errors);
1336
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1337
+			$errors = array_merge($errors, $hook_errors);
1338
+	}
1276 1339
 
1277 1340
 	// Make those changes!
1278 1341
 	if ((!empty($changes) || !empty($deletes)) && empty($context['password_auth_failed']) && empty($errors))
1279 1342
 	{
1280
-		if (!empty($changes))
1281
-			$smcFunc['db_insert']('replace',
1343
+		if (!empty($changes)) {
1344
+					$smcFunc['db_insert']('replace',
1282 1345
 				'{db_prefix}themes',
1283 1346
 				array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534', 'id_member' => 'int'),
1284 1347
 				$changes,
1285 1348
 				array('id_theme', 'variable', 'id_member')
1286 1349
 			);
1287
-		if (!empty($deletes))
1288
-			$smcFunc['db_query']('','
1350
+		}
1351
+		if (!empty($deletes)) {
1352
+					$smcFunc['db_query']('','
1289 1353
 				DELETE FROM {db_prefix}themes
1290 1354
 				WHERE id_theme = {int:id_theme} AND
1291 1355
 						variable = {string:variable} AND
1292 1356
 						id_member = {int:id_member}',
1293 1357
 				$deletes
1294 1358
 				);
1359
+		}
1295 1360
 		if (!empty($log_changes) && !empty($modSettings['modlog_enabled']))
1296 1361
 		{
1297 1362
 			require_once($sourcedir . '/Logging.php');
@@ -1299,9 +1364,10 @@  discard block
 block discarded – undo
1299 1364
 		}
1300 1365
 	}
1301 1366
 
1302
-	if ($returnErrors)
1303
-		return $errors;
1304
-}
1367
+	if ($returnErrors) {
1368
+			return $errors;
1369
+	}
1370
+	}
1305 1371
 
1306 1372
 /**
1307 1373
  * Show all the users buddies, as well as a add/delete interface.
@@ -1313,8 +1379,9 @@  discard block
 block discarded – undo
1313 1379
 	global $context, $txt, $modSettings;
1314 1380
 
1315 1381
 	// Do a quick check to ensure people aren't getting here illegally!
1316
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1317
-		fatal_lang_error('no_access', false);
1382
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1383
+			fatal_lang_error('no_access', false);
1384
+	}
1318 1385
 
1319 1386
 	// Can we email the user direct?
1320 1387
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1344,9 +1411,10 @@  discard block
 block discarded – undo
1344 1411
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1345 1412
 	$call = call_helper($subActions[$context['list_area']][0], true);
1346 1413
 
1347
-	if (!empty($call))
1348
-		call_user_func($call, $memID);
1349
-}
1414
+	if (!empty($call)) {
1415
+			call_user_func($call, $memID);
1416
+	}
1417
+	}
1350 1418
 
1351 1419
 /**
1352 1420
  * Show all the users buddies, as well as a add/delete interface.
@@ -1360,9 +1428,10 @@  discard block
 block discarded – undo
1360 1428
 
1361 1429
 	// For making changes!
1362 1430
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1363
-	foreach ($buddiesArray as $k => $dummy)
1364
-		if ($dummy == '')
1431
+	foreach ($buddiesArray as $k => $dummy) {
1432
+			if ($dummy == '')
1365 1433
 			unset($buddiesArray[$k]);
1434
+	}
1366 1435
 
1367 1436
 	// Removing a buddy?
1368 1437
 	if (isset($_GET['remove']))
@@ -1374,10 +1443,11 @@  discard block
 block discarded – undo
1374 1443
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1375 1444
 
1376 1445
 		// Heh, I'm lazy, do it the easy way...
1377
-		foreach ($buddiesArray as $key => $buddy)
1378
-			if ($buddy == (int) $_GET['remove'])
1446
+		foreach ($buddiesArray as $key => $buddy) {
1447
+					if ($buddy == (int) $_GET['remove'])
1379 1448
 			{
1380 1449
 				unset($buddiesArray[$key]);
1450
+		}
1381 1451
 				$_SESSION['prf-save'] = true;
1382 1452
 			}
1383 1453
 
@@ -1387,8 +1457,7 @@  discard block
 block discarded – undo
1387 1457
 
1388 1458
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1389 1459
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1390
-	}
1391
-	elseif (isset($_POST['new_buddy']))
1460
+	} elseif (isset($_POST['new_buddy']))
1392 1461
 	{
1393 1462
 		checkSession();
1394 1463
 
@@ -1401,8 +1470,9 @@  discard block
 block discarded – undo
1401 1470
 		{
1402 1471
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1403 1472
 
1404
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1405
-				unset($new_buddies[$k]);
1473
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1474
+							unset($new_buddies[$k]);
1475
+			}
1406 1476
 		}
1407 1477
 
1408 1478
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1422,16 +1492,18 @@  discard block
 block discarded – undo
1422 1492
 				)
1423 1493
 			);
1424 1494
 
1425
-			if ($smcFunc['db_num_rows']($request) != 0)
1426
-				$_SESSION['prf-save'] = true;
1495
+			if ($smcFunc['db_num_rows']($request) != 0) {
1496
+							$_SESSION['prf-save'] = true;
1497
+			}
1427 1498
 
1428 1499
 			// Add the new member to the buddies array.
1429 1500
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1430 1501
 			{
1431
-				if (in_array($row['id_member'], $buddiesArray))
1432
-					continue;
1433
-				else
1434
-					$buddiesArray[] = (int) $row['id_member'];
1502
+				if (in_array($row['id_member'], $buddiesArray)) {
1503
+									continue;
1504
+				} else {
1505
+									$buddiesArray[] = (int) $row['id_member'];
1506
+				}
1435 1507
 			}
1436 1508
 			$smcFunc['db_free_result']($request);
1437 1509
 
@@ -1461,18 +1533,20 @@  discard block
 block discarded – undo
1461 1533
 
1462 1534
 	$context['custom_pf'] = array();
1463 1535
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1464
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1465
-		if (!isset($disabled_fields[$row['col_name']]))
1536
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1537
+			if (!isset($disabled_fields[$row['col_name']]))
1466 1538
 			$context['custom_pf'][$row['col_name']] = array(
1467 1539
 				'label' => $row['field_name'],
1468 1540
 				'type' => $row['field_type'],
1469 1541
 				'bbc' => !empty($row['bbc']),
1470 1542
 				'enclose' => $row['enclose'],
1471 1543
 			);
1544
+	}
1472 1545
 
1473 1546
 	// Gotta disable the gender option.
1474
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None')
1475
-		unset($context['custom_pf']['cust_gender']);
1547
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') {
1548
+			unset($context['custom_pf']['cust_gender']);
1549
+	}
1476 1550
 
1477 1551
 	$smcFunc['db_free_result']($request);
1478 1552
 
@@ -1489,8 +1563,9 @@  discard block
 block discarded – undo
1489 1563
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1490 1564
 			)
1491 1565
 		);
1492
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1493
-			$buddies[] = $row['id_member'];
1566
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1567
+					$buddies[] = $row['id_member'];
1568
+		}
1494 1569
 		$smcFunc['db_free_result']($result);
1495 1570
 	}
1496 1571
 
@@ -1518,30 +1593,32 @@  discard block
 block discarded – undo
1518 1593
 					continue;
1519 1594
 				}
1520 1595
 
1521
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1522
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1523
-
1524
-				elseif ($column['type'] == 'check')
1525
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1596
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1597
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1598
+				} elseif ($column['type'] == 'check') {
1599
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1600
+				}
1526 1601
 
1527 1602
 				// Enclosing the user input within some other text?
1528
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1529
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1603
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1604
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1530 1605
 						'{SCRIPTURL}' => $scripturl,
1531 1606
 						'{IMAGES_URL}' => $settings['images_url'],
1532 1607
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1533 1608
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1534 1609
 					));
1610
+				}
1535 1611
 			}
1536 1612
 		}
1537 1613
 	}
1538 1614
 
1539 1615
 	if (isset($_SESSION['prf-save']))
1540 1616
 	{
1541
-		if ($_SESSION['prf-save'] === true)
1542
-			$context['saved_successful'] = true;
1543
-		else
1544
-			$context['saved_failed'] = $_SESSION['prf-save'];
1617
+		if ($_SESSION['prf-save'] === true) {
1618
+					$context['saved_successful'] = true;
1619
+		} else {
1620
+					$context['saved_failed'] = $_SESSION['prf-save'];
1621
+		}
1545 1622
 
1546 1623
 		unset($_SESSION['prf-save']);
1547 1624
 	}
@@ -1561,9 +1638,10 @@  discard block
 block discarded – undo
1561 1638
 
1562 1639
 	// For making changes!
1563 1640
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1564
-	foreach ($ignoreArray as $k => $dummy)
1565
-		if ($dummy == '')
1641
+	foreach ($ignoreArray as $k => $dummy) {
1642
+			if ($dummy == '')
1566 1643
 			unset($ignoreArray[$k]);
1644
+	}
1567 1645
 
1568 1646
 	// Removing a member from the ignore list?
1569 1647
 	if (isset($_GET['remove']))
@@ -1573,10 +1651,11 @@  discard block
 block discarded – undo
1573 1651
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1574 1652
 
1575 1653
 		// Heh, I'm lazy, do it the easy way...
1576
-		foreach ($ignoreArray as $key => $id_remove)
1577
-			if ($id_remove == (int) $_GET['remove'])
1654
+		foreach ($ignoreArray as $key => $id_remove) {
1655
+					if ($id_remove == (int) $_GET['remove'])
1578 1656
 			{
1579 1657
 				unset($ignoreArray[$key]);
1658
+		}
1580 1659
 				$_SESSION['prf-save'] = true;
1581 1660
 			}
1582 1661
 
@@ -1586,8 +1665,7 @@  discard block
 block discarded – undo
1586 1665
 
1587 1666
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1588 1667
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1589
-	}
1590
-	elseif (isset($_POST['new_ignore']))
1668
+	} elseif (isset($_POST['new_ignore']))
1591 1669
 	{
1592 1670
 		checkSession();
1593 1671
 		// Prepare the string for extraction...
@@ -1599,8 +1677,9 @@  discard block
 block discarded – undo
1599 1677
 		{
1600 1678
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1601 1679
 
1602
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1603
-				unset($new_entries[$k]);
1680
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1681
+							unset($new_entries[$k]);
1682
+			}
1604 1683
 		}
1605 1684
 
1606 1685
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1618,16 +1697,18 @@  discard block
 block discarded – undo
1618 1697
 				)
1619 1698
 			);
1620 1699
 
1621
-			if ($smcFunc['db_num_rows']($request) != 0)
1622
-				$_SESSION['prf-save'] = true;
1700
+			if ($smcFunc['db_num_rows']($request) != 0) {
1701
+							$_SESSION['prf-save'] = true;
1702
+			}
1623 1703
 
1624 1704
 			// Add the new member to the buddies array.
1625 1705
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1626 1706
 			{
1627
-				if (in_array($row['id_member'], $ignoreArray))
1628
-					continue;
1629
-				else
1630
-					$ignoreArray[] = (int) $row['id_member'];
1707
+				if (in_array($row['id_member'], $ignoreArray)) {
1708
+									continue;
1709
+				} else {
1710
+									$ignoreArray[] = (int) $row['id_member'];
1711
+				}
1631 1712
 			}
1632 1713
 			$smcFunc['db_free_result']($request);
1633 1714
 
@@ -1656,8 +1737,9 @@  discard block
 block discarded – undo
1656 1737
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1657 1738
 			)
1658 1739
 		);
1659
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1660
-			$ignored[] = $row['id_member'];
1740
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1741
+					$ignored[] = $row['id_member'];
1742
+		}
1661 1743
 		$smcFunc['db_free_result']($result);
1662 1744
 	}
1663 1745
 
@@ -1676,10 +1758,11 @@  discard block
 block discarded – undo
1676 1758
 
1677 1759
 	if (isset($_SESSION['prf-save']))
1678 1760
 	{
1679
-		if ($_SESSION['prf-save'] === true)
1680
-			$context['saved_successful'] = true;
1681
-		else
1682
-			$context['saved_failed'] = $_SESSION['prf-save'];
1761
+		if ($_SESSION['prf-save'] === true) {
1762
+					$context['saved_successful'] = true;
1763
+		} else {
1764
+					$context['saved_failed'] = $_SESSION['prf-save'];
1765
+		}
1683 1766
 
1684 1767
 		unset($_SESSION['prf-save']);
1685 1768
 	}
@@ -1695,8 +1778,9 @@  discard block
 block discarded – undo
1695 1778
 	global $context, $txt;
1696 1779
 
1697 1780
 	loadThemeOptions($memID);
1698
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1699
-		loadCustomFields($memID, 'account');
1781
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1782
+			loadCustomFields($memID, 'account');
1783
+	}
1700 1784
 
1701 1785
 	$context['sub_template'] = 'edit_options';
1702 1786
 	$context['page_desc'] = $txt['account_info'];
@@ -1723,8 +1807,9 @@  discard block
 block discarded – undo
1723 1807
 	global $context, $txt;
1724 1808
 
1725 1809
 	loadThemeOptions($memID);
1726
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1727
-		loadCustomFields($memID, 'forumprofile');
1810
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1811
+			loadCustomFields($memID, 'forumprofile');
1812
+	}
1728 1813
 
1729 1814
 	$context['sub_template'] = 'edit_options';
1730 1815
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1757,18 +1842,21 @@  discard block
 block discarded – undo
1757 1842
 	$dirs = array();
1758 1843
 	$files = array();
1759 1844
 
1760
-	if (!$dir)
1761
-		return array();
1845
+	if (!$dir) {
1846
+			return array();
1847
+	}
1762 1848
 
1763 1849
 	while ($line = $dir->read())
1764 1850
 	{
1765
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1766
-			continue;
1851
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1852
+					continue;
1853
+		}
1767 1854
 
1768
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1769
-			$dirs[] = $line;
1770
-		else
1771
-			$files[] = $line;
1855
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1856
+					$dirs[] = $line;
1857
+		} else {
1858
+					$files[] = $line;
1859
+		}
1772 1860
 	}
1773 1861
 	$dir->close();
1774 1862
 
@@ -1789,14 +1877,15 @@  discard block
 block discarded – undo
1789 1877
 	foreach ($dirs as $line)
1790 1878
 	{
1791 1879
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1792
-		if (!empty($tmp))
1793
-			$result[] = array(
1880
+		if (!empty($tmp)) {
1881
+					$result[] = array(
1794 1882
 				'filename' => $smcFunc['htmlspecialchars']($line),
1795 1883
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1796 1884
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1797 1885
 				'is_dir' => true,
1798 1886
 				'files' => $tmp
1799 1887
 		);
1888
+		}
1800 1889
 		unset($tmp);
1801 1890
 	}
1802 1891
 
@@ -1806,8 +1895,9 @@  discard block
 block discarded – undo
1806 1895
 		$extension = substr(strrchr($line, '.'), 1);
1807 1896
 
1808 1897
 		// Make sure it is an image.
1809
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1810
-			continue;
1898
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1899
+					continue;
1900
+		}
1811 1901
 
1812 1902
 		$result[] = array(
1813 1903
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1815,8 +1905,9 @@  discard block
 block discarded – undo
1815 1905
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1816 1906
 			'is_dir' => false
1817 1907
 		);
1818
-		if ($level == 1)
1819
-			$context['avatar_list'][] = $directory . '/' . $line;
1908
+		if ($level == 1) {
1909
+					$context['avatar_list'][] = $directory . '/' . $line;
1910
+		}
1820 1911
 	}
1821 1912
 
1822 1913
 	return $result;
@@ -1838,8 +1929,9 @@  discard block
 block discarded – undo
1838 1929
 	call_integration_hook('integrate_theme_options');
1839 1930
 
1840 1931
 	loadThemeOptions($memID);
1841
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1842
-		loadCustomFields($memID, 'theme');
1932
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1933
+			loadCustomFields($memID, 'theme');
1934
+	}
1843 1935
 
1844 1936
 	$context['sub_template'] = 'edit_options';
1845 1937
 	$context['page_desc'] = $txt['theme_info'];
@@ -1893,16 +1985,19 @@  discard block
 block discarded – undo
1893 1985
 {
1894 1986
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1895 1987
 
1896
-	if (!isset($context['token_check']))
1897
-		$context['token_check'] = 'profile-nt' . $memID;
1988
+	if (!isset($context['token_check'])) {
1989
+			$context['token_check'] = 'profile-nt' . $memID;
1990
+	}
1898 1991
 
1899 1992
 	is_not_guest();
1900
-	if (!$context['user']['is_owner'])
1901
-		isAllowedTo('profile_extra_any');
1993
+	if (!$context['user']['is_owner']) {
1994
+			isAllowedTo('profile_extra_any');
1995
+	}
1902 1996
 
1903 1997
 	// Set the post action if we're coming from the profile...
1904
-	if (!isset($context['action']))
1905
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1998
+	if (!isset($context['action'])) {
1999
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
2000
+	}
1906 2001
 
1907 2002
 	// What options are set
1908 2003
 	loadThemeOptions($memID);
@@ -1989,28 +2084,34 @@  discard block
 block discarded – undo
1989 2084
 	);
1990 2085
 
1991 2086
 	// There are certain things that are disabled at the group level.
1992
-	if (empty($modSettings['cal_enabled']))
1993
-		unset($alert_types['calendar']);
2087
+	if (empty($modSettings['cal_enabled'])) {
2088
+			unset($alert_types['calendar']);
2089
+	}
1994 2090
 
1995 2091
 	// Disable paid subscriptions at group level if they're disabled
1996
-	if (empty($modSettings['paid_enabled']))
1997
-		unset($alert_types['paidsubs']);
2092
+	if (empty($modSettings['paid_enabled'])) {
2093
+			unset($alert_types['paidsubs']);
2094
+	}
1998 2095
 
1999 2096
 	// Disable membergroup requests at group level if they're disabled
2000
-	if (empty($modSettings['show_group_membership']))
2001
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2097
+	if (empty($modSettings['show_group_membership'])) {
2098
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2099
+	}
2002 2100
 
2003 2101
 	// Disable mentions if they're disabled
2004
-	if (empty($modSettings['enable_mentions']))
2005
-		unset($alert_types['msg']['msg_mention']);
2102
+	if (empty($modSettings['enable_mentions'])) {
2103
+			unset($alert_types['msg']['msg_mention']);
2104
+	}
2006 2105
 
2007 2106
 	// Disable likes if they're disabled
2008
-	if (empty($modSettings['enable_likes']))
2009
-		unset($alert_types['msg']['msg_like']);
2107
+	if (empty($modSettings['enable_likes'])) {
2108
+			unset($alert_types['msg']['msg_like']);
2109
+	}
2010 2110
 
2011 2111
 	// Disable buddy requests if they're disabled
2012
-	if (empty($modSettings['enable_buddylist']))
2013
-		unset($alert_types['members']['buddy_request']);
2112
+	if (empty($modSettings['enable_buddylist'])) {
2113
+			unset($alert_types['members']['buddy_request']);
2114
+	}
2014 2115
 
2015 2116
 	// Now, now, we could pass this through global but we should really get into the habit of
2016 2117
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2038,15 +2139,17 @@  discard block
 block discarded – undo
2038 2139
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2039 2140
 		}
2040 2141
 
2041
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2042
-			unset($alert_types['members']['request_group']);
2142
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2143
+					unset($alert_types['members']['request_group']);
2144
+		}
2043 2145
 
2044 2146
 		foreach ($alert_types as $group => $items)
2045 2147
 		{
2046 2148
 			foreach ($items as $alert_key => $alert_value)
2047 2149
 			{
2048
-				if (!isset($alert_value['permission']))
2049
-					continue;
2150
+				if (!isset($alert_value['permission'])) {
2151
+									continue;
2152
+				}
2050 2153
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2051 2154
 				{
2052 2155
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2054,12 +2157,14 @@  discard block
 block discarded – undo
2054 2157
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2055 2158
 				}
2056 2159
 
2057
-				if (!$perms_cache[$alert_value['permission']['name']])
2058
-					unset ($alert_types[$group][$alert_key]);
2160
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2161
+									unset ($alert_types[$group][$alert_key]);
2162
+				}
2059 2163
 			}
2060 2164
 
2061
-			if (empty($alert_types[$group]))
2062
-				unset ($alert_types[$group]);
2165
+			if (empty($alert_types[$group])) {
2166
+							unset ($alert_types[$group]);
2167
+			}
2063 2168
 		}
2064 2169
 	}
2065 2170
 
@@ -2091,9 +2196,9 @@  discard block
 block discarded – undo
2091 2196
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2092 2197
 						break;
2093 2198
 					case 'select':
2094
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2095
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2096
-						else
2199
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2200
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2201
+						} else
2097 2202
 						{
2098 2203
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2099 2204
 							$keys = array_keys($this_option['opts']);
@@ -2113,23 +2218,28 @@  discard block
 block discarded – undo
2113 2218
 				$this_value = 0;
2114 2219
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2115 2220
 				{
2116
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2117
-						$this_value |= $bitvalue;
2221
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2222
+											$this_value |= $bitvalue;
2223
+					}
2224
+				}
2225
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2226
+									$update_prefs[$item_key] = $this_value;
2118 2227
 				}
2119
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2120
-					$update_prefs[$item_key] = $this_value;
2121 2228
 			}
2122 2229
 		}
2123 2230
 
2124
-		if (!empty($_POST['opt_alert_timeout']))
2125
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2231
+		if (!empty($_POST['opt_alert_timeout'])) {
2232
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2233
+		}
2126 2234
 
2127
-		if (!empty($_POST['notify_announcements']))
2128
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2235
+		if (!empty($_POST['notify_announcements'])) {
2236
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2237
+		}
2129 2238
 
2130 2239
 		setNotifyPrefs((int) $memID, $update_prefs);
2131
-		foreach ($update_prefs as $pref => $value)
2132
-			$context['alert_prefs'][$pref] = $value;
2240
+		foreach ($update_prefs as $pref => $value) {
2241
+					$context['alert_prefs'][$pref] = $value;
2242
+		}
2133 2243
 
2134 2244
 		makeNotificationChanges($memID);
2135 2245
 
@@ -2159,8 +2269,9 @@  discard block
 block discarded – undo
2159 2269
 
2160 2270
 	// Now we're all set up.
2161 2271
 	is_not_guest();
2162
-	if (!$context['user']['is_owner'])
2163
-		fatal_error('no_access');
2272
+	if (!$context['user']['is_owner']) {
2273
+			fatal_error('no_access');
2274
+	}
2164 2275
 
2165 2276
 	checkSession('get');
2166 2277
 
@@ -2192,8 +2303,9 @@  discard block
 block discarded – undo
2192 2303
 {
2193 2304
 	global $smcFunc;
2194 2305
 
2195
-	if (empty($toMark) || empty($memID))
2196
-		return false;
2306
+	if (empty($toMark) || empty($memID)) {
2307
+			return false;
2308
+	}
2197 2309
 
2198 2310
 	$toMark = (array) $toMark;
2199 2311
 
@@ -2227,8 +2339,9 @@  discard block
 block discarded – undo
2227 2339
 {
2228 2340
 	global $smcFunc;
2229 2341
 
2230
-	if (empty($toDelete))
2231
-		return false;
2342
+	if (empty($toDelete)) {
2343
+			return false;
2344
+	}
2232 2345
 
2233 2346
 	$toDelete = (array) $toDelete;
2234 2347
 
@@ -2263,8 +2376,9 @@  discard block
 block discarded – undo
2263 2376
 {
2264 2377
 	global $smcFunc;
2265 2378
 
2266
-	if (empty($memID))
2267
-		return false;
2379
+	if (empty($memID)) {
2380
+			return false;
2381
+	}
2268 2382
 
2269 2383
 	$request = $smcFunc['db_query']('', '
2270 2384
 		SELECT id_alert
@@ -2341,8 +2455,9 @@  discard block
 block discarded – undo
2341 2455
 					{
2342 2456
 						$link = $topic['link'];
2343 2457
 
2344
-						if ($topic['new'])
2345
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2458
+						if ($topic['new']) {
2459
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2460
+						}
2346 2461
 
2347 2462
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2348 2463
 
@@ -2493,8 +2608,9 @@  discard block
 block discarded – undo
2493 2608
 					{
2494 2609
 						$link = $board['link'];
2495 2610
 
2496
-						if ($board['new'])
2497
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2611
+						if ($board['new']) {
2612
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2613
+						}
2498 2614
 
2499 2615
 						return $link;
2500 2616
 					},
@@ -2694,8 +2810,8 @@  discard block
 block discarded – undo
2694 2810
 		)
2695 2811
 	);
2696 2812
 	$notification_boards = array();
2697
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2698
-		$notification_boards[] = array(
2813
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2814
+			$notification_boards[] = array(
2699 2815
 			'id' => $row['id_board'],
2700 2816
 			'name' => $row['name'],
2701 2817
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2703,6 +2819,7 @@  discard block
 block discarded – undo
2703 2819
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2704 2820
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2705 2821
 		);
2822
+	}
2706 2823
 	$smcFunc['db_free_result']($request);
2707 2824
 
2708 2825
 	return $notification_boards;
@@ -2717,17 +2834,18 @@  discard block
 block discarded – undo
2717 2834
 {
2718 2835
 	global $context, $options, $cur_profile, $smcFunc;
2719 2836
 
2720
-	if (isset($_POST['default_options']))
2721
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2837
+	if (isset($_POST['default_options'])) {
2838
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2839
+	}
2722 2840
 
2723 2841
 	if ($context['user']['is_owner'])
2724 2842
 	{
2725 2843
 		$context['member']['options'] = $options;
2726
-		if (isset($_POST['options']) && is_array($_POST['options']))
2727
-			foreach ($_POST['options'] as $k => $v)
2844
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2845
+					foreach ($_POST['options'] as $k => $v)
2728 2846
 				$context['member']['options'][$k] = $v;
2729
-	}
2730
-	else
2847
+		}
2848
+	} else
2731 2849
 	{
2732 2850
 		$request = $smcFunc['db_query']('', '
2733 2851
 			SELECT id_member, variable, value
@@ -2748,8 +2866,9 @@  discard block
 block discarded – undo
2748 2866
 				continue;
2749 2867
 			}
2750 2868
 
2751
-			if (isset($_POST['options'][$row['variable']]))
2752
-				$row['value'] = $_POST['options'][$row['variable']];
2869
+			if (isset($_POST['options'][$row['variable']])) {
2870
+							$row['value'] = $_POST['options'][$row['variable']];
2871
+			}
2753 2872
 			$context['member']['options'][$row['variable']] = $row['value'];
2754 2873
 		}
2755 2874
 		$smcFunc['db_free_result']($request);
@@ -2757,8 +2876,9 @@  discard block
 block discarded – undo
2757 2876
 		// Load up the default theme options for any missing.
2758 2877
 		foreach ($temp as $k => $v)
2759 2878
 		{
2760
-			if (!isset($context['member']['options'][$k]))
2761
-				$context['member']['options'][$k] = $v;
2879
+			if (!isset($context['member']['options'][$k])) {
2880
+							$context['member']['options'][$k] = $v;
2881
+			}
2762 2882
 		}
2763 2883
 	}
2764 2884
 }
@@ -2773,8 +2893,9 @@  discard block
 block discarded – undo
2773 2893
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2774 2894
 
2775 2895
 	// Have the admins enabled this option?
2776
-	if (empty($modSettings['allow_ignore_boards']))
2777
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2896
+	if (empty($modSettings['allow_ignore_boards'])) {
2897
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2898
+	}
2778 2899
 
2779 2900
 	// Find all the boards this user is allowed to see.
2780 2901
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2794,12 +2915,13 @@  discard block
 block discarded – undo
2794 2915
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2795 2916
 	{
2796 2917
 		// This category hasn't been set up yet..
2797
-		if (!isset($context['categories'][$row['id_cat']]))
2798
-			$context['categories'][$row['id_cat']] = array(
2918
+		if (!isset($context['categories'][$row['id_cat']])) {
2919
+					$context['categories'][$row['id_cat']] = array(
2799 2920
 				'id' => $row['id_cat'],
2800 2921
 				'name' => $row['cat_name'],
2801 2922
 				'boards' => array()
2802 2923
 			);
2924
+		}
2803 2925
 
2804 2926
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2805 2927
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2829,18 +2951,20 @@  discard block
 block discarded – undo
2829 2951
 	}
2830 2952
 
2831 2953
 	$max_boards = ceil(count($temp_boards) / 2);
2832
-	if ($max_boards == 1)
2833
-		$max_boards = 2;
2954
+	if ($max_boards == 1) {
2955
+			$max_boards = 2;
2956
+	}
2834 2957
 
2835 2958
 	// Now, alternate them so they can be shown left and right ;).
2836 2959
 	$context['board_columns'] = array();
2837 2960
 	for ($i = 0; $i < $max_boards; $i++)
2838 2961
 	{
2839 2962
 		$context['board_columns'][] = $temp_boards[$i];
2840
-		if (isset($temp_boards[$i + $max_boards]))
2841
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2842
-		else
2843
-			$context['board_columns'][] = array();
2963
+		if (isset($temp_boards[$i + $max_boards])) {
2964
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2965
+		} else {
2966
+					$context['board_columns'][] = array();
2967
+		}
2844 2968
 	}
2845 2969
 
2846 2970
 	loadThemeOptions($memID);
@@ -2909,8 +3033,9 @@  discard block
 block discarded – undo
2909 3033
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2910 3034
 	{
2911 3035
 		// We should skip the administrator group if they don't have the admin_forum permission!
2912
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2913
-			continue;
3036
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3037
+					continue;
3038
+		}
2914 3039
 
2915 3040
 		$context['member_groups'][$row['id_group']] = array(
2916 3041
 			'id' => $row['id_group'],
@@ -2956,16 +3081,17 @@  discard block
 block discarded – undo
2956 3081
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2957 3082
 	// Warning message for signature image limits?
2958 3083
 	$context['signature_warning'] = '';
2959
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2960
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2961
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2962
-		$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']);
3084
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3085
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3086
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3087
+			$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']);
3088
+	}
2963 3089
 
2964 3090
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2965 3091
 
2966
-	if (empty($context['do_preview']))
2967
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2968
-	else
3092
+	if (empty($context['do_preview'])) {
3093
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3094
+	} else
2969 3095
 	{
2970 3096
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2971 3097
 		$validation = profileValidateSignature($signature);
@@ -2975,8 +3101,9 @@  discard block
 block discarded – undo
2975 3101
 			$context['post_errors'] = array();
2976 3102
 		}
2977 3103
 		$context['post_errors'][] = 'signature_not_yet_saved';
2978
-		if ($validation !== true && $validation !== false)
2979
-			$context['post_errors'][] = $validation;
3104
+		if ($validation !== true && $validation !== false) {
3105
+					$context['post_errors'][] = $validation;
3106
+		}
2980 3107
 
2981 3108
 		censorText($context['member']['signature']);
2982 3109
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2986,8 +3113,9 @@  discard block
 block discarded – undo
2986 3113
 	}
2987 3114
 
2988 3115
 	// Load the spell checker?
2989
-	if ($context['show_spellchecking'])
2990
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
3116
+	if ($context['show_spellchecking']) {
3117
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
3118
+	}
2991 3119
 
2992 3120
 	return true;
2993 3121
 }
@@ -3021,8 +3149,7 @@  discard block
 block discarded – undo
3021 3149
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3022 3150
 		);
3023 3151
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3024
-	}
3025
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3152
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3026 3153
 	{
3027 3154
 		$context['member']['avatar'] += array(
3028 3155
 			'choice' => 'upload',
@@ -3032,33 +3159,34 @@  discard block
 block discarded – undo
3032 3159
 		$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'];
3033 3160
 	}
3034 3161
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3035
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3036
-		$context['member']['avatar'] += array(
3162
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3163
+			$context['member']['avatar'] += array(
3037 3164
 			'choice' => 'external',
3038 3165
 			'server_pic' => 'blank.png',
3039 3166
 			'external' => $cur_profile['avatar_original']
3040 3167
 		);
3041
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3042
-		$context['member']['avatar'] += array(
3168
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3169
+			$context['member']['avatar'] += array(
3043 3170
 			'choice' => 'server_stored',
3044 3171
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3045 3172
 			'external' => 'http://'
3046 3173
 		);
3047
-	else
3048
-		$context['member']['avatar'] += array(
3174
+	} else {
3175
+			$context['member']['avatar'] += array(
3049 3176
 			'choice' => 'none',
3050 3177
 			'server_pic' => 'blank.png',
3051 3178
 			'external' => 'http://'
3052 3179
 		);
3180
+	}
3053 3181
 
3054 3182
 	// Get a list of all the avatars.
3055 3183
 	if ($context['member']['avatar']['allow_server_stored'])
3056 3184
 	{
3057 3185
 		$context['avatar_list'] = array();
3058 3186
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3187
+	} else {
3188
+			$context['avatars'] = array();
3059 3189
 	}
3060
-	else
3061
-		$context['avatars'] = array();
3062 3190
 
3063 3191
 	// Second level selected avatar...
3064 3192
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3087,19 +3215,22 @@  discard block
 block discarded – undo
3087 3215
 			)
3088 3216
 		);
3089 3217
 		$protected_groups = array(1);
3090
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3091
-			$protected_groups[] = $row['id_group'];
3218
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3219
+					$protected_groups[] = $row['id_group'];
3220
+		}
3092 3221
 		$smcFunc['db_free_result']($request);
3093 3222
 
3094 3223
 		$protected_groups = array_unique($protected_groups);
3095 3224
 	}
3096 3225
 
3097 3226
 	// The account page allows the change of your id_group - but not to a protected group!
3098
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3099
-		$value = (int) $value;
3227
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3228
+			$value = (int) $value;
3229
+	}
3100 3230
 	// ... otherwise it's the old group sir.
3101
-	else
3102
-		$value = $old_profile['id_group'];
3231
+	else {
3232
+			$value = $old_profile['id_group'];
3233
+	}
3103 3234
 
3104 3235
 	// Find the additional membergroups (if any)
3105 3236
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3108,16 +3239,18 @@  discard block
 block discarded – undo
3108 3239
 		foreach ($_POST['additional_groups'] as $group_id)
3109 3240
 		{
3110 3241
 			$group_id = (int) $group_id;
3111
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3112
-				$additional_groups[] = $group_id;
3242
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3243
+							$additional_groups[] = $group_id;
3244
+			}
3113 3245
 		}
3114 3246
 
3115 3247
 		// Put the protected groups back in there if you don't have permission to take them away.
3116 3248
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3117 3249
 		foreach ($old_additional_groups as $group_id)
3118 3250
 		{
3119
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3120
-				$additional_groups[] = $group_id;
3251
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3252
+							$additional_groups[] = $group_id;
3253
+			}
3121 3254
 		}
3122 3255
 
3123 3256
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3149,18 +3282,20 @@  discard block
 block discarded – undo
3149 3282
 			list ($another) = $smcFunc['db_fetch_row']($request);
3150 3283
 			$smcFunc['db_free_result']($request);
3151 3284
 
3152
-			if (empty($another))
3153
-				fatal_lang_error('at_least_one_admin', 'critical');
3285
+			if (empty($another)) {
3286
+							fatal_lang_error('at_least_one_admin', 'critical');
3287
+			}
3154 3288
 		}
3155 3289
 	}
3156 3290
 
3157 3291
 	// If we are changing group status, update permission cache as necessary.
3158 3292
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3159 3293
 	{
3160
-		if ($context['user']['is_owner'])
3161
-			$_SESSION['mc']['time'] = 0;
3162
-		else
3163
-			updateSettings(array('settings_updated' => time()));
3294
+		if ($context['user']['is_owner']) {
3295
+					$_SESSION['mc']['time'] = 0;
3296
+		} else {
3297
+					updateSettings(array('settings_updated' => time()));
3298
+		}
3164 3299
 	}
3165 3300
 
3166 3301
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3181,8 +3316,9 @@  discard block
 block discarded – undo
3181 3316
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3182 3317
 
3183 3318
 	$memID = $context['id_member'];
3184
-	if (empty($memID) && !empty($context['password_auth_failed']))
3185
-		return false;
3319
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3320
+			return false;
3321
+	}
3186 3322
 
3187 3323
 	require_once($sourcedir . '/ManageAttachments.php');
3188 3324
 
@@ -3193,8 +3329,9 @@  discard block
 block discarded – undo
3193 3329
 	$downloadedExternalAvatar = false;
3194 3330
 	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']))
3195 3331
 	{
3196
-		if (!is_writable($uploadDir))
3197
-			fatal_lang_error('attachments_no_write', 'critical');
3332
+		if (!is_writable($uploadDir)) {
3333
+					fatal_lang_error('attachments_no_write', 'critical');
3334
+		}
3198 3335
 
3199 3336
 		$url = parse_url($_POST['userpicpersonal']);
3200 3337
 		$contents = fetch_web_data($url['scheme'] . '://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
@@ -3236,19 +3373,18 @@  discard block
 block discarded – undo
3236 3373
 
3237 3374
 		// Get rid of their old avatar. (if uploaded.)
3238 3375
 		removeAttachments(array('id_member' => $memID));
3239
-	}
3240
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3376
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3241 3377
 	{
3242 3378
 		// 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.
3243
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3244
-			$profile_vars['avatar'] = 'gravatar://';
3245
-		else
3246
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3379
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3380
+					$profile_vars['avatar'] = 'gravatar://';
3381
+		} else {
3382
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3383
+		}
3247 3384
 
3248 3385
 		// Get rid of their old avatar. (if uploaded.)
3249 3386
 		removeAttachments(array('id_member' => $memID));
3250
-	}
3251
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3387
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3252 3388
 	{
3253 3389
 		// We need these clean...
3254 3390
 		$cur_profile['id_attach'] = 0;
@@ -3260,11 +3396,13 @@  discard block
 block discarded – undo
3260 3396
 
3261 3397
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3262 3398
 
3263
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3264
-			$profile_vars['avatar'] = '';
3399
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3400
+					$profile_vars['avatar'] = '';
3401
+		}
3265 3402
 		// Trying to make us do something we'll regret?
3266
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3267
-			return 'bad_avatar_invalid_url';
3403
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3404
+					return 'bad_avatar_invalid_url';
3405
+		}
3268 3406
 		// Should we check dimensions?
3269 3407
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3270 3408
 		{
@@ -3274,9 +3412,9 @@  discard block
 block discarded – undo
3274 3412
 			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']))))
3275 3413
 			{
3276 3414
 				// Houston, we have a problem. The avatar is too large!!
3277
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3278
-					return 'bad_avatar_too_large';
3279
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3415
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3416
+									return 'bad_avatar_too_large';
3417
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3280 3418
 				{
3281 3419
 					// @todo remove this if appropriate
3282 3420
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3286,26 +3424,27 @@  discard block
 block discarded – undo
3286 3424
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3287 3425
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3288 3426
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3427
+					} else {
3428
+											return 'bad_avatar';
3289 3429
 					}
3290
-					else
3291
-						return 'bad_avatar';
3292 3430
 				}
3293 3431
 			}
3294 3432
 		}
3295
-	}
3296
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3433
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3297 3434
 	{
3298 3435
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3299 3436
 		{
3300 3437
 			// Get the dimensions of the image.
3301 3438
 			if (!$downloadedExternalAvatar)
3302 3439
 			{
3303
-				if (!is_writable($uploadDir))
3304
-					fatal_lang_error('attachments_no_write', 'critical');
3440
+				if (!is_writable($uploadDir)) {
3441
+									fatal_lang_error('attachments_no_write', 'critical');
3442
+				}
3305 3443
 
3306 3444
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3307
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3308
-					fatal_lang_error('attach_timeout', 'critical');
3445
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3446
+									fatal_lang_error('attach_timeout', 'critical');
3447
+				}
3309 3448
 
3310 3449
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3311 3450
 			}
@@ -3418,17 +3557,19 @@  discard block
 block discarded – undo
3418 3557
 			$profile_vars['avatar'] = '';
3419 3558
 
3420 3559
 			// Delete any temporary file.
3421
-			if (file_exists($_FILES['attachment']['tmp_name']))
3422
-				@unlink($_FILES['attachment']['tmp_name']);
3560
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3561
+							@unlink($_FILES['attachment']['tmp_name']);
3562
+			}
3423 3563
 		}
3424 3564
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3425
-		else
3565
+		else {
3566
+					$profile_vars['avatar'] = '';
3567
+		}
3568
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3569
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3570
+	} else {
3426 3571
 			$profile_vars['avatar'] = '';
3427 3572
 	}
3428
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3429
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3430
-	else
3431
-		$profile_vars['avatar'] = '';
3432 3573
 
3433 3574
 	// Setup the profile variables so it shows things right on display!
3434 3575
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3476,9 +3617,9 @@  discard block
 block discarded – undo
3476 3617
 		$smiley_parsed = $unparsed_signature;
3477 3618
 		parsesmileys($smiley_parsed);
3478 3619
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3479
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3480
-			return 'signature_allow_smileys';
3481
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3620
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3621
+					return 'signature_allow_smileys';
3622
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3482 3623
 		{
3483 3624
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3484 3625
 			return 'signature_max_smileys';
@@ -3491,14 +3632,15 @@  discard block
 block discarded – undo
3491 3632
 			{
3492 3633
 				$limit_broke = 0;
3493 3634
 				// Attempt to allow all sizes of abuse, so to speak.
3494
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3495
-					$limit_broke = $sig_limits[7] . 'px';
3496
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3497
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3498
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3499
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3500
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3501
-					$limit_broke = 'large';
3635
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3636
+									$limit_broke = $sig_limits[7] . 'px';
3637
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3638
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3639
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3640
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3641
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3642
+									$limit_broke = 'large';
3643
+				}
3502 3644
 
3503 3645
 				if ($limit_broke)
3504 3646
 				{
@@ -3540,24 +3682,26 @@  discard block
 block discarded – undo
3540 3682
 					$width = -1; $height = -1;
3541 3683
 
3542 3684
 					// Does it have predefined restraints? Width first.
3543
-					if ($matches[6][$key])
3544
-						$matches[2][$key] = $matches[6][$key];
3685
+					if ($matches[6][$key]) {
3686
+											$matches[2][$key] = $matches[6][$key];
3687
+					}
3545 3688
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3546 3689
 					{
3547 3690
 						$width = $sig_limits[5];
3548 3691
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3692
+					} elseif ($matches[2][$key]) {
3693
+											$width = $matches[2][$key];
3549 3694
 					}
3550
-					elseif ($matches[2][$key])
3551
-						$width = $matches[2][$key];
3552 3695
 					// ... and height.
3553 3696
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3554 3697
 					{
3555 3698
 						$height = $sig_limits[6];
3556
-						if ($width != -1)
3557
-							$width = $width * ($height / $matches[4][$key]);
3699
+						if ($width != -1) {
3700
+													$width = $width * ($height / $matches[4][$key]);
3701
+						}
3702
+					} elseif ($matches[4][$key]) {
3703
+											$height = $matches[4][$key];
3558 3704
 					}
3559
-					elseif ($matches[4][$key])
3560
-						$height = $matches[4][$key];
3561 3705
 
3562 3706
 					// If the dimensions are still not fixed - we need to check the actual image.
3563 3707
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3575,21 +3719,24 @@  discard block
 block discarded – undo
3575 3719
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3576 3720
 							{
3577 3721
 								$height = $sig_limits[6];
3578
-								if ($width == -1)
3579
-									$width = $sizes[0];
3722
+								if ($width == -1) {
3723
+																	$width = $sizes[0];
3724
+								}
3580 3725
 								$width = $width * ($height / $sizes[1]);
3726
+							} elseif ($width != -1) {
3727
+															$height = $sizes[1];
3581 3728
 							}
3582
-							elseif ($width != -1)
3583
-								$height = $sizes[1];
3584 3729
 						}
3585 3730
 					}
3586 3731
 
3587 3732
 					// Did we come up with some changes? If so remake the string.
3588
-					if ($width != -1 || $height != -1)
3589
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3733
+					if ($width != -1 || $height != -1) {
3734
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3735
+					}
3736
+				}
3737
+				if (!empty($replaces)) {
3738
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3590 3739
 				}
3591
-				if (!empty($replaces))
3592
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3593 3740
 			}
3594 3741
 		}
3595 3742
 
@@ -3633,10 +3780,12 @@  discard block
 block discarded – undo
3633 3780
 	$email = strtr($email, array('&#039;' => '\''));
3634 3781
 
3635 3782
 	// Check the name and email for validity.
3636
-	if (trim($email) == '')
3637
-		return 'no_email';
3638
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3639
-		return 'bad_email';
3783
+	if (trim($email) == '') {
3784
+			return 'no_email';
3785
+	}
3786
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3787
+			return 'bad_email';
3788
+	}
3640 3789
 
3641 3790
 	// Email addresses should be and stay unique.
3642 3791
 	$request = $smcFunc['db_query']('', '
@@ -3651,8 +3800,9 @@  discard block
 block discarded – undo
3651 3800
 		)
3652 3801
 	);
3653 3802
 
3654
-	if ($smcFunc['db_num_rows']($request) > 0)
3655
-		return 'email_taken';
3803
+	if ($smcFunc['db_num_rows']($request) > 0) {
3804
+			return 'email_taken';
3805
+	}
3656 3806
 	$smcFunc['db_free_result']($request);
3657 3807
 
3658 3808
 	return true;
@@ -3665,8 +3815,9 @@  discard block
 block discarded – undo
3665 3815
 {
3666 3816
 	global $modSettings, $context, $cur_profile;
3667 3817
 
3668
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3669
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3818
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3819
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3820
+	}
3670 3821
 
3671 3822
 	loadUserSettings();
3672 3823
 	writeLog();
@@ -3682,8 +3833,9 @@  discard block
 block discarded – undo
3682 3833
 	require_once($sourcedir . '/Subs-Post.php');
3683 3834
 
3684 3835
 	// Shouldn't happen but just in case.
3685
-	if (empty($profile_vars['email_address']))
3686
-		return;
3836
+	if (empty($profile_vars['email_address'])) {
3837
+			return;
3838
+	}
3687 3839
 
3688 3840
 	$replacements = array(
3689 3841
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3706,8 +3858,9 @@  discard block
 block discarded – undo
3706 3858
 	$_SESSION['log_time'] = 0;
3707 3859
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3708 3860
 
3709
-	if (isset($_COOKIE[$cookiename]))
3710
-		$_COOKIE[$cookiename] = '';
3861
+	if (isset($_COOKIE[$cookiename])) {
3862
+			$_COOKIE[$cookiename] = '';
3863
+	}
3711 3864
 
3712 3865
 	loadUserSettings();
3713 3866
 
@@ -3740,11 +3893,13 @@  discard block
 block discarded – undo
3740 3893
 	$groups[] = $curMember['id_group'];
3741 3894
 
3742 3895
 	// Ensure the query doesn't croak!
3743
-	if (empty($groups))
3744
-		$groups = array(0);
3896
+	if (empty($groups)) {
3897
+			$groups = array(0);
3898
+	}
3745 3899
 	// Just to be sure...
3746
-	foreach ($groups as $k => $v)
3747
-		$groups[$k] = (int) $v;
3900
+	foreach ($groups as $k => $v) {
3901
+			$groups[$k] = (int) $v;
3902
+	}
3748 3903
 
3749 3904
 	// Get all the membergroups they can join.
3750 3905
 	$request = $smcFunc['db_query']('', '
@@ -3774,12 +3929,14 @@  discard block
 block discarded – undo
3774 3929
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3775 3930
 	{
3776 3931
 		// Can they edit their primary group?
3777
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3778
-			$context['can_edit_primary'] = true;
3932
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3933
+					$context['can_edit_primary'] = true;
3934
+		}
3779 3935
 
3780 3936
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3781
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3782
-			continue;
3937
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3938
+					continue;
3939
+		}
3783 3940
 
3784 3941
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3785 3942
 			'id' => $row['id_group'],
@@ -3808,13 +3965,15 @@  discard block
 block discarded – undo
3808 3965
 	);
3809 3966
 
3810 3967
 	// No changing primary one unless you have enough groups!
3811
-	if (count($context['groups']['member']) < 2)
3812
-		$context['can_edit_primary'] = false;
3968
+	if (count($context['groups']['member']) < 2) {
3969
+			$context['can_edit_primary'] = false;
3970
+	}
3813 3971
 
3814 3972
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3815
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3816
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3817
-}
3973
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3974
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3975
+	}
3976
+	}
3818 3977
 
3819 3978
 /**
3820 3979
  * This function actually makes all the group changes
@@ -3829,10 +3988,12 @@  discard block
 block discarded – undo
3829 3988
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3830 3989
 
3831 3990
 	// Let's be extra cautious...
3832
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3833
-		isAllowedTo('manage_membergroups');
3834
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3835
-		fatal_lang_error('no_access', false);
3991
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3992
+			isAllowedTo('manage_membergroups');
3993
+	}
3994
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3995
+			fatal_lang_error('no_access', false);
3996
+	}
3836 3997
 
3837 3998
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3838 3999
 
@@ -3851,8 +4012,9 @@  discard block
 block discarded – undo
3851 4012
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3852 4013
 
3853 4014
 	// Sanity check!!
3854
-	if ($group_id == 1)
3855
-		isAllowedTo('admin_forum');
4015
+	if ($group_id == 1) {
4016
+			isAllowedTo('admin_forum');
4017
+	}
3856 4018
 	// Protected groups too!
3857 4019
 	else
3858 4020
 	{
@@ -3869,8 +4031,9 @@  discard block
 block discarded – undo
3869 4031
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3870 4032
 		$smcFunc['db_free_result']($request);
3871 4033
 
3872
-		if ($is_protected == 1)
3873
-			isAllowedTo('admin_forum');
4034
+		if ($is_protected == 1) {
4035
+					isAllowedTo('admin_forum');
4036
+		}
3874 4037
 	}
3875 4038
 
3876 4039
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3892,36 +4055,43 @@  discard block
 block discarded – undo
3892 4055
 			$group_name = $row['group_name'];
3893 4056
 
3894 4057
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3895
-			if ($changeType == 'request' && $row['group_type'] != 2)
3896
-				fatal_lang_error('no_access', false);
4058
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4059
+							fatal_lang_error('no_access', false);
4060
+			}
3897 4061
 			// What about leaving a requestable group we are not a member of?
3898
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3899
-				fatal_lang_error('no_access', false);
3900
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3901
-				fatal_lang_error('no_access', false);
4062
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4063
+							fatal_lang_error('no_access', false);
4064
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4065
+							fatal_lang_error('no_access', false);
4066
+			}
3902 4067
 
3903 4068
 			// We can't change the primary group if this is hidden!
3904
-			if ($row['hidden'] == 2)
3905
-				$canChangePrimary = false;
4069
+			if ($row['hidden'] == 2) {
4070
+							$canChangePrimary = false;
4071
+			}
3906 4072
 		}
3907 4073
 
3908 4074
 		// If this is their old primary, can we change it?
3909
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3910
-			$canChangePrimary = 1;
4075
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4076
+					$canChangePrimary = 1;
4077
+		}
3911 4078
 
3912 4079
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3913
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3914
-			$canChangePrimary = false;
4080
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4081
+					$canChangePrimary = false;
4082
+		}
3915 4083
 
3916 4084
 		// If this is the one we are acting on, can we even act?
3917
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3918
-			$canChangePrimary = false;
4085
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4086
+					$canChangePrimary = false;
4087
+		}
3919 4088
 	}
3920 4089
 	$smcFunc['db_free_result']($request);
3921 4090
 
3922 4091
 	// Didn't find the target?
3923
-	if (!$foundTarget)
3924
-		fatal_lang_error('no_access', false);
4092
+	if (!$foundTarget) {
4093
+			fatal_lang_error('no_access', false);
4094
+	}
3925 4095
 
3926 4096
 	// Final security check, don't allow users to promote themselves to admin.
3927 4097
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3941,8 +4111,9 @@  discard block
 block discarded – undo
3941 4111
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3942 4112
 		$smcFunc['db_free_result']($request);
3943 4113
 
3944
-		if ($disallow)
3945
-			isAllowedTo('admin_forum');
4114
+		if ($disallow) {
4115
+					isAllowedTo('admin_forum');
4116
+		}
3946 4117
 	}
3947 4118
 
3948 4119
 	// If we're requesting, add the note then return.
@@ -3960,8 +4131,9 @@  discard block
 block discarded – undo
3960 4131
 				'status_open' => 0,
3961 4132
 			)
3962 4133
 		);
3963
-		if ($smcFunc['db_num_rows']($request) != 0)
3964
-			fatal_lang_error('profile_error_already_requested_group');
4134
+		if ($smcFunc['db_num_rows']($request) != 0) {
4135
+					fatal_lang_error('profile_error_already_requested_group');
4136
+		}
3965 4137
 		$smcFunc['db_free_result']($request);
3966 4138
 
3967 4139
 		// Log the request.
@@ -3995,10 +4167,11 @@  discard block
 block discarded – undo
3995 4167
 		// Are we leaving?
3996 4168
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3997 4169
 		{
3998
-			if ($old_profile['id_group'] == $group_id)
3999
-				$newPrimary = 0;
4000
-			else
4001
-				unset($addGroups[$group_id]);
4170
+			if ($old_profile['id_group'] == $group_id) {
4171
+							$newPrimary = 0;
4172
+			} else {
4173
+							unset($addGroups[$group_id]);
4174
+			}
4002 4175
 		}
4003 4176
 		// ... if not, must be joining.
4004 4177
 		else
@@ -4006,36 +4179,42 @@  discard block
 block discarded – undo
4006 4179
 			// Can we change the primary, and do we want to?
4007 4180
 			if ($canChangePrimary)
4008 4181
 			{
4009
-				if ($old_profile['id_group'] != 0)
4010
-					$addGroups[$old_profile['id_group']] = -1;
4182
+				if ($old_profile['id_group'] != 0) {
4183
+									$addGroups[$old_profile['id_group']] = -1;
4184
+				}
4011 4185
 				$newPrimary = $group_id;
4012 4186
 			}
4013 4187
 			// Otherwise it's an additional group...
4014
-			else
4015
-				$addGroups[$group_id] = -1;
4188
+			else {
4189
+							$addGroups[$group_id] = -1;
4190
+			}
4016 4191
 		}
4017 4192
 	}
4018 4193
 	// Finally, we must be setting the primary.
4019 4194
 	elseif ($canChangePrimary)
4020 4195
 	{
4021
-		if ($old_profile['id_group'] != 0)
4022
-			$addGroups[$old_profile['id_group']] = -1;
4023
-		if (isset($addGroups[$group_id]))
4024
-			unset($addGroups[$group_id]);
4196
+		if ($old_profile['id_group'] != 0) {
4197
+					$addGroups[$old_profile['id_group']] = -1;
4198
+		}
4199
+		if (isset($addGroups[$group_id])) {
4200
+					unset($addGroups[$group_id]);
4201
+		}
4025 4202
 		$newPrimary = $group_id;
4026 4203
 	}
4027 4204
 
4028 4205
 	// Finally, we can make the changes!
4029
-	foreach ($addGroups as $id => $dummy)
4030
-		if (empty($id))
4206
+	foreach ($addGroups as $id => $dummy) {
4207
+			if (empty($id))
4031 4208
 			unset($addGroups[$id]);
4209
+	}
4032 4210
 	$addGroups = implode(',', array_flip($addGroups));
4033 4211
 
4034 4212
 	// Ensure that we don't cache permissions if the group is changing.
4035
-	if ($context['user']['is_owner'])
4036
-		$_SESSION['mc']['time'] = 0;
4037
-	else
4038
-		updateSettings(array('settings_updated' => time()));
4213
+	if ($context['user']['is_owner']) {
4214
+			$_SESSION['mc']['time'] = 0;
4215
+	} else {
4216
+			updateSettings(array('settings_updated' => time()));
4217
+	}
4039 4218
 
4040 4219
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4041 4220
 
@@ -4058,8 +4237,9 @@  discard block
 block discarded – undo
4058 4237
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4059 4238
 	{
4060 4239
 		// Check to ensure we're forcing SSL for authentication
4061
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
4062
-			fatal_lang_error('login_ssl_required');
4240
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
4241
+					fatal_lang_error('login_ssl_required');
4242
+		}
4063 4243
 
4064 4244
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4065 4245
 		// we do not want too much AJAX to confuse them.
@@ -4096,8 +4276,7 @@  discard block
 block discarded – undo
4096 4276
 				$context['sub_template'] = 'tfasetup_backup';
4097 4277
 
4098 4278
 				return;
4099
-			}
4100
-			else
4279
+			} else
4101 4280
 			{
4102 4281
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4103 4282
 				$context['tfa_error'] = !$valid_code;
@@ -4105,8 +4284,7 @@  discard block
 block discarded – undo
4105 4284
 				$context['tfa_pass_value'] = $_POST['passwd'];
4106 4285
 				$context['tfa_value'] = $_POST['tfa_code'];
4107 4286
 			}
4108
-		}
4109
-		else
4287
+		} else
4110 4288
 		{
4111 4289
 			$totp = new \TOTP\Auth();
4112 4290
 			$secret = $totp->generateCode();
@@ -4116,17 +4294,16 @@  discard block
 block discarded – undo
4116 4294
 		}
4117 4295
 
4118 4296
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4119
-	}
4120
-	elseif (isset($_REQUEST['disable']))
4297
+	} elseif (isset($_REQUEST['disable']))
4121 4298
 	{
4122 4299
 		updateMemberData($memID, array(
4123 4300
 			'tfa_secret' => '',
4124 4301
 			'tfa_backup' => '',
4125 4302
 		));
4126 4303
 		redirectexit('action=profile;area=account;u=' . $memID);
4304
+	} else {
4305
+			redirectexit('action=profile;area=account;u=' . $memID);
4306
+	}
4127 4307
 	}
4128
-	else
4129
-		redirectexit('action=profile;area=account;u=' . $memID);
4130
-}
4131 4308
 
4132 4309
 ?>
4133 4310
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +177 added lines, -128 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -170,16 +181,19 @@  discard block
 block discarded – undo
170 181
 		if (in_array('website', $reg_fields))
171 182
 		{
172 183
 			unset($reg_fields['website']);
173
-			if (isset($_POST['website_title']))
174
-				$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
175
-			if (isset($_POST['website_url']))
176
-				$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
184
+			if (isset($_POST['website_title'])) {
185
+							$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
186
+			}
187
+			if (isset($_POST['website_url'])) {
188
+							$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
189
+			}
177 190
 		}
178 191
 
179 192
 		// We might have had some submissions on this front - go check.
180
-		foreach ($reg_fields as $field)
181
-			if (isset($_POST[$field]))
193
+		foreach ($reg_fields as $field) {
194
+					if (isset($_POST[$field]))
182 195
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
196
+		}
183 197
 
184 198
 		// Load all the fields in question.
185 199
 		setupProfileContext($reg_fields);
@@ -196,8 +210,9 @@  discard block
 block discarded – undo
196 210
 		$context['visual_verification_id'] = $verificationOptions['id'];
197 211
 	}
198 212
 	// Otherwise we have nothing to show.
199
-	else
200
-		$context['visual_verification'] = false;
213
+	else {
214
+			$context['visual_verification'] = false;
215
+	}
201 216
 
202 217
 
203 218
 	$context += array(
@@ -208,8 +223,9 @@  discard block
 block discarded – undo
208 223
 
209 224
 	// Were there any errors?
210 225
 	$context['registration_errors'] = array();
211
-	if (!empty($reg_errors))
212
-		$context['registration_errors'] = $reg_errors;
226
+	if (!empty($reg_errors)) {
227
+			$context['registration_errors'] = $reg_errors;
228
+	}
213 229
 
214 230
 	createToken('register');
215 231
 }
@@ -226,27 +242,32 @@  discard block
 block discarded – undo
226 242
 	validateToken('register');
227 243
 
228 244
 	// Check to ensure we're forcing SSL for authentication
229
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
230
-		fatal_lang_error('register_ssl_required');
245
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
246
+			fatal_lang_error('register_ssl_required');
247
+	}
231 248
 
232 249
 	// Start collecting together any errors.
233 250
 	$reg_errors = array();
234 251
 
235 252
 	// You can't register if it's disabled.
236
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
237
-		fatal_lang_error('registration_disabled', false);
253
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
254
+			fatal_lang_error('registration_disabled', false);
255
+	}
238 256
 
239 257
 	// Well, if you don't agree, you can't register.
240
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
241
-		redirectexit();
258
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
259
+			redirectexit();
260
+	}
242 261
 
243 262
 	// Make sure they came from *somewhere*, have a session.
244
-	if (!isset($_SESSION['old_url']))
245
-		redirectexit('action=signup');
263
+	if (!isset($_SESSION['old_url'])) {
264
+			redirectexit('action=signup');
265
+	}
246 266
 
247 267
 	// If we don't require an agreement, we need a extra check for coppa.
248
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
249
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
268
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
269
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
270
+	}
250 271
 	// Are they under age, and under age users are banned?
251 272
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
252 273
 	{
@@ -255,8 +276,9 @@  discard block
 block discarded – undo
255 276
 	}
256 277
 
257 278
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
258
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
259
-		redirectexit('action=signup');
279
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
280
+			redirectexit('action=signup');
281
+	}
260 282
 	// Failing that, check the time on it.
261 283
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
262 284
 	{
@@ -276,15 +298,17 @@  discard block
 block discarded – undo
276 298
 		if (is_array($context['visual_verification']))
277 299
 		{
278 300
 			loadLanguage('Errors');
279
-			foreach ($context['visual_verification'] as $error)
280
-				$reg_errors[] = $txt['error_' . $error];
301
+			foreach ($context['visual_verification'] as $error) {
302
+							$reg_errors[] = $txt['error_' . $error];
303
+			}
281 304
 		}
282 305
 	}
283 306
 
284 307
 	foreach ($_POST as $key => $value)
285 308
 	{
286
-		if (!is_array($_POST[$key]))
287
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
309
+		if (!is_array($_POST[$key])) {
310
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
311
+		}
288 312
 	}
289 313
 
290 314
 	// Collect all extra registration fields someone might have filled in.
@@ -319,13 +343,15 @@  discard block
 block discarded – undo
319 343
 			$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
320 344
 
321 345
 			// Make sure their website URL is squeaky clean
322
-			if (isset($_POST['website_url']))
323
-				$_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url']));
346
+			if (isset($_POST['website_url'])) {
347
+							$_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url']));
348
+			}
324 349
 		}
325 350
 	}
326 351
 
327
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
328
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
352
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
353
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
354
+	}
329 355
 
330 356
 	// Needed for isReservedName() and registerMember().
331 357
 	require_once($sourcedir . '/Subs-Members.php');
@@ -334,8 +360,9 @@  discard block
 block discarded – undo
334 360
 	if (isset($_POST['real_name']))
335 361
 	{
336 362
 		// Are you already allowed to edit the displayed name?
337
-		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))
338
-			$canEditDisplayName = true;
363
+		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) {
364
+					$canEditDisplayName = true;
365
+		}
339 366
 
340 367
 		// If you are a guest, will you be allowed to once you register?
341 368
 		else
@@ -359,33 +386,38 @@  discard block
 block discarded – undo
359 386
 			$_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
360 387
 
361 388
 			// Only set it if we are sure it is good
362
-			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
363
-				$possible_strings[] = 'real_name';
389
+			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
390
+							$possible_strings[] = 'real_name';
391
+			}
364 392
 		}
365 393
 	}
366 394
 
367 395
 	// Handle a string as a birthdate...
368
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
369
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
396
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
397
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
398
+	}
370 399
 	// Or birthdate parts...
371
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
372
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
400
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
401
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
402
+	}
373 403
 
374 404
 	// Validate the passed language file.
375 405
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
376 406
 	{
377 407
 		// Do we have any languages?
378
-		if (empty($context['languages']))
379
-			getLanguages();
408
+		if (empty($context['languages'])) {
409
+					getLanguages();
410
+		}
380 411
 
381 412
 		// Did we find it?
382
-		if (isset($context['languages'][$_POST['lngfile']]))
383
-			$_SESSION['language'] = $_POST['lngfile'];
384
-		else
413
+		if (isset($context['languages'][$_POST['lngfile']])) {
414
+					$_SESSION['language'] = $_POST['lngfile'];
415
+		} else {
416
+					unset($_POST['lngfile']);
417
+		}
418
+	} else {
385 419
 			unset($_POST['lngfile']);
386 420
 	}
387
-	else
388
-		unset($_POST['lngfile']);
389 421
 
390 422
 	// Set the options needed for registration.
391 423
 	$regOptions = array(
@@ -405,22 +437,27 @@  discard block
 block discarded – undo
405 437
 	);
406 438
 
407 439
 	// Include the additional options that might have been filled in.
408
-	foreach ($possible_strings as $var)
409
-		if (isset($_POST[$var]))
440
+	foreach ($possible_strings as $var) {
441
+			if (isset($_POST[$var]))
410 442
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
411
-	foreach ($possible_ints as $var)
412
-		if (isset($_POST[$var]))
443
+	}
444
+	foreach ($possible_ints as $var) {
445
+			if (isset($_POST[$var]))
413 446
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
414
-	foreach ($possible_floats as $var)
415
-		if (isset($_POST[$var]))
447
+	}
448
+	foreach ($possible_floats as $var) {
449
+			if (isset($_POST[$var]))
416 450
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
417
-	foreach ($possible_bools as $var)
418
-		if (isset($_POST[$var]))
451
+	}
452
+	foreach ($possible_bools as $var) {
453
+			if (isset($_POST[$var]))
419 454
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
455
+	}
420 456
 
421 457
 	// Registration options are always default options...
422
-	if (isset($_POST['default_options']))
423
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
458
+	if (isset($_POST['default_options'])) {
459
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
460
+	}
424 461
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
425 462
 
426 463
 	// Make sure they are clean, dammit!
@@ -440,12 +477,14 @@  discard block
 block discarded – undo
440 477
 	while ($row = $smcFunc['db_fetch_assoc']($request))
441 478
 	{
442 479
 		// Don't allow overriding of the theme variables.
443
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
444
-			unset($regOptions['theme_vars'][$row['col_name']]);
480
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
481
+					unset($regOptions['theme_vars'][$row['col_name']]);
482
+		}
445 483
 
446 484
 		// Not actually showing it then?
447
-		if (!$row['show_reg'])
448
-			continue;
485
+		if (!$row['show_reg']) {
486
+					continue;
487
+		}
449 488
 
450 489
 		// Prepare the value!
451 490
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -454,24 +493,27 @@  discard block
 block discarded – undo
454 493
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
455 494
 		{
456 495
 			// Is it too long?
457
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
458
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
496
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
497
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
498
+			}
459 499
 
460 500
 			// Any masks to apply?
461 501
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
462 502
 			{
463
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
464
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
465
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
466
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
467
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
468
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
503
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
504
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
505
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
506
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
507
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
508
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
509
+				}
469 510
 			}
470 511
 		}
471 512
 
472 513
 		// Is this required but not there?
473
-		if (trim($value) == '' && $row['show_reg'] > 1)
474
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
514
+		if (trim($value) == '' && $row['show_reg'] > 1) {
515
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
516
+		}
475 517
 	}
476 518
 	$smcFunc['db_free_result']($request);
477 519
 
@@ -479,8 +521,9 @@  discard block
 block discarded – undo
479 521
 	if (!empty($custom_field_errors))
480 522
 	{
481 523
 		loadLanguage('Errors');
482
-		foreach ($custom_field_errors as $error)
483
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
524
+		foreach ($custom_field_errors as $error) {
525
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
526
+		}
484 527
 	}
485 528
 
486 529
 	// Lets check for other errors before trying to register the member.
@@ -525,8 +568,9 @@  discard block
 block discarded – undo
525 568
 	}
526 569
 
527 570
 	// If COPPA has been selected then things get complicated, setup the template.
528
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
529
-		redirectexit('action=coppa;member=' . $memberID);
571
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
572
+			redirectexit('action=coppa;member=' . $memberID);
573
+	}
530 574
 	// Basic template variable setup.
531 575
 	elseif (!empty($modSettings['registration_method']))
532 576
 	{
@@ -538,8 +582,7 @@  discard block
 block discarded – undo
538 582
 			'sub_template' => 'after',
539 583
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
540 584
 		);
541
-	}
542
-	else
585
+	} else
543 586
 	{
544 587
 		call_integration_hook('integrate_activate', array($regOptions['username']));
545 588
 
@@ -559,16 +602,18 @@  discard block
 block discarded – undo
559 602
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
560 603
 
561 604
 	// Logged in users should not bother to activate their accounts
562
-	if (!empty($user_info['id']))
563
-		redirectexit();
605
+	if (!empty($user_info['id'])) {
606
+			redirectexit();
607
+	}
564 608
 
565 609
 	loadLanguage('Login');
566 610
 	loadTemplate('Login');
567 611
 
568 612
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
569 613
 	{
570
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
571
-			fatal_lang_error('no_access', false);
614
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
615
+					fatal_lang_error('no_access', false);
616
+		}
572 617
 
573 618
 		$context['member_id'] = 0;
574 619
 		$context['sub_template'] = 'resend';
@@ -608,11 +653,13 @@  discard block
 block discarded – undo
608 653
 	// Change their email address? (they probably tried a fake one first :P.)
609 654
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
610 655
 	{
611
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
612
-			fatal_lang_error('no_access', false);
656
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
657
+					fatal_lang_error('no_access', false);
658
+		}
613 659
 
614
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
615
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
660
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
661
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
662
+		}
616 663
 
617 664
 		// Make sure their email isn't banned.
618 665
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -628,8 +675,9 @@  discard block
 block discarded – undo
628 675
 			)
629 676
 		);
630 677
 
631
-		if ($smcFunc['db_num_rows']($request) != 0)
632
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
678
+		if ($smcFunc['db_num_rows']($request) != 0) {
679
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
680
+		}
633 681
 		$smcFunc['db_free_result']($request);
634 682
 
635 683
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -667,9 +715,9 @@  discard block
 block discarded – undo
667 715
 	// Quit if this code is not right.
668 716
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
669 717
 	{
670
-		if (!empty($row['is_activated']))
671
-			fatal_lang_error('already_activated', false);
672
-		elseif ($row['validation_code'] == '')
718
+		if (!empty($row['is_activated'])) {
719
+					fatal_lang_error('already_activated', false);
720
+		} elseif ($row['validation_code'] == '')
673 721
 		{
674 722
 			loadLanguage('Profile');
675 723
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -719,8 +767,9 @@  discard block
 block discarded – undo
719 767
 	loadTemplate('Register');
720 768
 
721 769
 	// No User ID??
722
-	if (!isset($_GET['member']))
723
-		fatal_lang_error('no_access', false);
770
+	if (!isset($_GET['member'])) {
771
+			fatal_lang_error('no_access', false);
772
+	}
724 773
 
725 774
 	// Get the user details...
726 775
 	$request = $smcFunc['db_query']('', '
@@ -733,8 +782,9 @@  discard block
 block discarded – undo
733 782
 			'is_coppa' => 5,
734 783
 		)
735 784
 	);
736
-	if ($smcFunc['db_num_rows']($request) == 0)
737
-		fatal_lang_error('no_access', false);
785
+	if ($smcFunc['db_num_rows']($request) == 0) {
786
+			fatal_lang_error('no_access', false);
787
+	}
738 788
 	list ($username) = $smcFunc['db_fetch_row']($request);
739 789
 	$smcFunc['db_free_result']($request);
740 790
 
@@ -772,8 +822,7 @@  discard block
 block discarded – undo
772 822
 			echo $data;
773 823
 			obExit(false);
774 824
 		}
775
-	}
776
-	else
825
+	} else
777 826
 	{
778 827
 		$context += array(
779 828
 			'page_title' => $txt['coppa_title'],
@@ -826,8 +875,9 @@  discard block
 block discarded – undo
826 875
 	{
827 876
 		require_once($sourcedir . '/Subs-Graphics.php');
828 877
 
829
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
830
-			header('HTTP/1.1 400 Bad Request');
878
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
879
+					header('HTTP/1.1 400 Bad Request');
880
+		}
831 881
 
832 882
 		// Otherwise just show a pre-defined letter.
833 883
 		elseif (isset($_REQUEST['letter']))
@@ -845,14 +895,13 @@  discard block
 block discarded – undo
845 895
 			header('content-type: image/gif');
846 896
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
847 897
 		}
848
-	}
849
-
850
-	elseif ($_REQUEST['format'] === '.wav')
898
+	} elseif ($_REQUEST['format'] === '.wav')
851 899
 	{
852 900
 		require_once($sourcedir . '/Subs-Sound.php');
853 901
 
854
-		if (!createWaveFile($code))
855
-			header('HTTP/1.1 400 Bad Request');
902
+		if (!createWaveFile($code)) {
903
+					header('HTTP/1.1 400 Bad Request');
904
+		}
856 905
 	}
857 906
 
858 907
 	// We all die one day...
Please login to merge, or discard this patch.
Themes/default/Profile.template.php 1 patch
Braces   +535 added lines, -410 removed lines patch added patch discarded remove patch
@@ -18,23 +18,25 @@  discard block
 block discarded – undo
18 18
 	global $context;
19 19
 
20 20
 	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
21
-	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
22
-		echo '
21
+	if (isBrowser('is_chrome') && !$context['user']['is_owner']) {
22
+			echo '
23 23
 			<script>
24 24
 				disableAutoComplete();
25 25
 			</script>';
26
+	}
26 27
 
27 28
 	// If an error occurred while trying to save previously, give the user a clue!
28 29
 	echo '
29 30
 			', template_error_message();
30 31
 
31 32
 	// If the profile was update successfully, let the user know this.
32
-	if (!empty($context['profile_updated']))
33
-		echo '
33
+	if (!empty($context['profile_updated'])) {
34
+			echo '
34 35
 			<div class="infobox">
35 36
 				', $context['profile_updated'], '
36 37
 			</div>';
37
-}
38
+	}
39
+	}
38 40
 
39 41
 /**
40 42
  * Template for any HTML needed below the profile (closing off divs/tables, etc.)
@@ -99,19 +101,19 @@  discard block
 block discarded – undo
99 101
 		</div>
100 102
 		<div class="alerts_unread">';
101 103
 
102
-	if (empty($context['unread_alerts']))
103
-		template_alerts_all_read();
104
-
105
-	else
104
+	if (empty($context['unread_alerts'])) {
105
+			template_alerts_all_read();
106
+	} else
106 107
 	{
107
-		foreach ($context['unread_alerts'] as $id_alert => $details)
108
-			echo '
108
+		foreach ($context['unread_alerts'] as $id_alert => $details) {
109
+					echo '
109 110
 			<div class="unread">
110 111
 				', !empty($details['sender']) ? $details['sender']['avatar']['image'] : '', '
111 112
 				<div class="details">
112 113
 					', !empty($details['icon']) ? $details['icon'] : '', '<span>', $details['text'], '</span> - ', $details['time'], '
113 114
 				</div>
114 115
 			</div>';
116
+		}
115 117
 	}
116 118
 
117 119
 	echo '
@@ -158,37 +160,41 @@  discard block
 block discarded – undo
158 160
 	if (!empty($context['print_custom_fields']['above_member']))
159 161
 	{
160 162
 		$fields = '';
161
-		foreach ($context['print_custom_fields']['above_member'] as $field)
162
-			if (!empty($field['output_html']))
163
+		foreach ($context['print_custom_fields']['above_member'] as $field) {
164
+					if (!empty($field['output_html']))
163 165
 				$fields .= '
164 166
 					<li>' . $field['output_html'] . '</li>';
167
+		}
165 168
 
166
-		if (!empty($fields))
167
-			echo '
169
+		if (!empty($fields)) {
170
+					echo '
168 171
 			<div class="custom_fields_above_name">
169 172
 				<ul>', $fields, '
170 173
 				</ul>
171 174
 			</div>';
175
+		}
172 176
 	}
173 177
 
174 178
 	echo '
175 179
 			<div class="username clear">
176 180
 				<h4>';
177 181
 
178
-	if (!empty($context['print_custom_fields']['before_member']))
179
-		foreach ($context['print_custom_fields']['before_member'] as $field)
182
+	if (!empty($context['print_custom_fields']['before_member'])) {
183
+			foreach ($context['print_custom_fields']['before_member'] as $field)
180 184
 			if (!empty($field['output_html']))
181 185
 				echo '
182 186
 					<span>', $field['output_html'], '</span>';
187
+	}
183 188
 
184 189
 	echo '
185 190
 					', $context['member']['name'];
186 191
 
187
-	if (!empty($context['print_custom_fields']['after_member']))
188
-		foreach ($context['print_custom_fields']['after_member'] as $field)
192
+	if (!empty($context['print_custom_fields']['after_member'])) {
193
+			foreach ($context['print_custom_fields']['after_member'] as $field)
189 194
 			if (!empty($field['output_html']))
190 195
 				echo '
191 196
 					<span>', $field['output_html'], '</span>';
197
+	}
192 198
 
193 199
 
194 200
 	echo '
@@ -201,39 +207,44 @@  discard block
 block discarded – undo
201 207
 	if (!empty($context['print_custom_fields']['below_avatar']))
202 208
 	{
203 209
 		$fields = '';
204
-		foreach ($context['print_custom_fields']['below_avatar'] as $field)
205
-			if (!empty($field['output_html']))
210
+		foreach ($context['print_custom_fields']['below_avatar'] as $field) {
211
+					if (!empty($field['output_html']))
206 212
 				$fields .= '
207 213
 					<li>' . $field['output_html'] . '</li>';
214
+		}
208 215
 
209
-		if (!empty($fields))
210
-			echo '
216
+		if (!empty($fields)) {
217
+					echo '
211 218
 			<div class="custom_fields_below_avatar">
212 219
 				<ul>', $fields, '
213 220
 				</ul>
214 221
 			</div>';
222
+		}
215 223
 	}
216 224
 
217 225
 	echo '
218 226
 			<ul class="icon_fields clear">';
219 227
 
220 228
 	// Email is only visible if it's your profile or you have the moderate_forum permission
221
-	if ($context['member']['show_email'])
222
-		echo '
229
+	if ($context['member']['show_email']) {
230
+			echo '
223 231
 				<li><a href="mailto:', $context['member']['email'], '" title="', $context['member']['email'], '" rel="nofollow"><span class="generic_icons mail" title="' . $txt['email'] . '"></span></a></li>';
232
+	}
224 233
 
225 234
 	// Don't show an icon if they haven't specified a website.
226
-	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
227
-		echo '
235
+	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website'])) {
236
+			echo '
228 237
 				<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www" title="' . $context['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
238
+	}
229 239
 
230 240
 	// Are there any custom profile fields as icons?
231 241
 	if (!empty($context['print_custom_fields']['icons']))
232 242
 	{
233
-		foreach ($context['print_custom_fields']['icons'] as $field)
234
-			if (!empty($field['output_html']))
243
+		foreach ($context['print_custom_fields']['icons'] as $field) {
244
+					if (!empty($field['output_html']))
235 245
 				echo '
236 246
 				<li class="custom_field">', $field['output_html'], '</li>';
247
+		}
237 248
 	}
238 249
 
239 250
 	echo '
@@ -242,24 +253,27 @@  discard block
 block discarded – undo
242 253
 				', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['text'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<span class="' . ($context['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $context['member']['online']['text'] . '"></span>' : $context['member']['online']['label'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['label'] . '</span>' : '';
243 254
 
244 255
 	// Can they add this member as a buddy?
245
-	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
246
-		echo '
256
+	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner']) {
257
+			echo '
247 258
 				<br>
248 259
 				<a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
260
+	}
249 261
 
250 262
 	echo '
251 263
 			</span>';
252 264
 
253
-	if (!$context['user']['is_owner'] && $context['can_send_pm'])
254
-		echo '
265
+	if (!$context['user']['is_owner'] && $context['can_send_pm']) {
266
+			echo '
255 267
 			<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '" class="infolinks">', $txt['profile_sendpm_short'], '</a>';
268
+	}
256 269
 
257 270
 	echo '
258 271
 			<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '" class="infolinks">', $txt['showPosts'], '</a>';
259 272
 
260
-	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled']))
261
-		echo '
273
+	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled'])) {
274
+			echo '
262 275
 			<a href="', $scripturl, '?action=profile;area=showdrafts;u=', $context['id_member'], '" class="infolinks">', $txt['drafts_show'], '</a>';
276
+	}
263 277
 
264 278
 	echo '
265 279
 			<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '" class="infolinks">', $txt['statPanel'], '</a>';
@@ -268,17 +282,19 @@  discard block
 block discarded – undo
268 282
 	if (!empty($context['print_custom_fields']['bottom_poster']))
269 283
 	{
270 284
 		$fields = '';
271
-		foreach ($context['print_custom_fields']['bottom_poster'] as $field)
272
-			if (!empty($field['output_html']))
285
+		foreach ($context['print_custom_fields']['bottom_poster'] as $field) {
286
+					if (!empty($field['output_html']))
273 287
 				$fields .= '
274 288
 					<li>' . $field['output_html'] . '</li>';
289
+		}
275 290
 
276
-		if (!empty($fields))
277
-			echo '
291
+		if (!empty($fields)) {
292
+					echo '
278 293
 			<div class="custom_fields_bottom">
279 294
 				<ul class="nolist">', $fields, '
280 295
 				</ul>
281 296
 			</div>';
297
+		}
282 298
 	}
283 299
 
284 300
 	echo '
@@ -287,30 +303,35 @@  discard block
 block discarded – undo
287 303
 		<div id="detailedinfo">
288 304
 			<dl class="settings">';
289 305
 
290
-	if ($context['user']['is_owner'] || $context['user']['is_admin'])
291
-		echo '
306
+	if ($context['user']['is_owner'] || $context['user']['is_admin']) {
307
+			echo '
292 308
 				<dt>', $txt['username'], ': </dt>
293 309
 				<dd>', $context['member']['username'], '</dd>';
310
+	}
294 311
 
295
-	if (!isset($context['disabled_fields']['posts']))
296
-		echo '
312
+	if (!isset($context['disabled_fields']['posts'])) {
313
+			echo '
297 314
 				<dt>', $txt['profile_posts'], ': </dt>
298 315
 				<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
316
+	}
299 317
 
300
-	if ($context['member']['show_email'])
301
-		echo '
318
+	if ($context['member']['show_email']) {
319
+			echo '
302 320
 				<dt>', $txt['email'], ': </dt>
303 321
 				<dd><a href="mailto:', $context['member']['email'], '">', $context['member']['email'], '</a></dd>';
322
+	}
304 323
 
305
-	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
306
-		echo '
324
+	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title'])) {
325
+			echo '
307 326
 				<dt>', $txt['custom_title'], ': </dt>
308 327
 				<dd>', $context['member']['title'], '</dd>';
328
+	}
309 329
 
310
-	if (!empty($context['member']['blurb']))
311
-		echo '
330
+	if (!empty($context['member']['blurb'])) {
331
+			echo '
312 332
 				<dt>', $txt['personal_text'], ': </dt>
313 333
 				<dd>', $context['member']['blurb'], '</dd>';
334
+	}
314 335
 
315 336
 	echo '
316 337
 				<dt>', $txt['age'], ':</dt>
@@ -324,19 +345,21 @@  discard block
 block discarded – undo
324 345
 	{
325 346
 		$fields = array();
326 347
 
327
-		foreach ($context['print_custom_fields']['standard'] as $field)
328
-			if (!empty($field['output_html']))
348
+		foreach ($context['print_custom_fields']['standard'] as $field) {
349
+					if (!empty($field['output_html']))
329 350
 				$fields[] = $field;
351
+		}
330 352
 
331 353
 		if (count($fields) > 0)
332 354
 		{
333 355
 			echo '
334 356
 			<dl class="settings">';
335 357
 
336
-			foreach ($fields as $field)
337
-				echo '
358
+			foreach ($fields as $field) {
359
+							echo '
338 360
 				<dt>', $field['name'], ':</dt>
339 361
 				<dd>', $field['output_html'], '</dd>';
362
+			}
340 363
 
341 364
 			echo '
342 365
 			</dl>';
@@ -356,9 +379,10 @@  discard block
 block discarded – undo
356 379
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', ($context['can_issue_warning'] && !$context['user']['is_owner'] ? 'issuewarning' : 'viewwarning'), '">', $context['member']['warning'], '%</a>';
357 380
 
358 381
 		// Can we provide information on what this means?
359
-		if (!empty($context['warning_status']))
360
-			echo '
382
+		if (!empty($context['warning_status'])) {
383
+					echo '
361 384
 					<span class="smalltext">(', $context['warning_status'], ')</span>';
385
+		}
362 386
 
363 387
 		echo '
364 388
 				</dd>';
@@ -369,11 +393,12 @@  discard block
 block discarded – undo
369 393
 	{
370 394
 
371 395
 		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
372
-		if (!empty($context['activate_message']))
373
-			echo '
396
+		if (!empty($context['activate_message'])) {
397
+					echo '
374 398
 				<dt class="clear">
375 399
 					<span class="alert">', $context['activate_message'], '</span> (<a href="', $context['activate_link'], '"', ($context['activate_type'] == 4 ? ' class="you_sure" data-confirm="' . $txt['profileConfirm'] . '"' : ''), '>', $context['activate_link_text'], '</a>)
376 400
 				</dt>';
401
+		}
377 402
 
378 403
 		// If the current member is banned, show a message and possibly a link to the ban.
379 404
 		if (!empty($context['member']['bans']))
@@ -385,10 +410,11 @@  discard block
 block discarded – undo
385 410
 				<dt class="clear" id="ban_info" style="display: none;">
386 411
 					<strong>', $txt['user_banned_by_following'], ':</strong>';
387 412
 
388
-			foreach ($context['member']['bans'] as $ban)
389
-				echo '
413
+			foreach ($context['member']['bans'] as $ban) {
414
+							echo '
390 415
 					<br>
391 416
 					<span class="smalltext">', $ban['explanation'], '</span>';
417
+			}
392 418
 
393 419
 			echo '
394 420
 				</dt>';
@@ -402,30 +428,34 @@  discard block
 block discarded – undo
402 428
 	// If the person looking is allowed, they can check the members IP address and hostname.
403 429
 	if ($context['can_see_ip'])
404 430
 	{
405
-		if (!empty($context['member']['ip']))
406
-		echo '
431
+		if (!empty($context['member']['ip'])) {
432
+				echo '
407 433
 				<dt>', $txt['ip'], ': </dt>
408 434
 				<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
435
+		}
409 436
 
410
-		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
411
-			echo '
437
+		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip'])) {
438
+					echo '
412 439
 				<dt>', $txt['hostname'], ': </dt>
413 440
 				<dd>', $context['member']['hostname'], '</dd>';
441
+		}
414 442
 	}
415 443
 
416 444
 	echo '
417 445
 				<dt>', $txt['local_time'], ':</dt>
418 446
 				<dd>', $context['member']['local_time'], '</dd>';
419 447
 
420
-	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
421
-		echo '
448
+	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language'])) {
449
+			echo '
422 450
 				<dt>', $txt['language'], ':</dt>
423 451
 				<dd>', $context['member']['language'], '</dd>';
452
+	}
424 453
 
425
-	if ($context['member']['show_last_login'])
426
-		echo '
454
+	if ($context['member']['show_last_login']) {
455
+			echo '
427 456
 				<dt>', $txt['lastLoggedIn'], ': </dt>
428 457
 				<dd>', $context['member']['last_login'], (!empty($context['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</dd>';
458
+	}
429 459
 
430 460
 	echo '
431 461
 			</dl>';
@@ -434,42 +464,47 @@  discard block
 block discarded – undo
434 464
 	if (!empty($context['print_custom_fields']['above_signature']))
435 465
 	{
436 466
 		$fields = '';
437
-		foreach ($context['print_custom_fields']['above_signature'] as $field)
438
-			if (!empty($field['output_html']))
467
+		foreach ($context['print_custom_fields']['above_signature'] as $field) {
468
+					if (!empty($field['output_html']))
439 469
 				$fields .= '
440 470
 					<li>' . $field['output_html'] . '</li>';
471
+		}
441 472
 
442
-		if (!empty($fields))
443
-			echo '
473
+		if (!empty($fields)) {
474
+					echo '
444 475
 			<div class="custom_fields_above_signature">
445 476
 				<ul class="nolist">', $fields, '
446 477
 				</ul>
447 478
 			</div>';
479
+		}
448 480
 	}
449 481
 
450 482
 	// Show the users signature.
451
-	if ($context['signature_enabled'] && !empty($context['member']['signature']))
452
-		echo '
483
+	if ($context['signature_enabled'] && !empty($context['member']['signature'])) {
484
+			echo '
453 485
 			<div class="signature">
454 486
 				<h5>', $txt['signature'], ':</h5>
455 487
 				', $context['member']['signature'], '
456 488
 			</div>';
489
+	}
457 490
 
458 491
 	// Are there any custom profile fields for below the signature?
459 492
 	if (!empty($context['print_custom_fields']['below_signature']))
460 493
 	{
461 494
 		$fields = '';
462
-		foreach ($context['print_custom_fields']['below_signature'] as $field)
463
-			if (!empty($field['output_html']))
495
+		foreach ($context['print_custom_fields']['below_signature'] as $field) {
496
+					if (!empty($field['output_html']))
464 497
 				$fields .=  '
465 498
 					<li>' . $field['output_html'] . '</li>';
499
+		}
466 500
 
467
-		if (!empty($fields))
468
-			echo '
501
+		if (!empty($fields)) {
502
+					echo '
469 503
 			<div class="custom_fields_below_signature">
470 504
 				<ul class="nolist">', $fields, '
471 505
 				</ul>
472 506
 			</div>';
507
+		}
473 508
 	}
474 509
 
475 510
 	echo '
@@ -511,62 +546,70 @@  discard block
 block discarded – undo
511 546
 			</div>
512 547
 			<div class="list_posts">';
513 548
 
514
-			if (!$post['approved'])
515
-				echo '
549
+			if (!$post['approved']) {
550
+							echo '
516 551
 				<div class="approve_post">
517 552
 					<em>', $txt['post_awaiting_approval'], '</em>
518 553
 				</div>';
554
+			}
519 555
 
520 556
 			echo '
521 557
 				', $post['body'], '
522 558
 			</div>';
523 559
 
524
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
525
-				echo '
560
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
561
+							echo '
526 562
 			<div class="floatright">
527 563
 				<ul class="quickbuttons">';
564
+			}
528 565
 
529 566
 			// If they *can* reply?
530
-			if ($post['can_reply'])
531
-				echo '
567
+			if ($post['can_reply']) {
568
+							echo '
532 569
 					<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
570
+			}
533 571
 
534 572
 			// If they *can* quote?
535
-			if ($post['can_quote'])
536
-				echo '
573
+			if ($post['can_quote']) {
574
+							echo '
537 575
 					<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
576
+			}
538 577
 
539 578
 			// How about... even... remove it entirely?!
540
-			if ($post['can_delete'])
541
-				echo '
579
+			if ($post['can_delete']) {
580
+							echo '
542 581
 					<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
582
+			}
543 583
 
544
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
545
-				echo '
584
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
585
+							echo '
546 586
 				</ul>
547 587
 			</div><!-- .floatright -->';
588
+			}
548 589
 
549 590
 			echo '
550 591
 		</div><!-- $post[css_class] -->';
551 592
 		}
593
+	} else {
594
+			template_show_list('attachments');
552 595
 	}
553
-	else
554
-		template_show_list('attachments');
555 596
 
556 597
 	// No posts? Just end with a informative message.
557
-	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
558
-		echo '
598
+	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts']))) {
599
+			echo '
559 600
 		<div class="windowbg2">
560 601
 			', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
561 602
 		</div>';
603
+	}
562 604
 
563 605
 	// Show more page numbers.
564
-	if (!empty($context['page_index']))
565
-		echo '
606
+	if (!empty($context['page_index'])) {
607
+			echo '
566 608
 		<div class="pagesection">
567 609
 			<div class="pagelinks">', $context['page_index'], '</div>
568 610
 		</div>';
569
-}
611
+	}
612
+	}
570 613
 
571 614
 /**
572 615
  * Template for showing alerts within the alerts popup
@@ -576,11 +619,12 @@  discard block
 block discarded – undo
576 619
 	global $context, $txt, $scripturl;
577 620
 
578 621
 	// Do we have an update message?
579
-	if (!empty($context['update_message']))
580
-		echo '
622
+	if (!empty($context['update_message'])) {
623
+			echo '
581 624
 		<div class="infobox">
582 625
 			', $context['update_message'], '
583 626
 		</div>';
627
+	}
584 628
 
585 629
 	echo '
586 630
 		<div class="cat_bar">
@@ -589,19 +633,19 @@  discard block
 block discarded – undo
589 633
 			</h3>
590 634
 		</div>';
591 635
 
592
-	if (empty($context['alerts']))
593
-		echo '
636
+	if (empty($context['alerts'])) {
637
+			echo '
594 638
 		<div class="information">
595 639
 			', $txt['alerts_none'], '
596 640
 		</div>';
597
-
598
-	else
641
+	} else
599 642
 	{
600 643
 	
601 644
 		// Start the form if checkboxes are in use	
602
-		if ($context['showCheckboxes'])
603
-			echo '
645
+		if ($context['showCheckboxes']) {
646
+					echo '
604 647
 		<form action="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=showalerts;save" method="post" accept-charset="', $context['character_set'], '" id="mark_all">';
648
+		}
605 649
 
606 650
 		echo '
607 651
 			<table id="alerts" class="table_grid">';
@@ -617,9 +661,10 @@  discard block
 block discarded – undo
617 661
 							<li><a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=showalerts;do=remove;aid=', $id, ';', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['delete'], '</a></li>
618 662
 							<li><a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=showalerts;do=', ($alert['is_read'] != 0 ? 'unread' : 'read'), ';aid=', $id, ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons ', $alert['is_read'] != 0 ? 'unread_button' : 'read_button', '"></span>', ($alert['is_read'] != 0 ? $txt['mark_unread'] : $txt['mark_read_short']), '</a></li>';
619 663
 
620
-					if ($context['showCheckboxes'])
621
-						echo '
664
+					if ($context['showCheckboxes']) {
665
+											echo '
622 666
 							<li><input type="checkbox" name="mark[', $id, ']" value="', $id, '"></li>';
667
+					}
623 668
 
624 669
 			echo '
625 670
 						</ul>
@@ -634,8 +679,8 @@  discard block
 block discarded – undo
634 679
 					', $context['pagination'], '
635 680
 				</div>';
636 681
 
637
-		if ($context['showCheckboxes'])
638
-			echo '
682
+		if ($context['showCheckboxes']) {
683
+					echo '
639 684
 				<div class="floatright">
640 685
 					', $txt['check_all'], ': <input type="checkbox" name="select_all" id="select_all">
641 686
 					<select name="mark_as">
@@ -646,14 +691,16 @@  discard block
 block discarded – undo
646 691
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
647 692
 					<input type="submit" name="req" value="', $txt['quick_mod_go'], '" class="button you_sure">
648 693
 				</div>';
694
+		}
649 695
 
650 696
 	echo '
651 697
 			</div>';
652 698
 
653
-	if ($context['showCheckboxes'])
654
-		echo '
699
+	if ($context['showCheckboxes']) {
700
+			echo '
655 701
 		</form>';
656 702
 	}
703
+	}
657 704
 }
658 705
 
659 706
 /**
@@ -674,12 +721,12 @@  discard block
 block discarded – undo
674 721
 		</div>' : '';
675 722
 
676 723
 	// No drafts? Just show an informative message.
677
-	if (empty($context['drafts']))
678
-		echo '
724
+	if (empty($context['drafts'])) {
725
+			echo '
679 726
 		<div class="windowbg2 centertext">
680 727
 			', $txt['draft_none'], '
681 728
 		</div>';
682
-	else
729
+	} else
683 730
 	{
684 731
 		// For every draft to be displayed, give it its own div, and show the important details of the draft.
685 732
 		foreach ($context['drafts'] as $draft)
@@ -691,13 +738,15 @@  discard block
 block discarded – undo
691 738
 				<h5>
692 739
 					<strong><a href="', $scripturl, '?board=', $draft['board']['id'], '.0">', $draft['board']['name'], '</a> / ', $draft['topic']['link'], '</strong> &nbsp; &nbsp;';
693 740
 
694
-			if (!empty($draft['sticky']))
695
-				echo '
741
+			if (!empty($draft['sticky'])) {
742
+							echo '
696 743
 					<span class="generic_icons sticky" title="', $txt['sticky_topic'], '"></span>';
744
+			}
697 745
 
698
-			if (!empty($draft['locked']))
699
-				echo '
746
+			if (!empty($draft['locked'])) {
747
+							echo '
700 748
 					<span class="generic_icons lock" title="', $txt['locked_topic'], '"></span>';
749
+			}
701 750
 
702 751
 			echo '
703 752
 				</h5>
@@ -730,13 +779,13 @@  discard block
 block discarded – undo
730 779
 {
731 780
 	global $context, $scripturl, $txt;
732 781
 
733
-	if (!empty($context['saved_successful']))
734
-		echo '
782
+	if (!empty($context['saved_successful'])) {
783
+			echo '
735 784
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
736
-
737
-	elseif (!empty($context['saved_failed']))
738
-		echo '
785
+	} elseif (!empty($context['saved_failed'])) {
786
+			echo '
739 787
 	<div class="errorbox">', $context['saved_failed'], '</div>';
788
+	}
740 789
 
741 790
 	echo '
742 791
 	<div id="edit_buddies">
@@ -751,14 +800,16 @@  discard block
 block discarded – undo
751 800
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
752 801
 					<th scope="col">', $txt['status'], '</th>';
753 802
 
754
-	if (allowedTo('moderate_forum'))
755
-		echo '
803
+	if (allowedTo('moderate_forum')) {
804
+			echo '
756 805
 					<th scope="col">', $txt['email'], '</th>';
806
+	}
757 807
 
758
-	if (!empty($context['custom_pf']))
759
-		foreach ($context['custom_pf'] as $column)
808
+	if (!empty($context['custom_pf'])) {
809
+			foreach ($context['custom_pf'] as $column)
760 810
 				echo '
761 811
 					<th scope="col">', $column['label'], '</th>';
812
+	}
762 813
 
763 814
 	echo '
764 815
 					<th scope="col">', $txt['remove'], '</th>
@@ -767,13 +818,14 @@  discard block
 block discarded – undo
767 818
 			<tbody>';
768 819
 
769 820
 	// If they don't have any buddies don't list them!
770
-	if (empty($context['buddies']))
771
-		echo '
821
+	if (empty($context['buddies'])) {
822
+			echo '
772 823
 				<tr class="windowbg">
773 824
 					<td colspan="', allowedTo('moderate_forum') ? '10' : '9', '">
774 825
 						<strong>', $txt['no_buddies'], '</strong>
775 826
 					</td>
776 827
 				</tr>';
828
+	}
777 829
 
778 830
 		// Now loop through each buddy showing info on each.
779 831
 	else
@@ -787,17 +839,19 @@  discard block
 block discarded – undo
787 839
 						<a href="', $buddy['online']['href'], '"><span class="' . ($buddy['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $buddy['online']['text'] . '"></span></a>
788 840
 					</td>';
789 841
 
790
-			if ($buddy['show_email'])
791
-				echo '
842
+			if ($buddy['show_email']) {
843
+							echo '
792 844
 					<td>
793 845
 						<a href="mailto:' . $buddy['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $buddy['name'] . '"></span></a>
794 846
 					</td>';
847
+			}
795 848
 
796 849
 			// Show the custom profile fields for this user.
797
-			if (!empty($context['custom_pf']))
798
-				foreach ($context['custom_pf'] as $key => $column)
850
+			if (!empty($context['custom_pf'])) {
851
+							foreach ($context['custom_pf'] as $key => $column)
799 852
 					echo '
800 853
 					<td class="lefttext">', $buddy['options'][$key], '</td>';
854
+			}
801 855
 
802 856
 			echo '
803 857
 					<td>
@@ -830,9 +884,10 @@  discard block
 block discarded – undo
830 884
 			</dl>
831 885
 		</div>';
832 886
 
833
-	if (!empty($context['token_check']))
834
-		echo '
887
+	if (!empty($context['token_check'])) {
888
+			echo '
835 889
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
890
+	}
836 891
 
837 892
 	echo '
838 893
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -858,13 +913,13 @@  discard block
 block discarded – undo
858 913
 {
859 914
 	global $context, $scripturl, $txt;
860 915
 
861
-	if (!empty($context['saved_successful']))
862
-		echo '
916
+	if (!empty($context['saved_successful'])) {
917
+			echo '
863 918
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
864
-
865
-	elseif (!empty($context['saved_failed']))
866
-		echo '
919
+	} elseif (!empty($context['saved_failed'])) {
920
+			echo '
867 921
 	<div class="errorbox">', $context['saved_failed'], '</div>';
922
+	}
868 923
 
869 924
 	echo '
870 925
 	<div id="edit_buddies">
@@ -879,9 +934,10 @@  discard block
 block discarded – undo
879 934
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
880 935
 					<th scope="col">', $txt['status'], '</th>';
881 936
 
882
-	if (allowedTo('moderate_forum'))
883
-		echo '
937
+	if (allowedTo('moderate_forum')) {
938
+			echo '
884 939
 					<th scope="col">', $txt['email'], '</th>';
940
+	}
885 941
 
886 942
 	echo '
887 943
 					<th scope="col">', $txt['ignore_remove'], '</th>
@@ -890,13 +946,14 @@  discard block
 block discarded – undo
890 946
 			<tbody>';
891 947
 
892 948
 	// If they don't have anyone on their ignore list, don't list it!
893
-	if (empty($context['ignore_list']))
894
-		echo '
949
+	if (empty($context['ignore_list'])) {
950
+			echo '
895 951
 				<tr class="windowbg">
896 952
 					<td colspan="', allowedTo('moderate_forum') ? '4' : '3', '">
897 953
 						<strong>', $txt['no_ignore'], '</strong>
898 954
 					</td>
899 955
 				</tr>';
956
+	}
900 957
 
901 958
 	// Now loop through each buddy showing info on each.
902 959
 	foreach ($context['ignore_list'] as $member)
@@ -908,11 +965,12 @@  discard block
 block discarded – undo
908 965
 						<a href="', $member['online']['href'], '"><span class="' . ($member['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $member['online']['text'] . '"></span></a>
909 966
 					</td>';
910 967
 
911
-		if ($member['show_email'])
912
-			echo '
968
+		if ($member['show_email']) {
969
+					echo '
913 970
 					<td>
914 971
 						<a href="mailto:' . $member['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $member['name'] . '"></span></a>
915 972
 					</td>';
973
+		}
916 974
 		echo '
917 975
 					<td>
918 976
 						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons delete" title="', $txt['ignore_remove'], '"></span></a>
@@ -942,9 +1000,10 @@  discard block
 block discarded – undo
942 1000
 			</dl>
943 1001
 		</div>';
944 1002
 
945
-	if (!empty($context['token_check']))
946
-		echo '
1003
+	if (!empty($context['token_check'])) {
1004
+			echo '
947 1005
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
1006
+	}
948 1007
 
949 1008
 	echo '
950 1009
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -990,9 +1049,10 @@  discard block
 block discarded – undo
990 1049
 					<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
991 1050
 
992 1051
 	// Second address detected?
993
-	if (!empty($context['last_ip2']))
994
-		echo '
1052
+	if (!empty($context['last_ip2'])) {
1053
+			echo '
995 1054
 					, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
1055
+	}
996 1056
 
997 1057
 	echo '
998 1058
 				</dd>';
@@ -1058,9 +1118,10 @@  discard block
 block discarded – undo
1058 1118
 		</div>
1059 1119
 		<div class="windowbg2 noup">';
1060 1120
 
1061
-		foreach ($context['whois_servers'] as $server)
1062
-			echo '
1121
+		foreach ($context['whois_servers'] as $server) {
1122
+					echo '
1063 1123
 			<a href="', $server['url'], '" target="_blank" rel="noopener"', '>', $server['name'], '</a><br>';
1124
+		}
1064 1125
 		echo '
1065 1126
 		</div>
1066 1127
 		<br>';
@@ -1072,13 +1133,12 @@  discard block
 block discarded – undo
1072 1133
 			<h3 class="catbg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
1073 1134
 		</div>';
1074 1135
 
1075
-	if (empty($context['ips']))
1076
-		echo '
1136
+	if (empty($context['ips'])) {
1137
+			echo '
1077 1138
 		<p class="windowbg2 description">
1078 1139
 			<em>', $txt['no_members_from_ip'], '</em>
1079 1140
 		</p>';
1080
-
1081
-	else
1141
+	} else
1082 1142
 	{
1083 1143
 		echo '
1084 1144
 		<table class="table_grid">
@@ -1091,12 +1151,13 @@  discard block
 block discarded – undo
1091 1151
 			<tbody>';
1092 1152
 
1093 1153
 		// Loop through each of the members and display them.
1094
-		foreach ($context['ips'] as $ip => $memberlist)
1095
-			echo '
1154
+		foreach ($context['ips'] as $ip => $memberlist) {
1155
+					echo '
1096 1156
 				<tr class="windowbg">
1097 1157
 					<td><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
1098 1158
 					<td>', implode(', ', $memberlist), '</td>
1099 1159
 				</tr>';
1160
+		}
1100 1161
 
1101 1162
 		echo '
1102 1163
 			</tbody>
@@ -1138,11 +1199,10 @@  discard block
 block discarded – undo
1138 1199
 			</h3>
1139 1200
 		</div>';
1140 1201
 
1141
-	if ($context['member']['has_all_permissions'])
1142
-		echo '
1202
+	if ($context['member']['has_all_permissions']) {
1203
+			echo '
1143 1204
 		<div class="information">', $txt['showPermissions_all'], '</div>';
1144
-
1145
-	else
1205
+	} else
1146 1206
 	{
1147 1207
 		echo '
1148 1208
 		<div class="information">',$txt['showPermissions_help'], '</div>
@@ -1157,9 +1217,10 @@  discard block
 block discarded – undo
1157 1217
 			<div class="windowbg smalltext">
1158 1218
 				', $txt['showPermissions_restricted_boards_desc'], ':<br>';
1159 1219
 
1160
-			foreach ($context['no_access_boards'] as $no_access_board)
1161
-				echo '
1220
+			foreach ($context['no_access_boards'] as $no_access_board) {
1221
+							echo '
1162 1222
 				<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
1223
+			}
1163 1224
 			echo '
1164 1225
 			</div>';
1165 1226
 		}
@@ -1191,12 +1252,13 @@  discard block
 block discarded – undo
1191 1252
 							</td>
1192 1253
 							<td class="smalltext">';
1193 1254
 
1194
-				if ($permission['is_denied'])
1195
-					echo '
1255
+				if ($permission['is_denied']) {
1256
+									echo '
1196 1257
 								<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1197
-				else
1198
-					echo '
1258
+				} else {
1259
+									echo '
1199 1260
 								', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1261
+				}
1200 1262
 
1201 1263
 				echo '
1202 1264
 							</td>
@@ -1207,10 +1269,10 @@  discard block
 block discarded – undo
1207 1269
 				</table>
1208 1270
 			</div><!-- .tborder -->
1209 1271
 			<br>';
1210
-		}
1211
-		else
1212
-			echo '
1272
+		} else {
1273
+					echo '
1213 1274
 			<p class="windowbg2">', $txt['showPermissions_none_general'], '</p>';
1275
+		}
1214 1276
 
1215 1277
 		// Board permission section.
1216 1278
 		echo '
@@ -1221,14 +1283,16 @@  discard block
 block discarded – undo
1221 1283
 						<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
1222 1284
 							<option value="0"', $context['board'] == 0 ? ' selected' : '', '>', $txt['showPermissions_global'], '</option>';
1223 1285
 
1224
-		if (!empty($context['boards']))
1225
-			echo '
1286
+		if (!empty($context['boards'])) {
1287
+					echo '
1226 1288
 							<option value="" disabled>---------------------------</option>';
1289
+		}
1227 1290
 
1228 1291
 		// Fill the box with any local permission boards.
1229
-		foreach ($context['boards'] as $board)
1230
-			echo '
1292
+		foreach ($context['boards'] as $board) {
1293
+					echo '
1231 1294
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
1295
+		}
1232 1296
 
1233 1297
 		echo '
1234 1298
 						</select>
@@ -1257,13 +1321,13 @@  discard block
 block discarded – undo
1257 1321
 						</td>
1258 1322
 						<td class="smalltext">';
1259 1323
 
1260
-				if ($permission['is_denied'])
1261
-					echo '
1324
+				if ($permission['is_denied']) {
1325
+									echo '
1262 1326
 							<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1263
-
1264
-				else
1265
-					echo '
1327
+				} else {
1328
+									echo '
1266 1329
 							', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1330
+				}
1267 1331
 
1268 1332
 				echo '
1269 1333
 						</td>
@@ -1272,10 +1336,10 @@  discard block
 block discarded – undo
1272 1336
 			echo '
1273 1337
 				</tbody>
1274 1338
 			</table>';
1275
-		}
1276
-		else
1277
-			echo '
1339
+		} else {
1340
+					echo '
1278 1341
 			<p class="windowbg2">', $txt['showPermissions_none_board'], '</p>';
1342
+		}
1279 1343
 	echo '
1280 1344
 		</div><!-- #permissions -->';
1281 1345
 	}
@@ -1316,9 +1380,10 @@  discard block
 block discarded – undo
1316 1380
 			</div>';
1317 1381
 
1318 1382
 	// If they haven't post at all, don't draw the graph.
1319
-	if (empty($context['posts_by_time']))
1320
-		echo '
1383
+	if (empty($context['posts_by_time'])) {
1384
+			echo '
1321 1385
 			<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1386
+	}
1322 1387
 
1323 1388
 	// Otherwise do!
1324 1389
 	else
@@ -1327,8 +1392,8 @@  discard block
 block discarded – undo
1327 1392
 			<ul class="activity_stats flow_hidden">';
1328 1393
 
1329 1394
 		// The labels.
1330
-		foreach ($context['posts_by_time'] as $time_of_day)
1331
-			echo '
1395
+		foreach ($context['posts_by_time'] as $time_of_day) {
1396
+					echo '
1332 1397
 				<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
1333 1398
 					<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
1334 1399
 						<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
@@ -1337,6 +1402,7 @@  discard block
 block discarded – undo
1337 1402
 					</div>
1338 1403
 					<span class="stats_hour">', $time_of_day['hour_format'], '</span>
1339 1404
 				</li>';
1405
+		}
1340 1406
 
1341 1407
 		echo '
1342 1408
 			</ul>';
@@ -1355,11 +1421,10 @@  discard block
 block discarded – undo
1355 1421
 					</h3>
1356 1422
 				</div>';
1357 1423
 
1358
-	if (empty($context['popular_boards']))
1359
-		echo '
1424
+	if (empty($context['popular_boards'])) {
1425
+			echo '
1360 1426
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1361
-
1362
-	else
1427
+	} else
1363 1428
 	{
1364 1429
 		echo '
1365 1430
 				<dl class="stats">';
@@ -1389,10 +1454,10 @@  discard block
 block discarded – undo
1389 1454
 					</h3>
1390 1455
 				</div>';
1391 1456
 
1392
-	if (empty($context['board_activity']))
1393
-		echo '
1457
+	if (empty($context['board_activity'])) {
1458
+			echo '
1394 1459
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1395
-	else
1460
+	} else
1396 1461
 	{
1397 1462
 		echo '
1398 1463
 				<dl class="stats">';
@@ -1443,90 +1508,97 @@  discard block
 block discarded – undo
1443 1508
 				<h3 class="catbg profile_hd">';
1444 1509
 
1445 1510
 		// Don't say "Profile" if this isn't the profile...
1446
-		if (!empty($context['profile_header_text']))
1447
-			echo '
1511
+		if (!empty($context['profile_header_text'])) {
1512
+					echo '
1448 1513
 					', $context['profile_header_text'];
1449
-		else
1450
-			echo '
1514
+		} else {
1515
+					echo '
1451 1516
 					', $txt['profile'];
1517
+		}
1452 1518
 
1453 1519
 		echo '
1454 1520
 				</h3>
1455 1521
 			</div>';
1456 1522
 
1457 1523
 	// Have we some description?
1458
-	if ($context['page_desc'])
1459
-		echo '
1524
+	if ($context['page_desc']) {
1525
+			echo '
1460 1526
 			<p class="information">', $context['page_desc'], '</p>';
1527
+	}
1461 1528
 
1462 1529
 	echo '
1463 1530
 			<div class="roundframe">';
1464 1531
 
1465 1532
 	// Any bits at the start?
1466
-	if (!empty($context['profile_prehtml']))
1467
-		echo '
1533
+	if (!empty($context['profile_prehtml'])) {
1534
+			echo '
1468 1535
 				<div>', $context['profile_prehtml'], '</div>';
1536
+	}
1469 1537
 
1470
-	if (!empty($context['profile_fields']))
1471
-		echo '
1538
+	if (!empty($context['profile_fields'])) {
1539
+			echo '
1472 1540
 				<dl class="settings">';
1541
+	}
1473 1542
 
1474 1543
 	// Start the big old loop 'of love.
1475 1544
 	$lastItem = 'hr';
1476 1545
 	foreach ($context['profile_fields'] as $key => $field)
1477 1546
 	{
1478 1547
 		// We add a little hack to be sure we never get more than one hr in a row!
1479
-		if ($lastItem == 'hr' && $field['type'] == 'hr')
1480
-			continue;
1548
+		if ($lastItem == 'hr' && $field['type'] == 'hr') {
1549
+					continue;
1550
+		}
1481 1551
 
1482 1552
 		$lastItem = $field['type'];
1483
-		if ($field['type'] == 'hr')
1484
-			echo '
1553
+		if ($field['type'] == 'hr') {
1554
+					echo '
1485 1555
 				</dl>
1486 1556
 				<hr>
1487 1557
 				<dl class="settings">';
1488
-
1489
-		elseif ($field['type'] == 'callback')
1558
+		} elseif ($field['type'] == 'callback')
1490 1559
 		{
1491 1560
 			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
1492 1561
 			{
1493 1562
 				$callback_func = 'template_profile_' . $field['callback_func'];
1494 1563
 				$callback_func();
1495 1564
 			}
1496
-		}
1497
-		else
1565
+		} else
1498 1566
 		{
1499 1567
 			echo '
1500 1568
 					<dt>
1501 1569
 						<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
1502 1570
 
1503 1571
 			// Does it have any subtext to show?
1504
-			if (!empty($field['subtext']))
1505
-				echo '
1572
+			if (!empty($field['subtext'])) {
1573
+							echo '
1506 1574
 						<br>
1507 1575
 						<span class="smalltext">', $field['subtext'], '</span>';
1576
+			}
1508 1577
 
1509 1578
 			echo '
1510 1579
 					</dt>
1511 1580
 					<dd>';
1512 1581
 
1513 1582
 			// Want to put something infront of the box?
1514
-			if (!empty($field['preinput']))
1515
-				echo '
1583
+			if (!empty($field['preinput'])) {
1584
+							echo '
1516 1585
 						', $field['preinput'];
1586
+			}
1517 1587
 
1518 1588
 			// What type of data are we showing?
1519
-			if ($field['type'] == 'label')
1520
-				echo '
1589
+			if ($field['type'] == 'label') {
1590
+							echo '
1521 1591
 						', $field['value'];
1592
+			}
1522 1593
 
1523 1594
 			// Maybe it's a text box - very likely!
1524 1595
 			elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number', 'time', 'url')))
1525 1596
 			{
1526
-				if ($field['type'] == 'int' || $field['type'] == 'float')
1527
-					$type = 'number';
1528
-				else
1529
-					$type = $field['type'];
1597
+				if ($field['type'] == 'int' || $field['type'] == 'float') {
1598
+									$type = 'number';
1599
+				} else {
1600
+									$type = $field['type'];
1601
+				}
1530 1602
 				$step = $field['type'] == 'float' ? ' step="0.1"' : '';
1531 1603
 
1532 1604
 
@@ -1534,10 +1606,11 @@  discard block
 block discarded – undo
1534 1606
 						<input type="', $type, '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' ', $step, '>';
1535 1607
 			}
1536 1608
 			// You "checking" me out? ;)
1537
-			elseif ($field['type'] == 'check')
1538
-				echo '
1609
+			elseif ($field['type'] == 'check') {
1610
+							echo '
1539 1611
 						<input type="hidden" name="', $key, '" value="0">
1540 1612
 						<input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" ', $field['input_attr'], '>';
1613
+			}
1541 1614
 
1542 1615
 			// Always fun - select boxes!
1543 1616
 			elseif ($field['type'] == 'select')
@@ -1548,14 +1621,16 @@  discard block
 block discarded – undo
1548 1621
 				if (isset($field['options']))
1549 1622
 				{
1550 1623
 					// Is this some code to generate the options?
1551
-					if (!is_array($field['options']))
1552
-						$field['options'] = $field['options']();
1624
+					if (!is_array($field['options'])) {
1625
+											$field['options'] = $field['options']();
1626
+					}
1553 1627
 
1554 1628
 					// Assuming we now have some!
1555
-					if (is_array($field['options']))
1556
-						foreach ($field['options'] as $value => $name)
1629
+					if (is_array($field['options'])) {
1630
+											foreach ($field['options'] as $value => $name)
1557 1631
 							echo '
1558 1632
 							<option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>';
1633
+					}
1559 1634
 				}
1560 1635
 
1561 1636
 				echo '
@@ -1563,31 +1638,34 @@  discard block
 block discarded – undo
1563 1638
 			}
1564 1639
 
1565 1640
 			// Something to end with?
1566
-			if (!empty($field['postinput']))
1567
-				echo '
1641
+			if (!empty($field['postinput'])) {
1642
+							echo '
1568 1643
 						', $field['postinput'];
1644
+			}
1569 1645
 
1570 1646
 			echo '
1571 1647
 					</dd>';
1572 1648
 		}
1573 1649
 	}
1574 1650
 
1575
-	if (!empty($context['profile_fields']))
1576
-		echo '
1651
+	if (!empty($context['profile_fields'])) {
1652
+			echo '
1577 1653
 				</dl>';
1654
+	}
1578 1655
 
1579 1656
 	// Are there any custom profile fields - if so print them!
1580 1657
 	if (!empty($context['custom_fields']))
1581 1658
 	{
1582
-		if ($lastItem != 'hr')
1583
-			echo '
1659
+		if ($lastItem != 'hr') {
1660
+					echo '
1584 1661
 				<hr>';
1662
+		}
1585 1663
 
1586 1664
 		echo '
1587 1665
 				<dl class="settings">';
1588 1666
 
1589
-		foreach ($context['custom_fields'] as $field)
1590
-			echo '
1667
+		foreach ($context['custom_fields'] as $field) {
1668
+					echo '
1591 1669
 					<dt>
1592 1670
 						<strong>', $field['name'], ': </strong><br>
1593 1671
 						<span class="smalltext">', $field['desc'], '</span>
@@ -1595,6 +1673,7 @@  discard block
 block discarded – undo
1595 1673
 					<dd>
1596 1674
 						', $field['input_html'], '
1597 1675
 					</dd>';
1676
+		}
1598 1677
 
1599 1678
 		echo '
1600 1679
 				</dl>';
@@ -1602,13 +1681,14 @@  discard block
 block discarded – undo
1602 1681
 	}
1603 1682
 
1604 1683
 	// Any closing HTML?
1605
-	if (!empty($context['profile_posthtml']))
1606
-		echo '
1684
+	if (!empty($context['profile_posthtml'])) {
1685
+			echo '
1607 1686
 				<div>', $context['profile_posthtml'], '</div>';
1687
+	}
1608 1688
 
1609 1689
 	// Only show the password box if it's actually needed.
1610
-	if ($context['require_password'])
1611
-		echo '
1690
+	if ($context['require_password']) {
1691
+			echo '
1612 1692
 				<dl class="settings">
1613 1693
 					<dt>
1614 1694
 						<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br>
@@ -1618,18 +1698,21 @@  discard block
 block discarded – undo
1618 1698
 						<input type="password" name="oldpasswrd" id="oldpasswrd" size="20">
1619 1699
 					</dd>
1620 1700
 				</dl>';
1701
+	}
1621 1702
 
1622 1703
 	// The button shouldn't say "Change profile" unless we're changing the profile...
1623
-	if (!empty($context['submit_button_text']))
1624
-		echo '
1704
+	if (!empty($context['submit_button_text'])) {
1705
+			echo '
1625 1706
 				<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button floatright">';
1626
-	else
1627
-		echo '
1707
+	} else {
1708
+			echo '
1628 1709
 				<input type="submit" name="save" value="', $txt['change_profile'], '" class="button floatright">';
1710
+	}
1629 1711
 
1630
-	if (!empty($context['token_check']))
1631
-		echo '
1712
+	if (!empty($context['token_check'])) {
1713
+			echo '
1632 1714
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
1715
+	}
1633 1716
 
1634 1717
 	echo '
1635 1718
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -1639,10 +1722,11 @@  discard block
 block discarded – undo
1639 1722
 		</form>';
1640 1723
 
1641 1724
 	// Any final spellchecking stuff?
1642
-	if (!empty($context['show_spellchecking']))
1643
-		echo '
1725
+	if (!empty($context['show_spellchecking'])) {
1726
+			echo '
1644 1727
 		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value=""></form>';
1645
-}
1728
+	}
1729
+	}
1646 1730
 
1647 1731
 /**
1648 1732
  * Personal Message settings.
@@ -1679,10 +1763,11 @@  discard block
 block discarded – undo
1679 1763
 						<select name="pm_receive_from" id="pm_receive_from">
1680 1764
 							<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
1681 1765
 
1682
-	if (!empty($modSettings['enable_buddylist']))
1683
-		echo '
1766
+	if (!empty($modSettings['enable_buddylist'])) {
1767
+			echo '
1684 1768
 							<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected' : '', '>', $txt['pm_receive_from_ignore'], '</option>
1685 1769
 							<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
1770
+	}
1686 1771
 
1687 1772
 	echo '
1688 1773
 							<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected' : '', '>', $txt['pm_receive_from_admins'], '</option>
@@ -1725,11 +1810,12 @@  discard block
 block discarded – undo
1725 1810
 		if (empty($setting) || !is_array($setting))
1726 1811
 		{
1727 1812
 			// Insert a separator (unless this is the first item in the list)
1728
-			if ($i !== $first_option_key)
1729
-				echo '
1813
+			if ($i !== $first_option_key) {
1814
+							echo '
1730 1815
 				</dl>
1731 1816
 				<hr>
1732 1817
 				<dl class="settings">';
1818
+			}
1733 1819
 
1734 1820
 			// Should we give a name to this section?
1735 1821
 			if (is_string($setting) && !empty($setting))
@@ -1738,69 +1824,67 @@  discard block
 block discarded – undo
1738 1824
 				echo '
1739 1825
 					<dt><strong>' . $setting . '</strong></dt>
1740 1826
 					<dd></dd>';
1827
+			} else {
1828
+							$titled_section = false;
1741 1829
 			}
1742
-			else
1743
-				$titled_section = false;
1744 1830
 
1745 1831
 			continue;
1746 1832
 		}
1747 1833
 
1748 1834
 		// Is this disabled?
1749
-		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
1750
-			continue;
1751
-
1752
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
1753
-			continue;
1754
-
1755
-		elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored']))
1756
-			continue;
1757
-
1758
-		elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist']))
1759
-			continue;
1760
-
1761
-		elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg']))
1762
-			continue;
1763
-
1764
-		elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1765
-			continue;
1766
-
1767
-		elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1768
-			continue;
1835
+		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) {
1836
+					continue;
1837
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) {
1838
+					continue;
1839
+		} elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored'])) {
1840
+					continue;
1841
+		} elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist'])) {
1842
+					continue;
1843
+		} elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg'])) {
1844
+					continue;
1845
+		} elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1846
+					continue;
1847
+		} elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1848
+					continue;
1849
+		}
1769 1850
 
1770 1851
 		// Some of these may not be set...  Set to defaults here
1771 1852
 		$opts = array('topics_per_page', 'messages_per_page', 'display_quick_mod');
1772
-		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']]))
1773
-			$context['member']['options'][$setting['id']] = 0;
1774
-
1775
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
1776
-			$setting['type'] = 'checkbox';
1777
-
1778
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
1779
-			$setting['type'] = 'number';
1853
+		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']])) {
1854
+					$context['member']['options'][$setting['id']] = 0;
1855
+		}
1780 1856
 
1781
-		elseif ($setting['type'] == 'string')
1782
-			$setting['type'] = 'text';
1857
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
1858
+					$setting['type'] = 'checkbox';
1859
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
1860
+					$setting['type'] = 'number';
1861
+		} elseif ($setting['type'] == 'string') {
1862
+					$setting['type'] = 'text';
1863
+		}
1783 1864
 
1784
-		if (isset($setting['options']))
1785
-			$setting['type'] = 'list';
1865
+		if (isset($setting['options'])) {
1866
+					$setting['type'] = 'list';
1867
+		}
1786 1868
 
1787 1869
 		echo '
1788 1870
 					<dt>
1789 1871
 						<label for="', $setting['id'], '">', !$titled_section ? '<strong>' : '', $setting['label'], !$titled_section ? '</strong>' : '', '</label>';
1790 1872
 
1791
-		if (isset($setting['description']))
1792
-			echo '
1873
+		if (isset($setting['description'])) {
1874
+					echo '
1793 1875
 						<br>
1794 1876
 						<span class="smalltext">', $setting['description'], '</span>';
1877
+		}
1795 1878
 		echo '
1796 1879
 					</dt>
1797 1880
 					<dd>';
1798 1881
 
1799 1882
 		// Display checkbox options
1800
-		if ($setting['type'] == 'checkbox')
1801
-			echo '
1883
+		if ($setting['type'] == 'checkbox') {
1884
+					echo '
1802 1885
 						<input type="hidden" name="default_options[' . $setting['id'] . ']" value="0">
1803 1886
 						<input type="checkbox" name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($context['member']['options'][$setting['id']]) ? ' checked' : '', ' value="1">';
1887
+		}
1804 1888
 
1805 1889
 		// How about selection lists, we all love them
1806 1890
 		elseif ($setting['type'] == 'list')
@@ -1808,9 +1892,10 @@  discard block
 block discarded – undo
1808 1892
 			echo '
1809 1893
 						<select name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', '>';
1810 1894
 
1811
-			foreach ($setting['options'] as $value => $label)
1812
-				echo '
1895
+			foreach ($setting['options'] as $value => $label) {
1896
+							echo '
1813 1897
 							<option value="', $value, '"', $value == $context['member']['options'][$setting['id']] ? ' selected' : '', '>', $label, '</option>';
1898
+			}
1814 1899
 
1815 1900
 			echo '
1816 1901
 						</select>';
@@ -1826,14 +1911,13 @@  discard block
 block discarded – undo
1826 1911
 
1827 1912
 				echo '
1828 1913
 						<input type="number"', $min . $max . $step;
1829
-			}
1830
-			elseif (isset($setting['type']) && $setting['type'] == 'url')
1831
-				echo'
1914
+			} elseif (isset($setting['type']) && $setting['type'] == 'url') {
1915
+							echo'
1832 1916
 						<input type="url"';
1833
-
1834
-			else
1835
-				echo '
1917
+			} else {
1918
+							echo '
1836 1919
 						<input type="text"';
1920
+			}
1837 1921
 
1838 1922
 			echo ' name="default_options[', $setting['id'], ']" id="', $setting['id'], '" value="', isset($context['member']['options'][$setting['id']]) ? $context['member']['options'][$setting['id']] : $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', '>';
1839 1923
 		}
@@ -1870,8 +1954,8 @@  discard block
 block discarded – undo
1870 1954
 				<dl class="settings">';
1871 1955
 
1872 1956
 	// Allow notification on announcements to be disabled?
1873
-	if (!empty($modSettings['allow_disableAnnounce']))
1874
-		echo '
1957
+	if (!empty($modSettings['allow_disableAnnounce'])) {
1958
+			echo '
1875 1959
 					<dt>
1876 1960
 						<label for="notify_announcements">', $txt['notify_important_email'], '</label>
1877 1961
 					</dt>
@@ -1879,15 +1963,17 @@  discard block
 block discarded – undo
1879 1963
 						<input type="hidden" name="notify_announcements" value="0">
1880 1964
 						<input type="checkbox" id="notify_announcements" name="notify_announcements" value="1"', !empty($context['member']['notify_announcements']) ? ' checked' : '', '>
1881 1965
 					</dd>';
1966
+	}
1882 1967
 
1883
-	if (!empty($modSettings['enable_ajax_alerts']))
1884
-		echo '
1968
+	if (!empty($modSettings['enable_ajax_alerts'])) {
1969
+			echo '
1885 1970
 					<dt>
1886 1971
 						<label for="notify_send_body">', $txt['notify_alert_timeout'], '</label>
1887 1972
 					</dt>
1888 1973
 					<dd>
1889 1974
 						<input type="number" size="4" id="notify_alert_timeout" name="opt_alert_timeout" min="0" value="', $context['member']['alert_timeout'], '">
1890 1975
 					</dd>';
1976
+	}
1891 1977
 
1892 1978
 	echo '
1893 1979
 				</dl>
@@ -1919,9 +2005,10 @@  discard block
 block discarded – undo
1919 2005
 
1920 2006
 				$label = $txt['alert_opt_' . $opts[1]];
1921 2007
 				$label_pos = isset($opts['label']) ? $opts['label'] : '';
1922
-				if ($label_pos == 'before')
1923
-					echo '
2008
+				if ($label_pos == 'before') {
2009
+									echo '
1924 2010
 						<label for="opt_', $opts[1], '">', $label, '</label>';
2011
+				}
1925 2012
 
1926 2013
 				$this_value = isset($context['alert_prefs'][$opts[1]]) ? $context['alert_prefs'][$opts[1]] : 0;
1927 2014
 				switch ($opts[0])
@@ -1935,17 +2022,19 @@  discard block
 block discarded – undo
1935 2022
 						echo '
1936 2023
 						<select name="opt_', $opts[1], '" id="opt_', $opts[1], '">';
1937 2024
 
1938
-						foreach ($opts['opts'] as $k => $v)
1939
-							echo '
2025
+						foreach ($opts['opts'] as $k => $v) {
2026
+													echo '
1940 2027
 							<option value="', $k, '"', $this_value == $k ? ' selected' : '', '>', $v, '</option>';
2028
+						}
1941 2029
 						echo '
1942 2030
 						</select>';
1943 2031
 						break;
1944 2032
 				}
1945 2033
 
1946
-				if ($label_pos == 'after')
1947
-					echo '
2034
+				if ($label_pos == 'after') {
2035
+									echo '
1948 2036
 						<label for="opt_', $opts[1], '">', $label, '</label>';
2037
+				}
1949 2038
 
1950 2039
 				echo '
1951 2040
 					</td>
@@ -2062,11 +2151,12 @@  discard block
 block discarded – undo
2062 2151
 			<p class="information">', $txt['groupMembership_info'], '</p>';
2063 2152
 
2064 2153
 	// Do we have an update message?
2065
-	if (!empty($context['update_message']))
2066
-		echo '
2154
+	if (!empty($context['update_message'])) {
2155
+			echo '
2067 2156
 			<div class="infobox">
2068 2157
 				', $context['update_message'], '.
2069 2158
 			</div>';
2159
+	}
2070 2160
 
2071 2161
 	echo '
2072 2162
 			<div id="groups">';
@@ -2088,8 +2178,7 @@  discard block
 block discarded – undo
2088 2178
 						</div>
2089 2179
 					</div>
2090 2180
 				</div><!-- .groupmembership -->';
2091
-	}
2092
-	else
2181
+	} else
2093 2182
 	{
2094 2183
 		echo '
2095 2184
 				<div class="title_bar">
@@ -2101,27 +2190,30 @@  discard block
 block discarded – undo
2101 2190
 			echo '
2102 2191
 				<div class="windowbg" id="primdiv_', $group['id'], '">';
2103 2192
 
2104
-				if ($context['can_edit_primary'])
2105
-					echo '
2193
+				if ($context['can_edit_primary']) {
2194
+									echo '
2106 2195
 					<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '"', $group['is_primary'] ? ' checked' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');"', $group['can_be_primary'] ? '' : ' disabled', '>';
2196
+				}
2107 2197
 
2108 2198
 				echo '
2109 2199
 					<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>';
2110 2200
 
2111 2201
 				// Can they leave their group?
2112
-				if ($group['can_leave'])
2113
-					echo '
2202
+				if ($group['can_leave']) {
2203
+									echo '
2114 2204
 					<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
2205
+				}
2115 2206
 
2116 2207
 				echo '
2117 2208
 				</div><!-- .windowbg -->';
2118 2209
 		}
2119 2210
 
2120
-		if ($context['can_edit_primary'])
2121
-			echo '
2211
+		if ($context['can_edit_primary']) {
2212
+					echo '
2122 2213
 				<div class="padding righttext">
2123 2214
 					<input type="submit" value="', $txt['make_primary'], '" class="button">
2124 2215
 				</div>';
2216
+		}
2125 2217
 
2126 2218
 		// Any groups they can join?
2127 2219
 		if (!empty($context['groups']['available']))
@@ -2137,17 +2229,16 @@  discard block
 block discarded – undo
2137 2229
 				<div class="windowbg">
2138 2230
 					<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '';
2139 2231
 
2140
-				if ($group['type'] == 3)
2141
-					echo '
2232
+				if ($group['type'] == 3) {
2233
+									echo '
2142 2234
 					<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '" class="button floatright">', $txt['join_group'], '</a>';
2143
-
2144
-				elseif ($group['type'] == 2 && $group['pending'])
2145
-					echo '
2235
+				} elseif ($group['type'] == 2 && $group['pending']) {
2236
+									echo '
2146 2237
 					<span class="floatright">', $txt['approval_pending'], '</span>';
2147
-
2148
-				elseif ($group['type'] == 2)
2149
-					echo '
2238
+				} elseif ($group['type'] == 2) {
2239
+									echo '
2150 2240
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '" class="button floatright">', $txt['request_group'], '</a>';
2241
+				}
2151 2242
 
2152 2243
 				echo '
2153 2244
 				</div><!-- .windowbg -->';
@@ -2170,9 +2261,10 @@  discard block
 block discarded – undo
2170 2261
 
2171 2262
 						prevDiv.className = "windowbg";
2172 2263
 					}';
2173
-		if (isset($context['groups']['member'][$context['primary_group']]))
2174
-			echo '
2264
+		if (isset($context['groups']['member'][$context['primary_group']])) {
2265
+					echo '
2175 2266
 					highlightSelected("primdiv_' . $context['primary_group'] . '");';
2267
+		}
2176 2268
 
2177 2269
 		echo '
2178 2270
 				</script>';
@@ -2181,9 +2273,10 @@  discard block
 block discarded – undo
2181 2273
 	echo '
2182 2274
 			</div><!-- #groups -->';
2183 2275
 
2184
-	if (!empty($context['token_check']))
2185
-		echo '
2276
+	if (!empty($context['token_check'])) {
2277
+			echo '
2186 2278
 			<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2279
+	}
2187 2280
 
2188 2281
 	echo '
2189 2282
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2231,14 +2324,15 @@  discard block
 block discarded – undo
2231 2324
 
2232 2325
 		foreach ($category['boards'] as $board)
2233 2326
 		{
2234
-			if ($i == $limit)
2235
-				echo '
2327
+			if ($i == $limit) {
2328
+							echo '
2236 2329
 						</ul>
2237 2330
 					</li>
2238 2331
 				</ul>
2239 2332
 				<ul class="ignoreboards floatright">
2240 2333
 					<li class="category">
2241 2334
 						<ul>';
2335
+			}
2242 2336
 
2243 2337
 			echo '
2244 2338
 							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
@@ -2284,10 +2378,11 @@  discard block
 block discarded – undo
2284 2378
 
2285 2379
 	// Work out the starting color.
2286 2380
 	$context['current_color'] = $context['colors'][0];
2287
-	foreach ($context['colors'] as $limit => $color)
2288
-		if ($context['member']['warning'] >= $limit)
2381
+	foreach ($context['colors'] as $limit => $color) {
2382
+			if ($context['member']['warning'] >= $limit)
2289 2383
 			$context['current_color'] = $color;
2290
-}
2384
+	}
2385
+	}
2291 2386
 
2292 2387
 // Show all warnings of a user?
2293 2388
 function template_viewWarning()
@@ -2326,14 +2421,15 @@  discard block
 block discarded – undo
2326 2421
 				</dd>';
2327 2422
 
2328 2423
 	// There's some impact of this?
2329
-	if (!empty($context['level_effects'][$context['current_level']]))
2330
-		echo '
2424
+	if (!empty($context['level_effects'][$context['current_level']])) {
2425
+			echo '
2331 2426
 				<dt>
2332 2427
 					<strong>', $txt['profile_viewwarning_impact'], ':</strong>
2333 2428
 				</dt>
2334 2429
 				<dd>
2335 2430
 					', $context['level_effects'][$context['current_level']], '
2336 2431
 				</dd>';
2432
+	}
2337 2433
 
2338 2434
 	echo '
2339 2435
 			</dl>
@@ -2371,10 +2467,11 @@  discard block
 block discarded – undo
2371 2467
 
2372 2468
 			// Otherwise see what we can do...';
2373 2469
 
2374
-	foreach ($context['notification_templates'] as $k => $type)
2375
-		echo '
2470
+	foreach ($context['notification_templates'] as $k => $type) {
2471
+			echo '
2376 2472
 			if (index == ', $k, ')
2377 2473
 				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
2474
+	}
2378 2475
 
2379 2476
 	echo '
2380 2477
 		}
@@ -2384,10 +2481,11 @@  discard block
 block discarded – undo
2384 2481
 			// Also set the right effect.
2385 2482
 			effectText = "";';
2386 2483
 
2387
-	foreach ($context['level_effects'] as $limit => $text)
2388
-		echo '
2484
+	foreach ($context['level_effects'] as $limit => $text) {
2485
+			echo '
2389 2486
 			if (slideAmount >= ', $limit, ')
2390 2487
 				effectText = "', $text, '";';
2488
+	}
2391 2489
 
2392 2490
 	echo '
2393 2491
 			setInnerHTML(document.getElementById(\'cur_level_div\'), slideAmount + \'% (\' + effectText + \')\');
@@ -2402,32 +2500,35 @@  discard block
 block discarded – undo
2402 2500
 			</h3>
2403 2501
 		</div>';
2404 2502
 
2405
-	if (!$context['user']['is_owner'])
2406
-		echo '
2503
+	if (!$context['user']['is_owner']) {
2504
+			echo '
2407 2505
 		<p class="information">', $txt['profile_warning_desc'], '</p>';
2506
+	}
2408 2507
 
2409 2508
 	echo '
2410 2509
 		<div class="windowbg">
2411 2510
 			<dl class="settings">';
2412 2511
 
2413
-	if (!$context['user']['is_owner'])
2414
-		echo '
2512
+	if (!$context['user']['is_owner']) {
2513
+			echo '
2415 2514
 				<dt>
2416 2515
 					<strong>', $txt['profile_warning_name'], ':</strong>
2417 2516
 				</dt>
2418 2517
 				<dd>
2419 2518
 					<strong>', $context['member']['name'], '</strong>
2420 2519
 				</dd>';
2520
+	}
2421 2521
 
2422 2522
 	echo '
2423 2523
 				<dt>
2424 2524
 					<strong>', $txt['profile_warning_level'], ':</strong>';
2425 2525
 
2426 2526
 	// Is there only so much they can apply?
2427
-	if ($context['warning_limit'])
2428
-		echo '
2527
+	if ($context['warning_limit']) {
2528
+			echo '
2429 2529
 					<br>
2430 2530
 					<span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
2531
+	}
2431 2532
 
2432 2533
 	echo '
2433 2534
 				</dt>
@@ -2482,9 +2583,10 @@  discard block
 block discarded – undo
2482 2583
 						<option value="-1">', $txt['profile_warning_notify_template'], '</option>
2483 2584
 						<option value="-1" disabled>------------------------------</option>';
2484 2585
 
2485
-		foreach ($context['notification_templates'] as $id_template => $template)
2486
-			echo '
2586
+		foreach ($context['notification_templates'] as $id_template => $template) {
2587
+					echo '
2487 2588
 						<option value="', $id_template, '">', $template['title'], '</option>';
2589
+		}
2488 2590
 
2489 2591
 		echo '
2490 2592
 					</select>
@@ -2497,9 +2599,10 @@  discard block
 block discarded – undo
2497 2599
 			</dl>
2498 2600
 			<div class="righttext">';
2499 2601
 
2500
-	if (!empty($context['token_check']))
2501
-		echo '
2602
+	if (!empty($context['token_check'])) {
2603
+			echo '
2502 2604
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2605
+	}
2503 2606
 
2504 2607
 	echo '
2505 2608
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2515,8 +2618,8 @@  discard block
 block discarded – undo
2515 2618
 	echo '
2516 2619
 	<script>';
2517 2620
 
2518
-	if (!$context['user']['is_owner'])
2519
-		echo '
2621
+	if (!$context['user']['is_owner']) {
2622
+			echo '
2520 2623
 		modifyWarnNotify();
2521 2624
 		$(document).ready(function() {
2522 2625
 			$("#preview_button").click(function() {
@@ -2555,6 +2658,7 @@  discard block
 block discarded – undo
2555 2658
 			});
2556 2659
 			return false;
2557 2660
 		}';
2661
+	}
2558 2662
 
2559 2663
 	echo '
2560 2664
 	</script>';
@@ -2577,17 +2681,19 @@  discard block
 block discarded – undo
2577 2681
 			</div>';
2578 2682
 
2579 2683
 	// If deleting another account give them a lovely info box.
2580
-	if (!$context['user']['is_owner'])
2581
-		echo '
2684
+	if (!$context['user']['is_owner']) {
2685
+			echo '
2582 2686
 			<p class="information">', $txt['deleteAccount_desc'], '</p>';
2687
+	}
2583 2688
 
2584 2689
 	echo '
2585 2690
 			<div class="windowbg2">';
2586 2691
 
2587 2692
 	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
2588
-	if ($context['needs_approval'])
2589
-		echo '
2693
+	if ($context['needs_approval']) {
2694
+			echo '
2590 2695
 				<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
2696
+	}
2591 2697
 
2592 2698
 	// If the user is deleting their own account warn them first - and require a password!
2593 2699
 	if ($context['user']['is_owner'])
@@ -2599,9 +2705,10 @@  discard block
 block discarded – undo
2599 2705
 					<input type="password" name="oldpasswrd" size="20">
2600 2706
 					<input type="submit" value="', $txt['yes'], '" class="button">';
2601 2707
 
2602
-		if (!empty($context['token_check']))
2603
-			echo '
2708
+		if (!empty($context['token_check'])) {
2709
+					echo '
2604 2710
 					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2711
+		}
2605 2712
 
2606 2713
 		echo '
2607 2714
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2631,10 +2738,11 @@  discard block
 block discarded – undo
2631 2738
 						<option value="topics">', $txt['deleteAccount_topics'], '</option>
2632 2739
 					</select>';
2633 2740
 
2634
-			if ($context['show_perma_delete'])
2635
-				echo '
2741
+			if ($context['show_perma_delete']) {
2742
+							echo '
2636 2743
 					<br>
2637 2744
 					<label for="perma_delete"><input type="checkbox" name="perma_delete" id="perma_delete" value="1">', $txt['deleteAccount_permanent'], ':</label>';
2745
+			}
2638 2746
 
2639 2747
 			echo '
2640 2748
 				</div>';
@@ -2647,9 +2755,10 @@  discard block
 block discarded – undo
2647 2755
 				<div>
2648 2756
 					<input type="submit" value="', $txt['delete'], '" class="button">';
2649 2757
 
2650
-		if (!empty($context['token_check']))
2651
-			echo '
2758
+		if (!empty($context['token_check'])) {
2759
+					echo '
2652 2760
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2761
+		}
2653 2762
 
2654 2763
 		echo '
2655 2764
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2675,8 +2784,8 @@  discard block
 block discarded – undo
2675 2784
 					<hr>';
2676 2785
 
2677 2786
 	// Only show the password box if it's actually needed.
2678
-	if ($context['require_password'])
2679
-		echo '
2787
+	if ($context['require_password']) {
2788
+			echo '
2680 2789
 					<dl class="settings">
2681 2790
 						<dt>
2682 2791
 							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br>
@@ -2686,13 +2795,15 @@  discard block
 block discarded – undo
2686 2795
 							<input type="password" name="oldpasswrd" size="20">
2687 2796
 						</dd>
2688 2797
 					</dl>';
2798
+	}
2689 2799
 
2690 2800
 	echo '
2691 2801
 					<div class="righttext">';
2692 2802
 
2693
-	if (!empty($context['token_check']))
2694
-		echo '
2803
+	if (!empty($context['token_check'])) {
2804
+			echo '
2695 2805
 						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2806
+	}
2696 2807
 
2697 2808
 	echo '
2698 2809
 						<input type="submit" value="', $txt['change_profile'], '" class="button">
@@ -2719,9 +2830,10 @@  discard block
 block discarded – undo
2719 2830
 			<ul id="list_errors">';
2720 2831
 
2721 2832
 		// Cycle through each error and display an error message.
2722
-		foreach ($context['post_errors'] as $error)
2723
-			echo '
2833
+		foreach ($context['post_errors'] as $error) {
2834
+					echo '
2724 2835
 				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
2836
+		}
2725 2837
 
2726 2838
 		echo '
2727 2839
 			</ul>';
@@ -2747,12 +2859,13 @@  discard block
 block discarded – undo
2747 2859
 								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
2748 2860
 
2749 2861
 	// Fill the select box with all primary member groups that can be assigned to a member.
2750
-	foreach ($context['member_groups'] as $member_group)
2751
-		if (!empty($member_group['can_be_primary']))
2862
+	foreach ($context['member_groups'] as $member_group) {
2863
+			if (!empty($member_group['can_be_primary']))
2752 2864
 			echo '
2753 2865
 									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected' : '', '>
2754 2866
 										', $member_group['name'], '
2755 2867
 									</option>';
2868
+	}
2756 2869
 
2757 2870
 	echo '
2758 2871
 								</select>
@@ -2765,10 +2878,11 @@  discard block
 block discarded – undo
2765 2878
 									<input type="hidden" name="additional_groups[]" value="0">';
2766 2879
 
2767 2880
 	// For each membergroup show a checkbox so members can be assigned to more than one group.
2768
-	foreach ($context['member_groups'] as $member_group)
2769
-		if ($member_group['can_be_additional'])
2881
+	foreach ($context['member_groups'] as $member_group) {
2882
+			if ($member_group['can_be_additional'])
2770 2883
 			echo '
2771 2884
 									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked' : '', '> ', $member_group['name'], '</label><br>';
2885
+	}
2772 2886
 
2773 2887
 	echo '
2774 2888
 								</span>
@@ -2828,9 +2942,10 @@  discard block
 block discarded – undo
2828 2942
 								<span class="smalltext">', $txt['sig_info'], '</span><br>
2829 2943
 								<br>';
2830 2944
 
2831
-	if ($context['show_spellchecking'])
2832
-		echo '
2945
+	if ($context['show_spellchecking']) {
2946
+			echo '
2833 2947
 								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button">';
2948
+	}
2834 2949
 
2835 2950
 	echo '
2836 2951
 							</dt>
@@ -2838,17 +2953,20 @@  discard block
 block discarded – undo
2838 2953
 								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br>';
2839 2954
 
2840 2955
 	// If there is a limit at all!
2841
-	if (!empty($context['signature_limits']['max_length']))
2842
-		echo '
2956
+	if (!empty($context['signature_limits']['max_length'])) {
2957
+			echo '
2843 2958
 								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br>';
2959
+	}
2844 2960
 
2845
-	if (!empty($context['show_preview_button']))
2846
-		echo '
2961
+	if (!empty($context['show_preview_button'])) {
2962
+			echo '
2847 2963
 								<input type="button" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button floatright">';
2964
+	}
2848 2965
 
2849
-	if ($context['signature_warning'])
2850
-		echo '
2966
+	if ($context['signature_warning']) {
2967
+			echo '
2851 2968
 								<span class="smalltext">', $context['signature_warning'], '</span>';
2969
+	}
2852 2970
 
2853 2971
 	// Some javascript used to count how many characters have been used so far in the signature.
2854 2972
 	echo '
@@ -2893,9 +3011,10 @@  discard block
 block discarded – undo
2893 3011
 										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
2894 3012
 
2895 3013
 		// This lists all the file categories.
2896
-		foreach ($context['avatars'] as $avatar)
2897
-			echo '
3014
+		foreach ($context['avatars'] as $avatar) {
3015
+					echo '
2898 3016
 											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected' : ''), '>', $avatar['name'], '</option>';
3017
+		}
2899 3018
 
2900 3019
 		echo '
2901 3020
 										</select>
@@ -2927,20 +3046,22 @@  discard block
 block discarded – undo
2927 3046
 	}
2928 3047
 
2929 3048
 	// If the user can link to an off server avatar, show them a box to input the address.
2930
-	if (!empty($context['member']['avatar']['allow_external']))
2931
-		echo '
3049
+	if (!empty($context['member']['avatar']['allow_external'])) {
3050
+			echo '
2932 3051
 								<div id="avatar_external">
2933 3052
 									<div class="smalltext">', $txt['avatar_by_url'], '</div>', !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_download_and_resize' ? template_max_size('external') : '', '
2934 3053
 									<input type="text" name="userpicpersonal" size="45" value="', ((stristr($context['member']['avatar']['external'], 'http://') || stristr($context['member']['avatar']['external'], 'https://')) ? $context['member']['avatar']['external'] : 'http://'), '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);">
2935 3054
 								</div>';
3055
+	}
2936 3056
 
2937 3057
 	// If the user is able to upload avatars to the server show them an upload box.
2938
-	if (!empty($context['member']['avatar']['allow_upload']))
2939
-		echo '
3058
+	if (!empty($context['member']['avatar']['allow_upload'])) {
3059
+			echo '
2940 3060
 								<div id="avatar_upload">
2941 3061
 									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onchange="readfromUpload(this)"  onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" accept="image/gif, image/jpeg, image/jpg, image/png">', template_max_size('upload'), '
2942 3062
 									', (!empty($context['member']['avatar']['id_attach']) ? '<br><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" id="attached_image"><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '">' : ''), '
2943 3063
 								</div>';
3064
+	}
2944 3065
 
2945 3066
 	// if the user is able to use Gravatar avatars show then the image preview
2946 3067
 	if (!empty($context['member']['avatar']['allow_gravatar']))
@@ -2949,16 +3070,17 @@  discard block
 block discarded – undo
2949 3070
 								<div id="avatar_gravatar">
2950 3071
 									<img src="' . $context['member']['avatar']['href'] . '" alt="">';
2951 3072
 
2952
-		if (empty($modSettings['gravatarAllowExtraEmail']))
2953
-			echo '
3073
+		if (empty($modSettings['gravatarAllowExtraEmail'])) {
3074
+					echo '
2954 3075
 									<div class="smalltext">', $txt['gravatar_noAlternateEmail'], '</div>';
2955
-		else
3076
+		} else
2956 3077
 		{
2957 3078
 			// Depending on other stuff, the stored value here might have some odd things in it from other areas.
2958
-			if ($context['member']['avatar']['external'] == $context['member']['email'])
2959
-				$textbox_value = '';
2960
-			else
2961
-				$textbox_value = $context['member']['avatar']['external'];
3079
+			if ($context['member']['avatar']['external'] == $context['member']['email']) {
3080
+							$textbox_value = '';
3081
+			} else {
3082
+							$textbox_value = $context['member']['avatar']['external'];
3083
+			}
2962 3084
 
2963 3085
 			echo '
2964 3086
 									<div class="smalltext">', $txt['gravatar_alternateEmail'], '</div>
@@ -3030,8 +3152,9 @@  discard block
 block discarded – undo
3030 3152
 	$h = !empty($modSettings['avatar_max_height_' . $type]) ? comma_format($modSettings['avatar_max_height_' . $type]) : 0;
3031 3153
 
3032 3154
 	$suffix = (!empty($w) ? 'w' : '') . (!empty($h) ? 'h' : '');
3033
-	if (empty($suffix))
3034
-		return;
3155
+	if (empty($suffix)) {
3156
+			return;
3157
+	}
3035 3158
 
3036 3159
 	echo '
3037 3160
 								<div class="smalltext">', sprintf($txt['avatar_max_size_' . $suffix], $w, $h), '</div>';
@@ -3056,9 +3179,10 @@  discard block
 block discarded – undo
3056 3179
 								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;">';
3057 3180
 
3058 3181
 	// Help the user by showing a list of common time formats.
3059
-	foreach ($context['easy_timeformats'] as $time_format)
3060
-		echo '
3182
+	foreach ($context['easy_timeformats'] as $time_format) {
3183
+			echo '
3061 3184
 									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected' : '', '>', $time_format['title'], '</option>';
3185
+	}
3062 3186
 
3063 3187
 	echo '
3064 3188
 								</select>
@@ -3096,9 +3220,10 @@  discard block
 block discarded – undo
3096 3220
 							<dd>
3097 3221
 								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.png\';">';
3098 3222
 
3099
-	foreach ($context['smiley_sets'] as $set)
3100
-		echo '
3223
+	foreach ($context['smiley_sets'] as $set) {
3224
+			echo '
3101 3225
 									<option value="', $set['id'], '"', $set['selected'] ? ' selected' : '', '>', $set['name'], '</option>';
3226
+	}
3102 3227
 
3103 3228
 	echo '
3104 3229
 								</select>
@@ -3150,10 +3275,11 @@  discard block
 block discarded – undo
3150 3275
 										<img src="', $context['tfa_qr_url'], '" alt="">
3151 3276
 									</div>';
3152 3277
 
3153
-	if (!empty($context['from_ajax']))
3154
-		echo '
3278
+	if (!empty($context['from_ajax'])) {
3279
+			echo '
3155 3280
 					<br>
3156 3281
 					<a href="javascript:self.close();"></a>';
3282
+	}
3157 3283
 
3158 3284
 	echo '
3159 3285
 				</div>
@@ -3193,17 +3319,16 @@  discard block
 block discarded – undo
3193 3319
 							</dt>
3194 3320
 							<dd>';
3195 3321
 
3196
-	if (!$context['tfa_enabled'] && $context['user']['is_owner'])
3197
-		echo '
3322
+	if (!$context['tfa_enabled'] && $context['user']['is_owner']) {
3323
+			echo '
3198 3324
 								<a href="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, '?action=profile;area=tfasetup" id="enable_tfa">', $txt['tfa_profile_enable'], '</a>';
3199
-
3200
-	elseif (!$context['tfa_enabled'])
3201
-		echo '
3325
+	} elseif (!$context['tfa_enabled']) {
3326
+			echo '
3202 3327
 								', $txt['tfa_profile_disabled'];
3203
-
3204
-	else
3205
-		echo '
3328
+	} else {
3329
+			echo '
3206 3330
 								', sprintf($txt['tfa_profile_enabled'], $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=tfasetup;disable');
3331
+	}
3207 3332
 
3208 3333
 	echo '
3209 3334
 							</dd>';
Please login to merge, or discard this patch.