Completed
Pull Request — release-2.1 (#4375)
by Colin
08:21
created
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '
', '  ' => '  ', '[' => '[', ']' => ']')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -389,16 +409,19 @@  discard block
 block discarded – undo
389 409
 					$desired_height = $height;
390 410
 				}
391 411
 				// Scale it to the width...
392
-				elseif (empty($desired_width) && !empty($height))
393
-					$desired_width = (int) (($desired_height * $width) / $height);
412
+				elseif (empty($desired_width) && !empty($height)) {
413
+									$desired_width = (int) (($desired_height * $width) / $height);
414
+				}
394 415
 				// Scale if to the height.
395
-				elseif (!empty($width))
396
-					$desired_height = (int) (($desired_width * $height) / $width);
416
+				elseif (!empty($width)) {
417
+									$desired_height = (int) (($desired_width * $height) / $width);
418
+				}
397 419
 			}
398 420
 
399 421
 			// If the width and height are fine, just continue along...
400
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
401
-				continue;
422
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
423
+							continue;
424
+			}
402 425
 
403 426
 			// Too bad, it's too wide.  Make it as wide as the maximum.
404 427
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -418,8 +441,9 @@  discard block
 block discarded – undo
418 441
 		}
419 442
 
420 443
 		// If any img tags were actually changed...
421
-		if (!empty($replaces))
422
-			$message = strtr($message, $replaces);
444
+		if (!empty($replaces)) {
445
+					$message = strtr($message, $replaces);
446
+		}
423 447
 	}
424 448
 }
425 449
 
@@ -438,10 +462,11 @@  discard block
 block discarded – undo
438 462
 {
439 463
 	global $boardurl, $scripturl;
440 464
 
441
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
442
-		$domain_url = $match[1];
443
-	else
444
-		$domain_url = $boardurl . '/';
465
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
466
+			$domain_url = $match[1];
467
+	} else {
468
+			$domain_url = $boardurl . '/';
469
+	}
445 470
 
446 471
 	$replaces = array();
447 472
 
@@ -449,11 +474,11 @@  discard block
 block discarded – undo
449 474
 	{
450 475
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
451 476
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} elseif ($hasEqualSign) {
478
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
479
+	} else {
480
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
452 481
 	}
453
-	elseif ($hasEqualSign)
454
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
455
-	else
456
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
457 482
 
458 483
 	foreach ($matches[0] as $k => $dummy)
459 484
 	{
@@ -466,49 +491,53 @@  discard block
 block discarded – undo
466 491
 		foreach ($protocols as $protocol)
467 492
 		{
468 493
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
469
-			if ($found)
470
-				break;
494
+			if ($found) {
495
+							break;
496
+			}
471 497
 		}
472 498
 
473 499
 		if (!$found && $protocols[0] == 'http')
474 500
 		{
475
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
476
-				$replace = $domain_url . $replace;
477
-			elseif (substr($replace, 0, 1) == '?')
478
-				$replace = $scripturl . $replace;
479
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
501
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
502
+							$replace = $domain_url . $replace;
503
+			} elseif (substr($replace, 0, 1) == '?') {
504
+							$replace = $scripturl . $replace;
505
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
480 506
 			{
481 507
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
482 508
 				$this_tag = 'iurl';
483 509
 				$this_close = 'iurl';
510
+			} elseif (substr($replace, 0, 2) != '//') {
511
+							$replace = $protocols[0] . '://' . $replace;
484 512
 			}
485
-			elseif (substr($replace, 0, 2) != '//')
486
-				$replace = $protocols[0] . '://' . $replace;
487
-		}
488
-		elseif (!$found && $protocols[0] == 'ftp')
489
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
490
-		elseif (!$found)
491
-			$replace = $protocols[0] . '://' . $replace;
492
-
493
-		if ($hasEqualSign && $embeddedUrl)
494
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
495
-		elseif ($hasEqualSign)
496
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
497
-		elseif ($embeddedUrl)
498
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
499
-		else
500
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
513
+		} elseif (!$found && $protocols[0] == 'ftp') {
514
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
515
+		} elseif (!$found) {
516
+					$replace = $protocols[0] . '://' . $replace;
517
+		}
518
+
519
+		if ($hasEqualSign && $embeddedUrl) {
520
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
521
+		} elseif ($hasEqualSign) {
522
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
523
+		} elseif ($embeddedUrl) {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
525
+		} else {
526
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
527
+		}
501 528
 	}
502 529
 
503 530
 	foreach ($replaces as $k => $v)
504 531
 	{
505
-		if ($k == $v)
506
-			unset($replaces[$k]);
532
+		if ($k == $v) {
533
+					unset($replaces[$k]);
534
+		}
507 535
 	}
508 536
 
509
-	if (!empty($replaces))
510
-		$message = strtr($message, $replaces);
511
-}
537
+	if (!empty($replaces)) {
538
+			$message = strtr($message, $replaces);
539
+	}
540
+	}
512 541
 
513 542
 /**
514 543
  * This function sends an email to the specified recipient(s).
@@ -552,8 +581,9 @@  discard block
 block discarded – undo
552 581
 	}
553 582
 
554 583
 	// Nothing left? Nothing else to do
555
-	if (empty($to_array))
556
-		return true;
584
+	if (empty($to_array)) {
585
+			return true;
586
+	}
557 587
 
558 588
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
559 589
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -570,15 +600,17 @@  discard block
 block discarded – undo
570 600
 		}
571 601
 
572 602
 		// Call this function recursively for the hotmail addresses.
573
-		if (!empty($hotmail_to))
574
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		if (!empty($hotmail_to)) {
604
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
605
+		}
575 606
 
576 607
 		// The remaining addresses no longer need the fix.
577 608
 		$hotmail_fix = false;
578 609
 
579 610
 		// No other addresses left? Return instantly.
580
-		if (empty($to_array))
581
-			return $mail_result;
611
+		if (empty($to_array)) {
612
+					return $mail_result;
613
+		}
582 614
 	}
583 615
 
584 616
 	// Get rid of entities.
@@ -603,13 +635,15 @@  discard block
 block discarded – undo
603 635
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
604 636
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
605 637
 
606
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
607
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
639
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
640
+	}
608 641
 	$headers .= 'X-Mailer: SMF' . $line_break;
609 642
 
610 643
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
611
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
612
-		return false;
644
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
645
+			return false;
646
+	}
613 647
 
614 648
 	// Save the original message...
615 649
 	$orig_message = $message;
@@ -658,17 +692,19 @@  discard block
 block discarded – undo
658 692
 	}
659 693
 
660 694
 	// Are we using the mail queue, if so this is where we butt in...
661
-	if ($priority != 0)
662
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	if ($priority != 0) {
696
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
697
+	}
663 698
 
664 699
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
665 700
 	elseif (!empty($modSettings['mail_limit']))
666 701
 	{
667 702
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
668
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
669
-			$new_queue_stat = time() . '|' . 1;
670
-		else
671
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
703
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
704
+					$new_queue_stat = time() . '|' . 1;
705
+		} else {
706
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
707
+		}
672 708
 
673 709
 		updateSettings(array('mail_recent' => $new_queue_stat));
674 710
 	}
@@ -693,12 +729,13 @@  discard block
 block discarded – undo
693 729
 
694 730
 			// Wait, wait, I'm still sending here!
695 731
 			@set_time_limit(300);
696
-			if (function_exists('apache_reset_timeout'))
697
-				@apache_reset_timeout();
732
+			if (function_exists('apache_reset_timeout')) {
733
+							@apache_reset_timeout();
734
+			}
698 735
 		}
736
+	} else {
737
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
699 738
 	}
700
-	else
701
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
702 739
 
703 740
 	// Everything go smoothly?
704 741
 	return $mail_result;
@@ -724,8 +761,9 @@  discard block
 block discarded – undo
724 761
 	static $cur_insert = array();
725 762
 	static $cur_insert_len = 0;
726 763
 
727
-	if ($cur_insert_len == 0)
728
-		$cur_insert = array();
764
+	if ($cur_insert_len == 0) {
765
+			$cur_insert = array();
766
+	}
729 767
 
730 768
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
731 769
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -800,8 +838,9 @@  discard block
 block discarded – undo
800 838
 	}
801 839
 
802 840
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
803
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
804
-		return AddMailQueue(true);
841
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
842
+			return AddMailQueue(true);
843
+	}
805 844
 
806 845
 	return true;
807 846
 }
@@ -832,23 +871,26 @@  discard block
 block discarded – undo
832 871
 		'sent' => array()
833 872
 	);
834 873
 
835
-	if ($from === null)
836
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
837 876
 			'id' => $user_info['id'],
838 877
 			'name' => $user_info['name'],
839 878
 			'username' => $user_info['username']
840 879
 		);
880
+	}
841 881
 
842 882
 	// This is the one that will go in their inbox.
843 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
844 884
 	preparsecode($htmlmessage);
845 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
846
-	if ($smcFunc['strlen']($htmlsubject) > 100)
847
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
848 889
 
849 890
 	// Make sure is an array
850
-	if (!is_array($recipients))
851
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
852 894
 
853 895
 	// Integrated PMs
854 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -876,21 +918,23 @@  discard block
 block discarded – undo
876 918
 				'usernames' => array_keys($usernames),
877 919
 			)
878 920
 		);
879
-		while ($row = $smcFunc['db_fetch_assoc']($request))
880
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
881 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
882 925
 		$smcFunc['db_free_result']($request);
883 926
 
884 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
885
-		foreach ($recipients as $rec_type => $rec)
886
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
887 930
 			{
888 931
 				if (is_numeric($recipients[$rec_type][$id]))
889 932
 					continue;
933
+		}
890 934
 
891
-				if (!empty($usernames[$member]))
892
-					$recipients[$rec_type][$id] = $usernames[$member];
893
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
894 938
 				{
895 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
896 940
 					unset($recipients[$rec_type][$id]);
@@ -928,8 +972,9 @@  discard block
 block discarded – undo
928 972
 		$delete = false;
929 973
 		foreach ($criteria as $criterium)
930 974
 		{
931
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
932
-				$delete = true;
975
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
976
+							$delete = true;
977
+			}
933 978
 			// If we're adding and one criteria don't match then we stop!
934 979
 			elseif (!$row['is_or'])
935 980
 			{
@@ -937,8 +982,9 @@  discard block
 block discarded – undo
937 982
 				break;
938 983
 			}
939 984
 		}
940
-		if ($delete)
941
-			$deletes[$row['id_member']] = 1;
985
+		if ($delete) {
986
+					$deletes[$row['id_member']] = 1;
987
+		}
942 988
 	}
943 989
 	$smcFunc['db_free_result']($request);
944 990
 
@@ -953,8 +999,9 @@  discard block
 block discarded – undo
953 999
 			array(
954 1000
 			)
955 1001
 		);
956
-		while ($row = $smcFunc['db_fetch_assoc']($request))
957
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1004
+		}
958 1005
 		$smcFunc['db_free_result']($request);
959 1006
 	}
960 1007
 
@@ -962,8 +1009,9 @@  discard block
 block discarded – undo
962 1009
 	require_once($sourcedir . '/Subs-Members.php');
963 1010
 	$pmReadGroups = groupsAllowedTo('pm_read');
964 1011
 
965
-	if (empty($modSettings['permission_enable_deny']))
966
-		$pmReadGroups['denied'] = array();
1012
+	if (empty($modSettings['permission_enable_deny'])) {
1013
+			$pmReadGroups['denied'] = array();
1014
+	}
967 1015
 
968 1016
 	// Load their alert preferences
969 1017
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 	while ($row = $smcFunc['db_fetch_assoc']($request))
996 1044
 	{
997 1045
 		// Don't do anything for members to be deleted!
998
-		if (isset($deletes[$row['id_member']]))
999
-			continue;
1046
+		if (isset($deletes[$row['id_member']])) {
1047
+					continue;
1048
+		}
1000 1049
 
1001 1050
 		// Load the preferences for this member (if any)
1002 1051
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1017,8 +1066,9 @@  discard block
 block discarded – undo
1017 1066
 		{
1018 1067
 			foreach ($groups as $id)
1019 1068
 			{
1020
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1021
-					$message_limit = $message_limit_cache[$id];
1069
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1070
+									$message_limit = $message_limit_cache[$id];
1071
+				}
1022 1072
 			}
1023 1073
 
1024 1074
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1066,8 +1116,9 @@  discard block
 block discarded – undo
1066 1116
 	$smcFunc['db_free_result']($request);
1067 1117
 
1068 1118
 	// Only 'send' the message if there are any recipients left.
1069
-	if (empty($all_to))
1070
-		return $log;
1119
+	if (empty($all_to)) {
1120
+			return $log;
1121
+	}
1071 1122
 
1072 1123
 	// Insert the message itself and then grab the last insert id.
1073 1124
 	$id_pm = $smcFunc['db_insert']('',
@@ -1088,8 +1139,8 @@  discard block
 block discarded – undo
1088 1139
 	if (!empty($id_pm))
1089 1140
 	{
1090 1141
 		// If this is new we need to set it part of it's own conversation.
1091
-		if (empty($pm_head))
1092
-			$smcFunc['db_query']('', '
1142
+		if (empty($pm_head)) {
1143
+					$smcFunc['db_query']('', '
1093 1144
 				UPDATE {db_prefix}personal_messages
1094 1145
 				SET id_pm_head = {int:id_pm_head}
1095 1146
 				WHERE id_pm = {int:id_pm_head}',
@@ -1097,6 +1148,7 @@  discard block
 block discarded – undo
1097 1148
 					'id_pm_head' => $id_pm,
1098 1149
 				)
1099 1150
 			);
1151
+		}
1100 1152
 
1101 1153
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1102 1154
 		$smcFunc['db_query']('', '
@@ -1112,8 +1164,9 @@  discard block
 block discarded – undo
1112 1164
 		foreach ($all_to as $to)
1113 1165
 		{
1114 1166
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1115
-			if (!in_array($to, $recipients['bcc']))
1116
-				$to_list[] = $to;
1167
+			if (!in_array($to, $recipients['bcc'])) {
1168
+							$to_list[] = $to;
1169
+			}
1117 1170
 		}
1118 1171
 
1119 1172
 		$smcFunc['db_insert']('insert',
@@ -1131,9 +1184,9 @@  discard block
 block discarded – undo
1131 1184
 	{
1132 1185
 		censorText($message);
1133 1186
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1187
+	} else {
1188
+			$message = '';
1134 1189
 	}
1135
-	else
1136
-		$message = '';
1137 1190
 
1138 1191
 	$to_names = array();
1139 1192
 	if (count($to_list) > 1)
@@ -1146,8 +1199,9 @@  discard block
 block discarded – undo
1146 1199
 				'to_members' => $to_list,
1147 1200
 			)
1148 1201
 		);
1149
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1150
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1203
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1204
+		}
1151 1205
 		$smcFunc['db_free_result']($request);
1152 1206
 	}
1153 1207
 	$replacements = array(
@@ -1175,11 +1229,13 @@  discard block
 block discarded – undo
1175 1229
 	loadLanguage('index+PersonalMessage');
1176 1230
 
1177 1231
 	// Add one to their unread and read message counts.
1178
-	foreach ($all_to as $k => $id)
1179
-		if (isset($deletes[$id]))
1232
+	foreach ($all_to as $k => $id) {
1233
+			if (isset($deletes[$id]))
1180 1234
 			unset($all_to[$k]);
1181
-	if (!empty($all_to))
1182
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1235
+	}
1236
+	if (!empty($all_to)) {
1237
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1238
+	}
1183 1239
 
1184 1240
 	return $log;
1185 1241
 }
@@ -1209,15 +1265,17 @@  discard block
 block discarded – undo
1209 1265
 		// Let's, for now, assume there are only &#021;'ish characters.
1210 1266
 		$simple = true;
1211 1267
 
1212
-		foreach ($matches[1] as $entity)
1213
-			if ($entity > 128)
1268
+		foreach ($matches[1] as $entity) {
1269
+					if ($entity > 128)
1214 1270
 				$simple = false;
1271
+		}
1215 1272
 		unset($matches);
1216 1273
 
1217
-		if ($simple)
1218
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1274
+		if ($simple) {
1275
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1219 1276
 			{
1220 1277
 				return chr("$m[1]");
1278
+		}
1221 1279
 			}, $string);
1222 1280
 		else
1223 1281
 		{
@@ -1225,8 +1283,9 @@  discard block
 block discarded – undo
1225 1283
 			if (!$context['utf8'] && function_exists('iconv'))
1226 1284
 			{
1227 1285
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1228
-				if ($newstring)
1229
-					$string = $newstring;
1286
+				if ($newstring) {
1287
+									$string = $newstring;
1288
+				}
1230 1289
 			}
1231 1290
 
1232 1291
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1242,23 +1301,25 @@  discard block
 block discarded – undo
1242 1301
 		if (!$context['utf8'] && function_exists('iconv'))
1243 1302
 		{
1244 1303
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1245
-			if ($newstring)
1246
-				$string = $newstring;
1304
+			if ($newstring) {
1305
+							$string = $newstring;
1306
+			}
1247 1307
 		}
1248 1308
 
1249 1309
 		$entityConvert = function($m)
1250 1310
 		{
1251 1311
 			$c = $m[1];
1252
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1253
-				return $c;
1254
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1255
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1256
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1259
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1260
-			else
1261
-				return "";
1312
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1313
+							return $c;
1314
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1318
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1319
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1320
+			} else {
1321
+							return "";
1322
+			}
1262 1323
 		};
1263 1324
 
1264 1325
 		// Convert all 'special' characters to HTML entities.
@@ -1272,19 +1333,20 @@  discard block
 block discarded – undo
1272 1333
 		$string = base64_encode($string);
1273 1334
 
1274 1335
 		// Show the characterset and the transfer-encoding for header strings.
1275
-		if ($with_charset)
1276
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		if ($with_charset) {
1337
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1338
+		}
1277 1339
 
1278 1340
 		// Break it up in lines (mail body).
1279
-		else
1280
-			$string = chunk_split($string, 76, $line_break);
1341
+		else {
1342
+					$string = chunk_split($string, 76, $line_break);
1343
+		}
1281 1344
 
1282 1345
 		return array($charset, $string, 'base64');
1346
+	} else {
1347
+			return array($charset, $string, '7bit');
1348
+	}
1283 1349
 	}
1284
-
1285
-	else
1286
-		return array($charset, $string, '7bit');
1287
-}
1288 1350
 
1289 1351
 /**
1290 1352
  * Sends mail, like mail() but over SMTP.
@@ -1308,8 +1370,9 @@  discard block
 block discarded – undo
1308 1370
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1309 1371
 	{
1310 1372
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1311
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1312
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1374
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1375
+		}
1313 1376
 
1314 1377
 		if ($socket)
1315 1378
 		{
@@ -1330,8 +1393,9 @@  discard block
 block discarded – undo
1330 1393
 		// Maybe we can still save this?  The port might be wrong.
1331 1394
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1332 1395
 		{
1333
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1334
-				log_error($txt['smtp_port_ssl']);
1396
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1397
+							log_error($txt['smtp_port_ssl']);
1398
+			}
1335 1399
 		}
1336 1400
 
1337 1401
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1343,20 +1407,23 @@  discard block
 block discarded – undo
1343 1407
 	}
1344 1408
 
1345 1409
 	// Wait for a response of 220, without "-" continuer.
1346
-	if (!server_parse(null, $socket, '220'))
1347
-		return false;
1410
+	if (!server_parse(null, $socket, '220')) {
1411
+			return false;
1412
+	}
1348 1413
 
1349 1414
 	// Try and determine the servers name, fall back to the mail servers if not found
1350 1415
 	$helo = false;
1351
-	if (function_exists('gethostname') && gethostname() !== false)
1352
-		$helo = gethostname();
1353
-	elseif (function_exists('php_uname'))
1354
-		$helo = php_uname('n');
1355
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1356
-		$helo = $_SERVER['SERVER_NAME'];
1416
+	if (function_exists('gethostname') && gethostname() !== false) {
1417
+			$helo = gethostname();
1418
+	} elseif (function_exists('php_uname')) {
1419
+			$helo = php_uname('n');
1420
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1421
+			$helo = $_SERVER['SERVER_NAME'];
1422
+	}
1357 1423
 
1358
-	if (empty($helo))
1359
-		$helo = $modSettings['smtp_host'];
1424
+	if (empty($helo)) {
1425
+			$helo = $modSettings['smtp_host'];
1426
+	}
1360 1427
 
1361 1428
 	// SMTP = 1, SMTP - STARTTLS = 2
1362 1429
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1368,33 +1435,39 @@  discard block
 block discarded – undo
1368 1435
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1369 1436
 			{
1370 1437
 				// Send STARTTLS to enable encryption
1371
-				if (!server_parse('STARTTLS', $socket, '220'))
1372
-					return false;
1438
+				if (!server_parse('STARTTLS', $socket, '220')) {
1439
+									return false;
1440
+				}
1373 1441
 				// Enable the encryption
1374
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1375
-					return false;
1442
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1443
+									return false;
1444
+				}
1376 1445
 				// Send the EHLO command again
1377
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1378
-					return false;
1446
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1447
+									return false;
1448
+				}
1379 1449
 			}
1380 1450
 
1381
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1382
-				return false;
1451
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1452
+							return false;
1453
+			}
1383 1454
 			// Send the username and password, encoded.
1384
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1385
-				return false;
1455
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1456
+							return false;
1457
+			}
1386 1458
 			// The password is already encoded ;)
1387
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1388
-				return false;
1459
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1460
+							return false;
1461
+			}
1462
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1463
+					return false;
1389 1464
 		}
1390
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1391
-			return false;
1392
-	}
1393
-	else
1465
+	} else
1394 1466
 	{
1395 1467
 		// Just say "helo".
1396
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1397
-			return false;
1468
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1469
+					return false;
1470
+		}
1398 1471
 	}
1399 1472
 
1400 1473
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1407,31 +1480,38 @@  discard block
 block discarded – undo
1407 1480
 		// Reset the connection to send another email.
1408 1481
 		if ($i != 0)
1409 1482
 		{
1410
-			if (!server_parse('RSET', $socket, '250'))
1411
-				return false;
1483
+			if (!server_parse('RSET', $socket, '250')) {
1484
+							return false;
1485
+			}
1412 1486
 		}
1413 1487
 
1414 1488
 		// From, to, and then start the data...
1415
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1416
-			return false;
1417
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('DATA', $socket, '354'))
1420
-			return false;
1489
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1490
+					return false;
1491
+		}
1492
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1493
+					return false;
1494
+		}
1495
+		if (!server_parse('DATA', $socket, '354')) {
1496
+					return false;
1497
+		}
1421 1498
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1422
-		if (strlen($mail_to) > 0)
1423
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		if (strlen($mail_to) > 0) {
1500
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1501
+		}
1424 1502
 		fputs($socket, $headers . "\r\n\r\n");
1425 1503
 		fputs($socket, $message . "\r\n");
1426 1504
 
1427 1505
 		// Send a ., or in other words "end of data".
1428
-		if (!server_parse('.', $socket, '250'))
1429
-			return false;
1506
+		if (!server_parse('.', $socket, '250')) {
1507
+					return false;
1508
+		}
1430 1509
 
1431 1510
 		// Almost done, almost done... don't stop me just yet!
1432 1511
 		@set_time_limit(300);
1433
-		if (function_exists('apache_reset_timeout'))
1434
-			@apache_reset_timeout();
1512
+		if (function_exists('apache_reset_timeout')) {
1513
+					@apache_reset_timeout();
1514
+		}
1435 1515
 	}
1436 1516
 	fputs($socket, 'QUIT' . "\r\n");
1437 1517
 	fclose($socket);
@@ -1455,8 +1535,9 @@  discard block
 block discarded – undo
1455 1535
 {
1456 1536
 	global $txt;
1457 1537
 
1458
-	if ($message !== null)
1459
-		fputs($socket, $message . "\r\n");
1538
+	if ($message !== null) {
1539
+			fputs($socket, $message . "\r\n");
1540
+	}
1460 1541
 
1461 1542
 	// No response yet.
1462 1543
 	$server_response = '';
@@ -1472,8 +1553,9 @@  discard block
 block discarded – undo
1472 1553
 		$response .= $server_response;
1473 1554
 	}
1474 1555
 
1475
-	if ($code === null)
1476
-		return substr($server_response, 0, 3);
1556
+	if ($code === null) {
1557
+			return substr($server_response, 0, 3);
1558
+	}
1477 1559
 
1478 1560
 	if (substr($server_response, 0, 3) != $code)
1479 1561
 	{
@@ -1503,8 +1585,9 @@  discard block
 block discarded – undo
1503 1585
 	// Create a pspell or enchant dictionary resource
1504 1586
 	$dict = spell_init();
1505 1587
 
1506
-	if (!isset($_POST['spellstring']) || !$dict)
1507
-		die;
1588
+	if (!isset($_POST['spellstring']) || !$dict) {
1589
+			die;
1590
+	}
1508 1591
 
1509 1592
 	// Construct a bit of Javascript code.
1510 1593
 	$context['spell_js'] = '
@@ -1522,8 +1605,9 @@  discard block
 block discarded – undo
1522 1605
 		$check_word = explode('|', $alphas[$i]);
1523 1606
 
1524 1607
 		// If the word is a known word, or spelled right...
1525
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1526
-			continue;
1608
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1609
+					continue;
1610
+		}
1527 1611
 
1528 1612
 		// Find the word, and move up the "last occurrence" to here.
1529 1613
 		$found_words = true;
@@ -1537,20 +1621,23 @@  discard block
 block discarded – undo
1537 1621
 		if (!empty($suggestions))
1538 1622
 		{
1539 1623
 			// But first check they aren't going to be censored - no naughty words!
1540
-			foreach ($suggestions as $k => $word)
1541
-				if ($suggestions[$k] != censorText($word))
1624
+			foreach ($suggestions as $k => $word) {
1625
+							if ($suggestions[$k] != censorText($word))
1542 1626
 					unset($suggestions[$k]);
1627
+			}
1543 1628
 
1544
-			if (!empty($suggestions))
1545
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			if (!empty($suggestions)) {
1630
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1631
+			}
1546 1632
 		}
1547 1633
 
1548 1634
 		$context['spell_js'] .= ']),';
1549 1635
 	}
1550 1636
 
1551 1637
 	// If words were found, take off the last comma.
1552
-	if ($found_words)
1553
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	if ($found_words) {
1639
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1640
+	}
1554 1641
 
1555 1642
 	$context['spell_js'] .= '
1556 1643
 		);';
@@ -1585,11 +1672,13 @@  discard block
 block discarded – undo
1585 1672
 	global $user_info, $smcFunc;
1586 1673
 
1587 1674
 	// Can't do it if there's no topics.
1588
-	if (empty($topics))
1589
-		return;
1675
+	if (empty($topics)) {
1676
+			return;
1677
+	}
1590 1678
 	// It must be an array - it must!
1591
-	if (!is_array($topics))
1592
-		$topics = array($topics);
1679
+	if (!is_array($topics)) {
1680
+			$topics = array($topics);
1681
+	}
1593 1682
 
1594 1683
 	// Get the subject and body...
1595 1684
 	$result = $smcFunc['db_query']('', '
@@ -1637,14 +1726,15 @@  discard block
 block discarded – undo
1637 1726
 	}
1638 1727
 	$smcFunc['db_free_result']($result);
1639 1728
 
1640
-	if (!empty($task_rows))
1641
-		$smcFunc['db_insert']('',
1729
+	if (!empty($task_rows)) {
1730
+			$smcFunc['db_insert']('',
1642 1731
 			'{db_prefix}background_tasks',
1643 1732
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1644 1733
 			$task_rows,
1645 1734
 			array('id_task')
1646 1735
 		);
1647
-}
1736
+	}
1737
+	}
1648 1738
 
1649 1739
 /**
1650 1740
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1682,9 +1772,9 @@  discard block
 block discarded – undo
1682 1772
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1683 1773
 
1684 1774
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1685
-	if (!$modSettings['postmod_active'])
1686
-		$topicOptions['is_approved'] = true;
1687
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1775
+	if (!$modSettings['postmod_active']) {
1776
+			$topicOptions['is_approved'] = true;
1777
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1688 1778
 	{
1689 1779
 		$request = $smcFunc['db_query']('', '
1690 1780
 			SELECT approved
@@ -1707,8 +1797,7 @@  discard block
 block discarded – undo
1707 1797
 			$posterOptions['id'] = 0;
1708 1798
 			$posterOptions['name'] = $txt['guest_title'];
1709 1799
 			$posterOptions['email'] = '';
1710
-		}
1711
-		elseif ($posterOptions['id'] != $user_info['id'])
1800
+		} elseif ($posterOptions['id'] != $user_info['id'])
1712 1801
 		{
1713 1802
 			$request = $smcFunc['db_query']('', '
1714 1803
 				SELECT member_name, email_address
@@ -1726,12 +1815,11 @@  discard block
 block discarded – undo
1726 1815
 				$posterOptions['id'] = 0;
1727 1816
 				$posterOptions['name'] = $txt['guest_title'];
1728 1817
 				$posterOptions['email'] = '';
1818
+			} else {
1819
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1729 1820
 			}
1730
-			else
1731
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1732 1821
 			$smcFunc['db_free_result']($request);
1733
-		}
1734
-		else
1822
+		} else
1735 1823
 		{
1736 1824
 			$posterOptions['name'] = $user_info['name'];
1737 1825
 			$posterOptions['email'] = $user_info['email'];
@@ -1741,8 +1829,9 @@  discard block
 block discarded – undo
1741 1829
 	if (!empty($modSettings['enable_mentions']))
1742 1830
 	{
1743 1831
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1744
-		if (!empty($msgOptions['mentioned_members']))
1745
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		if (!empty($msgOptions['mentioned_members'])) {
1833
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1834
+		}
1746 1835
 	}
1747 1836
 
1748 1837
 	// It's do or die time: forget any user aborts!
@@ -1775,12 +1864,13 @@  discard block
 block discarded – undo
1775 1864
 	);
1776 1865
 
1777 1866
 	// Something went wrong creating the message...
1778
-	if (empty($msgOptions['id']))
1779
-		return false;
1867
+	if (empty($msgOptions['id'])) {
1868
+			return false;
1869
+	}
1780 1870
 
1781 1871
 	// Fix the attachments.
1782
-	if (!empty($msgOptions['attachments']))
1783
-		$smcFunc['db_query']('', '
1872
+	if (!empty($msgOptions['attachments'])) {
1873
+			$smcFunc['db_query']('', '
1784 1874
 			UPDATE {db_prefix}attachments
1785 1875
 			SET id_msg = {int:id_msg}
1786 1876
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1789,6 +1879,7 @@  discard block
 block discarded – undo
1789 1879
 				'id_msg' => $msgOptions['id'],
1790 1880
 			)
1791 1881
 		);
1882
+	}
1792 1883
 
1793 1884
 	// What if we want to export new posts out to a CMS?
1794 1885
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1865,20 +1956,23 @@  discard block
 block discarded – undo
1865 1956
 			'id_topic' => $topicOptions['id'],
1866 1957
 			'counter_increment' => 1,
1867 1958
 		);
1868
-		if ($msgOptions['approved'])
1869
-			$topics_columns = array(
1959
+		if ($msgOptions['approved']) {
1960
+					$topics_columns = array(
1870 1961
 				'id_member_updated = {int:poster_id}',
1871 1962
 				'id_last_msg = {int:id_msg}',
1872 1963
 				'num_replies = num_replies + {int:counter_increment}',
1873 1964
 			);
1874
-		else
1875
-			$topics_columns = array(
1965
+		} else {
1966
+					$topics_columns = array(
1876 1967
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1877 1968
 			);
1878
-		if ($topicOptions['lock_mode'] !== null)
1879
-			$topics_columns[] = 'locked = {int:locked}';
1880
-		if ($topicOptions['sticky_mode'] !== null)
1881
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1969
+		}
1970
+		if ($topicOptions['lock_mode'] !== null) {
1971
+					$topics_columns[] = 'locked = {int:locked}';
1972
+		}
1973
+		if ($topicOptions['sticky_mode'] !== null) {
1974
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1975
+		}
1882 1976
 
1883 1977
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1884 1978
 
@@ -1907,8 +2001,8 @@  discard block
 block discarded – undo
1907 2001
 	);
1908 2002
 
1909 2003
 	// Increase the number of posts and topics on the board.
1910
-	if ($msgOptions['approved'])
1911
-		$smcFunc['db_query']('', '
2004
+	if ($msgOptions['approved']) {
2005
+			$smcFunc['db_query']('', '
1912 2006
 			UPDATE {db_prefix}boards
1913 2007
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1914 2008
 			WHERE id_board = {int:id_board}',
@@ -1916,7 +2010,7 @@  discard block
 block discarded – undo
1916 2010
 				'id_board' => $topicOptions['board'],
1917 2011
 			)
1918 2012
 		);
1919
-	else
2013
+	} else
1920 2014
 	{
1921 2015
 		$smcFunc['db_query']('', '
1922 2016
 			UPDATE {db_prefix}boards
@@ -1986,8 +2080,8 @@  discard block
 block discarded – undo
1986 2080
 		}
1987 2081
 	}
1988 2082
 
1989
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1990
-		$smcFunc['db_insert']('',
2083
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2084
+			$smcFunc['db_insert']('',
1991 2085
 			'{db_prefix}background_tasks',
1992 2086
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1993 2087
 			array(
@@ -1999,19 +2093,22 @@  discard block
 block discarded – undo
1999 2093
 			),
2000 2094
 			array('id_task')
2001 2095
 		);
2096
+	}
2002 2097
 
2003 2098
 	// If there's a custom search index, it may need updating...
2004 2099
 	require_once($sourcedir . '/Search.php');
2005 2100
 	$searchAPI = findSearchAPI();
2006
-	if (is_callable(array($searchAPI, 'postCreated')))
2007
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2102
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	}
2008 2104
 
2009 2105
 	// Increase the post counter for the user that created the post.
2010 2106
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2011 2107
 	{
2012 2108
 		// Are you the one that happened to create this post?
2013
-		if ($user_info['id'] == $posterOptions['id'])
2014
-			$user_info['posts']++;
2109
+		if ($user_info['id'] == $posterOptions['id']) {
2110
+					$user_info['posts']++;
2111
+		}
2015 2112
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2016 2113
 	}
2017 2114
 
@@ -2019,19 +2116,21 @@  discard block
 block discarded – undo
2019 2116
 	$_SESSION['last_read_topic'] = 0;
2020 2117
 
2021 2118
 	// Better safe than sorry.
2022
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2023
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2120
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	}
2024 2122
 
2025 2123
 	// Update all the stats so everyone knows about this new topic and message.
2026 2124
 	updateStats('message', true, $msgOptions['id']);
2027 2125
 
2028 2126
 	// Update the last message on the board assuming it's approved AND the topic is.
2029
-	if ($msgOptions['approved'])
2030
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	if ($msgOptions['approved']) {
2128
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	}
2031 2130
 
2032 2131
 	// Queue createPost background notification
2033
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2034
-		$smcFunc['db_insert']('',
2132
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2133
+			$smcFunc['db_insert']('',
2035 2134
 			'{db_prefix}background_tasks',
2036 2135
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2037 2136
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2042,6 +2141,7 @@  discard block
 block discarded – undo
2042 2141
 			)), 0),
2043 2142
 			array('id_task')
2044 2143
 		);
2144
+	}
2045 2145
 
2046 2146
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2047 2147
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2068,14 +2168,18 @@  discard block
 block discarded – undo
2068 2168
 
2069 2169
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2070 2170
 	$messages_columns = array();
2071
-	if (isset($posterOptions['name']))
2072
-		$messages_columns['poster_name'] = $posterOptions['name'];
2073
-	if (isset($posterOptions['email']))
2074
-		$messages_columns['poster_email'] = $posterOptions['email'];
2075
-	if (isset($msgOptions['icon']))
2076
-		$messages_columns['icon'] = $msgOptions['icon'];
2077
-	if (isset($msgOptions['subject']))
2078
-		$messages_columns['subject'] = $msgOptions['subject'];
2171
+	if (isset($posterOptions['name'])) {
2172
+			$messages_columns['poster_name'] = $posterOptions['name'];
2173
+	}
2174
+	if (isset($posterOptions['email'])) {
2175
+			$messages_columns['poster_email'] = $posterOptions['email'];
2176
+	}
2177
+	if (isset($msgOptions['icon'])) {
2178
+			$messages_columns['icon'] = $msgOptions['icon'];
2179
+	}
2180
+	if (isset($msgOptions['subject'])) {
2181
+			$messages_columns['subject'] = $msgOptions['subject'];
2182
+	}
2079 2183
 	if (isset($msgOptions['body']))
2080 2184
 	{
2081 2185
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2102,8 +2206,9 @@  discard block
 block discarded – undo
2102 2206
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2103 2207
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2104 2208
 	}
2105
-	if (isset($msgOptions['smileys_enabled']))
2106
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	if (isset($msgOptions['smileys_enabled'])) {
2210
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	}
2107 2212
 
2108 2213
 	// Which columns need to be ints?
2109 2214
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2121,23 +2226,27 @@  discard block
 block discarded – undo
2121 2226
 		{
2122 2227
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2123 2228
 
2124
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2125
-				foreach ($match[1] as $i => $oldID)
2229
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2230
+							foreach ($match[1] as $i => $oldID)
2126 2231
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2232
+			}
2127 2233
 
2128
-			if (empty($modSettings['search_custom_index_config']))
2129
-				unset($msgOptions['old_body']);
2234
+			if (empty($modSettings['search_custom_index_config'])) {
2235
+							unset($msgOptions['old_body']);
2236
+			}
2130 2237
 		}
2131 2238
 
2132 2239
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2133 2240
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2134 2241
 
2135 2242
 		// Remove the poster.
2136
-		if (isset($mentions[$user_info['id']]))
2137
-			unset($mentions[$user_info['id']]);
2243
+		if (isset($mentions[$user_info['id']])) {
2244
+					unset($mentions[$user_info['id']]);
2245
+		}
2138 2246
 
2139
-		if (isset($oldmentions[$user_info['id']]))
2140
-			unset($oldmentions[$user_info['id']]);
2247
+		if (isset($oldmentions[$user_info['id']])) {
2248
+					unset($oldmentions[$user_info['id']]);
2249
+		}
2141 2250
 
2142 2251
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2143 2252
 		{
@@ -2167,8 +2276,9 @@  discard block
 block discarded – undo
2167 2276
 	}
2168 2277
 
2169 2278
 	// Nothing to do?
2170
-	if (empty($messages_columns))
2171
-		return true;
2279
+	if (empty($messages_columns)) {
2280
+			return true;
2281
+	}
2172 2282
 
2173 2283
 	// Change the post.
2174 2284
 	$smcFunc['db_query']('', '
@@ -2229,8 +2339,9 @@  discard block
 block discarded – undo
2229 2339
 	// If there's a custom search index, it needs to be modified...
2230 2340
 	require_once($sourcedir . '/Search.php');
2231 2341
 	$searchAPI = findSearchAPI();
2232
-	if (is_callable(array($searchAPI, 'postModified')))
2233
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	if (is_callable(array($searchAPI, 'postModified'))) {
2343
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	}
2234 2345
 
2235 2346
 	if (isset($msgOptions['subject']))
2236 2347
 	{
@@ -2244,14 +2355,16 @@  discard block
 block discarded – undo
2244 2355
 				'id_first_msg' => $msgOptions['id'],
2245 2356
 			)
2246 2357
 		);
2247
-		if ($smcFunc['db_num_rows']($request) == 1)
2248
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		if ($smcFunc['db_num_rows']($request) == 1) {
2359
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		}
2249 2361
 		$smcFunc['db_free_result']($request);
2250 2362
 	}
2251 2363
 
2252 2364
 	// Finally, if we are setting the approved state we need to do much more work :(
2253
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2254
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2366
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	}
2255 2368
 
2256 2369
 	return true;
2257 2370
 }
@@ -2268,11 +2381,13 @@  discard block
 block discarded – undo
2268 2381
 {
2269 2382
 	global $smcFunc;
2270 2383
 
2271
-	if (!is_array($msgs))
2272
-		$msgs = array($msgs);
2384
+	if (!is_array($msgs)) {
2385
+			$msgs = array($msgs);
2386
+	}
2273 2387
 
2274
-	if (empty($msgs))
2275
-		return false;
2388
+	if (empty($msgs)) {
2389
+			return false;
2390
+	}
2276 2391
 
2277 2392
 	// May as well start at the beginning, working out *what* we need to change.
2278 2393
 	$request = $smcFunc['db_query']('', '
@@ -2304,20 +2419,22 @@  discard block
 block discarded – undo
2304 2419
 		$topics[] = $row['id_topic'];
2305 2420
 
2306 2421
 		// Ensure our change array exists already.
2307
-		if (!isset($topic_changes[$row['id_topic']]))
2308
-			$topic_changes[$row['id_topic']] = array(
2422
+		if (!isset($topic_changes[$row['id_topic']])) {
2423
+					$topic_changes[$row['id_topic']] = array(
2309 2424
 				'id_last_msg' => $row['id_last_msg'],
2310 2425
 				'approved' => $row['topic_approved'],
2311 2426
 				'replies' => 0,
2312 2427
 				'unapproved_posts' => 0,
2313 2428
 			);
2314
-		if (!isset($board_changes[$row['id_board']]))
2315
-			$board_changes[$row['id_board']] = array(
2429
+		}
2430
+		if (!isset($board_changes[$row['id_board']])) {
2431
+					$board_changes[$row['id_board']] = array(
2316 2432
 				'posts' => 0,
2317 2433
 				'topics' => 0,
2318 2434
 				'unapproved_posts' => 0,
2319 2435
 				'unapproved_topics' => 0,
2320 2436
 			);
2437
+		}
2321 2438
 
2322 2439
 		// If it's the first message then the topic state changes!
2323 2440
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2338,14 +2455,13 @@  discard block
 block discarded – undo
2338 2455
 				'poster' => $row['id_member'],
2339 2456
 				'new_topic' => true,
2340 2457
 			);
2341
-		}
2342
-		else
2458
+		} else
2343 2459
 		{
2344 2460
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2345 2461
 
2346 2462
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2347
-			if ($row['id_msg'] > $row['id_last_msg'])
2348
-				$notification_posts[$row['id_topic']] = array(
2463
+			if ($row['id_msg'] > $row['id_last_msg']) {
2464
+							$notification_posts[$row['id_topic']] = array(
2349 2465
 					'id' => $row['id_msg'],
2350 2466
 					'body' => $row['body'],
2351 2467
 					'subject' => $row['subject'],
@@ -2356,28 +2472,33 @@  discard block
 block discarded – undo
2356 2472
 					'new_topic' => false,
2357 2473
 					'msg' => $row['id_msg'],
2358 2474
 				);
2475
+			}
2359 2476
 		}
2360 2477
 
2361 2478
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2362
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2363
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2480
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		}
2364 2482
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2365
-		elseif (!$approve)
2366
-			// Default to the first message and then we'll override in a bit ;)
2483
+		elseif (!$approve) {
2484
+					// Default to the first message and then we'll override in a bit ;)
2367 2485
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2486
+		}
2368 2487
 
2369 2488
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2489
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2372 2491
 
2373 2492
 		// Post count for the user?
2374
-		if ($row['id_member'] && empty($row['count_posts']))
2375
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		if ($row['id_member'] && empty($row['count_posts'])) {
2494
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		}
2376 2496
 	}
2377 2497
 	$smcFunc['db_free_result']($request);
2378 2498
 
2379
-	if (empty($msgs))
2380
-		return;
2499
+	if (empty($msgs)) {
2500
+			return;
2501
+	}
2381 2502
 
2382 2503
 	// Now we have the differences make the changes, first the easy one.
2383 2504
 	$smcFunc['db_query']('', '
@@ -2404,14 +2525,15 @@  discard block
 block discarded – undo
2404 2525
 				'approved' => 1,
2405 2526
 			)
2406 2527
 		);
2407
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2408
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2529
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		}
2409 2531
 		$smcFunc['db_free_result']($request);
2410 2532
 	}
2411 2533
 
2412 2534
 	// ... next the topics...
2413
-	foreach ($topic_changes as $id => $changes)
2414
-		$smcFunc['db_query']('', '
2535
+	foreach ($topic_changes as $id => $changes) {
2536
+			$smcFunc['db_query']('', '
2415 2537
 			UPDATE {db_prefix}topics
2416 2538
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2417 2539
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2424,10 +2546,11 @@  discard block
 block discarded – undo
2424 2546
 				'id_topic' => $id,
2425 2547
 			)
2426 2548
 		);
2549
+	}
2427 2550
 
2428 2551
 	// ... finally the boards...
2429
-	foreach ($board_changes as $id => $changes)
2430
-		$smcFunc['db_query']('', '
2552
+	foreach ($board_changes as $id => $changes) {
2553
+			$smcFunc['db_query']('', '
2431 2554
 			UPDATE {db_prefix}boards
2432 2555
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2433 2556
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2440,13 +2563,14 @@  discard block
 block discarded – undo
2440 2563
 				'id_board' => $id,
2441 2564
 			)
2442 2565
 		);
2566
+	}
2443 2567
 
2444 2568
 	// Finally, least importantly, notifications!
2445 2569
 	if ($approve)
2446 2570
 	{
2447 2571
 		$task_rows = array();
2448
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2449
-			$task_rows[] = array(
2572
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2573
+					$task_rows[] = array(
2450 2574
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2451 2575
 					'msgOptions' => array(
2452 2576
 						'id' => $topic['msg'],
@@ -2464,14 +2588,16 @@  discard block
 block discarded – undo
2464 2588
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2465 2589
 				)), 0
2466 2590
 			);
2591
+		}
2467 2592
 
2468
-		if ($notify)
2469
-			$smcFunc['db_insert']('',
2593
+		if ($notify) {
2594
+					$smcFunc['db_insert']('',
2470 2595
 				'{db_prefix}background_tasks',
2471 2596
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2472 2597
 				$task_rows,
2473 2598
 				array('id_task')
2474 2599
 			);
2600
+		}
2475 2601
 
2476 2602
 		$smcFunc['db_query']('', '
2477 2603
 			DELETE FROM {db_prefix}approval_queue
@@ -2487,8 +2613,9 @@  discard block
 block discarded – undo
2487 2613
 	else
2488 2614
 	{
2489 2615
 		$msgInserts = array();
2490
-		foreach ($msgs as $msg)
2491
-			$msgInserts[] = array($msg);
2616
+		foreach ($msgs as $msg) {
2617
+					$msgInserts[] = array($msg);
2618
+		}
2492 2619
 
2493 2620
 		$smcFunc['db_insert']('ignore',
2494 2621
 			'{db_prefix}approval_queue',
@@ -2502,9 +2629,10 @@  discard block
 block discarded – undo
2502 2629
 	updateLastMessages(array_keys($board_changes));
2503 2630
 
2504 2631
 	// Post count for the members?
2505
-	if (!empty($member_post_changes))
2506
-		foreach ($member_post_changes as $id_member => $count_change)
2632
+	if (!empty($member_post_changes)) {
2633
+			foreach ($member_post_changes as $id_member => $count_change)
2507 2634
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2635
+	}
2508 2636
 
2509 2637
 	return true;
2510 2638
 }
@@ -2521,11 +2649,13 @@  discard block
 block discarded – undo
2521 2649
 {
2522 2650
 	global $smcFunc;
2523 2651
 
2524
-	if (!is_array($topics))
2525
-		$topics = array($topics);
2652
+	if (!is_array($topics)) {
2653
+			$topics = array($topics);
2654
+	}
2526 2655
 
2527
-	if (empty($topics))
2528
-		return false;
2656
+	if (empty($topics)) {
2657
+			return false;
2658
+	}
2529 2659
 
2530 2660
 	$approve_type = $approve ? 0 : 1;
2531 2661
 
@@ -2541,8 +2671,9 @@  discard block
 block discarded – undo
2541 2671
 		)
2542 2672
 	);
2543 2673
 	$msgs = array();
2544
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2545
-		$msgs[] = $row['id_msg'];
2674
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2675
+			$msgs[] = $row['id_msg'];
2676
+	}
2546 2677
 	$smcFunc['db_free_result']($request);
2547 2678
 
2548 2679
 	return approvePosts($msgs, $approve);
@@ -2565,11 +2696,13 @@  discard block
 block discarded – undo
2565 2696
 	global $board_info, $board, $smcFunc;
2566 2697
 
2567 2698
 	// Please - let's be sane.
2568
-	if (empty($setboards))
2569
-		return false;
2699
+	if (empty($setboards)) {
2700
+			return false;
2701
+	}
2570 2702
 
2571
-	if (!is_array($setboards))
2572
-		$setboards = array($setboards);
2703
+	if (!is_array($setboards)) {
2704
+			$setboards = array($setboards);
2705
+	}
2573 2706
 
2574 2707
 	// If we don't know the id_msg we need to find it.
2575 2708
 	if (!$id_msg)
@@ -2587,15 +2720,16 @@  discard block
 block discarded – undo
2587 2720
 			)
2588 2721
 		);
2589 2722
 		$lastMsg = array();
2590
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2591
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2724
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		}
2592 2726
 		$smcFunc['db_free_result']($request);
2593
-	}
2594
-	else
2727
+	} else
2595 2728
 	{
2596 2729
 		// Just to note - there should only be one board passed if we are doing this.
2597
-		foreach ($setboards as $id_board)
2598
-			$lastMsg[$id_board] = $id_msg;
2730
+		foreach ($setboards as $id_board) {
2731
+					$lastMsg[$id_board] = $id_msg;
2732
+		}
2599 2733
 	}
2600 2734
 
2601 2735
 	$parent_boards = array();
@@ -2610,10 +2744,11 @@  discard block
 block discarded – undo
2610 2744
 			$lastModified[$id_board] = 0;
2611 2745
 		}
2612 2746
 
2613
-		if (!empty($board) && $id_board == $board)
2614
-			$parents = $board_info['parent_boards'];
2615
-		else
2616
-			$parents = getBoardParents($id_board);
2747
+		if (!empty($board) && $id_board == $board) {
2748
+					$parents = $board_info['parent_boards'];
2749
+		} else {
2750
+					$parents = getBoardParents($id_board);
2751
+		}
2617 2752
 
2618 2753
 		// Ignore any parents on the top child level.
2619 2754
 		// @todo Why?
@@ -2622,10 +2757,11 @@  discard block
 block discarded – undo
2622 2757
 			if ($parent['level'] != 0)
2623 2758
 			{
2624 2759
 				// If we're already doing this one as a board, is this a higher last modified?
2625
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2626
-					$lastModified[$id] = $lastModified[$id_board];
2627
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2628
-					$parent_boards[$id] = $lastModified[$id_board];
2760
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2761
+									$lastModified[$id] = $lastModified[$id_board];
2762
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2763
+									$parent_boards[$id] = $lastModified[$id_board];
2764
+				}
2629 2765
 			}
2630 2766
 		}
2631 2767
 	}
@@ -2638,23 +2774,24 @@  discard block
 block discarded – undo
2638 2774
 	// Finally, to save on queries make the changes...
2639 2775
 	foreach ($parent_boards as $id => $msg)
2640 2776
 	{
2641
-		if (!isset($parent_updates[$msg]))
2642
-			$parent_updates[$msg] = array($id);
2643
-		else
2644
-			$parent_updates[$msg][] = $id;
2777
+		if (!isset($parent_updates[$msg])) {
2778
+					$parent_updates[$msg] = array($id);
2779
+		} else {
2780
+					$parent_updates[$msg][] = $id;
2781
+		}
2645 2782
 	}
2646 2783
 
2647 2784
 	foreach ($lastMsg as $id => $msg)
2648 2785
 	{
2649
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2650
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2786
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2787
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2651 2788
 				'id' => $msg,
2652 2789
 				'updated' => $lastModified[$id],
2653 2790
 				'boards' => array($id)
2654 2791
 			);
2655
-
2656
-		else
2657
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		} else {
2793
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		}
2658 2795
 	}
2659 2796
 
2660 2797
 	// Now commit the changes!
@@ -2746,11 +2883,13 @@  discard block
 block discarded – undo
2746 2883
 	global $txt, $mbname, $scripturl, $settings;
2747 2884
 
2748 2885
 	// First things first, load up the email templates language file, if we need to.
2749
-	if ($loadLang)
2750
-		loadLanguage('EmailTemplates', $lang);
2886
+	if ($loadLang) {
2887
+			loadLanguage('EmailTemplates', $lang);
2888
+	}
2751 2889
 
2752
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2753
-		fatal_lang_error('email_no_template', 'template', array($template));
2890
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2891
+			fatal_lang_error('email_no_template', 'template', array($template));
2892
+	}
2754 2893
 
2755 2894
 	$ret = array(
2756 2895
 		'subject' => $txt[$template . '_subject'],
@@ -2800,17 +2939,18 @@  discard block
 block discarded – undo
2800 2939
 function user_info_callback($matches)
2801 2940
 {
2802 2941
 	global $user_info;
2803
-	if (empty($matches[1]))
2804
-		return '';
2942
+	if (empty($matches[1])) {
2943
+			return '';
2944
+	}
2805 2945
 
2806 2946
 	$use_ref = true;
2807 2947
 	$ref = &$user_info;
2808 2948
 
2809 2949
 	foreach (explode('.', $matches[1]) as $index)
2810 2950
 	{
2811
-		if ($use_ref && isset($ref[$index]))
2812
-			$ref = &$ref[$index];
2813
-		else
2951
+		if ($use_ref && isset($ref[$index])) {
2952
+					$ref = &$ref[$index];
2953
+		} else
2814 2954
 		{
2815 2955
 			$use_ref = false;
2816 2956
 			break;
@@ -2847,8 +2987,7 @@  discard block
 block discarded – undo
2847 2987
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2848 2988
 		{
2849 2989
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2850
-		}
2851
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2990
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2852 2991
 		{
2853 2992
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2854 2993
 		}
@@ -2858,8 +2997,7 @@  discard block
 block discarded – undo
2858 2997
 		{
2859 2998
 			$context['provider'] = 'enchant';
2860 2999
 			return $enchant_link;
2861
-		}
2862
-		else
3000
+		} else
2863 3001
 		{
2864 3002
 			// Free up any resources used...
2865 3003
 			@enchant_broker_free($context['enchant_broker']);
@@ -2880,8 +3018,9 @@  discard block
 block discarded – undo
2880 3018
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2881 3019
 
2882 3020
 		// Most people don't have anything but English installed... So we use English as a last resort.
2883
-		if (!$pspell_link)
2884
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		if (!$pspell_link) {
3022
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		}
2885 3024
 
2886 3025
 		error_reporting($old);
2887 3026
 		ob_end_clean();
@@ -2921,8 +3060,7 @@  discard block
 block discarded – undo
2921 3060
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2922 3061
 		}
2923 3062
 		return enchant_dict_check($dict, $word);
2924
-	}
2925
-	elseif ($context['provider'] == 'pspell')
3063
+	} elseif ($context['provider'] == 'pspell')
2926 3064
 	{
2927 3065
 		return pspell_check($dict, $word);
2928 3066
 	}
@@ -2958,13 +3096,11 @@  discard block
 block discarded – undo
2958 3096
 			}
2959 3097
 
2960 3098
 			return $suggestions;
2961
-		}
2962
-		else
3099
+		} else
2963 3100
 		{
2964 3101
 			return enchant_dict_suggest($dict, $word);
2965 3102
 		}
2966
-	}
2967
-	elseif ($context['provider'] == 'pspell')
3103
+	} elseif ($context['provider'] == 'pspell')
2968 3104
 	{
2969 3105
 		return pspell_suggest($dict, $word);
2970 3106
 	}
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +309 added lines, -239 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 4
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -142,10 +144,11 @@  discard block
 block discarded – undo
142 144
 
143 145
 	// If no cert, force_ssl must remain 0
144 146
 	require_once($sourcedir . '/Subs.php');
145
-	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl']))
146
-		$disable_force_ssl = true;
147
-	else
148
-		$disable_force_ssl = false;
147
+	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) {
148
+			$disable_force_ssl = true;
149
+	} else {
150
+			$disable_force_ssl = false;
151
+	}
149 152
 
150 153
 	/* If you're writing a mod, it's a bad idea to add things here....
151 154
 	For each option:
@@ -175,8 +178,9 @@  discard block
 block discarded – undo
175 178
 
176 179
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
177 180
 
178
-	if ($return_config)
179
-		return $config_vars;
181
+	if ($return_config) {
182
+			return $config_vars;
183
+	}
180 184
 
181 185
 	// Setup the template stuff.
182 186
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -193,16 +197,18 @@  discard block
 block discarded – undo
193 197
 			$registerSMStats = registerSMStats();
194 198
 
195 199
 			// Failed to register, disable it again.
196
-			if (empty($registerSMStats))
197
-				$_POST['enable_sm_stats'] = 0;
200
+			if (empty($registerSMStats)) {
201
+							$_POST['enable_sm_stats'] = 0;
202
+			}
198 203
 		}
199 204
 
200 205
 		// Ensure all URLs are aligned with the new force_ssl setting
201 206
 		// Treat unset like 0
202
-		if (isset($_POST['force_ssl']))
203
-			AlignURLsWithSSLSetting($_POST['force_ssl']);
204
-		else
205
-			AlignURLsWithSSLSetting(0);
207
+		if (isset($_POST['force_ssl'])) {
208
+					AlignURLsWithSSLSetting($_POST['force_ssl']);
209
+		} else {
210
+					AlignURLsWithSSLSetting(0);
211
+		}
206 212
 			
207 213
 		saveSettings($config_vars);
208 214
 		$_SESSION['adm-save'] = true;
@@ -255,10 +261,11 @@  discard block
 block discarded – undo
255 261
 	require_once($sourcedir . '/Subs-Admin.php');
256 262
 
257 263
 	// Check $boardurl
258
-	if ($new_force_ssl == 2)
259
-		$newval = strtr($boardurl, array('http://' => 'https://'));
260
-	else
261
-		$newval = strtr($boardurl, array('https://' => 'http://'));
264
+	if ($new_force_ssl == 2) {
265
+			$newval = strtr($boardurl, array('http://' => 'https://'));
266
+	} else {
267
+			$newval = strtr($boardurl, array('https://' => 'http://'));
268
+	}
262 269
 	updateSettingsFile(array('boardurl' => '\'' . addslashes($newval) . '\''));
263 270
 
264 271
 	$new_settings = array();
@@ -266,20 +273,22 @@  discard block
 block discarded – undo
266 273
 	// Check $smileys_url, but only if it points to a subfolder of $boardurl
267 274
 	if (BoardurlMatch($modSettings['smileys_url']))
268 275
 	{
269
-		if ($new_force_ssl == 2)
270
-			$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
271
-		else
272
-			$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
276
+		if ($new_force_ssl == 2) {
277
+					$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
278
+		} else {
279
+					$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
280
+		}
273 281
 		$new_settings['smileys_url'] = $newval;
274 282
 	}
275 283
 
276 284
 	// Check $avatar_url, but only if it points to a subfolder of $boardurl
277 285
 	if (BoardurlMatch($modSettings['avatar_url']))
278 286
 	{
279
-		if ($new_force_ssl == 2)
280
-			$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
281
-		else
282
-			$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
287
+		if ($new_force_ssl == 2) {
288
+					$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
289
+		} else {
290
+					$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
291
+		}
283 292
 		$new_settings['avatar_url'] = $newval;
284 293
 	}
285 294
 
@@ -287,16 +296,18 @@  discard block
 block discarded – undo
287 296
 	// This one had been optional in the past, make sure it is set first
288 297
 	if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url']))
289 298
 	{
290
-		if ($new_force_ssl == 2)
291
-			$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
292
-		else
293
-			$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
299
+		if ($new_force_ssl == 2) {
300
+					$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
301
+		} else {
302
+					$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
303
+		}
294 304
 		$new_settings['custom_avatar_url'] = $newval;
295 305
 	}
296 306
 
297 307
 	// Save updates to the settings table
298
-	if (!empty($new_settings))
299
-		updateSettings($new_settings, true);
308
+	if (!empty($new_settings)) {
309
+			updateSettings($new_settings, true);
310
+	}
300 311
 
301 312
 	// Now we move onto the themes.
302 313
 	// First, get a list of theme URLs...
@@ -317,10 +328,11 @@  discard block
 block discarded – undo
317 328
 		// First check to see if it points to a subfolder of $boardurl
318 329
 		if (BoardurlMatch($row['value']))
319 330
 		{
320
-			if ($new_force_ssl == 2)
321
-				$newval = strtr($row['value'], array('http://' => 'https://'));
322
-			else
323
-				$newval = strtr($row['value'], array('https://' => 'http://'));
331
+			if ($new_force_ssl == 2) {
332
+							$newval = strtr($row['value'], array('http://' => 'https://'));
333
+			} else {
334
+							$newval = strtr($row['value'], array('https://' => 'http://'));
335
+			}
324 336
 			$smcFunc['db_query']('', '
325 337
 				UPDATE {db_prefix}themes
326 338
 				   SET value = {string:theme_val}
@@ -360,11 +372,12 @@  discard block
 block discarded – undo
360 372
 
361 373
 	// If leftmost portion of path matches boardurl, return true
362 374
 	$result = strpos($urlpath, $boardurlpath);
363
-	if ($result === false || $result != 0)
364
-		return false;
365
-	else
366
-		return true;
367
-}
375
+	if ($result === false || $result != 0) {
376
+			return false;
377
+	} else {
378
+			return true;
379
+	}
380
+	}
368 381
 
369 382
 /**
370 383
  * Basic database and paths settings - database name, host, etc.
@@ -402,8 +415,9 @@  discard block
 block discarded – undo
402 415
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
403 416
 		$fts_language = array();
404 417
 
405
-		while ($row = $smcFunc['db_fetch_assoc']($request))
406
-			$fts_language[$row['cfgname']] = $row['cfgname'];
418
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
419
+					$fts_language[$row['cfgname']] = $row['cfgname'];
420
+		}
407 421
 
408 422
 		$config_vars = array_merge ($config_vars, array(
409 423
 				'',
@@ -415,8 +429,9 @@  discard block
 block discarded – undo
415 429
 
416 430
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
417 431
 
418
-	if ($return_config)
419
-		return $config_vars;
432
+	if ($return_config) {
433
+			return $config_vars;
434
+	}
420 435
 
421 436
 	// Setup the template stuff.
422 437
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -491,13 +506,15 @@  discard block
 block discarded – undo
491 506
 		hideGlobalCookies();
492 507
 	});', true);
493 508
 
494
-	if (empty($user_settings['tfa_secret']))
495
-		addInlineJavaScript('');
509
+	if (empty($user_settings['tfa_secret'])) {
510
+			addInlineJavaScript('');
511
+	}
496 512
 
497 513
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
498 514
 
499
-	if ($return_config)
500
-		return $config_vars;
515
+	if ($return_config) {
516
+			return $config_vars;
517
+	}
501 518
 
502 519
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
503 520
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -508,11 +525,13 @@  discard block
 block discarded – undo
508 525
 		call_integration_hook('integrate_save_cookie_settings');
509 526
 
510 527
 		// Local and global do not play nicely together.
511
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
512
-			unset ($_POST['globalCookies']);
528
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
529
+					unset ($_POST['globalCookies']);
530
+		}
513 531
 
514
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
515
-			fatal_lang_error('invalid_cookie_domain', false);
532
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
533
+					fatal_lang_error('invalid_cookie_domain', false);
534
+		}
516 535
 
517 536
 		saveSettings($config_vars);
518 537
 
@@ -595,8 +614,9 @@  discard block
 block discarded – undo
595 614
 
596 615
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
597 616
 
598
-	if ($return_config)
599
-		return $config_vars;
617
+	if ($return_config) {
618
+			return $config_vars;
619
+	}
600 620
 
601 621
 	// Saving?
602 622
 	if (isset($_GET['save']))
@@ -635,8 +655,7 @@  discard block
 block discarded – undo
635 655
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
636 656
 		$cache_level = array($txt['cache_off']);
637 657
 		$detected['none'] = $txt['cache_off'];
638
-	}
639
-	else
658
+	} else
640 659
 	{
641 660
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
642 661
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -673,8 +692,9 @@  discard block
 block discarded – undo
673 692
 			}
674 693
 		}
675 694
 	}
676
-	if ($return_config)
677
-		return $config_vars;
695
+	if ($return_config) {
696
+			return $config_vars;
697
+	}
678 698
 
679 699
 	// Saving again?
680 700
 	if (isset($_GET['save']))
@@ -702,8 +722,9 @@  discard block
 block discarded – undo
702 722
 	$context['save_disabled'] = $context['settings_not_writable'];
703 723
 
704 724
 	// Decide what message to show.
705
-	if (!$context['save_disabled'])
706
-		$context['settings_message'] = $txt['caching_information'];
725
+	if (!$context['save_disabled']) {
726
+			$context['settings_message'] = $txt['caching_information'];
727
+	}
707 728
 
708 729
 	// Prepare the template.
709 730
 	prepareServerSettingsContext($config_vars);
@@ -726,24 +747,25 @@  discard block
 block discarded – undo
726 747
 	if (stripos(PHP_OS, 'win') === 0)
727 748
 	{
728 749
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
729
-		if (isset($_GET['save']))
730
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
731
-	}
732
-	elseif (stripos(PHP_OS, 'darwin') === 0)
750
+		if (isset($_GET['save'])) {
751
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
752
+		}
753
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
733 754
 	{
734 755
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
735
-		if (isset($_GET['save']))
736
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
737
-	}
738
-	else
756
+		if (isset($_GET['save'])) {
757
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
758
+		}
759
+	} else
739 760
 	{
740 761
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
741
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
742
-			$modSettings['load_average'] = (float) $matches[1];
743
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
744
-			$modSettings['load_average'] = (float) $matches[1];
745
-		else
746
-			unset($modSettings['load_average']);
762
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
763
+					$modSettings['load_average'] = (float) $matches[1];
764
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
765
+					$modSettings['load_average'] = (float) $matches[1];
766
+		} else {
767
+					unset($modSettings['load_average']);
768
+		}
747 769
 
748 770
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
749 771
 		{
@@ -779,8 +801,9 @@  discard block
 block discarded – undo
779 801
 
780 802
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
781 803
 
782
-	if ($return_config)
783
-		return $config_vars;
804
+	if ($return_config) {
805
+			return $config_vars;
806
+	}
784 807
 
785 808
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
786 809
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -791,24 +814,27 @@  discard block
 block discarded – undo
791 814
 		// Stupidity is not allowed.
792 815
 		foreach ($_POST as $key => $value)
793 816
 		{
794
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
795
-				continue;
796
-			else
797
-				$_POST[$key] = (float) $value;
798
-
799
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
800
-				$_POST['loadavg_auto_opt'] = 1.0;
801
-			elseif ($key == 'loadavg_forum' && $value < 10)
802
-				$_POST['loadavg_forum'] = 10.0;
803
-			elseif ($value < 2)
804
-				$_POST[$key] = 2.0;
817
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
818
+							continue;
819
+			} else {
820
+							$_POST[$key] = (float) $value;
821
+			}
822
+
823
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
824
+							$_POST['loadavg_auto_opt'] = 1.0;
825
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
826
+							$_POST['loadavg_forum'] = 10.0;
827
+			} elseif ($value < 2) {
828
+							$_POST[$key] = 2.0;
829
+			}
805 830
 		}
806 831
 
807 832
 		call_integration_hook('integrate_save_loadavg_settings');
808 833
 
809 834
 		saveDBSettings($config_vars);
810
-		if (!isset($_SESSION['adm-save']))
811
-			$_SESSION['adm-save'] = true;
835
+		if (!isset($_SESSION['adm-save'])) {
836
+					$_SESSION['adm-save'] = true;
837
+		}
812 838
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
813 839
 	}
814 840
 
@@ -844,10 +870,11 @@  discard block
 block discarded – undo
844 870
 
845 871
 	if (isset($_SESSION['adm-save']))
846 872
 	{
847
-		if ($_SESSION['adm-save'] === true)
848
-			$context['saved_successful'] = true;
849
-		else
850
-			$context['saved_failed'] = $_SESSION['adm-save'];
873
+		if ($_SESSION['adm-save'] === true) {
874
+					$context['saved_successful'] = true;
875
+		} else {
876
+					$context['saved_failed'] = $_SESSION['adm-save'];
877
+		}
851 878
 
852 879
 		unset($_SESSION['adm-save']);
853 880
 	}
@@ -855,9 +882,9 @@  discard block
 block discarded – undo
855 882
 	$context['config_vars'] = array();
856 883
 	foreach ($config_vars as $identifier => $config_var)
857 884
 	{
858
-		if (!is_array($config_var) || !isset($config_var[1]))
859
-			$context['config_vars'][] = $config_var;
860
-		else
885
+		if (!is_array($config_var) || !isset($config_var[1])) {
886
+					$context['config_vars'][] = $config_var;
887
+		} else
861 888
 		{
862 889
 			$varname = $config_var[0];
863 890
 			global $$varname;
@@ -892,16 +919,19 @@  discard block
 block discarded – undo
892 919
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
893 920
 			{
894 921
 				// Default to a min of 0 if one isn't set
895
-				if (isset($config_var['min']))
896
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
897
-				else
898
-					$context['config_vars'][$config_var[0]]['min'] = 0;
922
+				if (isset($config_var['min'])) {
923
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
924
+				} else {
925
+									$context['config_vars'][$config_var[0]]['min'] = 0;
926
+				}
899 927
 
900
-				if (isset($config_var['max']))
901
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
928
+				if (isset($config_var['max'])) {
929
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
930
+				}
902 931
 
903
-				if (isset($config_var['step']))
904
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
932
+				if (isset($config_var['step'])) {
933
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
934
+				}
905 935
 			}
906 936
 
907 937
 			// If this is a select box handle any data.
@@ -909,12 +939,13 @@  discard block
 block discarded – undo
909 939
 			{
910 940
 				// If it's associative
911 941
 				$config_values = array_values($config_var[4]);
912
-				if (isset($config_values[0]) && is_array($config_values[0]))
913
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
914
-				else
942
+				if (isset($config_values[0]) && is_array($config_values[0])) {
943
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
944
+				} else
915 945
 				{
916
-					foreach ($config_var[4] as $key => $item)
917
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
946
+					foreach ($config_var[4] as $key => $item) {
947
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
948
+					}
918 949
 				}
919 950
 			}
920 951
 		}
@@ -939,10 +970,11 @@  discard block
 block discarded – undo
939 970
 
940 971
 	if (isset($_SESSION['adm-save']))
941 972
 	{
942
-		if ($_SESSION['adm-save'] === true)
943
-			$context['saved_successful'] = true;
944
-		else
945
-			$context['saved_failed'] = $_SESSION['adm-save'];
973
+		if ($_SESSION['adm-save'] === true) {
974
+					$context['saved_successful'] = true;
975
+		} else {
976
+					$context['saved_failed'] = $_SESSION['adm-save'];
977
+		}
946 978
 
947 979
 		unset($_SESSION['adm-save']);
948 980
 	}
@@ -954,26 +986,30 @@  discard block
 block discarded – undo
954 986
 	foreach ($config_vars as $config_var)
955 987
 	{
956 988
 		// HR?
957
-		if (!is_array($config_var))
958
-			$context['config_vars'][] = $config_var;
959
-		else
989
+		if (!is_array($config_var)) {
990
+					$context['config_vars'][] = $config_var;
991
+		} else
960 992
 		{
961 993
 			// If it has no name it doesn't have any purpose!
962
-			if (empty($config_var[1]))
963
-				continue;
994
+			if (empty($config_var[1])) {
995
+							continue;
996
+			}
964 997
 
965 998
 			// Special case for inline permissions
966
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
967
-				$inlinePermissions[] = $config_var[1];
968
-			elseif ($config_var[0] == 'permissions')
969
-				continue;
999
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
1000
+							$inlinePermissions[] = $config_var[1];
1001
+			} elseif ($config_var[0] == 'permissions') {
1002
+							continue;
1003
+			}
970 1004
 
971
-			if ($config_var[0] == 'boards')
972
-				$board_list = true;
1005
+			if ($config_var[0] == 'boards') {
1006
+							$board_list = true;
1007
+			}
973 1008
 
974 1009
 			// Are we showing the BBC selection box?
975
-			if ($config_var[0] == 'bbc')
976
-				$bbcChoice[] = $config_var[1];
1010
+			if ($config_var[0] == 'bbc') {
1011
+							$bbcChoice[] = $config_var[1];
1012
+			}
977 1013
 
978 1014
 			// We need to do some parsing of the value before we pass it in.
979 1015
 			if (isset($modSettings[$config_var[1]]))
@@ -992,8 +1028,7 @@  discard block
 block discarded – undo
992 1028
 					default:
993 1029
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
994 1030
 				}
995
-			}
996
-			else
1031
+			} else
997 1032
 			{
998 1033
 				// Darn, it's empty. What type is expected?
999 1034
 				switch ($config_var[0])
@@ -1033,16 +1068,19 @@  discard block
 block discarded – undo
1033 1068
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
1034 1069
 			{
1035 1070
 				// Default to a min of 0 if one isn't set
1036
-				if (isset($config_var['min']))
1037
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1038
-				else
1039
-					$context['config_vars'][$config_var[1]]['min'] = 0;
1071
+				if (isset($config_var['min'])) {
1072
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1073
+				} else {
1074
+									$context['config_vars'][$config_var[1]]['min'] = 0;
1075
+				}
1040 1076
 
1041
-				if (isset($config_var['max']))
1042
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1077
+				if (isset($config_var['max'])) {
1078
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1079
+				}
1043 1080
 
1044
-				if (isset($config_var['step']))
1045
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1081
+				if (isset($config_var['step'])) {
1082
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1083
+				}
1046 1084
 			}
1047 1085
 
1048 1086
 			// If this is a select box handle any data.
@@ -1056,12 +1094,13 @@  discard block
 block discarded – undo
1056 1094
 				}
1057 1095
 
1058 1096
 				// If it's associative
1059
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
1060
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1061
-				else
1097
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
1098
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1099
+				} else
1062 1100
 				{
1063
-					foreach ($config_var[2] as $key => $item)
1064
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1101
+					foreach ($config_var[2] as $key => $item) {
1102
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1103
+					}
1065 1104
 				}
1066 1105
 			}
1067 1106
 
@@ -1070,17 +1109,19 @@  discard block
 block discarded – undo
1070 1109
 			{
1071 1110
 				if (!is_numeric($k))
1072 1111
 				{
1073
-					if (substr($k, 0, 2) == 'on')
1074
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1075
-					else
1076
-						$context['config_vars'][$config_var[1]][$k] = $v;
1112
+					if (substr($k, 0, 2) == 'on') {
1113
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1114
+					} else {
1115
+											$context['config_vars'][$config_var[1]][$k] = $v;
1116
+					}
1077 1117
 				}
1078 1118
 
1079 1119
 				// See if there are any other labels that might fit?
1080
-				if (isset($txt['setting_' . $config_var[1]]))
1081
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1082
-				elseif (isset($txt['groups_' . $config_var[1]]))
1083
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1120
+				if (isset($txt['setting_' . $config_var[1]])) {
1121
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1122
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
1123
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1124
+				}
1084 1125
 			}
1085 1126
 
1086 1127
 			// Set the subtext in case it's part of the label.
@@ -1113,8 +1154,9 @@  discard block
 block discarded – undo
1113 1154
 		// What are the options, eh?
1114 1155
 		$temp = parse_bbc(false);
1115 1156
 		$bbcTags = array();
1116
-		foreach ($temp as $tag)
1117
-			$bbcTags[] = $tag['tag'];
1157
+		foreach ($temp as $tag) {
1158
+					$bbcTags[] = $tag['tag'];
1159
+		}
1118 1160
 
1119 1161
 		$bbcTags = array_unique($bbcTags);
1120 1162
 		$totalTags = count($bbcTags);
@@ -1129,8 +1171,9 @@  discard block
 block discarded – undo
1129 1171
 		$col = 0; $i = 0;
1130 1172
 		foreach ($bbcTags as $tag)
1131 1173
 		{
1132
-			if ($i % $tagsPerColumn == 0 && $i != 0)
1133
-				$col++;
1174
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1175
+							$col++;
1176
+			}
1134 1177
 
1135 1178
 			$context['bbc_columns'][$col][] = array(
1136 1179
 				'tag' => $tag,
@@ -1173,18 +1216,21 @@  discard block
 block discarded – undo
1173 1216
 	validateToken('admin-ssc');
1174 1217
 
1175 1218
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1176
-	if (isset($_POST['cookiename']))
1177
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1219
+	if (isset($_POST['cookiename'])) {
1220
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1221
+	}
1178 1222
 
1179 1223
 	// Fix the forum's URL if necessary.
1180 1224
 	if (isset($_POST['boardurl']))
1181 1225
 	{
1182
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1183
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1184
-		elseif (substr($_POST['boardurl'], -1) == '/')
1185
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1186
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1187
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1226
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1227
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1228
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1229
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1230
+		}
1231
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1232
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1233
+		}
1188 1234
 	}
1189 1235
 
1190 1236
 	// Any passwords?
@@ -1219,21 +1265,21 @@  discard block
 block discarded – undo
1219 1265
 	// Figure out which config vars we're saving here...
1220 1266
 	foreach ($config_vars as $var)
1221 1267
 	{
1222
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1223
-			continue;
1268
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1269
+					continue;
1270
+		}
1224 1271
 
1225 1272
 		$config_var = $var[0];
1226 1273
 
1227 1274
 		if (in_array($config_var, $config_passwords))
1228 1275
 		{
1229
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1230
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1231
-		}
1232
-		elseif (in_array($config_var, $config_strs))
1276
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1277
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1278
+			}
1279
+		} elseif (in_array($config_var, $config_strs))
1233 1280
 		{
1234 1281
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1235
-		}
1236
-		elseif (in_array($config_var, $config_ints))
1282
+		} elseif (in_array($config_var, $config_ints))
1237 1283
 		{
1238 1284
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1239 1285
 
@@ -1242,17 +1288,17 @@  discard block
 block discarded – undo
1242 1288
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1243 1289
 
1244 1290
 			// Is there a max value for this as well?
1245
-			if (isset($var['max']))
1246
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1247
-		}
1248
-		elseif (in_array($config_var, $config_bools))
1291
+			if (isset($var['max'])) {
1292
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1293
+			}
1294
+		} elseif (in_array($config_var, $config_bools))
1249 1295
 		{
1250
-			if (!empty($_POST[$config_var]))
1251
-				$new_settings[$config_var] = '1';
1252
-			else
1253
-				$new_settings[$config_var] = '0';
1254
-		}
1255
-		else
1296
+			if (!empty($_POST[$config_var])) {
1297
+							$new_settings[$config_var] = '1';
1298
+			} else {
1299
+							$new_settings[$config_var] = '0';
1300
+			}
1301
+		} else
1256 1302
 		{
1257 1303
 			// This shouldn't happen, but it might...
1258 1304
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1268,30 +1314,35 @@  discard block
 block discarded – undo
1268 1314
 	foreach ($config_vars as $config_var)
1269 1315
 	{
1270 1316
 		// We just saved the file-based settings, so skip their definitions.
1271
-		if (!is_array($config_var) || $config_var[2] == 'file')
1272
-			continue;
1317
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1318
+					continue;
1319
+		}
1273 1320
 
1274 1321
 		$new_setting = array($config_var[3], $config_var[0]);
1275 1322
 
1276 1323
 		// Select options need carried over, too.
1277
-		if (isset($config_var[4]))
1278
-			$new_setting[] = $config_var[4];
1324
+		if (isset($config_var[4])) {
1325
+					$new_setting[] = $config_var[4];
1326
+		}
1279 1327
 
1280 1328
 		// Include min and max if necessary
1281
-		if (isset($config_var['min']))
1282
-			$new_setting['min'] = $config_var['min'];
1329
+		if (isset($config_var['min'])) {
1330
+					$new_setting['min'] = $config_var['min'];
1331
+		}
1283 1332
 
1284
-		if (isset($config_var['max']))
1285
-			$new_setting['max'] = $config_var['max'];
1333
+		if (isset($config_var['max'])) {
1334
+					$new_setting['max'] = $config_var['max'];
1335
+		}
1286 1336
 
1287 1337
 		// Rewrite the definition a bit.
1288 1338
 		$new_settings[] = $new_setting;
1289 1339
 	}
1290 1340
 
1291 1341
 	// Save the new database-based settings, if any.
1292
-	if (!empty($new_settings))
1293
-		saveDBSettings($new_settings);
1294
-}
1342
+	if (!empty($new_settings)) {
1343
+			saveDBSettings($new_settings);
1344
+	}
1345
+	}
1295 1346
 
1296 1347
 /**
1297 1348
  * Helper function for saving database settings.
@@ -1309,22 +1360,25 @@  discard block
 block discarded – undo
1309 1360
 	$inlinePermissions = array();
1310 1361
 	foreach ($config_vars as $var)
1311 1362
 	{
1312
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1313
-			continue;
1363
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1364
+					continue;
1365
+		}
1314 1366
 
1315 1367
 		// Checkboxes!
1316
-		elseif ($var[0] == 'check')
1317
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1368
+		elseif ($var[0] == 'check') {
1369
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1370
+		}
1318 1371
 		// Select boxes!
1319
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1320
-			$setArray[$var[1]] = $_POST[$var[1]];
1321
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1372
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1373
+					$setArray[$var[1]] = $_POST[$var[1]];
1374
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1322 1375
 		{
1323 1376
 			// For security purposes we validate this line by line.
1324 1377
 			$lOptions = array();
1325
-			foreach ($_POST[$var[1]] as $invar)
1326
-				if (in_array($invar, array_keys($var[2])))
1378
+			foreach ($_POST[$var[1]] as $invar) {
1379
+							if (in_array($invar, array_keys($var[2])))
1327 1380
 					$lOptions[] = $invar;
1381
+			}
1328 1382
 
1329 1383
 			$setArray[$var[1]] = $smcFunc['json_encode']($lOptions);
1330 1384
 		}
@@ -1338,18 +1392,20 @@  discard block
 block discarded – undo
1338 1392
 				$request = $smcFunc['db_query']('', '
1339 1393
 					SELECT id_board
1340 1394
 					FROM {db_prefix}boards');
1341
-				while ($row = $smcFunc['db_fetch_row']($request))
1342
-					$board_list[$row[0]] = true;
1395
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1396
+									$board_list[$row[0]] = true;
1397
+				}
1343 1398
 
1344 1399
 				$smcFunc['db_free_result']($request);
1345 1400
 			}
1346 1401
 
1347 1402
 			$lOptions = array();
1348 1403
 
1349
-			if (!empty($_POST[$var[1]]))
1350
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1404
+			if (!empty($_POST[$var[1]])) {
1405
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1351 1406
 					if (isset($board_list[$invar]))
1352 1407
 						$lOptions[] = $invar;
1408
+			}
1353 1409
 
1354 1410
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1355 1411
 		}
@@ -1363,8 +1419,9 @@  discard block
 block discarded – undo
1363 1419
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1364 1420
 
1365 1421
 			// Do we have a max value for this as well?
1366
-			if (isset($var['max']))
1367
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1422
+			if (isset($var['max'])) {
1423
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1424
+			}
1368 1425
 		}
1369 1426
 		// Floating point!
1370 1427
 		elseif ($var[0] == 'float')
@@ -1376,40 +1433,47 @@  discard block
 block discarded – undo
1376 1433
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1377 1434
 
1378 1435
 			// Do we have a max value for this as well?
1379
-			if (isset($var['max']))
1380
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1436
+			if (isset($var['max'])) {
1437
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1438
+			}
1381 1439
 		}
1382 1440
 		// Text!
1383
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1384
-			$setArray[$var[1]] = $_POST[$var[1]];
1441
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1442
+					$setArray[$var[1]] = $_POST[$var[1]];
1443
+		}
1385 1444
 		// Passwords!
1386 1445
 		elseif ($var[0] == 'password')
1387 1446
 		{
1388
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1389
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1447
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1448
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1449
+			}
1390 1450
 		}
1391 1451
 		// BBC.
1392 1452
 		elseif ($var[0] == 'bbc')
1393 1453
 		{
1394 1454
 
1395 1455
 			$bbcTags = array();
1396
-			foreach (parse_bbc(false) as $tag)
1397
-				$bbcTags[] = $tag['tag'];
1456
+			foreach (parse_bbc(false) as $tag) {
1457
+							$bbcTags[] = $tag['tag'];
1458
+			}
1398 1459
 
1399
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1400
-				$_POST[$var[1] . '_enabledTags'] = array();
1401
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1402
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1460
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1461
+							$_POST[$var[1] . '_enabledTags'] = array();
1462
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1463
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1464
+			}
1403 1465
 
1404 1466
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1405 1467
 		}
1406 1468
 		// Permissions?
1407
-		elseif ($var[0] == 'permissions')
1408
-			$inlinePermissions[] = $var[1];
1469
+		elseif ($var[0] == 'permissions') {
1470
+					$inlinePermissions[] = $var[1];
1471
+		}
1409 1472
 	}
1410 1473
 
1411
-	if (!empty($setArray))
1412
-		updateSettings($setArray);
1474
+	if (!empty($setArray)) {
1475
+			updateSettings($setArray);
1476
+	}
1413 1477
 
1414 1478
 	// If we have inline permissions we need to save them.
1415 1479
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1446,18 +1510,21 @@  discard block
 block discarded – undo
1446 1510
 	// put all of it into an array
1447 1511
 	foreach ($info_lines as $line)
1448 1512
 	{
1449
-		if (preg_match('~(' . $remove . ')~', $line))
1450
-			continue;
1513
+		if (preg_match('~(' . $remove . ')~', $line)) {
1514
+					continue;
1515
+		}
1451 1516
 
1452 1517
 		// new category?
1453
-		if (strpos($line, '<h2>') !== false)
1454
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1518
+		if (strpos($line, '<h2>') !== false) {
1519
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1520
+		}
1455 1521
 
1456 1522
 		// load it as setting => value or the old setting local master
1457
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1458
-			$pinfo[$category][$val[1]] = $val[2];
1459
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1460
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1523
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1524
+					$pinfo[$category][$val[1]] = $val[2];
1525
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1526
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1527
+		}
1461 1528
 	}
1462 1529
 
1463 1530
 	// load it in to context and display it
@@ -1492,8 +1559,9 @@  discard block
 block discarded – undo
1492 1559
 				$testAPI = new $cache_class_name();
1493 1560
 
1494 1561
 				// No Support?  NEXT!
1495
-				if (!$testAPI->isSupported(true))
1496
-					continue;
1562
+				if (!$testAPI->isSupported(true)) {
1563
+									continue;
1564
+				}
1497 1565
 
1498 1566
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1499 1567
 			}
@@ -1518,8 +1586,9 @@  discard block
 block discarded – undo
1518 1586
 	global $modSettings, $boardurl, $smcFunc;
1519 1587
 
1520 1588
 	// Already have a key?  Can't register again.
1521
-	if (!empty($modSettings['sm_stats_key']))
1522
-		return true;
1589
+	if (!empty($modSettings['sm_stats_key'])) {
1590
+			return true;
1591
+	}
1523 1592
 
1524 1593
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1525 1594
 	if ($fp)
@@ -1530,8 +1599,9 @@  discard block
 block discarded – undo
1530 1599
 		fwrite($fp, $out);
1531 1600
 
1532 1601
 		$return_data = '';
1533
-		while (!feof($fp))
1534
-			$return_data .= fgets($fp, 128);
1602
+		while (!feof($fp)) {
1603
+					$return_data .= fgets($fp, 128);
1604
+		}
1535 1605
 
1536 1606
 		fclose($fp);
1537 1607
 
Please login to merge, or discard this patch.
Sources/Likes.php 1 patch
Braces   +103 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Class Likes
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 		$this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false;
107 108
 
108 109
 		// We do not want to output debug information here.
109
-		if ($this->_js)
110
-			$db_show_debug = false;
110
+		if ($this->_js) {
111
+					$db_show_debug = false;
112
+		}
111 113
 	}
112 114
 
113 115
 	/**
@@ -141,8 +143,9 @@  discard block
 block discarded – undo
141 143
 			$call = $this->_sa;
142 144
 
143 145
 			// Guest can only view likes.
144
-			if ($call != 'view')
145
-				is_not_guest();
146
+			if ($call != 'view') {
147
+							is_not_guest();
148
+			}
146 149
 
147 150
 			checkSession('get');
148 151
 
@@ -180,15 +183,17 @@  discard block
 block discarded – undo
180 183
 		global $smcFunc, $modSettings;
181 184
 
182 185
 		// This feature is currently disable.
183
-		if (empty($modSettings['enable_likes']))
184
-			return $this->_error = 'like_disable';
186
+		if (empty($modSettings['enable_likes'])) {
187
+					return $this->_error = 'like_disable';
188
+		}
185 189
 
186 190
 		// Zerothly, they did indicate some kind of content to like, right?
187 191
 		preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches);
188 192
 		$this->_type = isset($matches[1]) ? $matches[1] : '';
189 193
 
190
-		if ($this->_type == '' || $this->_content <= 0)
191
-			return $this->_error = 'cannot_';
194
+		if ($this->_type == '' || $this->_content <= 0) {
195
+					return $this->_error = 'cannot_';
196
+		}
192 197
 
193 198
 		// First we need to verify if the user can see the type of content or not. This is set up to be extensible,
194 199
 		// so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks.
@@ -207,12 +212,14 @@  discard block
 block discarded – undo
207 212
 					'msg' => $this->_content,
208 213
 				)
209 214
 			);
210
-			if ($smcFunc['db_num_rows']($request) == 1)
211
-				list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
215
+			if ($smcFunc['db_num_rows']($request) == 1) {
216
+							list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
217
+			}
212 218
 
213 219
 			$smcFunc['db_free_result']($request);
214
-			if (empty($this->_idTopic))
215
-				return $this->_error = 'cannot_';
220
+			if (empty($this->_idTopic)) {
221
+							return $this->_error = 'cannot_';
222
+			}
216 223
 
217 224
 			// So we know what topic it's in and more importantly we know the user can see it.
218 225
 			// If we're not viewing, we need some info set up.
@@ -221,9 +228,7 @@  discard block
 block discarded – undo
221 228
 			$this->_validLikes['redirect'] = 'topic=' . $this->_idTopic . '.msg' . $this->_content . '#msg' . $this->_content;
222 229
 
223 230
 			$this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content'));
224
-		}
225
-
226
-		else
231
+		} else
227 232
 		{
228 233
 			// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
229 234
 			// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 					if ($result !== false)
242 247
 					{
243 248
 						// Match the type with what we already have.
244
-						if (!isset($result['type']) || $result['type'] != $this->_type)
245
-							return $this->_error = 'not_valid_like_type';
249
+						if (!isset($result['type']) || $result['type'] != $this->_type) {
250
+													return $this->_error = 'not_valid_like_type';
251
+						}
246 252
 
247 253
 						// Fill out the rest.
248 254
 						$this->_type = $result['type'];
@@ -253,13 +259,15 @@  discard block
 block discarded – undo
253 259
 				}
254 260
 			}
255 261
 
256
-			if (!$found)
257
-				return $this->_error = 'cannot_';
262
+			if (!$found) {
263
+							return $this->_error = 'cannot_';
264
+			}
258 265
 		}
259 266
 
260 267
 		// Does the user can like this? Viewing a list of likes doesn't require this permission.
261
-			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like']))
262
-				return $this->_error = $this->_validLikes['can_like'];
268
+			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) {
269
+							return $this->_error = $this->_validLikes['can_like'];
270
+			}
263 271
 	}
264 272
 
265 273
 	/**
@@ -284,8 +292,9 @@  discard block
 block discarded – undo
284 292
 		);
285 293
 
286 294
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
287
-		if ($this->_sa == __FUNCTION__)
288
-			$this->_data = __FUNCTION__;
295
+		if ($this->_sa == __FUNCTION__) {
296
+					$this->_data = __FUNCTION__;
297
+		}
289 298
 	}
290 299
 
291 300
 	/**
@@ -315,8 +324,8 @@  discard block
 block discarded – undo
315 324
 
316 325
 		// Add a background task to process sending alerts.
317 326
 		// Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this.
318
-		if ($this->_type == 'msg')
319
-			$smcFunc['db_insert']('insert',
327
+		if ($this->_type == 'msg') {
328
+					$smcFunc['db_insert']('insert',
320 329
 				'{db_prefix}background_tasks',
321 330
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
322 331
 				array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', $smcFunc['json_encode'](array(
@@ -328,10 +337,12 @@  discard block
 block discarded – undo
328 337
 				)), 0),
329 338
 				array('id_task')
330 339
 			);
340
+		}
331 341
 
332 342
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
333
-		if ($this->_sa == __FUNCTION__)
334
-			$this->_data = __FUNCTION__;
343
+		if ($this->_sa == __FUNCTION__) {
344
+					$this->_data = __FUNCTION__;
345
+		}
335 346
 	}
336 347
 
337 348
 	/**
@@ -357,8 +368,9 @@  discard block
 block discarded – undo
357 368
 		$smcFunc['db_free_result']($request);
358 369
 
359 370
 		// If you want to call this directly, fill out _data property too.
360
-		if ($this->_sa == __FUNCTION__)
361
-			$this->_data = $this->_numLikes;
371
+		if ($this->_sa == __FUNCTION__) {
372
+					$this->_data = $this->_numLikes;
373
+		}
362 374
 	}
363 375
 
364 376
 	/**
@@ -371,8 +383,9 @@  discard block
 block discarded – undo
371 383
 		global $smcFunc;
372 384
 
373 385
 		// Safety first!
374
-		if (empty($this->_type) || empty($this->_content))
375
-			return $this->_error = 'cannot_';
386
+		if (empty($this->_type) || empty($this->_content)) {
387
+					return $this->_error = 'cannot_';
388
+		}
376 389
 
377 390
 		// Do we already like this?
378 391
 		$request = $smcFunc['db_query']('', '
@@ -390,26 +403,28 @@  discard block
 block discarded – undo
390 403
 		$this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0;
391 404
 		$smcFunc['db_free_result']($request);
392 405
 
393
-		if ($this->_alreadyLiked)
394
-			$this->delete();
395
-
396
-		else
397
-			$this->insert();
406
+		if ($this->_alreadyLiked) {
407
+					$this->delete();
408
+		} else {
409
+					$this->insert();
410
+		}
398 411
 
399 412
 		// Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable.
400 413
 		$this->_count();
401 414
 
402 415
 		// Update the likes count for messages.
403
-		if ($this->_type == 'msg')
404
-			$this->msgIssueLike();
416
+		if ($this->_type == 'msg') {
417
+					$this->msgIssueLike();
418
+		}
405 419
 
406 420
 		// Any callbacks?
407 421
 		elseif (!empty($this->_validLikes['callback']))
408 422
 		{
409 423
 			$call = call_helper($this->_validLikes['callback'], true);
410 424
 
411
-			if (!empty($call))
412
-				call_user_func_array($call, array($this));
425
+			if (!empty($call)) {
426
+							call_user_func_array($call, array($this));
427
+			}
413 428
 		}
414 429
 
415 430
 		// Sometimes there might be other things that need updating after we do this like.
@@ -418,8 +433,9 @@  discard block
 block discarded – undo
418 433
 		// Now some clean up. This is provided here for any like handlers that want to do any cache flushing.
419 434
 		// This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so
420 435
 		// in integrate_valid_likes where it absolutely has to exist.
421
-		if (!empty($this->_validLikes['flush_cache']))
422
-			cache_put_data($this->_validLikes['flush_cache'], null);
436
+		if (!empty($this->_validLikes['flush_cache'])) {
437
+					cache_put_data($this->_validLikes['flush_cache'], null);
438
+		}
423 439
 
424 440
 		// All done, start building the data to pass as response.
425 441
 		$this->_data = array(
@@ -442,8 +458,9 @@  discard block
 block discarded – undo
442 458
 	{
443 459
 		global $smcFunc;
444 460
 
445
-		if ($this->_type !== 'msg')
446
-			return;
461
+		if ($this->_type !== 'msg') {
462
+					return;
463
+		}
447 464
 
448 465
 		$smcFunc['db_query']('', '
449 466
 			UPDATE {db_prefix}messages
@@ -484,8 +501,9 @@  discard block
 block discarded – undo
484 501
 				'like_type' => $this->_type,
485 502
 			)
486 503
 		);
487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
488
-			$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
504
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
505
+					$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
506
+		}
489 507
 
490 508
 		// Now to get member data, including avatars and so on.
491 509
 		$members = array_keys($context['likers']);
@@ -493,8 +511,9 @@  discard block
 block discarded – undo
493 511
 		if (count($loaded) != count($members))
494 512
 		{
495 513
 			$members = array_diff($members, $loaded);
496
-			foreach ($members as $not_loaded)
497
-				unset ($context['likers'][$not_loaded]);
514
+			foreach ($members as $not_loaded) {
515
+							unset ($context['likers'][$not_loaded]);
516
+			}
498 517
 		}
499 518
 
500 519
 		foreach ($context['likers'] as $liker => $dummy)
@@ -536,12 +555,14 @@  discard block
 block discarded – undo
536 555
 		global $context, $txt;
537 556
 
538 557
 		// Don't do anything if someone else has already take care of the response.
539
-		if (!$this->_setResponse)
540
-			return;
558
+		if (!$this->_setResponse) {
559
+					return;
560
+		}
541 561
 
542 562
 		// Want a json response huh?
543
-		if ($this->_validLikes['json'])
544
-			return $this->jsonResponse();
563
+		if ($this->_validLikes['json']) {
564
+					return $this->jsonResponse();
565
+		}
545 566
 
546 567
 		// Set everything up for display.
547 568
 		loadTemplate('Likes');
@@ -551,8 +572,9 @@  discard block
 block discarded – undo
551 572
 		if ($this->_error)
552 573
 		{
553 574
 			// If this is a generic error, set it up good.
554
-			if ($this->_error == 'cannot_')
555
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
575
+			if ($this->_error == 'cannot_') {
576
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
577
+			}
556 578
 
557 579
 			// Is this request coming from an ajax call?
558 580
 			if ($this->_js)
@@ -562,8 +584,9 @@  discard block
 block discarded – undo
562 584
 			}
563 585
 
564 586
 			// Nope?  then just do a redirect to whatever URL was provided.
565
-			else
566
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
587
+			else {
588
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
589
+			}
567 590
 
568 591
 			return;
569 592
 		}
@@ -572,8 +595,9 @@  discard block
 block discarded – undo
572 595
 		else
573 596
 		{
574 597
 			// Not an ajax request so send the user back to the previous location or the main page.
575
-			if (!$this->_js)
576
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
598
+			if (!$this->_js) {
599
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
600
+			}
577 601
 
578 602
 			// These fine gentlemen all share the same template.
579 603
 			$generic = array('delete', 'insert', '_count');
@@ -606,8 +630,9 @@  discard block
 block discarded – undo
606 630
 		// If there is an error, send it.
607 631
 		if ($this->_error)
608 632
 		{
609
-			if ($this->_error == 'cannot_')
610
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
633
+			if ($this->_error == 'cannot_') {
634
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
635
+			}
611 636
 
612 637
 			$print['error'] = $this->_error;
613 638
 		}
@@ -643,33 +668,36 @@  discard block
 block discarded – undo
643 668
 	<body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
644 669
 		<div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
645 670
 
646
-	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
647
-		$_GET['verse'] = '4:16';
671
+	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) {
672
+			$_GET['verse'] = '4:16';
673
+	}
648 674
 
649
-	if ($_GET['verse'] == '2:18')
650
-		echo '
675
+	if ($_GET['verse'] == '2:18') {
676
+			echo '
651 677
 			Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
652
-	elseif ($_GET['verse'] == '4:16')
653
-		echo '
678
+	} elseif ($_GET['verse'] == '4:16') {
679
+			echo '
654 680
 			And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
655
-	elseif ($_GET['verse'] == '22:1-2')
656
-		echo '
681
+	} elseif ($_GET['verse'] == '22:1-2') {
682
+			echo '
657 683
 			<p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer.&nbsp; Alas, it needed more than <em>only one</em>, but yet even thought otherwise.&nbsp; It became that the opposition <em>rumored</em> and lied, but still to no avail.&nbsp; Their match, though not <em>perfect</em>, had them outdone.</p>
658 684
 			<p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue.&nbsp; <em>The end</em>.</p>';
685
+	}
659 686
 
660 687
 	echo '
661 688
 		</div>
662 689
 		<div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
663 690
 
664
-	if ($_GET['verse'] == '2:18')
665
-		echo '
691
+	if ($_GET['verse'] == '2:18') {
692
+			echo '
666 693
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
667
-	elseif ($_GET['verse'] == '4:16')
668
-		echo '
694
+	} elseif ($_GET['verse'] == '4:16') {
695
+			echo '
669 696
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
670
-	elseif ($_GET['verse'] == '22:1-2')
671
-		echo '
697
+	} elseif ($_GET['verse'] == '22:1-2') {
698
+			echo '
672 699
 			from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
700
+	}
673 701
 
674 702
 	echo '
675 703
 		</div>
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +224 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 	static $timezone_array = array();
134 136
 	require_once($sourcedir . '/Subs.php');
135 137
 
136
-	if (empty($timezone_array['default']))
137
-		$timezone_array['default'] = timezone_open(date_default_timezone_get());
138
+	if (empty($timezone_array['default'])) {
139
+			$timezone_array['default'] = timezone_open(date_default_timezone_get());
140
+	}
138 141
 
139 142
 	$low_object = date_create($low_date);
140 143
 	$high_object = date_create($high_date);
@@ -161,8 +164,9 @@  discard block
 block discarded – undo
161 164
 	while ($row = $smcFunc['db_fetch_assoc']($result))
162 165
 	{
163 166
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
164
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
165
-			continue;
167
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
168
+					continue;
169
+		}
166 170
 
167 171
 		// Force a censor of the title - as often these are used by others.
168 172
 		censorText($row['title'], $use_permissions ? false : true);
@@ -170,12 +174,14 @@  discard block
 block discarded – undo
170 174
 		// Get the various time and date properties for this event
171 175
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
172 176
 
173
-		if (empty($timezone_array[$tz]))
174
-			$timezone_array[$tz] = timezone_open($tz);
177
+		if (empty($timezone_array[$tz])) {
178
+					$timezone_array[$tz] = timezone_open($tz);
179
+		}
175 180
 
176 181
 		// Sanity check
177
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
178
-			continue;
182
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
183
+					continue;
184
+		}
179 185
 
180 186
 		// Get set up for the loop
181 187
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]);
@@ -239,8 +245,8 @@  discard block
 block discarded – undo
239 245
 			);
240 246
 
241 247
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
242
-			if ($use_permissions)
243
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
248
+			if ($use_permissions) {
249
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
244 250
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
245 251
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
246 252
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -248,9 +254,10 @@  discard block
 block discarded – undo
248 254
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
249 255
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
250 256
 				));
257
+			}
251 258
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
252
-			else
253
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
259
+			else {
260
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
254 261
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
255 262
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
256 263
 					'can_edit' => false,
@@ -260,6 +267,7 @@  discard block
 block discarded – undo
260 267
 					'poster' => $row['id_member'],
261 268
 					'allowed_groups' => explode(',', $row['member_groups']),
262 269
 				));
270
+			}
263 271
 
264 272
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
265 273
 		}
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
270 278
 	if ($use_permissions)
271 279
 	{
272
-		foreach ($events as $mday => $array)
273
-			$events[$mday][count($array) - 1]['is_last'] = true;
280
+		foreach ($events as $mday => $array) {
281
+					$events[$mday][count($array) - 1]['is_last'] = true;
282
+		}
274 283
 	}
275 284
 
276 285
 	ksort($events);
@@ -290,11 +299,12 @@  discard block
 block discarded – undo
290 299
 	global $smcFunc;
291 300
 
292 301
 	// Get the lowest and highest dates for "all years".
293
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
294
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
302
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
303
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
295 304
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
296
-	else
297
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
305
+	} else {
306
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
307
+	}
298 308
 
299 309
 	// Find some holidays... ;).
300 310
 	$result = $smcFunc['db_query']('', '
@@ -314,10 +324,11 @@  discard block
 block discarded – undo
314 324
 	$holidays = array();
315 325
 	while ($row = $smcFunc['db_fetch_assoc']($result))
316 326
 	{
317
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
318
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
319
-		else
320
-			$event_year = substr($low_date, 0, 4);
327
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
328
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
329
+		} else {
330
+					$event_year = substr($low_date, 0, 4);
331
+		}
321 332
 
322 333
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
323 334
 	}
@@ -343,10 +354,12 @@  discard block
 block discarded – undo
343 354
 	isAllowedTo('calendar_post');
344 355
 
345 356
 	// No board?  No topic?!?
346
-	if (empty($board))
347
-		fatal_lang_error('missing_board_id', false);
348
-	if (empty($topic))
349
-		fatal_lang_error('missing_topic_id', false);
357
+	if (empty($board)) {
358
+			fatal_lang_error('missing_board_id', false);
359
+	}
360
+	if (empty($topic)) {
361
+			fatal_lang_error('missing_topic_id', false);
362
+	}
350 363
 
351 364
 	// Administrator, Moderator, or owner.  Period.
352 365
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -364,12 +377,14 @@  discard block
 block discarded – undo
364 377
 		if ($row = $smcFunc['db_fetch_assoc']($result))
365 378
 		{
366 379
 			// Not the owner of the topic.
367
-			if ($row['id_member_started'] != $user_info['id'])
368
-				fatal_lang_error('not_your_topic', 'user');
380
+			if ($row['id_member_started'] != $user_info['id']) {
381
+							fatal_lang_error('not_your_topic', 'user');
382
+			}
369 383
 		}
370 384
 		// Topic/Board doesn't exist.....
371
-		else
372
-			fatal_lang_error('calendar_no_topic', 'general');
385
+		else {
386
+					fatal_lang_error('calendar_no_topic', 'general');
387
+		}
373 388
 		$smcFunc['db_free_result']($result);
374 389
 	}
375 390
 }
@@ -457,14 +472,16 @@  discard block
 block discarded – undo
457 472
 	if (!empty($calendarOptions['start_day']))
458 473
 	{
459 474
 		$nShift -= $calendarOptions['start_day'];
460
-		if ($nShift < 0)
461
-			$nShift = 7 + $nShift;
475
+		if ($nShift < 0) {
476
+					$nShift = 7 + $nShift;
477
+		}
462 478
 	}
463 479
 
464 480
 	// Number of rows required to fit the month.
465 481
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
466
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
467
-		$nRows++;
482
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
483
+			$nRows++;
484
+	}
468 485
 
469 486
 	// Fetch the arrays for birthdays, posted events, and holidays.
470 487
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -477,8 +494,9 @@  discard block
 block discarded – undo
477 494
 	{
478 495
 		$calendarGrid['week_days'][] = $count;
479 496
 		$count++;
480
-		if ($count == 7)
481
-			$count = 0;
497
+		if ($count == 7) {
498
+					$count = 0;
499
+		}
482 500
 	}
483 501
 
484 502
 	// Iterate through each week.
@@ -495,8 +513,9 @@  discard block
 block discarded – undo
495 513
 		{
496 514
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
497 515
 
498
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
499
-				$nDay = 0;
516
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
517
+							$nDay = 0;
518
+			}
500 519
 
501 520
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
502 521
 
@@ -514,8 +533,9 @@  discard block
 block discarded – undo
514 533
 	}
515 534
 
516 535
 	// What is the last day of the month?
517
-	if ($is_previous === true)
518
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
536
+	if ($is_previous === true) {
537
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
538
+	}
519 539
 
520 540
 	// We'll use the shift in the template.
521 541
 	$calendarGrid['shift'] = $nShift;
@@ -549,8 +569,9 @@  discard block
 block discarded – undo
549 569
 	{
550 570
 		// Here we offset accordingly to get things to the real start of a week.
551 571
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
552
-		if ($date_diff < 0)
553
-			$date_diff += 7;
572
+		if ($date_diff < 0) {
573
+					$date_diff += 7;
574
+		}
554 575
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
555 576
 		$day = (int) strftime('%d', $new_timestamp);
556 577
 		$month = (int) strftime('%m', $new_timestamp);
@@ -680,18 +701,20 @@  discard block
 block discarded – undo
680 701
 	{
681 702
 		foreach ($date_events as $event_key => $event_val)
682 703
 		{
683
-			if (in_array($event_val['id'], $temp))
684
-				unset($calendarGrid['events'][$date][$event_key]);
685
-			else
686
-				$temp[] = $event_val['id'];
704
+			if (in_array($event_val['id'], $temp)) {
705
+							unset($calendarGrid['events'][$date][$event_key]);
706
+			} else {
707
+							$temp[] = $event_val['id'];
708
+			}
687 709
 		}
688 710
 	}
689 711
 
690 712
 	// Give birthdays and holidays a friendly format, without the year
691
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
692
-		$date_format = '%b %d';
693
-	else
694
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
713
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
714
+			$date_format = '%b %d';
715
+	} else {
716
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
717
+	}
695 718
 
696 719
 	foreach (array('birthdays', 'holidays') as $type)
697 720
 	{
@@ -790,8 +813,9 @@  discard block
 block discarded – undo
790 813
 		// Holidays between now and now + days.
791 814
 		for ($i = $now; $i < $now + $days_for_index; $i += 86400)
792 815
 		{
793
-			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
794
-				$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
816
+			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
817
+							$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
818
+			}
795 819
 		}
796 820
 	}
797 821
 
@@ -803,8 +827,9 @@  discard block
 block discarded – undo
803 827
 			$loop_date = strftime('%Y-%m-%d', $i);
804 828
 			if (isset($cached_data['birthdays'][$loop_date]))
805 829
 			{
806
-				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
807
-					$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
830
+				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
831
+									$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
832
+				}
808 833
 				$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
809 834
 			}
810 835
 		}
@@ -819,8 +844,9 @@  discard block
 block discarded – undo
819 844
 			$loop_date = strftime('%Y-%m-%d', $i);
820 845
 
821 846
 			// No events today? Check the next day.
822
-			if (empty($cached_data['events'][$loop_date]))
823
-				continue;
847
+			if (empty($cached_data['events'][$loop_date])) {
848
+							continue;
849
+			}
824 850
 
825 851
 			// Loop through all events to add a few last-minute values.
826 852
 			foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -833,9 +859,9 @@  discard block
 block discarded – undo
833 859
 				{
834 860
 					unset($cached_data['events'][$loop_date][$ev]);
835 861
 					continue;
862
+				} else {
863
+									$duplicates[$this_event['topic'] . $this_event['title']] = true;
836 864
 				}
837
-				else
838
-					$duplicates[$this_event['topic'] . $this_event['title']] = true;
839 865
 
840 866
 				// Might be set to true afterwards, depending on the permissions.
841 867
 				$this_event['can_edit'] = false;
@@ -843,16 +869,19 @@  discard block
 block discarded – undo
843 869
 				$this_event['date'] = $loop_date;
844 870
 			}
845 871
 
846
-			if (!empty($cached_data['events'][$loop_date]))
847
-				$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
872
+			if (!empty($cached_data['events'][$loop_date])) {
873
+							$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
874
+			}
848 875
 		}
849 876
 	}
850 877
 
851 878
 	// Mark the last item so that a list separator can be used in the template.
852
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
853
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
854
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
855
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
879
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
880
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
881
+	}
882
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
883
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
884
+	}
856 885
 
857 886
 	return array(
858 887
 		'data' => $return_data,
@@ -900,37 +929,46 @@  discard block
 block discarded – undo
900 929
 		if (isset($_POST['start_date']))
901 930
 		{
902 931
 			$d = date_parse($_POST['start_date']);
903
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
904
-				fatal_lang_error('invalid_date', false);
905
-			if (empty($d['year']))
906
-				fatal_lang_error('event_year_missing', false);
907
-			if (empty($d['month']))
908
-				fatal_lang_error('event_month_missing', false);
909
-		}
910
-		elseif (isset($_POST['start_datetime']))
932
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
933
+							fatal_lang_error('invalid_date', false);
934
+			}
935
+			if (empty($d['year'])) {
936
+							fatal_lang_error('event_year_missing', false);
937
+			}
938
+			if (empty($d['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+		} elseif (isset($_POST['start_datetime']))
911 942
 		{
912 943
 			$d = date_parse($_POST['start_datetime']);
913
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
914
-				fatal_lang_error('invalid_date', false);
915
-			if (empty($d['year']))
916
-				fatal_lang_error('event_year_missing', false);
917
-			if (empty($d['month']))
918
-				fatal_lang_error('event_month_missing', false);
944
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
945
+							fatal_lang_error('invalid_date', false);
946
+			}
947
+			if (empty($d['year'])) {
948
+							fatal_lang_error('event_year_missing', false);
949
+			}
950
+			if (empty($d['month'])) {
951
+							fatal_lang_error('event_month_missing', false);
952
+			}
919 953
 		}
920 954
 		// The 2.0 way
921 955
 		else
922 956
 		{
923 957
 			// No month?  No year?
924
-			if (!isset($_POST['month']))
925
-				fatal_lang_error('event_month_missing', false);
926
-			if (!isset($_POST['year']))
927
-				fatal_lang_error('event_year_missing', false);
958
+			if (!isset($_POST['month'])) {
959
+							fatal_lang_error('event_month_missing', false);
960
+			}
961
+			if (!isset($_POST['year'])) {
962
+							fatal_lang_error('event_year_missing', false);
963
+			}
928 964
 
929 965
 			// Check the month and year...
930
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
931
-				fatal_lang_error('invalid_month', false);
932
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
933
-				fatal_lang_error('invalid_year', false);
966
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
967
+							fatal_lang_error('invalid_month', false);
968
+			}
969
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
970
+							fatal_lang_error('invalid_year', false);
971
+			}
934 972
 		}
935 973
 	}
936 974
 
@@ -940,8 +978,9 @@  discard block
 block discarded – undo
940 978
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
941 979
 	if (isset($_POST['span']))
942 980
 	{
943
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
944
-			fatal_lang_error('invalid_days_numb', false);
981
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
982
+					fatal_lang_error('invalid_days_numb', false);
983
+		}
945 984
 	}
946 985
 
947 986
 	// There is no need to validate the following values if we are just deleting the event.
@@ -951,24 +990,29 @@  discard block
 block discarded – undo
951 990
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
952 991
 		{
953 992
 			// No day?
954
-			if (!isset($_POST['day']))
955
-				fatal_lang_error('event_day_missing', false);
993
+			if (!isset($_POST['day'])) {
994
+							fatal_lang_error('event_day_missing', false);
995
+			}
956 996
 
957 997
 			// Bad day?
958
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
959
-				fatal_lang_error('invalid_date', false);
998
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
999
+							fatal_lang_error('invalid_date', false);
1000
+			}
960 1001
 		}
961 1002
 
962
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
963
-			fatal_lang_error('event_title_missing', false);
964
-		elseif (!isset($_POST['evtitle']))
965
-			$_POST['evtitle'] = $_POST['subject'];
1003
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
1004
+					fatal_lang_error('event_title_missing', false);
1005
+		} elseif (!isset($_POST['evtitle'])) {
1006
+					$_POST['evtitle'] = $_POST['subject'];
1007
+		}
966 1008
 
967 1009
 		// No title?
968
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
969
-			fatal_lang_error('no_event_title', false);
970
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
971
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1010
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
1011
+					fatal_lang_error('no_event_title', false);
1012
+		}
1013
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
1014
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1015
+		}
972 1016
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
973 1017
 	}
974 1018
 }
@@ -995,8 +1039,9 @@  discard block
 block discarded – undo
995 1039
 	);
996 1040
 
997 1041
 	// No results, return false.
998
-	if ($smcFunc['db_num_rows'] === 0)
999
-		return false;
1042
+	if ($smcFunc['db_num_rows'] === 0) {
1043
+			return false;
1044
+	}
1000 1045
 
1001 1046
 	// Grab the results and return.
1002 1047
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1130,8 +1175,9 @@  discard block
 block discarded – undo
1130 1175
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1131 1176
 
1132 1177
 	$column_clauses = array();
1133
-	foreach ($event_columns as $col => $crit)
1134
-		$column_clauses[] = $col . ' = ' . $crit;
1178
+	foreach ($event_columns as $col => $crit) {
1179
+			$column_clauses[] = $col . ' = ' . $crit;
1180
+	}
1135 1181
 
1136 1182
 	$smcFunc['db_query']('', '
1137 1183
 		UPDATE {db_prefix}calendar
@@ -1216,8 +1262,9 @@  discard block
 block discarded – undo
1216 1262
 	);
1217 1263
 
1218 1264
 	// If nothing returned, we are in poo, poo.
1219
-	if ($smcFunc['db_num_rows']($request) === 0)
1220
-		return false;
1265
+	if ($smcFunc['db_num_rows']($request) === 0) {
1266
+			return false;
1267
+	}
1221 1268
 
1222 1269
 	$row = $smcFunc['db_fetch_assoc']($request);
1223 1270
 	$smcFunc['db_free_result']($request);
@@ -1225,8 +1272,9 @@  discard block
 block discarded – undo
1225 1272
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1226 1273
 
1227 1274
 	// Sanity check
1228
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1229
-		return false;
1275
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1276
+			return false;
1277
+	}
1230 1278
 
1231 1279
 	$return_value = array(
1232 1280
 		'boards' => array(),
@@ -1363,24 +1411,27 @@  discard block
 block discarded – undo
1363 1411
 
1364 1412
 	// Set $span, in case we need it
1365 1413
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1366
-	if ($span > 0)
1367
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1414
+	if ($span > 0) {
1415
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1416
+	}
1368 1417
 
1369 1418
 	// Define the timezone for this event, falling back to the default if not provided
1370
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1371
-		$tz = $eventOptions['tz'];
1372
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1373
-		$tz = $_POST['tz'];
1374
-	else
1375
-		$tz = getUserTimezone();
1419
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1420
+			$tz = $eventOptions['tz'];
1421
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1422
+			$tz = $_POST['tz'];
1423
+	} else {
1424
+			$tz = getUserTimezone();
1425
+	}
1376 1426
 
1377 1427
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1378
-	if (isset($eventOptions['allday']))
1379
-		$allday = $eventOptions['allday'];
1380
-	elseif (empty($_POST['allday']))
1381
-		$allday = false;
1382
-	else
1383
-		$allday = true;
1428
+	if (isset($eventOptions['allday'])) {
1429
+			$allday = $eventOptions['allday'];
1430
+	} elseif (empty($_POST['allday'])) {
1431
+			$allday = false;
1432
+	} else {
1433
+			$allday = true;
1434
+	}
1384 1435
 
1385 1436
 	// Input might come as individual parameters...
1386 1437
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1407,10 +1458,12 @@  discard block
 block discarded – undo
1407 1458
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1408 1459
 
1409 1460
 	// If the date and time were given in separate strings, combine them
1410
-	if (empty($start_string) && isset($start_date_string))
1411
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1412
-	if (empty($end_string) && isset($end_date_string))
1413
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1461
+	if (empty($start_string) && isset($start_date_string)) {
1462
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1463
+	}
1464
+	if (empty($end_string) && isset($end_date_string)) {
1465
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1466
+	}
1414 1467
 
1415 1468
 	// If some form of string input was given, override individually defined options with it
1416 1469
 	if (isset($start_string))
@@ -1501,10 +1554,11 @@  discard block
 block discarded – undo
1501 1554
 	if ($start_object >= $end_object)
1502 1555
 	{
1503 1556
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1504
-		if ($span > 0)
1505
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1506
-		else
1507
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1557
+		if ($span > 0) {
1558
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1559
+		} else {
1560
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1561
+		}
1508 1562
 	}
1509 1563
 
1510 1564
 	// Is $end_object too late?
@@ -1517,9 +1571,9 @@  discard block
 block discarded – undo
1517 1571
 			{
1518 1572
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1519 1573
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1574
+			} else {
1575
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1520 1576
 			}
1521
-			else
1522
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1523 1577
 		}
1524 1578
 	}
1525 1579
 
@@ -1532,8 +1586,7 @@  discard block
 block discarded – undo
1532 1586
 		$start_time = null;
1533 1587
 		$end_time = null;
1534 1588
 		$tz = null;
1535
-	}
1536
-	else
1589
+	} else
1537 1590
 	{
1538 1591
 		$start_time = date_format($start_object, 'H:i:s');
1539 1592
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1559,19 +1612,21 @@  discard block
 block discarded – undo
1559 1612
 	// First, try to create a better date format, ignoring the "time" elements.
1560 1613
 	if (empty($date_format))
1561 1614
 	{
1562
-		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1563
-			$date_format = '%F';
1564
-		else
1565
-			$date_format = $matches[0];
1615
+		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1616
+					$date_format = '%F';
1617
+		} else {
1618
+					$date_format = $matches[0];
1619
+		}
1566 1620
 	}
1567 1621
 
1568 1622
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1569 1623
 	if (empty($time_format))
1570 1624
 	{
1571
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1572
-			$time_format = '%k:%M';
1573
-		else
1574
-			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1625
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1626
+					$time_format = '%k:%M';
1627
+		} else {
1628
+					$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1629
+		}
1575 1630
 	}
1576 1631
 
1577 1632
 	// Should this be an all day event?
@@ -1581,11 +1636,13 @@  discard block
 block discarded – undo
1581 1636
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1582 1637
 
1583 1638
 	// We need to have a defined timezone in the steps below
1584
-	if (empty($row['timezone']))
1585
-		$row['timezone'] = getUserTimezone();
1639
+	if (empty($row['timezone'])) {
1640
+			$row['timezone'] = getUserTimezone();
1641
+	}
1586 1642
 
1587
-	if (empty($timezone_array[$row['timezone']]))
1588
-		$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1643
+	if (empty($timezone_array[$row['timezone']])) {
1644
+			$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1645
+	}
1589 1646
 
1590 1647
 	// Get most of the standard date information for the start and end datetimes
1591 1648
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1633,8 +1690,9 @@  discard block
 block discarded – undo
1633 1690
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1634 1691
 	static $member_cache = array();
1635 1692
 
1636
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1637
-		$id_member = $context['user']['id'];
1693
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1694
+			$id_member = $context['user']['id'];
1695
+	}
1638 1696
 
1639 1697
 	//check if the cache got the data
1640 1698
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1663,11 +1721,13 @@  discard block
 block discarded – undo
1663 1721
 		$smcFunc['db_free_result']($request);
1664 1722
 	}
1665 1723
 
1666
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1667
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1724
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1725
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1726
+	}
1668 1727
 
1669
-	if (isset($id_member))
1670
-		$member_cache[$id_member] = $timezone;
1728
+	if (isset($id_member)) {
1729
+			$member_cache[$id_member] = $timezone;
1730
+	}
1671 1731
 
1672 1732
 	return $timezone;
1673 1733
 }
@@ -1696,8 +1756,9 @@  discard block
 block discarded – undo
1696 1756
 		)
1697 1757
 	);
1698 1758
 	$holidays = array();
1699
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1700
-		$holidays[] = $row;
1759
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1760
+			$holidays[] = $row;
1761
+	}
1701 1762
 	$smcFunc['db_free_result']($request);
1702 1763
 
1703 1764
 	return $holidays;
Please login to merge, or discard this patch.
Sources/Profile-View.php 1 patch
Braces   +303 added lines, -222 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -195,9 +202,10 @@  discard block
 block discarded – undo
195 202
 	$context['print_custom_fields'] = array();
196 203
 
197 204
 	// Any custom profile fields?
198
-	if (!empty($context['custom_fields']))
199
-		foreach ($context['custom_fields'] as $custom)
205
+	if (!empty($context['custom_fields'])) {
206
+			foreach ($context['custom_fields'] as $custom)
200 207
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
208
+	}
201 209
 
202 210
 }
203 211
 
@@ -242,16 +250,18 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	if($withSender)
251 260
 	{
252 261
 		$senders = loadMemberData($senders);
253
-		foreach ($senders as $member)
254
-			loadMemberContext($member);
262
+		foreach ($senders as $member) {
263
+					loadMemberContext($member);
264
+		}
255 265
 	}
256 266
 
257 267
 	// Now go through and actually make with the text.
@@ -266,12 +276,15 @@  discard block
 block discarded – undo
266 276
 	$msgs = array();
267 277
 	foreach ($alerts as $id_alert => $alert)
268 278
 	{
269
-		if (isset($alert['extra']['board']))
270
-			$boards[$alert['extra']['board']] = $txt['board_na'];
271
-		if (isset($alert['extra']['topic']))
272
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
273
-		if ($alert['content_type'] == 'msg')
274
-			$msgs[$alert['content_id']] = $txt['topic_na'];
279
+		if (isset($alert['extra']['board'])) {
280
+					$boards[$alert['extra']['board']] = $txt['board_na'];
281
+		}
282
+		if (isset($alert['extra']['topic'])) {
283
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
284
+		}
285
+		if ($alert['content_type'] == 'msg') {
286
+					$msgs[$alert['content_id']] = $txt['topic_na'];
287
+		}
275 288
 	}
276 289
 
277 290
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -286,8 +299,9 @@  discard block
 block discarded – undo
286 299
 				'boards' => array_keys($boards),
287 300
 			)
288 301
 		);
289
-		while ($row = $smcFunc['db_fetch_assoc']($request))
290
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
304
+		}
291 305
 	}
292 306
 	if (!empty($topics))
293 307
 	{
@@ -302,8 +316,9 @@  discard block
 block discarded – undo
302 316
 				'topics' => array_keys($topics),
303 317
 			)
304 318
 		);
305
-		while ($row = $smcFunc['db_fetch_assoc']($request))
306
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
319
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
320
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
321
+		}
307 322
 	}
308 323
 	if (!empty($msgs))
309 324
 	{
@@ -318,44 +333,51 @@  discard block
 block discarded – undo
318 333
 				'msgs' => array_keys($msgs),
319 334
 			)
320 335
 		);
321
-		while ($row = $smcFunc['db_fetch_assoc']($request))
322
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
336
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
337
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
338
+		}
323 339
 	}
324 340
 
325 341
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
326 342
 	foreach ($alerts as $id_alert => $alert)
327 343
 	{
328
-		if (!empty($alert['text']))
329
-			continue;
330
-		if (isset($alert['extra']['board']))
331
-			if ($boards[$alert['extra']['board']] == $txt['board_na'])
344
+		if (!empty($alert['text'])) {
345
+					continue;
346
+		}
347
+		if (isset($alert['extra']['board'])) {
348
+					if ($boards[$alert['extra']['board']] == $txt['board_na'])
332 349
 			{
333 350
 				unset($alerts[$id_alert]);
351
+		}
334 352
 				continue;
353
+			} else {
354
+							$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
335 355
 			}
336
-			else
337
-				$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
338
-		if (isset($alert['extra']['topic']))
339
-			if ($alert['extra']['topic'] == $txt['topic_na'])
356
+		if (isset($alert['extra']['topic'])) {
357
+					if ($alert['extra']['topic'] == $txt['topic_na'])
340 358
 			{
341 359
 				unset($alerts[$id_alert]);
360
+		}
342 361
 				continue;
362
+			} else {
363
+							$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
343 364
 			}
344
-			else
345
-				$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
346
-		if ($alert['content_type'] == 'msg')
347
-			if ($msgs[$alert['content_id']] == $txt['topic_na'])
365
+		if ($alert['content_type'] == 'msg') {
366
+					if ($msgs[$alert['content_id']] == $txt['topic_na'])
348 367
 			{
349 368
 				unset($alerts[$id_alert]);
369
+		}
350 370
 				continue;
351
-			}				
352
-			else
353
-				$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
354
-		if ($alert['content_type'] == 'profile')
355
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
371
+			} else {
372
+							$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
373
+			}
374
+		if ($alert['content_type'] == 'profile') {
375
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
376
+		}
356 377
 
357
-		if (!empty($memberContext[$alert['sender_id']]))
358
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
378
+		if (!empty($memberContext[$alert['sender_id']])) {
379
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
380
+		}
359 381
 
360 382
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
361 383
 		if (isset($txt[$string]))
@@ -443,11 +465,11 @@  discard block
 block discarded – undo
443 465
 		checkSession('request');
444 466
 
445 467
 		// Call it!
446
-		if ($action == 'remove')
447
-			alert_delete($toMark, $memID);
448
-
449
-		else
450
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
468
+		if ($action == 'remove') {
469
+					alert_delete($toMark, $memID);
470
+		} else {
471
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
472
+		}
451 473
 
452 474
 		// Set a nice update message.
453 475
 		$_SESSION['update_message'] = true;
@@ -497,23 +519,27 @@  discard block
 block discarded – undo
497 519
 	);
498 520
 
499 521
 	// Set the page title
500
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
501
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
502
-	else
503
-		$context['page_title'] = $txt['showPosts'];
522
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
523
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
524
+	} else {
525
+			$context['page_title'] = $txt['showPosts'];
526
+	}
504 527
 
505 528
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
506 529
 
507 530
 	// Is the load average too high to allow searching just now?
508
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
509
-		fatal_lang_error('loadavg_show_posts_disabled', false);
531
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
532
+			fatal_lang_error('loadavg_show_posts_disabled', false);
533
+	}
510 534
 
511 535
 	// If we're specifically dealing with attachments use that function!
512
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
513
-		return showAttachments($memID);
536
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
537
+			return showAttachments($memID);
538
+	}
514 539
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
515
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
516
-		return showUnwatched($memID);
540
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
541
+			return showUnwatched($memID);
542
+	}
517 543
 
518 544
 	// Are we just viewing topics?
519 545
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -536,27 +562,30 @@  discard block
 block discarded – undo
536 562
 		$smcFunc['db_free_result']($request);
537 563
 
538 564
 		// Trying to remove a message that doesn't exist.
539
-		if (empty($info))
540
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
565
+		if (empty($info)) {
566
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
567
+		}
541 568
 
542 569
 		// We can be lazy, since removeMessage() will check the permissions for us.
543 570
 		require_once($sourcedir . '/RemoveTopic.php');
544 571
 		removeMessage((int) $_GET['delete']);
545 572
 
546 573
 		// Add it to the mod log.
547
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
548
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
574
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
575
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
576
+		}
549 577
 
550 578
 		// Back to... where we are now ;).
551 579
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
552 580
 	}
553 581
 
554 582
 	// Default to 10.
555
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
556
-		$_REQUEST['viewscount'] = '10';
583
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
584
+			$_REQUEST['viewscount'] = '10';
585
+	}
557 586
 
558
-	if ($context['is_topics'])
559
-		$request = $smcFunc['db_query']('', '
587
+	if ($context['is_topics']) {
588
+			$request = $smcFunc['db_query']('', '
560 589
 			SELECT COUNT(*)
561 590
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
562 591
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -569,8 +598,8 @@  discard block
 block discarded – undo
569 598
 				'board' => $board,
570 599
 			)
571 600
 		);
572
-	else
573
-		$request = $smcFunc['db_query']('', '
601
+	} else {
602
+			$request = $smcFunc['db_query']('', '
574 603
 			SELECT COUNT(*)
575 604
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
576 605
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -583,6 +612,7 @@  discard block
 block discarded – undo
583 612
 				'board' => $board,
584 613
 			)
585 614
 		);
615
+	}
586 616
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
587 617
 	$smcFunc['db_free_result']($request);
588 618
 
@@ -603,10 +633,11 @@  discard block
 block discarded – undo
603 633
 
604 634
 	$range_limit = '';
605 635
 
606
-	if ($context['is_topics'])
607
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
608
-	else
609
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
636
+	if ($context['is_topics']) {
637
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
638
+	} else {
639
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
640
+	}
610 641
 
611 642
 	$maxIndex = $maxPerPage;
612 643
 
@@ -632,9 +663,9 @@  discard block
 block discarded – undo
632 663
 		{
633 664
 			$margin *= 5;
634 665
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
666
+		} else {
667
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
635 668
 		}
636
-		else
637
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
638 669
 	}
639 670
 
640 671
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -666,8 +697,7 @@  discard block
 block discarded – undo
666 697
 					'max' => $maxIndex,
667 698
 				)
668 699
 			);
669
-		}
670
-		else
700
+		} else
671 701
 		{
672 702
 			$request = $smcFunc['db_query']('', '
673 703
 				SELECT
@@ -696,8 +726,9 @@  discard block
 block discarded – undo
696 726
 		}
697 727
 
698 728
 		// Make sure we quit this loop.
699
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
700
-			break;
729
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
730
+					break;
731
+		}
701 732
 		$looped = true;
702 733
 		$range_limit = '';
703 734
 	}
@@ -741,19 +772,21 @@  discard block
 block discarded – undo
741 772
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
742 773
 		);
743 774
 
744
-		if ($user_info['id'] == $row['id_member_started'])
745
-			$board_ids['own'][$row['id_board']][] = $counter;
775
+		if ($user_info['id'] == $row['id_member_started']) {
776
+					$board_ids['own'][$row['id_board']][] = $counter;
777
+		}
746 778
 		$board_ids['any'][$row['id_board']][] = $counter;
747 779
 	}
748 780
 	$smcFunc['db_free_result']($request);
749 781
 
750 782
 	// All posts were retrieved in reverse order, get them right again.
751
-	if ($reverse)
752
-		$context['posts'] = array_reverse($context['posts'], true);
783
+	if ($reverse) {
784
+			$context['posts'] = array_reverse($context['posts'], true);
785
+	}
753 786
 
754 787
 	// These are all the permissions that are different from board to board..
755
-	if ($context['is_topics'])
756
-		$permissions = array(
788
+	if ($context['is_topics']) {
789
+			$permissions = array(
757 790
 			'own' => array(
758 791
 				'post_reply_own' => 'can_reply',
759 792
 			),
@@ -761,8 +794,8 @@  discard block
 block discarded – undo
761 794
 				'post_reply_any' => 'can_reply',
762 795
 			)
763 796
 		);
764
-	else
765
-		$permissions = array(
797
+	} else {
798
+			$permissions = array(
766 799
 			'own' => array(
767 800
 				'post_reply_own' => 'can_reply',
768 801
 				'delete_own' => 'can_delete',
@@ -772,6 +805,7 @@  discard block
 block discarded – undo
772 805
 				'delete_any' => 'can_delete',
773 806
 			)
774 807
 		);
808
+	}
775 809
 
776 810
 	// For every permission in the own/any lists...
777 811
 	foreach ($permissions as $type => $list)
@@ -782,19 +816,22 @@  discard block
 block discarded – undo
782 816
 			$boards = boardsAllowedTo($permission);
783 817
 
784 818
 			// Hmm, they can do it on all boards, can they?
785
-			if (!empty($boards) && $boards[0] == 0)
786
-				$boards = array_keys($board_ids[$type]);
819
+			if (!empty($boards) && $boards[0] == 0) {
820
+							$boards = array_keys($board_ids[$type]);
821
+			}
787 822
 
788 823
 			// Now go through each board they can do the permission on.
789 824
 			foreach ($boards as $board_id)
790 825
 			{
791 826
 				// There aren't any posts displayed from this board.
792
-				if (!isset($board_ids[$type][$board_id]))
793
-					continue;
827
+				if (!isset($board_ids[$type][$board_id])) {
828
+									continue;
829
+				}
794 830
 
795 831
 				// Set the permission to true ;).
796
-				foreach ($board_ids[$type][$board_id] as $counter)
797
-					$context['posts'][$counter][$allowed] = true;
832
+				foreach ($board_ids[$type][$board_id] as $counter) {
833
+									$context['posts'][$counter][$allowed] = true;
834
+				}
798 835
 			}
799 836
 		}
800 837
 	}
@@ -825,8 +862,9 @@  discard block
 block discarded – undo
825 862
 	$boardsAllowed = boardsAllowedTo('view_attachments');
826 863
 
827 864
 	// Make sure we can't actually see anything...
828
-	if (empty($boardsAllowed))
829
-		$boardsAllowed = array(-1);
865
+	if (empty($boardsAllowed)) {
866
+			$boardsAllowed = array(-1);
867
+	}
830 868
 
831 869
 	require_once($sourcedir . '/Subs-List.php');
832 870
 
@@ -977,8 +1015,8 @@  discard block
 block discarded – undo
977 1015
 		)
978 1016
 	);
979 1017
 	$attachments = array();
980
-	while ($row = $smcFunc['db_fetch_assoc']($request))
981
-		$attachments[] = array(
1018
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1019
+			$attachments[] = array(
982 1020
 			'id' => $row['id_attach'],
983 1021
 			'filename' => $row['filename'],
984 1022
 			'downloads' => $row['downloads'],
@@ -990,6 +1028,7 @@  discard block
 block discarded – undo
990 1028
 			'board_name' => $row['name'],
991 1029
 			'approved' => $row['approved'],
992 1030
 		);
1031
+	}
993 1032
 
994 1033
 	$smcFunc['db_free_result']($request);
995 1034
 
@@ -1044,8 +1083,9 @@  discard block
 block discarded – undo
1044 1083
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1045 1084
 
1046 1085
 	// Only the owner can see the list (if the function is enabled of course)
1047
-	if ($user_info['id'] != $memID)
1048
-		return;
1086
+	if ($user_info['id'] != $memID) {
1087
+			return;
1088
+	}
1049 1089
 
1050 1090
 	require_once($sourcedir . '/Subs-List.php');
1051 1091
 
@@ -1191,8 +1231,9 @@  discard block
 block discarded – undo
1191 1231
 	);
1192 1232
 
1193 1233
 	$topics = array();
1194
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1195
-		$topics[] = $row['id_topic'];
1234
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1235
+			$topics[] = $row['id_topic'];
1236
+	}
1196 1237
 
1197 1238
 	$smcFunc['db_free_result']($request);
1198 1239
 
@@ -1212,8 +1253,9 @@  discard block
 block discarded – undo
1212 1253
 				'topics' => $topics,
1213 1254
 			)
1214 1255
 		);
1215
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1216
-			$topicsInfo[] = $row;
1256
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1257
+					$topicsInfo[] = $row;
1258
+		}
1217 1259
 		$smcFunc['db_free_result']($request);
1218 1260
 	}
1219 1261
 
@@ -1261,8 +1303,9 @@  discard block
 block discarded – undo
1261 1303
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1262 1304
 
1263 1305
 	// Is the load average too high to allow searching just now?
1264
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1265
-		fatal_lang_error('loadavg_userstats_disabled', false);
1306
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1307
+			fatal_lang_error('loadavg_userstats_disabled', false);
1308
+	}
1266 1309
 
1267 1310
 	// General user statistics.
1268 1311
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1405,11 +1448,13 @@  discard block
 block discarded – undo
1405 1448
 	}
1406 1449
 	$smcFunc['db_free_result']($result);
1407 1450
 
1408
-	if ($maxPosts > 0)
1409
-		for ($hour = 0; $hour < 24; $hour++)
1451
+	if ($maxPosts > 0) {
1452
+			for ($hour = 0;
1453
+	}
1454
+	$hour < 24; $hour++)
1410 1455
 		{
1411
-			if (!isset($context['posts_by_time'][$hour]))
1412
-				$context['posts_by_time'][$hour] = array(
1456
+			if (!isset($context['posts_by_time'][$hour])) {
1457
+							$context['posts_by_time'][$hour] = array(
1413 1458
 					'hour' => $hour,
1414 1459
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1415 1460
 					'posts' => 0,
@@ -1417,7 +1462,7 @@  discard block
 block discarded – undo
1417 1462
 					'relative_percent' => 0,
1418 1463
 					'is_last' => $hour == 23,
1419 1464
 				);
1420
-			else
1465
+			} else
1421 1466
 			{
1422 1467
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1423 1468
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1450,8 +1495,9 @@  discard block
 block discarded – undo
1450 1495
 
1451 1496
 	foreach ($subActions as $sa => $action)
1452 1497
 	{
1453
-		if (!allowedTo($action[2]))
1454
-			unset($subActions[$sa]);
1498
+		if (!allowedTo($action[2])) {
1499
+					unset($subActions[$sa]);
1500
+		}
1455 1501
 	}
1456 1502
 
1457 1503
 	// Create the tabs for the template.
@@ -1469,15 +1515,18 @@  discard block
 block discarded – undo
1469 1515
 	);
1470 1516
 
1471 1517
 	// Moderation must be on to track edits.
1472
-	if (empty($modSettings['userlog_enabled']))
1473
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1518
+	if (empty($modSettings['userlog_enabled'])) {
1519
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1520
+	}
1474 1521
 
1475 1522
 	// Group requests must be active to show it...
1476
-	if (empty($modSettings['show_group_membership']))
1477
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1523
+	if (empty($modSettings['show_group_membership'])) {
1524
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1525
+	}
1478 1526
 
1479
-	if (empty($subActions))
1480
-		fatal_lang_error('no_access', false);
1527
+	if (empty($subActions)) {
1528
+			fatal_lang_error('no_access', false);
1529
+	}
1481 1530
 
1482 1531
 	$keys = array_keys($subActions);
1483 1532
 	$default = array_shift($keys);
@@ -1490,9 +1539,10 @@  discard block
 block discarded – undo
1490 1539
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1491 1540
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1492 1541
 
1493
-	if (!empty($call))
1494
-		call_user_func($call, $memID);
1495
-}
1542
+	if (!empty($call)) {
1543
+			call_user_func($call, $memID);
1544
+	}
1545
+	}
1496 1546
 
1497 1547
 /**
1498 1548
  * Handles tracking a user's activity
@@ -1508,8 +1558,9 @@  discard block
 block discarded – undo
1508 1558
 	isAllowedTo('moderate_forum');
1509 1559
 
1510 1560
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1511
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1512
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1561
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1562
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1563
+	}
1513 1564
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1514 1565
 
1515 1566
 	// Set the options for the list component.
@@ -1675,8 +1726,9 @@  discard block
 block discarded – undo
1675 1726
 			)
1676 1727
 		);
1677 1728
 		$message_members = array();
1678
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1679
-			$message_members[] = $row['id_member'];
1729
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1730
+					$message_members[] = $row['id_member'];
1731
+		}
1680 1732
 		$smcFunc['db_free_result']($request);
1681 1733
 
1682 1734
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1691,8 +1743,9 @@  discard block
 block discarded – undo
1691 1743
 					'ip_list' => $ips,
1692 1744
 				)
1693 1745
 			);
1694
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1695
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1746
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1747
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1748
+			}
1696 1749
 			$smcFunc['db_free_result']($request);
1697 1750
 		}
1698 1751
 
@@ -1706,8 +1759,9 @@  discard block
 block discarded – undo
1706 1759
 				'ip_list' => $ips,
1707 1760
 			)
1708 1761
 		);
1709
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1710
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1762
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1763
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1764
+		}
1711 1765
 		$smcFunc['db_free_result']($request);
1712 1766
 	}
1713 1767
 }
@@ -1767,8 +1821,8 @@  discard block
 block discarded – undo
1767 1821
 		))
1768 1822
 	);
1769 1823
 	$error_messages = array();
1770
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1771
-		$error_messages[] = array(
1824
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1825
+			$error_messages[] = array(
1772 1826
 			'ip' => inet_dtop($row['ip']),
1773 1827
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1774 1828
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1776,6 +1830,7 @@  discard block
 block discarded – undo
1776 1830
 			'time' => timeformat($row['log_time']),
1777 1831
 			'timestamp' => forum_time(true, $row['log_time']),
1778 1832
 		);
1833
+	}
1779 1834
 	$smcFunc['db_free_result']($request);
1780 1835
 
1781 1836
 	return $error_messages;
@@ -1838,8 +1893,8 @@  discard block
 block discarded – undo
1838 1893
 		))
1839 1894
 	);
1840 1895
 	$messages = array();
1841
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1842
-		$messages[] = array(
1896
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1897
+			$messages[] = array(
1843 1898
 			'ip' => inet_dtop($row['poster_ip']),
1844 1899
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1845 1900
 			'board' => array(
@@ -1852,6 +1907,7 @@  discard block
 block discarded – undo
1852 1907
 			'time' => timeformat($row['poster_time']),
1853 1908
 			'timestamp' => forum_time(true, $row['poster_time'])
1854 1909
 		);
1910
+	}
1855 1911
 	$smcFunc['db_free_result']($request);
1856 1912
 
1857 1913
 	return $messages;
@@ -1878,19 +1934,20 @@  discard block
 block discarded – undo
1878 1934
 		$context['sub_template'] = 'trackIP';
1879 1935
 		$context['page_title'] = $txt['profile'];
1880 1936
 		$context['base_url'] = $scripturl . '?action=trackip';
1881
-	}
1882
-	else
1937
+	} else
1883 1938
 	{
1884 1939
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1885 1940
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1886 1941
 	}
1887 1942
 
1888 1943
 	// Searching?
1889
-	if (isset($_REQUEST['searchip']))
1890
-		$context['ip'] = trim($_REQUEST['searchip']);
1944
+	if (isset($_REQUEST['searchip'])) {
1945
+			$context['ip'] = trim($_REQUEST['searchip']);
1946
+	}
1891 1947
 
1892
-	if (isValidIP($context['ip']) === false)
1893
-		fatal_lang_error('invalid_tracking_ip', false);
1948
+	if (isValidIP($context['ip']) === false) {
1949
+			fatal_lang_error('invalid_tracking_ip', false);
1950
+	}
1894 1951
 
1895 1952
 	//mysql didn't support like search with varbinary
1896 1953
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1898,8 +1955,9 @@  discard block
 block discarded – undo
1898 1955
 	$ip_var = $context['ip'];
1899 1956
 	$ip_string = '= {inet:ip_address}';
1900 1957
 
1901
-	if (empty($context['tracking_area']))
1902
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1958
+	if (empty($context['tracking_area'])) {
1959
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1960
+	}
1903 1961
 
1904 1962
 	$request = $smcFunc['db_query']('', '
1905 1963
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1910,8 +1968,9 @@  discard block
 block discarded – undo
1910 1968
 		)
1911 1969
 	);
1912 1970
 	$context['ips'] = array();
1913
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1914
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1971
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1972
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1973
+	}
1915 1974
 	$smcFunc['db_free_result']($request);
1916 1975
 
1917 1976
 	ksort($context['ips']);
@@ -2140,8 +2199,9 @@  discard block
 block discarded – undo
2140 2199
 		foreach ($context['whois_servers'] as $whois)
2141 2200
 		{
2142 2201
 			// Strip off the "decimal point" and anything following...
2143
-			if (in_array((int) $context['ip'], $whois['range']))
2144
-				$context['auto_whois_server'] = $whois;
2202
+			if (in_array((int) $context['ip'], $whois['range'])) {
2203
+							$context['auto_whois_server'] = $whois;
2204
+			}
2145 2205
 		}
2146 2206
 	}
2147 2207
 }
@@ -2158,10 +2218,11 @@  discard block
 block discarded – undo
2158 2218
 	// Gonna want this for the list.
2159 2219
 	require_once($sourcedir . '/Subs-List.php');
2160 2220
 
2161
-	if ($memID == 0)
2162
-		$context['base_url'] = $scripturl . '?action=trackip';
2163
-	else
2164
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2221
+	if ($memID == 0) {
2222
+			$context['base_url'] = $scripturl . '?action=trackip';
2223
+	} else {
2224
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2225
+	}
2165 2226
 
2166 2227
 	// Start with the user messages.
2167 2228
 	$listOptions = array(
@@ -2271,12 +2332,13 @@  discard block
 block discarded – undo
2271 2332
 		)
2272 2333
 	);
2273 2334
 	$logins = array();
2274
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2275
-		$logins[] = array(
2335
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2336
+			$logins[] = array(
2276 2337
 			'time' => timeformat($row['time']),
2277 2338
 			'ip' => inet_dtop($row['ip']),
2278 2339
 			'ip2' => inet_dtop($row['ip2']),
2279 2340
 		);
2341
+	}
2280 2342
 	$smcFunc['db_free_result']($request);
2281 2343
 
2282 2344
 	return $logins;
@@ -2301,11 +2363,12 @@  discard block
 block discarded – undo
2301 2363
 		)
2302 2364
 	);
2303 2365
 	$context['custom_field_titles'] = array();
2304
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2305
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2366
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2367
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2306 2368
 			'title' => $row['field_name'],
2307 2369
 			'parse_bbc' => $row['bbc'],
2308 2370
 		);
2371
+	}
2309 2372
 	$smcFunc['db_free_result']($request);
2310 2373
 
2311 2374
 	// Set the options for the error lists.
@@ -2444,19 +2507,22 @@  discard block
 block discarded – undo
2444 2507
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2445 2508
 	{
2446 2509
 		$extra = $smcFunc['json_decode']($row['extra'], true);
2447
-		if (!empty($extra['applicator']))
2448
-			$members[] = $extra['applicator'];
2510
+		if (!empty($extra['applicator'])) {
2511
+					$members[] = $extra['applicator'];
2512
+		}
2449 2513
 
2450 2514
 		// Work out what the name of the action is.
2451
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2452
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2453
-		elseif (isset($txt[$row['action']]))
2454
-			$action_text = $txt[$row['action']];
2515
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2516
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2517
+		} elseif (isset($txt[$row['action']])) {
2518
+					$action_text = $txt[$row['action']];
2519
+		}
2455 2520
 		// Custom field?
2456
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2457
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2458
-		else
2459
-			$action_text = $row['action'];
2521
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2522
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2523
+		} else {
2524
+					$action_text = $row['action'];
2525
+		}
2460 2526
 
2461 2527
 		// Parse BBC?
2462 2528
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2488,13 +2554,15 @@  discard block
 block discarded – undo
2488 2554
 			)
2489 2555
 		);
2490 2556
 		$members = array();
2491
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2492
-			$members[$row['id_member']] = $row['real_name'];
2557
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2558
+					$members[$row['id_member']] = $row['real_name'];
2559
+		}
2493 2560
 		$smcFunc['db_free_result']($request);
2494 2561
 
2495
-		foreach ($edits as $key => $value)
2496
-			if (isset($members[$value['id_member']]))
2562
+		foreach ($edits as $key => $value) {
2563
+					if (isset($members[$value['id_member']]))
2497 2564
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2565
+		}
2498 2566
 	}
2499 2567
 
2500 2568
 	return $edits;
@@ -2695,10 +2763,11 @@  discard block
 block discarded – undo
2695 2763
 	$context['board'] = $board;
2696 2764
 
2697 2765
 	// Determine which groups this user is in.
2698
-	if (empty($user_profile[$memID]['additional_groups']))
2699
-		$curGroups = array();
2700
-	else
2701
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2766
+	if (empty($user_profile[$memID]['additional_groups'])) {
2767
+			$curGroups = array();
2768
+	} else {
2769
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2770
+	}
2702 2771
 	$curGroups[] = $user_profile[$memID]['id_group'];
2703 2772
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2704 2773
 
@@ -2718,28 +2787,30 @@  discard block
 block discarded – undo
2718 2787
 	$context['no_access_boards'] = array();
2719 2788
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2720 2789
 	{
2721
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2722
-			$context['no_access_boards'][] = array(
2790
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2791
+					$context['no_access_boards'][] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'is_last' => false,
2726 2795
 			);
2727
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2728
-			$context['boards'][$row['id_board']] = array(
2796
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2797
+					$context['boards'][$row['id_board']] = array(
2729 2798
 				'id' => $row['id_board'],
2730 2799
 				'name' => $row['name'],
2731 2800
 				'selected' => $board == $row['id_board'],
2732 2801
 				'profile' => $row['id_profile'],
2733 2802
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2734 2803
 			);
2804
+		}
2735 2805
 	}
2736 2806
 	$smcFunc['db_free_result']($request);
2737 2807
 
2738 2808
 	require_once($sourcedir . '/Subs-Boards.php');
2739 2809
 	sortBoards($context['boards']);
2740 2810
 
2741
-	if (!empty($context['no_access_boards']))
2742
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2811
+	if (!empty($context['no_access_boards'])) {
2812
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2813
+	}
2743 2814
 
2744 2815
 	$context['member']['permissions'] = array(
2745 2816
 		'general' => array(),
@@ -2748,8 +2819,9 @@  discard block
 block discarded – undo
2748 2819
 
2749 2820
 	// If you're an admin we know you can do everything, we might as well leave.
2750 2821
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2751
-	if ($context['member']['has_all_permissions'])
2752
-		return;
2822
+	if ($context['member']['has_all_permissions']) {
2823
+			return;
2824
+	}
2753 2825
 
2754 2826
 	$denied = array();
2755 2827
 
@@ -2768,21 +2840,24 @@  discard block
 block discarded – undo
2768 2840
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2769 2841
 	{
2770 2842
 		// We don't know about this permission, it doesn't exist :P.
2771
-		if (!isset($txt['permissionname_' . $row['permission']]))
2772
-			continue;
2843
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2844
+					continue;
2845
+		}
2773 2846
 
2774
-		if (empty($row['add_deny']))
2775
-			$denied[] = $row['permission'];
2847
+		if (empty($row['add_deny'])) {
2848
+					$denied[] = $row['permission'];
2849
+		}
2776 2850
 
2777 2851
 		// Permissions that end with _own or _any consist of two parts.
2778
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2779
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2780
-		else
2781
-			$name = $txt['permissionname_' . $row['permission']];
2852
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2853
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2854
+		} else {
2855
+					$name = $txt['permissionname_' . $row['permission']];
2856
+		}
2782 2857
 
2783 2858
 		// Add this permission if it doesn't exist yet.
2784
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2785
-			$context['member']['permissions']['general'][$row['permission']] = array(
2859
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2860
+					$context['member']['permissions']['general'][$row['permission']] = array(
2786 2861
 				'id' => $row['permission'],
2787 2862
 				'groups' => array(
2788 2863
 					'allowed' => array(),
@@ -2792,6 +2867,7 @@  discard block
 block discarded – undo
2792 2867
 				'is_denied' => false,
2793 2868
 				'is_global' => true,
2794 2869
 			);
2870
+		}
2795 2871
 
2796 2872
 		// Add the membergroup to either the denied or the allowed groups.
2797 2873
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2825,18 +2901,20 @@  discard block
 block discarded – undo
2825 2901
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2826 2902
 	{
2827 2903
 		// We don't know about this permission, it doesn't exist :P.
2828
-		if (!isset($txt['permissionname_' . $row['permission']]))
2829
-			continue;
2904
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2905
+					continue;
2906
+		}
2830 2907
 
2831 2908
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2832
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2833
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2834
-		else
2835
-			$name = $txt['permissionname_' . $row['permission']];
2909
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2910
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2911
+		} else {
2912
+					$name = $txt['permissionname_' . $row['permission']];
2913
+		}
2836 2914
 
2837 2915
 		// Create the structure for this permission.
2838
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2839
-			$context['member']['permissions']['board'][$row['permission']] = array(
2916
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2917
+					$context['member']['permissions']['board'][$row['permission']] = array(
2840 2918
 				'id' => $row['permission'],
2841 2919
 				'groups' => array(
2842 2920
 					'allowed' => array(),
@@ -2846,6 +2924,7 @@  discard block
 block discarded – undo
2846 2924
 				'is_denied' => false,
2847 2925
 				'is_global' => empty($board),
2848 2926
 			);
2927
+		}
2849 2928
 
2850 2929
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2851 2930
 
@@ -2864,8 +2943,9 @@  discard block
 block discarded – undo
2864 2943
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2865 2944
 
2866 2945
 	// Firstly, can we actually even be here?
2867
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2868
-		fatal_lang_error('no_access', false);
2946
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2947
+			fatal_lang_error('no_access', false);
2948
+	}
2869 2949
 
2870 2950
 	// Make sure things which are disabled stay disabled.
2871 2951
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2952,9 +3032,10 @@  discard block
 block discarded – undo
2952 3032
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2953 3033
 	);
2954 3034
 	$context['current_level'] = 0;
2955
-	foreach ($context['level_effects'] as $limit => $dummy)
2956
-		if ($context['member']['warning'] >= $limit)
3035
+	foreach ($context['level_effects'] as $limit => $dummy) {
3036
+			if ($context['member']['warning'] >= $limit)
2957 3037
 			$context['current_level'] = $limit;
2958
-}
3038
+	}
3039
+	}
2959 3040
 
2960 3041
 ?>
2961 3042
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Class-CacheAPI.php 1 patch
Braces   +20 added lines, -15 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Interface cache_api_interface
@@ -182,8 +183,9 @@  discard block
 block discarded – undo
182 183
 	{
183 184
 		global $cache_enable;
184 185
 
185
-		if ($test)
186
-			return true;
186
+		if ($test) {
187
+					return true;
188
+		}
187 189
 		return !empty($cache_enable);
188 190
 	}
189 191
 
@@ -202,18 +204,20 @@  discard block
 block discarded – undo
202 204
 		global $boardurl, $cachedir;
203 205
 
204 206
 		// Find a valid good file to do mtime checks on.
205
-		if (file_exists($cachedir . '/' . 'index.php'))
206
-			$filemtime = $cachedir . '/' . 'index.php';
207
-		elseif (is_dir($cachedir . '/'))
208
-			$filemtime = $cachedir . '/';
209
-		else
210
-			$filemtime = $boardurl . '/index.php';
207
+		if (file_exists($cachedir . '/' . 'index.php')) {
208
+					$filemtime = $cachedir . '/' . 'index.php';
209
+		} elseif (is_dir($cachedir . '/')) {
210
+					$filemtime = $cachedir . '/';
211
+		} else {
212
+					$filemtime = $boardurl . '/index.php';
213
+		}
211 214
 
212 215
 		// Set the default if no prefix was specified.
213
-		if (empty($prefix))
214
-			$this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-';
215
-		else
216
-			$this->prefix = $prefix;
216
+		if (empty($prefix)) {
217
+					$this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-';
218
+		} else {
219
+					$this->prefix = $prefix;
220
+		}
217 221
 
218 222
 		return true;
219 223
 	}
@@ -276,8 +280,9 @@  discard block
 block discarded – undo
276 280
 
277 281
 		// Invalidate cache, to be sure!
278 282
 		// ... as long as index.php can be modified, anyway.
279
-		if (is_writable($cachedir . '/' . 'index.php'))
280
-			@touch($cachedir . '/' . 'index.php');
283
+		if (is_writable($cachedir . '/' . 'index.php')) {
284
+					@touch($cachedir . '/' . 'index.php');
285
+		}
281 286
 
282 287
 		return true;
283 288
 	}
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 1 patch
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -68,8 +69,9 @@  discard block
 block discarded – undo
68 69
 	{
69 70
 		$supported = class_exists("SQLite3") && is_writable($this->cachedir);
70 71
 
71
-		if ($test)
72
-			return $supported;
72
+		if ($test) {
73
+					return $supported;
74
+		}
73 75
 
74 76
 		return parent::isSupported() && $supported;
75 77
 	}
@@ -84,8 +86,9 @@  discard block
 block discarded – undo
84 86
 		$result = $this->cacheDB->query($query);
85 87
 
86 88
 		$value = null;
87
-		while ($res = $result->fetchArray(SQLITE3_ASSOC))
88
-			$value = $res['value'];
89
+		while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
90
+					$value = $res['value'];
91
+		}
89 92
 
90 93
 		return !empty($value) ? $value : null;
91 94
 	}
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 		$config_vars[] = $txt['cache_sqlite_settings'];
126 129
 		$config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir');
127 130
 
128
-		if (!isset($context['settings_post_javascript']))
129
-			$context['settings_post_javascript'] = '';
131
+		if (!isset($context['settings_post_javascript'])) {
132
+					$context['settings_post_javascript'] = '';
133
+		}
130 134
 
131 135
 		$context['settings_post_javascript'] .= '
132 136
 			$("#cache_accelerator").change(function (e) {
@@ -149,10 +153,11 @@  discard block
 block discarded – undo
149 153
 		global $cachedir_sqlite;
150 154
 
151 155
 		// If its invalid, use SMF's.
152
-		if (is_null($dir) || !is_writable($dir))
153
-			$this->cachedir = $cachedir_sqlite;
154
-		else
155
-			$this->cachedir = $dir;
156
+		if (is_null($dir) || !is_writable($dir)) {
157
+					$this->cachedir = $cachedir_sqlite;
158
+		} else {
159
+					$this->cachedir = $dir;
160
+		}
156 161
 	}
157 162
 
158 163
 	/**
Please login to merge, or discard this patch.
Sources/CacheAPI-postgres.php 1 patch
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Sources/Modlog.php 1 patch
Braces   +99 added lines, -75 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
  * Prepares the information from the moderation log for viewing.
@@ -32,14 +33,16 @@  discard block
 block discarded – undo
32 33
 
33 34
 	// Are we looking at the moderation log or the administration log.
34 35
 	$context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1;
35
-	if ($context['log_type'] == 3)
36
-		isAllowedTo('admin_forum');
36
+	if ($context['log_type'] == 3) {
37
+			isAllowedTo('admin_forum');
38
+	}
37 39
 
38 40
 	// These change dependant on whether we are viewing the moderation or admin log.
39
-	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin')
40
-		$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
41
-	else
42
-		$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
41
+	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') {
42
+			$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
43
+	} else {
44
+			$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
45
+	}
43 46
 
44 47
 	$context['can_delete'] = allowedTo('admin_forum');
45 48
 
@@ -67,8 +70,7 @@  discard block
 block discarded – undo
67 70
 		$log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate';
68 71
 		logAction('clearlog_' . $log_type, array(), $log_type);
69 72
 
70
-	}
71
-	elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
73
+	} elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
72 74
 	{
73 75
 		checkSession();
74 76
 		validateToken('mod-ml');
@@ -114,15 +116,17 @@  discard block
 block discarded – undo
114 116
 		'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
115 117
 	);
116 118
 
117
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
118
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
119
-	else
120
-		$search_params_string = $search_params['string'];
119
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
120
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
121
+	} else {
122
+			$search_params_string = $search_params['string'];
123
+	}
121 124
 
122
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
123
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
124
-	else
125
-		$search_params_type = $search_params['type'];
125
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
126
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
127
+	} else {
128
+			$search_params_type = $search_params['type'];
129
+	}
126 130
 
127 131
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
128 132
 	$search_params = array(
@@ -301,15 +305,16 @@  discard block
 block discarded – undo
301 305
 	$context['default_list'] = 'moderation_log_list';
302 306
 
303 307
 	// If a hook has changed this, respect it.
304
-	if (!empty($moderation_menu_name))
305
-		$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
306
-	elseif (isset($context['moderation_menu_name']))
307
-		$context[$context['moderation_menu_name']]['tab_data'] = array(
308
+	if (!empty($moderation_menu_name)) {
309
+			$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
310
+	} elseif (isset($context['moderation_menu_name'])) {
311
+			$context[$context['moderation_menu_name']]['tab_data'] = array(
308 312
 			'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
309 313
 			'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog',
310 314
 			'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc']
311 315
 		);
312
-}
316
+	}
317
+	}
313 318
 
314 319
 /**
315 320
  * Get the number of mod log entries.
@@ -413,30 +418,35 @@  discard block
 block discarded – undo
413 418
 		// Add on some of the column stuff info
414 419
 		if (!empty($row['id_board']))
415 420
 		{
416
-			if ($row['action'] == 'move')
417
-				$row['extra']['board_to'] = $row['id_board'];
418
-			else
419
-				$row['extra']['board'] = $row['id_board'];
421
+			if ($row['action'] == 'move') {
422
+							$row['extra']['board_to'] = $row['id_board'];
423
+			} else {
424
+							$row['extra']['board'] = $row['id_board'];
425
+			}
420 426
 		}
421 427
 
422
-		if (!empty($row['id_topic']))
423
-			$row['extra']['topic'] = $row['id_topic'];
424
-		if (!empty($row['id_msg']))
425
-			$row['extra']['message'] = $row['id_msg'];
428
+		if (!empty($row['id_topic'])) {
429
+					$row['extra']['topic'] = $row['id_topic'];
430
+		}
431
+		if (!empty($row['id_msg'])) {
432
+					$row['extra']['message'] = $row['id_msg'];
433
+		}
426 434
 
427 435
 		// Is this associated with a topic?
428
-		if (isset($row['extra']['topic']))
429
-			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
430
-		if (isset($row['extra']['new_topic']))
431
-			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
436
+		if (isset($row['extra']['topic'])) {
437
+					$topics[(int) $row['extra']['topic']][] = $row['id_action'];
438
+		}
439
+		if (isset($row['extra']['new_topic'])) {
440
+					$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
441
+		}
432 442
 
433 443
 		// How about a member?
434 444
 		if (isset($row['extra']['member']))
435 445
 		{
436 446
 			// Guests don't have names!
437
-			if (empty($row['extra']['member']))
438
-				$row['extra']['member'] = $txt['modlog_parameter_guest'];
439
-			else
447
+			if (empty($row['extra']['member'])) {
448
+							$row['extra']['member'] = $txt['modlog_parameter_guest'];
449
+			} else
440 450
 			{
441 451
 				// Try to find it...
442 452
 				$members[(int) $row['extra']['member']][] = $row['id_action'];
@@ -444,35 +454,42 @@  discard block
 block discarded – undo
444 454
 		}
445 455
 
446 456
 		// Associated with a board?
447
-		if (isset($row['extra']['board_to']))
448
-			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
449
-		if (isset($row['extra']['board_from']))
450
-			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
451
-		if (isset($row['extra']['board']))
452
-			$boards[(int) $row['extra']['board']][] = $row['id_action'];
457
+		if (isset($row['extra']['board_to'])) {
458
+					$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
459
+		}
460
+		if (isset($row['extra']['board_from'])) {
461
+					$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
462
+		}
463
+		if (isset($row['extra']['board'])) {
464
+					$boards[(int) $row['extra']['board']][] = $row['id_action'];
465
+		}
453 466
 
454 467
 		// A message?
455
-		if (isset($row['extra']['message']))
456
-			$messages[(int) $row['extra']['message']][] = $row['id_action'];
468
+		if (isset($row['extra']['message'])) {
469
+					$messages[(int) $row['extra']['message']][] = $row['id_action'];
470
+		}
457 471
 
458 472
 		// IP Info?
459
-		if (isset($row['extra']['ip_range']))
460
-			if ($seeIP)
473
+		if (isset($row['extra']['ip_range'])) {
474
+					if ($seeIP)
461 475
 				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
462
-			else
463
-				$row['extra']['ip_range'] = $txt['logged'];
476
+		} else {
477
+							$row['extra']['ip_range'] = $txt['logged'];
478
+			}
464 479
 
465 480
 		// Email?
466
-		if (isset($row['extra']['email']))
467
-			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
481
+		if (isset($row['extra']['email'])) {
482
+					$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
483
+		}
468 484
 
469 485
 		// Bans are complex.
470 486
 		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
471 487
 		{
472 488
 			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
473
-			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
474
-				if (isset($row['extra'][$type]))
489
+			foreach (array('member', 'email', 'ip_range', 'hostname') as $type) {
490
+							if (isset($row['extra'][$type]))
475 491
 					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
492
+			}
476 493
 		}
477 494
 
478 495
 		// The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
@@ -508,12 +525,13 @@  discard block
 block discarded – undo
508 525
 			foreach ($boards[$row['id_board']] as $action)
509 526
 			{
510 527
 				// Make the board number into a link - dealing with moving too.
511
-				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
512
-					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
513
-				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
514
-					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
515
-				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
516
-					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
528
+				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) {
529
+									$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
530
+				} elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) {
531
+									$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
532
+				} elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) {
533
+									$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
534
+				}
517 535
 			}
518 536
 		}
519 537
 		$smcFunc['db_free_result']($request);
@@ -547,10 +565,11 @@  discard block
 block discarded – undo
547 565
 				);
548 566
 
549 567
 				// Make the topic number into a link - dealing with splitting too.
550
-				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
551
-					$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
552
-				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
553
-					$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
568
+				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) {
569
+									$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
570
+				} elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) {
571
+									$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
572
+				}
554 573
 			}
555 574
 		}
556 575
 		$smcFunc['db_free_result']($request);
@@ -583,8 +602,9 @@  discard block
 block discarded – undo
583 602
 				);
584 603
 
585 604
 				// Make the message number into a link.
586
-				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
587
-					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
605
+				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) {
606
+									$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
607
+				}
588 608
 			}
589 609
 		}
590 610
 		$smcFunc['db_free_result']($request);
@@ -624,25 +644,29 @@  discard block
 block discarded – undo
624 644
 	foreach ($entries as $k => $entry)
625 645
 	{
626 646
 		// Make any message info links so its easier to go find that message.
627
-		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
628
-			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
647
+		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) {
648
+					$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
649
+		}
629 650
 
630 651
 		// Mark up any deleted members, topics and boards.
631
-		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
632
-			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
652
+		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) {
653
+					if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
633 654
 				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
655
+		}
634 656
 
635 657
 		if (isset($entry['extra']['report']))
636 658
 		{
637 659
 			// Member profile reports go in a different area
638
-			if (stristr($entry['action'], 'user_report'))
639
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
640
-			else
641
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
660
+			if (stristr($entry['action'], 'user_report')) {
661
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
662
+			} else {
663
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
664
+			}
642 665
 		}
643 666
 
644
-		if (empty($entries[$k]['action_text']))
645
-			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
667
+		if (empty($entries[$k]['action_text'])) {
668
+					$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
669
+		}
646 670
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
647 671
 			function ($matches) use ($entries, $k)
648 672
 			{
Please login to merge, or discard this patch.