Completed
Pull Request — release-2.1 (#4166)
by 01
10:19
created
Sources/Subs-Post.php 1 patch
Braces   +528 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 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.
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 	$message = preg_replace('~\.{100,}~', '...', $message);
47 48
 
48 49
 	// Trim off trailing quotes - these often happen by accident.
49
-	while (substr($message, -7) == '[quote]')
50
-		$message = substr($message, 0, -7);
51
-	while (substr($message, 0, 8) == '[/quote]')
52
-		$message = substr($message, 8);
50
+	while (substr($message, -7) == '[quote]') {
51
+			$message = substr($message, 0, -7);
52
+	}
53
+	while (substr($message, 0, 8) == '[/quote]') {
54
+			$message = substr($message, 8);
55
+	}
53 56
 
54 57
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
55 58
 	$in_tag = false;
56 59
 	$had_tag = false;
57 60
 	$codeopen = 0;
58
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
59
-		foreach ($matches[0] as $index => $dummy)
61
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
62
+			foreach ($matches[0] as $index => $dummy)
60 63
 		{
61 64
 			// Closing?
62 65
 			if (!empty($matches[2][$index]))
@@ -64,6 +67,7 @@  discard block
 block discarded – undo
64 67
 				// If it's closing and we're not in a tag we need to open it...
65 68
 				if (!$in_tag)
66 69
 					$codeopen = true;
70
+	}
67 71
 				// Either way we ain't in one any more.
68 72
 				$in_tag = false;
69 73
 			}
@@ -72,17 +76,20 @@  discard block
 block discarded – undo
72 76
 			{
73 77
 				$had_tag = true;
74 78
 				// If we're in a tag don't do nought!
75
-				if (!$in_tag)
76
-					$in_tag = true;
79
+				if (!$in_tag) {
80
+									$in_tag = true;
81
+				}
77 82
 			}
78 83
 		}
79 84
 
80 85
 	// If we have an open tag, close it.
81
-	if ($in_tag)
82
-		$message .= '[/code]';
86
+	if ($in_tag) {
87
+			$message .= '[/code]';
88
+	}
83 89
 	// Open any ones that need to be open, only if we've never had a tag.
84
-	if ($codeopen && !$had_tag)
85
-		$message = '[code]' . $message;
90
+	if ($codeopen && !$had_tag) {
91
+			$message = '[code]' . $message;
92
+	}
86 93
 
87 94
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
88 95
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +115,26 @@  discard block
 block discarded – undo
108 115
 	fixTags($message);
109 116
 
110 117
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
118
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
119
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message);
120
+	} else {
121
+			$message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
122
+	}
115 123
 
116 124
 	if (!$previewing && strpos($message, '[html]') !== false)
117 125
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
126
+		if (allowedTo('admin_forum')) {
127
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 128
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '
', '  ' => '  ', '[' => '[', ']' => ']')) . '[/html]';
129
+		}
121 130
 			}, $message);
122 131
 
123 132
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 133
 		else
125 134
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
135
+			while (strpos($message, '[html]') !== false) {
136
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			}
128 138
 		}
129 139
 	}
130 140
 
@@ -146,10 +156,12 @@  discard block
 block discarded – undo
146 156
 
147 157
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 158
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
159
+	if ($list_close - $list_open > 0) {
160
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
161
+	}
162
+	if ($list_open - $list_close > 0) {
163
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
164
+	}
153 165
 
154 166
 	$mistake_fixes = array(
155 167
 		// Find [table]s not followed by [tr].
@@ -198,8 +210,9 @@  discard block
 block discarded – undo
198 210
 	);
199 211
 
200 212
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
213
+	for ($j = 0; $j < 3; $j++) {
214
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	}
203 216
 
204 217
 	// Remove empty bbc from the sections outside the code tags
205 218
 	$allowedEmpty = array(
@@ -209,24 +222,28 @@  discard block
 block discarded – undo
209 222
 
210 223
 	require_once($sourcedir . '/Subs.php');
211 224
 
212
-	foreach (($codes = parse_bbc(false)) as $code)
213
-		if (!in_array($code['tag'], $allowedEmpty))
225
+	foreach (($codes = parse_bbc(false)) as $code) {
226
+			if (!in_array($code['tag'], $allowedEmpty))
214 227
 			$alltags[] = $code['tag'];
228
+	}
215 229
 
216 230
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
217 231
 
218
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
219
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
232
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
233
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	}
220 235
 
221 236
 	// Restore code blocks
222
-	if (!empty($code_tags))
223
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
237
+	if (!empty($code_tags)) {
238
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	}
224 240
 
225 241
 	// Restore white space entities
226
-	if (!$previewing)
227
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
228
-	else
229
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
242
+	if (!$previewing) {
243
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	} else {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	}
230 247
 
231 248
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
232 249
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
270 287
 	}, $message);
271 288
 
272
-	if (!empty($code_tags))
273
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
289
+	if (!empty($code_tags)) {
290
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	}
274 292
 
275 293
 	// Change breaks back to \n's and &nsbp; back to spaces.
276 294
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -351,8 +369,9 @@  discard block
 block discarded – undo
351 369
 	);
352 370
 
353 371
 	// Fix each type of tag.
354
-	foreach ($fixArray as $param)
355
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
372
+	foreach ($fixArray as $param) {
373
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	}
356 375
 
357 376
 	// Now fix possible security problems with images loading links automatically...
358 377
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -388,16 +407,19 @@  discard block
 block discarded – undo
388 407
 					$desired_height = $height;
389 408
 				}
390 409
 				// Scale it to the width...
391
-				elseif (empty($desired_width) && !empty($height))
392
-					$desired_width = (int) (($desired_height * $width) / $height);
410
+				elseif (empty($desired_width) && !empty($height)) {
411
+									$desired_width = (int) (($desired_height * $width) / $height);
412
+				}
393 413
 				// Scale if to the height.
394
-				elseif (!empty($width))
395
-					$desired_height = (int) (($desired_width * $height) / $width);
414
+				elseif (!empty($width)) {
415
+									$desired_height = (int) (($desired_width * $height) / $width);
416
+				}
396 417
 			}
397 418
 
398 419
 			// If the width and height are fine, just continue along...
399
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
400
-				continue;
420
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
421
+							continue;
422
+			}
401 423
 
402 424
 			// Too bad, it's too wide.  Make it as wide as the maximum.
403 425
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -417,8 +439,9 @@  discard block
 block discarded – undo
417 439
 		}
418 440
 
419 441
 		// If any img tags were actually changed...
420
-		if (!empty($replaces))
421
-			$message = strtr($message, $replaces);
442
+		if (!empty($replaces)) {
443
+					$message = strtr($message, $replaces);
444
+		}
422 445
 	}
423 446
 }
424 447
 
@@ -437,10 +460,11 @@  discard block
 block discarded – undo
437 460
 {
438 461
 	global $boardurl, $scripturl;
439 462
 
440
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
441
-		$domain_url = $match[1];
442
-	else
443
-		$domain_url = $boardurl . '/';
463
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
464
+			$domain_url = $match[1];
465
+	} else {
466
+			$domain_url = $boardurl . '/';
467
+	}
444 468
 
445 469
 	$replaces = array();
446 470
 
@@ -448,11 +472,11 @@  discard block
 block discarded – undo
448 472
 	{
449 473
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
450 474
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
475
+	} elseif ($hasEqualSign) {
476
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} else {
478
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
451 479
 	}
452
-	elseif ($hasEqualSign)
453
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
454
-	else
455
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
456 480
 
457 481
 	foreach ($matches[0] as $k => $dummy)
458 482
 	{
@@ -465,49 +489,53 @@  discard block
 block discarded – undo
465 489
 		foreach ($protocols as $protocol)
466 490
 		{
467 491
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
468
-			if ($found)
469
-				break;
492
+			if ($found) {
493
+							break;
494
+			}
470 495
 		}
471 496
 
472 497
 		if (!$found && $protocols[0] == 'http')
473 498
 		{
474
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
475
-				$replace = $domain_url . $replace;
476
-			elseif (substr($replace, 0, 1) == '?')
477
-				$replace = $scripturl . $replace;
478
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
499
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
500
+							$replace = $domain_url . $replace;
501
+			} elseif (substr($replace, 0, 1) == '?') {
502
+							$replace = $scripturl . $replace;
503
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
479 504
 			{
480 505
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
481 506
 				$this_tag = 'iurl';
482 507
 				$this_close = 'iurl';
508
+			} elseif (substr($replace, 0, 2) != '//') {
509
+							$replace = $protocols[0] . '://' . $replace;
483 510
 			}
484
-			elseif (substr($replace, 0, 2) != '//')
485
-				$replace = $protocols[0] . '://' . $replace;
486
-		}
487
-		elseif (!$found && $protocols[0] == 'ftp')
488
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
489
-		elseif (!$found)
490
-			$replace = $protocols[0] . '://' . $replace;
491
-
492
-		if ($hasEqualSign && $embeddedUrl)
493
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
494
-		elseif ($hasEqualSign)
495
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
496
-		elseif ($embeddedUrl)
497
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
498
-		else
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
511
+		} elseif (!$found && $protocols[0] == 'ftp') {
512
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
513
+		} elseif (!$found) {
514
+					$replace = $protocols[0] . '://' . $replace;
515
+		}
516
+
517
+		if ($hasEqualSign && $embeddedUrl) {
518
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
519
+		} elseif ($hasEqualSign) {
520
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
521
+		} elseif ($embeddedUrl) {
522
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
523
+		} else {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
525
+		}
500 526
 	}
501 527
 
502 528
 	foreach ($replaces as $k => $v)
503 529
 	{
504
-		if ($k == $v)
505
-			unset($replaces[$k]);
530
+		if ($k == $v) {
531
+					unset($replaces[$k]);
532
+		}
506 533
 	}
507 534
 
508
-	if (!empty($replaces))
509
-		$message = strtr($message, $replaces);
510
-}
535
+	if (!empty($replaces)) {
536
+			$message = strtr($message, $replaces);
537
+	}
538
+	}
511 539
 
512 540
 /**
513 541
  * This function sends an email to the specified recipient(s).
@@ -551,8 +579,9 @@  discard block
 block discarded – undo
551 579
 	}
552 580
 
553 581
 	// Nothing left? Nothing else to do
554
-	if (empty($to_array))
555
-		return true;
582
+	if (empty($to_array)) {
583
+			return true;
584
+	}
556 585
 
557 586
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
558 587
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -569,15 +598,17 @@  discard block
 block discarded – undo
569 598
 		}
570 599
 
571 600
 		// Call this function recursively for the hotmail addresses.
572
-		if (!empty($hotmail_to))
573
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
601
+		if (!empty($hotmail_to)) {
602
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		}
574 604
 
575 605
 		// The remaining addresses no longer need the fix.
576 606
 		$hotmail_fix = false;
577 607
 
578 608
 		// No other addresses left? Return instantly.
579
-		if (empty($to_array))
580
-			return $mail_result;
609
+		if (empty($to_array)) {
610
+					return $mail_result;
611
+		}
581 612
 	}
582 613
 
583 614
 	// Get rid of entities.
@@ -602,13 +633,15 @@  discard block
 block discarded – undo
602 633
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
603 634
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
604 635
 
605
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
606
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
636
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
637
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	}
607 639
 	$headers .= 'X-Mailer: SMF' . $line_break;
608 640
 
609 641
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
610
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
611
-		return false;
642
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
643
+			return false;
644
+	}
612 645
 
613 646
 	// Save the original message...
614 647
 	$orig_message = $message;
@@ -657,17 +690,19 @@  discard block
 block discarded – undo
657 690
 	}
658 691
 
659 692
 	// Are we using the mail queue, if so this is where we butt in...
660
-	if ($priority != 0)
661
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
693
+	if ($priority != 0) {
694
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	}
662 696
 
663 697
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
664 698
 	elseif (!empty($modSettings['mail_limit']))
665 699
 	{
666 700
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
667
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
668
-			$new_queue_stat = time() . '|' . 1;
669
-		else
670
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
701
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
702
+					$new_queue_stat = time() . '|' . 1;
703
+		} else {
704
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
705
+		}
671 706
 
672 707
 		updateSettings(array('mail_recent' => $new_queue_stat));
673 708
 	}
@@ -692,12 +727,13 @@  discard block
 block discarded – undo
692 727
 
693 728
 			// Wait, wait, I'm still sending here!
694 729
 			@set_time_limit(300);
695
-			if (function_exists('apache_reset_timeout'))
696
-				@apache_reset_timeout();
730
+			if (function_exists('apache_reset_timeout')) {
731
+							@apache_reset_timeout();
732
+			}
697 733
 		}
734
+	} else {
735
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
698 736
 	}
699
-	else
700
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
701 737
 
702 738
 	// Everything go smoothly?
703 739
 	return $mail_result;
@@ -723,8 +759,9 @@  discard block
 block discarded – undo
723 759
 	static $cur_insert = array();
724 760
 	static $cur_insert_len = 0;
725 761
 
726
-	if ($cur_insert_len == 0)
727
-		$cur_insert = array();
762
+	if ($cur_insert_len == 0) {
763
+			$cur_insert = array();
764
+	}
728 765
 
729 766
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
730 767
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -799,8 +836,9 @@  discard block
 block discarded – undo
799 836
 	}
800 837
 
801 838
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
802
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
803
-		return AddMailQueue(true);
839
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
840
+			return AddMailQueue(true);
841
+	}
804 842
 
805 843
 	return true;
806 844
 }
@@ -831,23 +869,26 @@  discard block
 block discarded – undo
831 869
 		'sent' => array()
832 870
 	);
833 871
 
834
-	if ($from === null)
835
-		$from = array(
872
+	if ($from === null) {
873
+			$from = array(
836 874
 			'id' => $user_info['id'],
837 875
 			'name' => $user_info['name'],
838 876
 			'username' => $user_info['username']
839 877
 		);
878
+	}
840 879
 
841 880
 	// This is the one that will go in their inbox.
842 881
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
843 882
 	preparsecode($htmlmessage);
844 883
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
845
-	if ($smcFunc['strlen']($htmlsubject) > 100)
846
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
884
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
885
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	}
847 887
 
848 888
 	// Make sure is an array
849
-	if (!is_array($recipients))
850
-		$recipients = array($recipients);
889
+	if (!is_array($recipients)) {
890
+			$recipients = array($recipients);
891
+	}
851 892
 
852 893
 	// Integrated PMs
853 894
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -875,21 +916,23 @@  discard block
 block discarded – undo
875 916
 				'usernames' => array_keys($usernames),
876 917
 			)
877 918
 		);
878
-		while ($row = $smcFunc['db_fetch_assoc']($request))
879
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
919
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
920
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
880 921
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
922
+		}
881 923
 		$smcFunc['db_free_result']($request);
882 924
 
883 925
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
884
-		foreach ($recipients as $rec_type => $rec)
885
-			foreach ($rec as $id => $member)
926
+		foreach ($recipients as $rec_type => $rec) {
927
+					foreach ($rec as $id => $member)
886 928
 			{
887 929
 				if (is_numeric($recipients[$rec_type][$id]))
888 930
 					continue;
931
+		}
889 932
 
890
-				if (!empty($usernames[$member]))
891
-					$recipients[$rec_type][$id] = $usernames[$member];
892
-				else
933
+				if (!empty($usernames[$member])) {
934
+									$recipients[$rec_type][$id] = $usernames[$member];
935
+				} else
893 936
 				{
894 937
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
895 938
 					unset($recipients[$rec_type][$id]);
@@ -927,8 +970,9 @@  discard block
 block discarded – undo
927 970
 		$delete = false;
928 971
 		foreach ($criteria as $criterium)
929 972
 		{
930
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
931
-				$delete = true;
973
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
974
+							$delete = true;
975
+			}
932 976
 			// If we're adding and one criteria don't match then we stop!
933 977
 			elseif (!$row['is_or'])
934 978
 			{
@@ -936,8 +980,9 @@  discard block
 block discarded – undo
936 980
 				break;
937 981
 			}
938 982
 		}
939
-		if ($delete)
940
-			$deletes[$row['id_member']] = 1;
983
+		if ($delete) {
984
+					$deletes[$row['id_member']] = 1;
985
+		}
941 986
 	}
942 987
 	$smcFunc['db_free_result']($request);
943 988
 
@@ -952,8 +997,9 @@  discard block
 block discarded – undo
952 997
 			array(
953 998
 			)
954 999
 		);
955
-		while ($row = $smcFunc['db_fetch_assoc']($request))
956
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1000
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1001
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 	}
959 1005
 
@@ -961,8 +1007,9 @@  discard block
 block discarded – undo
961 1007
 	require_once($sourcedir . '/Subs-Members.php');
962 1008
 	$pmReadGroups = groupsAllowedTo('pm_read');
963 1009
 
964
-	if (empty($modSettings['permission_enable_deny']))
965
-		$pmReadGroups['denied'] = array();
1010
+	if (empty($modSettings['permission_enable_deny'])) {
1011
+			$pmReadGroups['denied'] = array();
1012
+	}
966 1013
 
967 1014
 	// Load their alert preferences
968 1015
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -994,8 +1041,9 @@  discard block
 block discarded – undo
994 1041
 	while ($row = $smcFunc['db_fetch_assoc']($request))
995 1042
 	{
996 1043
 		// Don't do anything for members to be deleted!
997
-		if (isset($deletes[$row['id_member']]))
998
-			continue;
1044
+		if (isset($deletes[$row['id_member']])) {
1045
+					continue;
1046
+		}
999 1047
 
1000 1048
 		// Load the preferences for this member (if any)
1001 1049
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1016,8 +1064,9 @@  discard block
 block discarded – undo
1016 1064
 		{
1017 1065
 			foreach ($groups as $id)
1018 1066
 			{
1019
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1020
-					$message_limit = $message_limit_cache[$id];
1067
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1068
+									$message_limit = $message_limit_cache[$id];
1069
+				}
1021 1070
 			}
1022 1071
 
1023 1072
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1065,8 +1114,9 @@  discard block
 block discarded – undo
1065 1114
 	$smcFunc['db_free_result']($request);
1066 1115
 
1067 1116
 	// Only 'send' the message if there are any recipients left.
1068
-	if (empty($all_to))
1069
-		return $log;
1117
+	if (empty($all_to)) {
1118
+			return $log;
1119
+	}
1070 1120
 
1071 1121
 	// Insert the message itself and then grab the last insert id.
1072 1122
 	$id_pm = $smcFunc['db_insert']('',
@@ -1087,8 +1137,8 @@  discard block
 block discarded – undo
1087 1137
 	if (!empty($id_pm))
1088 1138
 	{
1089 1139
 		// If this is new we need to set it part of it's own conversation.
1090
-		if (empty($pm_head))
1091
-			$smcFunc['db_query']('', '
1140
+		if (empty($pm_head)) {
1141
+					$smcFunc['db_query']('', '
1092 1142
 				UPDATE {db_prefix}personal_messages
1093 1143
 				SET id_pm_head = {int:id_pm_head}
1094 1144
 				WHERE id_pm = {int:id_pm_head}',
@@ -1096,6 +1146,7 @@  discard block
 block discarded – undo
1096 1146
 					'id_pm_head' => $id_pm,
1097 1147
 				)
1098 1148
 			);
1149
+		}
1099 1150
 
1100 1151
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1101 1152
 		$smcFunc['db_query']('', '
@@ -1111,8 +1162,9 @@  discard block
 block discarded – undo
1111 1162
 		foreach ($all_to as $to)
1112 1163
 		{
1113 1164
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1114
-			if (!in_array($to, $recipients['bcc']))
1115
-				$to_list[] = $to;
1165
+			if (!in_array($to, $recipients['bcc'])) {
1166
+							$to_list[] = $to;
1167
+			}
1116 1168
 		}
1117 1169
 
1118 1170
 		$smcFunc['db_insert']('insert',
@@ -1130,9 +1182,9 @@  discard block
 block discarded – undo
1130 1182
 	{
1131 1183
 		censorText($message);
1132 1184
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1185
+	} else {
1186
+			$message = '';
1133 1187
 	}
1134
-	else
1135
-		$message = '';
1136 1188
 
1137 1189
 	$to_names = array();
1138 1190
 	if (count($to_list) > 1)
@@ -1145,8 +1197,9 @@  discard block
 block discarded – undo
1145 1197
 				'to_members' => $to_list,
1146 1198
 			)
1147 1199
 		);
1148
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1149
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1200
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1201
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		}
1150 1203
 		$smcFunc['db_free_result']($request);
1151 1204
 	}
1152 1205
 	$replacements = array(
@@ -1174,11 +1227,13 @@  discard block
 block discarded – undo
1174 1227
 	loadLanguage('index+PersonalMessage');
1175 1228
 
1176 1229
 	// Add one to their unread and read message counts.
1177
-	foreach ($all_to as $k => $id)
1178
-		if (isset($deletes[$id]))
1230
+	foreach ($all_to as $k => $id) {
1231
+			if (isset($deletes[$id]))
1179 1232
 			unset($all_to[$k]);
1180
-	if (!empty($all_to))
1181
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1233
+	}
1234
+	if (!empty($all_to)) {
1235
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1182 1237
 
1183 1238
 	return $log;
1184 1239
 }
@@ -1208,15 +1263,17 @@  discard block
 block discarded – undo
1208 1263
 		// Let's, for now, assume there are only &#021;'ish characters.
1209 1264
 		$simple = true;
1210 1265
 
1211
-		foreach ($matches[1] as $entity)
1212
-			if ($entity > 128)
1266
+		foreach ($matches[1] as $entity) {
1267
+					if ($entity > 128)
1213 1268
 				$simple = false;
1269
+		}
1214 1270
 		unset($matches);
1215 1271
 
1216
-		if ($simple)
1217
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1272
+		if ($simple) {
1273
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1218 1274
 			{
1219 1275
 				return chr("$m[1]");
1276
+		}
1220 1277
 			}, $string);
1221 1278
 		else
1222 1279
 		{
@@ -1224,8 +1281,9 @@  discard block
 block discarded – undo
1224 1281
 			if (!$context['utf8'] && function_exists('iconv'))
1225 1282
 			{
1226 1283
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1227
-				if ($newstring)
1228
-					$string = $newstring;
1284
+				if ($newstring) {
1285
+									$string = $newstring;
1286
+				}
1229 1287
 			}
1230 1288
 
1231 1289
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1241,23 +1299,25 @@  discard block
 block discarded – undo
1241 1299
 		if (!$context['utf8'] && function_exists('iconv'))
1242 1300
 		{
1243 1301
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1244
-			if ($newstring)
1245
-				$string = $newstring;
1302
+			if ($newstring) {
1303
+							$string = $newstring;
1304
+			}
1246 1305
 		}
1247 1306
 
1248 1307
 		$entityConvert = function($m)
1249 1308
 		{
1250 1309
 			$c = $m[1];
1251
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1252
-				return $c;
1253
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1254
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1255
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1256
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1257
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1258
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1259
-			else
1260
-				return "";
1310
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1311
+							return $c;
1312
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1313
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1314
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1318
+			} else {
1319
+							return "";
1320
+			}
1261 1321
 		};
1262 1322
 
1263 1323
 		// Convert all 'special' characters to HTML entities.
@@ -1271,19 +1331,20 @@  discard block
 block discarded – undo
1271 1331
 		$string = base64_encode($string);
1272 1332
 
1273 1333
 		// Show the characterset and the transfer-encoding for header strings.
1274
-		if ($with_charset)
1275
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1334
+		if ($with_charset) {
1335
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		}
1276 1337
 
1277 1338
 		// Break it up in lines (mail body).
1278
-		else
1279
-			$string = chunk_split($string, 76, $line_break);
1339
+		else {
1340
+					$string = chunk_split($string, 76, $line_break);
1341
+		}
1280 1342
 
1281 1343
 		return array($charset, $string, 'base64');
1344
+	} else {
1345
+			return array($charset, $string, '7bit');
1346
+	}
1282 1347
 	}
1283
-
1284
-	else
1285
-		return array($charset, $string, '7bit');
1286
-}
1287 1348
 
1288 1349
 /**
1289 1350
  * Sends mail, like mail() but over SMTP.
@@ -1307,8 +1368,9 @@  discard block
 block discarded – undo
1307 1368
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1308 1369
 	{
1309 1370
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1310
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1311
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1371
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1372
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		}
1312 1374
 
1313 1375
 		if ($socket)
1314 1376
 		{
@@ -1329,8 +1391,9 @@  discard block
 block discarded – undo
1329 1391
 		// Maybe we can still save this?  The port might be wrong.
1330 1392
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1331 1393
 		{
1332
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1333
-				log_error($txt['smtp_port_ssl']);
1394
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1395
+							log_error($txt['smtp_port_ssl']);
1396
+			}
1334 1397
 		}
1335 1398
 
1336 1399
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1342,20 +1405,23 @@  discard block
 block discarded – undo
1342 1405
 	}
1343 1406
 
1344 1407
 	// Wait for a response of 220, without "-" continuer.
1345
-	if (!server_parse(null, $socket, '220'))
1346
-		return false;
1408
+	if (!server_parse(null, $socket, '220')) {
1409
+			return false;
1410
+	}
1347 1411
 
1348 1412
 	// Try and determine the servers name, fall back to the mail servers if not found
1349 1413
 	$helo = false;
1350
-	if (function_exists('gethostname') && gethostname() !== false)
1351
-		$helo = gethostname();
1352
-	elseif (function_exists('php_uname'))
1353
-		$helo = php_uname('n');
1354
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1355
-		$helo = $_SERVER['SERVER_NAME'];
1414
+	if (function_exists('gethostname') && gethostname() !== false) {
1415
+			$helo = gethostname();
1416
+	} elseif (function_exists('php_uname')) {
1417
+			$helo = php_uname('n');
1418
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1419
+			$helo = $_SERVER['SERVER_NAME'];
1420
+	}
1356 1421
 
1357
-	if (empty($helo))
1358
-		$helo = $modSettings['smtp_host'];
1422
+	if (empty($helo)) {
1423
+			$helo = $modSettings['smtp_host'];
1424
+	}
1359 1425
 
1360 1426
 	// SMTP = 1, SMTP - STARTTLS = 2
1361 1427
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1367,33 +1433,39 @@  discard block
 block discarded – undo
1367 1433
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1368 1434
 			{
1369 1435
 				// Send STARTTLS to enable encryption
1370
-				if (!server_parse('STARTTLS', $socket, '220'))
1371
-					return false;
1436
+				if (!server_parse('STARTTLS', $socket, '220')) {
1437
+									return false;
1438
+				}
1372 1439
 				// Enable the encryption
1373
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1374
-					return false;
1440
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1441
+									return false;
1442
+				}
1375 1443
 				// Send the EHLO command again
1376
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1377
-					return false;
1444
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1445
+									return false;
1446
+				}
1378 1447
 			}
1379 1448
 
1380
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1381
-				return false;
1449
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1450
+							return false;
1451
+			}
1382 1452
 			// Send the username and password, encoded.
1383
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1384
-				return false;
1453
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1454
+							return false;
1455
+			}
1385 1456
 			// The password is already encoded ;)
1386
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1387
-				return false;
1457
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1458
+							return false;
1459
+			}
1460
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1461
+					return false;
1388 1462
 		}
1389
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1390
-			return false;
1391
-	}
1392
-	else
1463
+	} else
1393 1464
 	{
1394 1465
 		// Just say "helo".
1395
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1396
-			return false;
1466
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1467
+					return false;
1468
+		}
1397 1469
 	}
1398 1470
 
1399 1471
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1406,31 +1478,38 @@  discard block
 block discarded – undo
1406 1478
 		// Reset the connection to send another email.
1407 1479
 		if ($i != 0)
1408 1480
 		{
1409
-			if (!server_parse('RSET', $socket, '250'))
1410
-				return false;
1481
+			if (!server_parse('RSET', $socket, '250')) {
1482
+							return false;
1483
+			}
1411 1484
 		}
1412 1485
 
1413 1486
 		// From, to, and then start the data...
1414
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1415
-			return false;
1416
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1417
-			return false;
1418
-		if (!server_parse('DATA', $socket, '354'))
1419
-			return false;
1487
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1488
+					return false;
1489
+		}
1490
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('DATA', $socket, '354')) {
1494
+					return false;
1495
+		}
1420 1496
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1421
-		if (strlen($mail_to) > 0)
1422
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1497
+		if (strlen($mail_to) > 0) {
1498
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		}
1423 1500
 		fputs($socket, $headers . "\r\n\r\n");
1424 1501
 		fputs($socket, $message . "\r\n");
1425 1502
 
1426 1503
 		// Send a ., or in other words "end of data".
1427
-		if (!server_parse('.', $socket, '250'))
1428
-			return false;
1504
+		if (!server_parse('.', $socket, '250')) {
1505
+					return false;
1506
+		}
1429 1507
 
1430 1508
 		// Almost done, almost done... don't stop me just yet!
1431 1509
 		@set_time_limit(300);
1432
-		if (function_exists('apache_reset_timeout'))
1433
-			@apache_reset_timeout();
1510
+		if (function_exists('apache_reset_timeout')) {
1511
+					@apache_reset_timeout();
1512
+		}
1434 1513
 	}
1435 1514
 	fputs($socket, 'QUIT' . "\r\n");
1436 1515
 	fclose($socket);
@@ -1454,8 +1533,9 @@  discard block
 block discarded – undo
1454 1533
 {
1455 1534
 	global $txt;
1456 1535
 
1457
-	if ($message !== null)
1458
-		fputs($socket, $message . "\r\n");
1536
+	if ($message !== null) {
1537
+			fputs($socket, $message . "\r\n");
1538
+	}
1459 1539
 
1460 1540
 	// No response yet.
1461 1541
 	$server_response = '';
@@ -1471,8 +1551,9 @@  discard block
 block discarded – undo
1471 1551
 		$response .= $server_response;
1472 1552
 	}
1473 1553
 
1474
-	if ($code === null)
1475
-		return substr($server_response, 0, 3);
1554
+	if ($code === null) {
1555
+			return substr($server_response, 0, 3);
1556
+	}
1476 1557
 
1477 1558
 	if (substr($server_response, 0, 3) != $code)
1478 1559
 	{
@@ -1502,8 +1583,9 @@  discard block
 block discarded – undo
1502 1583
 	// Create a pspell or enchant dictionary resource
1503 1584
 	$dict = spell_init();
1504 1585
 
1505
-	if (!isset($_POST['spellstring']) || !$dict)
1506
-		die;
1586
+	if (!isset($_POST['spellstring']) || !$dict) {
1587
+			die;
1588
+	}
1507 1589
 
1508 1590
 	// Construct a bit of Javascript code.
1509 1591
 	$context['spell_js'] = '
@@ -1521,8 +1603,9 @@  discard block
 block discarded – undo
1521 1603
 		$check_word = explode('|', $alphas[$i]);
1522 1604
 
1523 1605
 		// If the word is a known word, or spelled right...
1524
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1525
-			continue;
1606
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1607
+					continue;
1608
+		}
1526 1609
 
1527 1610
 		// Find the word, and move up the "last occurrence" to here.
1528 1611
 		$found_words = true;
@@ -1536,20 +1619,23 @@  discard block
 block discarded – undo
1536 1619
 		if (!empty($suggestions))
1537 1620
 		{
1538 1621
 			// But first check they aren't going to be censored - no naughty words!
1539
-			foreach ($suggestions as $k => $word)
1540
-				if ($suggestions[$k] != censorText($word))
1622
+			foreach ($suggestions as $k => $word) {
1623
+							if ($suggestions[$k] != censorText($word))
1541 1624
 					unset($suggestions[$k]);
1625
+			}
1542 1626
 
1543
-			if (!empty($suggestions))
1544
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1627
+			if (!empty($suggestions)) {
1628
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			}
1545 1630
 		}
1546 1631
 
1547 1632
 		$context['spell_js'] .= ']),';
1548 1633
 	}
1549 1634
 
1550 1635
 	// If words were found, take off the last comma.
1551
-	if ($found_words)
1552
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1636
+	if ($found_words) {
1637
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	}
1553 1639
 
1554 1640
 	$context['spell_js'] .= '
1555 1641
 		);';
@@ -1584,11 +1670,13 @@  discard block
 block discarded – undo
1584 1670
 	global $user_info, $smcFunc;
1585 1671
 
1586 1672
 	// Can't do it if there's no topics.
1587
-	if (empty($topics))
1588
-		return;
1673
+	if (empty($topics)) {
1674
+			return;
1675
+	}
1589 1676
 	// It must be an array - it must!
1590
-	if (!is_array($topics))
1591
-		$topics = array($topics);
1677
+	if (!is_array($topics)) {
1678
+			$topics = array($topics);
1679
+	}
1592 1680
 
1593 1681
 	// Get the subject and body...
1594 1682
 	$result = $smcFunc['db_query']('', '
@@ -1636,14 +1724,15 @@  discard block
 block discarded – undo
1636 1724
 	}
1637 1725
 	$smcFunc['db_free_result']($result);
1638 1726
 
1639
-	if (!empty($task_rows))
1640
-		$smcFunc['db_insert']('',
1727
+	if (!empty($task_rows)) {
1728
+			$smcFunc['db_insert']('',
1641 1729
 			'{db_prefix}background_tasks',
1642 1730
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1643 1731
 			$task_rows,
1644 1732
 			array('id_task')
1645 1733
 		);
1646
-}
1734
+	}
1735
+	}
1647 1736
 
1648 1737
 /**
1649 1738
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1681,9 +1770,9 @@  discard block
 block discarded – undo
1681 1770
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1682 1771
 
1683 1772
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1684
-	if (!$modSettings['postmod_active'])
1685
-		$topicOptions['is_approved'] = true;
1686
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1773
+	if (!$modSettings['postmod_active']) {
1774
+			$topicOptions['is_approved'] = true;
1775
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1687 1776
 	{
1688 1777
 		$request = $smcFunc['db_query']('', '
1689 1778
 			SELECT approved
@@ -1706,8 +1795,7 @@  discard block
 block discarded – undo
1706 1795
 			$posterOptions['id'] = 0;
1707 1796
 			$posterOptions['name'] = $txt['guest_title'];
1708 1797
 			$posterOptions['email'] = '';
1709
-		}
1710
-		elseif ($posterOptions['id'] != $user_info['id'])
1798
+		} elseif ($posterOptions['id'] != $user_info['id'])
1711 1799
 		{
1712 1800
 			$request = $smcFunc['db_query']('', '
1713 1801
 				SELECT member_name, email_address
@@ -1725,12 +1813,11 @@  discard block
 block discarded – undo
1725 1813
 				$posterOptions['id'] = 0;
1726 1814
 				$posterOptions['name'] = $txt['guest_title'];
1727 1815
 				$posterOptions['email'] = '';
1816
+			} else {
1817
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1728 1818
 			}
1729
-			else
1730
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1731 1819
 			$smcFunc['db_free_result']($request);
1732
-		}
1733
-		else
1820
+		} else
1734 1821
 		{
1735 1822
 			$posterOptions['name'] = $user_info['name'];
1736 1823
 			$posterOptions['email'] = $user_info['email'];
@@ -1740,8 +1827,9 @@  discard block
 block discarded – undo
1740 1827
 	if (!empty($modSettings['enable_mentions']))
1741 1828
 	{
1742 1829
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1743
-		if (!empty($msgOptions['mentioned_members']))
1744
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1830
+		if (!empty($msgOptions['mentioned_members'])) {
1831
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		}
1745 1833
 	}
1746 1834
 
1747 1835
 	// It's do or die time: forget any user aborts!
@@ -1774,12 +1862,13 @@  discard block
 block discarded – undo
1774 1862
 	);
1775 1863
 
1776 1864
 	// Something went wrong creating the message...
1777
-	if (empty($msgOptions['id']))
1778
-		return false;
1865
+	if (empty($msgOptions['id'])) {
1866
+			return false;
1867
+	}
1779 1868
 
1780 1869
 	// Fix the attachments.
1781
-	if (!empty($msgOptions['attachments']))
1782
-		$smcFunc['db_query']('', '
1870
+	if (!empty($msgOptions['attachments'])) {
1871
+			$smcFunc['db_query']('', '
1783 1872
 			UPDATE {db_prefix}attachments
1784 1873
 			SET id_msg = {int:id_msg}
1785 1874
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1788,6 +1877,7 @@  discard block
 block discarded – undo
1788 1877
 				'id_msg' => $msgOptions['id'],
1789 1878
 			)
1790 1879
 		);
1880
+	}
1791 1881
 
1792 1882
 	// What if we want to export new posts out to a CMS?
1793 1883
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1864,20 +1954,23 @@  discard block
 block discarded – undo
1864 1954
 			'id_topic' => $topicOptions['id'],
1865 1955
 			'counter_increment' => 1,
1866 1956
 		);
1867
-		if ($msgOptions['approved'])
1868
-			$topics_columns = array(
1957
+		if ($msgOptions['approved']) {
1958
+					$topics_columns = array(
1869 1959
 				'id_member_updated = {int:poster_id}',
1870 1960
 				'id_last_msg = {int:id_msg}',
1871 1961
 				'num_replies = num_replies + {int:counter_increment}',
1872 1962
 			);
1873
-		else
1874
-			$topics_columns = array(
1963
+		} else {
1964
+					$topics_columns = array(
1875 1965
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1876 1966
 			);
1877
-		if ($topicOptions['lock_mode'] !== null)
1878
-			$topics_columns[] = 'locked = {int:locked}';
1879
-		if ($topicOptions['sticky_mode'] !== null)
1880
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1967
+		}
1968
+		if ($topicOptions['lock_mode'] !== null) {
1969
+					$topics_columns[] = 'locked = {int:locked}';
1970
+		}
1971
+		if ($topicOptions['sticky_mode'] !== null) {
1972
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1973
+		}
1881 1974
 
1882 1975
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1883 1976
 
@@ -1906,8 +1999,8 @@  discard block
 block discarded – undo
1906 1999
 	);
1907 2000
 
1908 2001
 	// Increase the number of posts and topics on the board.
1909
-	if ($msgOptions['approved'])
1910
-		$smcFunc['db_query']('', '
2002
+	if ($msgOptions['approved']) {
2003
+			$smcFunc['db_query']('', '
1911 2004
 			UPDATE {db_prefix}boards
1912 2005
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1913 2006
 			WHERE id_board = {int:id_board}',
@@ -1915,7 +2008,7 @@  discard block
 block discarded – undo
1915 2008
 				'id_board' => $topicOptions['board'],
1916 2009
 			)
1917 2010
 		);
1918
-	else
2011
+	} else
1919 2012
 	{
1920 2013
 		$smcFunc['db_query']('', '
1921 2014
 			UPDATE {db_prefix}boards
@@ -1985,8 +2078,8 @@  discard block
 block discarded – undo
1985 2078
 		}
1986 2079
 	}
1987 2080
 
1988
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1989
-		$smcFunc['db_insert']('',
2081
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2082
+			$smcFunc['db_insert']('',
1990 2083
 			'{db_prefix}background_tasks',
1991 2084
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1992 2085
 			array(
@@ -1998,19 +2091,22 @@  discard block
 block discarded – undo
1998 2091
 			),
1999 2092
 			array('id_task')
2000 2093
 		);
2094
+	}
2001 2095
 
2002 2096
 	// If there's a custom search index, it may need updating...
2003 2097
 	require_once($sourcedir . '/Search.php');
2004 2098
 	$searchAPI = findSearchAPI();
2005
-	if (is_callable(array($searchAPI, 'postCreated')))
2006
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2099
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2100
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	}
2007 2102
 
2008 2103
 	// Increase the post counter for the user that created the post.
2009 2104
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2010 2105
 	{
2011 2106
 		// Are you the one that happened to create this post?
2012
-		if ($user_info['id'] == $posterOptions['id'])
2013
-			$user_info['posts']++;
2107
+		if ($user_info['id'] == $posterOptions['id']) {
2108
+					$user_info['posts']++;
2109
+		}
2014 2110
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2015 2111
 	}
2016 2112
 
@@ -2018,19 +2114,21 @@  discard block
 block discarded – undo
2018 2114
 	$_SESSION['last_read_topic'] = 0;
2019 2115
 
2020 2116
 	// Better safe than sorry.
2021
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2022
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2117
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2118
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	}
2023 2120
 
2024 2121
 	// Update all the stats so everyone knows about this new topic and message.
2025 2122
 	updateStats('message', true, $msgOptions['id']);
2026 2123
 
2027 2124
 	// Update the last message on the board assuming it's approved AND the topic is.
2028
-	if ($msgOptions['approved'])
2029
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2125
+	if ($msgOptions['approved']) {
2126
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	}
2030 2128
 
2031 2129
 	// Queue createPost background notification
2032
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2033
-		$smcFunc['db_insert']('',
2130
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2131
+			$smcFunc['db_insert']('',
2034 2132
 			'{db_prefix}background_tasks',
2035 2133
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2036 2134
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
@@ -2041,6 +2139,7 @@  discard block
 block discarded – undo
2041 2139
 			)), 0),
2042 2140
 			array('id_task')
2043 2141
 		);
2142
+	}
2044 2143
 
2045 2144
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2046 2145
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2067,14 +2166,18 @@  discard block
 block discarded – undo
2067 2166
 
2068 2167
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2069 2168
 	$messages_columns = array();
2070
-	if (isset($posterOptions['name']))
2071
-		$messages_columns['poster_name'] = $posterOptions['name'];
2072
-	if (isset($posterOptions['email']))
2073
-		$messages_columns['poster_email'] = $posterOptions['email'];
2074
-	if (isset($msgOptions['icon']))
2075
-		$messages_columns['icon'] = $msgOptions['icon'];
2076
-	if (isset($msgOptions['subject']))
2077
-		$messages_columns['subject'] = $msgOptions['subject'];
2169
+	if (isset($posterOptions['name'])) {
2170
+			$messages_columns['poster_name'] = $posterOptions['name'];
2171
+	}
2172
+	if (isset($posterOptions['email'])) {
2173
+			$messages_columns['poster_email'] = $posterOptions['email'];
2174
+	}
2175
+	if (isset($msgOptions['icon'])) {
2176
+			$messages_columns['icon'] = $msgOptions['icon'];
2177
+	}
2178
+	if (isset($msgOptions['subject'])) {
2179
+			$messages_columns['subject'] = $msgOptions['subject'];
2180
+	}
2078 2181
 	if (isset($msgOptions['body']))
2079 2182
 	{
2080 2183
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2101,8 +2204,9 @@  discard block
 block discarded – undo
2101 2204
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2102 2205
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2103 2206
 	}
2104
-	if (isset($msgOptions['smileys_enabled']))
2105
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2207
+	if (isset($msgOptions['smileys_enabled'])) {
2208
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	}
2106 2210
 
2107 2211
 	// Which columns need to be ints?
2108 2212
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2120,23 +2224,27 @@  discard block
 block discarded – undo
2120 2224
 		{
2121 2225
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2122 2226
 
2123
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2124
-				foreach ($match[1] as $i => $oldID)
2227
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2228
+							foreach ($match[1] as $i => $oldID)
2125 2229
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2230
+			}
2126 2231
 
2127
-			if (empty($modSettings['search_custom_index_config']))
2128
-				unset($msgOptions['old_body']);
2232
+			if (empty($modSettings['search_custom_index_config'])) {
2233
+							unset($msgOptions['old_body']);
2234
+			}
2129 2235
 		}
2130 2236
 
2131 2237
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2132 2238
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2133 2239
 
2134 2240
 		// Remove the poster.
2135
-		if (isset($mentions[$user_info['id']]))
2136
-			unset($mentions[$user_info['id']]);
2241
+		if (isset($mentions[$user_info['id']])) {
2242
+					unset($mentions[$user_info['id']]);
2243
+		}
2137 2244
 
2138
-		if (isset($oldmentions[$user_info['id']]))
2139
-			unset($oldmentions[$user_info['id']]);
2245
+		if (isset($oldmentions[$user_info['id']])) {
2246
+					unset($oldmentions[$user_info['id']]);
2247
+		}
2140 2248
 
2141 2249
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2142 2250
 		{
@@ -2166,8 +2274,9 @@  discard block
 block discarded – undo
2166 2274
 	}
2167 2275
 
2168 2276
 	// Nothing to do?
2169
-	if (empty($messages_columns))
2170
-		return true;
2277
+	if (empty($messages_columns)) {
2278
+			return true;
2279
+	}
2171 2280
 
2172 2281
 	// Change the post.
2173 2282
 	$smcFunc['db_query']('', '
@@ -2228,8 +2337,9 @@  discard block
 block discarded – undo
2228 2337
 	// If there's a custom search index, it needs to be modified...
2229 2338
 	require_once($sourcedir . '/Search.php');
2230 2339
 	$searchAPI = findSearchAPI();
2231
-	if (is_callable(array($searchAPI, 'postModified')))
2232
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2340
+	if (is_callable(array($searchAPI, 'postModified'))) {
2341
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	}
2233 2343
 
2234 2344
 	if (isset($msgOptions['subject']))
2235 2345
 	{
@@ -2243,14 +2353,16 @@  discard block
 block discarded – undo
2243 2353
 				'id_first_msg' => $msgOptions['id'],
2244 2354
 			)
2245 2355
 		);
2246
-		if ($smcFunc['db_num_rows']($request) == 1)
2247
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2356
+		if ($smcFunc['db_num_rows']($request) == 1) {
2357
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		}
2248 2359
 		$smcFunc['db_free_result']($request);
2249 2360
 	}
2250 2361
 
2251 2362
 	// Finally, if we are setting the approved state we need to do much more work :(
2252
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2253
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2363
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2364
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	}
2254 2366
 
2255 2367
 	return true;
2256 2368
 }
@@ -2267,11 +2379,13 @@  discard block
 block discarded – undo
2267 2379
 {
2268 2380
 	global $smcFunc;
2269 2381
 
2270
-	if (!is_array($msgs))
2271
-		$msgs = array($msgs);
2382
+	if (!is_array($msgs)) {
2383
+			$msgs = array($msgs);
2384
+	}
2272 2385
 
2273
-	if (empty($msgs))
2274
-		return false;
2386
+	if (empty($msgs)) {
2387
+			return false;
2388
+	}
2275 2389
 
2276 2390
 	// May as well start at the beginning, working out *what* we need to change.
2277 2391
 	$request = $smcFunc['db_query']('', '
@@ -2303,20 +2417,22 @@  discard block
 block discarded – undo
2303 2417
 		$topics[] = $row['id_topic'];
2304 2418
 
2305 2419
 		// Ensure our change array exists already.
2306
-		if (!isset($topic_changes[$row['id_topic']]))
2307
-			$topic_changes[$row['id_topic']] = array(
2420
+		if (!isset($topic_changes[$row['id_topic']])) {
2421
+					$topic_changes[$row['id_topic']] = array(
2308 2422
 				'id_last_msg' => $row['id_last_msg'],
2309 2423
 				'approved' => $row['topic_approved'],
2310 2424
 				'replies' => 0,
2311 2425
 				'unapproved_posts' => 0,
2312 2426
 			);
2313
-		if (!isset($board_changes[$row['id_board']]))
2314
-			$board_changes[$row['id_board']] = array(
2427
+		}
2428
+		if (!isset($board_changes[$row['id_board']])) {
2429
+					$board_changes[$row['id_board']] = array(
2315 2430
 				'posts' => 0,
2316 2431
 				'topics' => 0,
2317 2432
 				'unapproved_posts' => 0,
2318 2433
 				'unapproved_topics' => 0,
2319 2434
 			);
2435
+		}
2320 2436
 
2321 2437
 		// If it's the first message then the topic state changes!
2322 2438
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2337,14 +2453,13 @@  discard block
 block discarded – undo
2337 2453
 				'poster' => $row['id_member'],
2338 2454
 				'new_topic' => true,
2339 2455
 			);
2340
-		}
2341
-		else
2456
+		} else
2342 2457
 		{
2343 2458
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2344 2459
 
2345 2460
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2346
-			if ($row['id_msg'] > $row['id_last_msg'])
2347
-				$notification_posts[$row['id_topic']] = array(
2461
+			if ($row['id_msg'] > $row['id_last_msg']) {
2462
+							$notification_posts[$row['id_topic']] = array(
2348 2463
 					'id' => $row['id_msg'],
2349 2464
 					'body' => $row['body'],
2350 2465
 					'subject' => $row['subject'],
@@ -2355,28 +2470,33 @@  discard block
 block discarded – undo
2355 2470
 					'new_topic' => false,
2356 2471
 					'msg' => $row['id_msg'],
2357 2472
 				);
2473
+			}
2358 2474
 		}
2359 2475
 
2360 2476
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2361
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2362
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2477
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2478
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		}
2363 2480
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2364
-		elseif (!$approve)
2365
-			// Default to the first message and then we'll override in a bit ;)
2481
+		elseif (!$approve) {
2482
+					// Default to the first message and then we'll override in a bit ;)
2366 2483
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2484
+		}
2367 2485
 
2368 2486
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2369 2487
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2488
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2371 2489
 
2372 2490
 		// Post count for the user?
2373
-		if ($row['id_member'] && empty($row['count_posts']))
2374
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2491
+		if ($row['id_member'] && empty($row['count_posts'])) {
2492
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		}
2375 2494
 	}
2376 2495
 	$smcFunc['db_free_result']($request);
2377 2496
 
2378
-	if (empty($msgs))
2379
-		return;
2497
+	if (empty($msgs)) {
2498
+			return;
2499
+	}
2380 2500
 
2381 2501
 	// Now we have the differences make the changes, first the easy one.
2382 2502
 	$smcFunc['db_query']('', '
@@ -2403,14 +2523,15 @@  discard block
 block discarded – undo
2403 2523
 				'approved' => 1,
2404 2524
 			)
2405 2525
 		);
2406
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2407
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2526
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2527
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		}
2408 2529
 		$smcFunc['db_free_result']($request);
2409 2530
 	}
2410 2531
 
2411 2532
 	// ... next the topics...
2412
-	foreach ($topic_changes as $id => $changes)
2413
-		$smcFunc['db_query']('', '
2533
+	foreach ($topic_changes as $id => $changes) {
2534
+			$smcFunc['db_query']('', '
2414 2535
 			UPDATE {db_prefix}topics
2415 2536
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2416 2537
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2423,10 +2544,11 @@  discard block
 block discarded – undo
2423 2544
 				'id_topic' => $id,
2424 2545
 			)
2425 2546
 		);
2547
+	}
2426 2548
 
2427 2549
 	// ... finally the boards...
2428
-	foreach ($board_changes as $id => $changes)
2429
-		$smcFunc['db_query']('', '
2550
+	foreach ($board_changes as $id => $changes) {
2551
+			$smcFunc['db_query']('', '
2430 2552
 			UPDATE {db_prefix}boards
2431 2553
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2432 2554
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2439,13 +2561,14 @@  discard block
 block discarded – undo
2439 2561
 				'id_board' => $id,
2440 2562
 			)
2441 2563
 		);
2564
+	}
2442 2565
 
2443 2566
 	// Finally, least importantly, notifications!
2444 2567
 	if ($approve)
2445 2568
 	{
2446 2569
 		$task_rows = array();
2447
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2448
-			$task_rows[] = array(
2570
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2571
+					$task_rows[] = array(
2449 2572
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
2450 2573
 					'msgOptions' => array(
2451 2574
 						'id' => $topic['msg'],
@@ -2463,14 +2586,16 @@  discard block
 block discarded – undo
2463 2586
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2464 2587
 				)), 0
2465 2588
 			);
2589
+		}
2466 2590
 
2467
-		if ($notify)
2468
-			$smcFunc['db_insert']('',
2591
+		if ($notify) {
2592
+					$smcFunc['db_insert']('',
2469 2593
 				'{db_prefix}background_tasks',
2470 2594
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2471 2595
 				$task_rows,
2472 2596
 				array('id_task')
2473 2597
 			);
2598
+		}
2474 2599
 
2475 2600
 		$smcFunc['db_query']('', '
2476 2601
 			DELETE FROM {db_prefix}approval_queue
@@ -2486,8 +2611,9 @@  discard block
 block discarded – undo
2486 2611
 	else
2487 2612
 	{
2488 2613
 		$msgInserts = array();
2489
-		foreach ($msgs as $msg)
2490
-			$msgInserts[] = array($msg);
2614
+		foreach ($msgs as $msg) {
2615
+					$msgInserts[] = array($msg);
2616
+		}
2491 2617
 
2492 2618
 		$smcFunc['db_insert']('ignore',
2493 2619
 			'{db_prefix}approval_queue',
@@ -2501,9 +2627,10 @@  discard block
 block discarded – undo
2501 2627
 	updateLastMessages(array_keys($board_changes));
2502 2628
 
2503 2629
 	// Post count for the members?
2504
-	if (!empty($member_post_changes))
2505
-		foreach ($member_post_changes as $id_member => $count_change)
2630
+	if (!empty($member_post_changes)) {
2631
+			foreach ($member_post_changes as $id_member => $count_change)
2506 2632
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2633
+	}
2507 2634
 
2508 2635
 	return true;
2509 2636
 }
@@ -2520,11 +2647,13 @@  discard block
 block discarded – undo
2520 2647
 {
2521 2648
 	global $smcFunc;
2522 2649
 
2523
-	if (!is_array($topics))
2524
-		$topics = array($topics);
2650
+	if (!is_array($topics)) {
2651
+			$topics = array($topics);
2652
+	}
2525 2653
 
2526
-	if (empty($topics))
2527
-		return false;
2654
+	if (empty($topics)) {
2655
+			return false;
2656
+	}
2528 2657
 
2529 2658
 	$approve_type = $approve ? 0 : 1;
2530 2659
 
@@ -2540,8 +2669,9 @@  discard block
 block discarded – undo
2540 2669
 		)
2541 2670
 	);
2542 2671
 	$msgs = array();
2543
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2544
-		$msgs[] = $row['id_msg'];
2672
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2673
+			$msgs[] = $row['id_msg'];
2674
+	}
2545 2675
 	$smcFunc['db_free_result']($request);
2546 2676
 
2547 2677
 	return approvePosts($msgs, $approve);
@@ -2564,11 +2694,13 @@  discard block
 block discarded – undo
2564 2694
 	global $board_info, $board, $smcFunc;
2565 2695
 
2566 2696
 	// Please - let's be sane.
2567
-	if (empty($setboards))
2568
-		return false;
2697
+	if (empty($setboards)) {
2698
+			return false;
2699
+	}
2569 2700
 
2570
-	if (!is_array($setboards))
2571
-		$setboards = array($setboards);
2701
+	if (!is_array($setboards)) {
2702
+			$setboards = array($setboards);
2703
+	}
2572 2704
 
2573 2705
 	// If we don't know the id_msg we need to find it.
2574 2706
 	if (!$id_msg)
@@ -2586,15 +2718,16 @@  discard block
 block discarded – undo
2586 2718
 			)
2587 2719
 		);
2588 2720
 		$lastMsg = array();
2589
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2590
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2721
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2722
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		}
2591 2724
 		$smcFunc['db_free_result']($request);
2592
-	}
2593
-	else
2725
+	} else
2594 2726
 	{
2595 2727
 		// Just to note - there should only be one board passed if we are doing this.
2596
-		foreach ($setboards as $id_board)
2597
-			$lastMsg[$id_board] = $id_msg;
2728
+		foreach ($setboards as $id_board) {
2729
+					$lastMsg[$id_board] = $id_msg;
2730
+		}
2598 2731
 	}
2599 2732
 
2600 2733
 	$parent_boards = array();
@@ -2609,10 +2742,11 @@  discard block
 block discarded – undo
2609 2742
 			$lastModified[$id_board] = 0;
2610 2743
 		}
2611 2744
 
2612
-		if (!empty($board) && $id_board == $board)
2613
-			$parents = $board_info['parent_boards'];
2614
-		else
2615
-			$parents = getBoardParents($id_board);
2745
+		if (!empty($board) && $id_board == $board) {
2746
+					$parents = $board_info['parent_boards'];
2747
+		} else {
2748
+					$parents = getBoardParents($id_board);
2749
+		}
2616 2750
 
2617 2751
 		// Ignore any parents on the top child level.
2618 2752
 		// @todo Why?
@@ -2621,10 +2755,11 @@  discard block
 block discarded – undo
2621 2755
 			if ($parent['level'] != 0)
2622 2756
 			{
2623 2757
 				// If we're already doing this one as a board, is this a higher last modified?
2624
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2625
-					$lastModified[$id] = $lastModified[$id_board];
2626
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2627
-					$parent_boards[$id] = $lastModified[$id_board];
2758
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2759
+									$lastModified[$id] = $lastModified[$id_board];
2760
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2761
+									$parent_boards[$id] = $lastModified[$id_board];
2762
+				}
2628 2763
 			}
2629 2764
 		}
2630 2765
 	}
@@ -2637,23 +2772,24 @@  discard block
 block discarded – undo
2637 2772
 	// Finally, to save on queries make the changes...
2638 2773
 	foreach ($parent_boards as $id => $msg)
2639 2774
 	{
2640
-		if (!isset($parent_updates[$msg]))
2641
-			$parent_updates[$msg] = array($id);
2642
-		else
2643
-			$parent_updates[$msg][] = $id;
2775
+		if (!isset($parent_updates[$msg])) {
2776
+					$parent_updates[$msg] = array($id);
2777
+		} else {
2778
+					$parent_updates[$msg][] = $id;
2779
+		}
2644 2780
 	}
2645 2781
 
2646 2782
 	foreach ($lastMsg as $id => $msg)
2647 2783
 	{
2648
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2649
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2784
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2785
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2650 2786
 				'id' => $msg,
2651 2787
 				'updated' => $lastModified[$id],
2652 2788
 				'boards' => array($id)
2653 2789
 			);
2654
-
2655
-		else
2656
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2790
+		} else {
2791
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		}
2657 2793
 	}
2658 2794
 
2659 2795
 	// Now commit the changes!
@@ -2745,11 +2881,13 @@  discard block
 block discarded – undo
2745 2881
 	global $txt, $mbname, $scripturl, $settings;
2746 2882
 
2747 2883
 	// First things first, load up the email templates language file, if we need to.
2748
-	if ($loadLang)
2749
-		loadLanguage('EmailTemplates', $lang);
2884
+	if ($loadLang) {
2885
+			loadLanguage('EmailTemplates', $lang);
2886
+	}
2750 2887
 
2751
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2752
-		fatal_lang_error('email_no_template', 'template', array($template));
2888
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2889
+			fatal_lang_error('email_no_template', 'template', array($template));
2890
+	}
2753 2891
 
2754 2892
 	$ret = array(
2755 2893
 		'subject' => $txt[$template . '_subject'],
@@ -2799,17 +2937,18 @@  discard block
 block discarded – undo
2799 2937
 function user_info_callback($matches)
2800 2938
 {
2801 2939
 	global $user_info;
2802
-	if (empty($matches[1]))
2803
-		return '';
2940
+	if (empty($matches[1])) {
2941
+			return '';
2942
+	}
2804 2943
 
2805 2944
 	$use_ref = true;
2806 2945
 	$ref = &$user_info;
2807 2946
 
2808 2947
 	foreach (explode('.', $matches[1]) as $index)
2809 2948
 	{
2810
-		if ($use_ref && isset($ref[$index]))
2811
-			$ref = &$ref[$index];
2812
-		else
2949
+		if ($use_ref && isset($ref[$index])) {
2950
+					$ref = &$ref[$index];
2951
+		} else
2813 2952
 		{
2814 2953
 			$use_ref = false;
2815 2954
 			break;
@@ -2846,8 +2985,7 @@  discard block
 block discarded – undo
2846 2985
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2847 2986
 		{
2848 2987
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2849
-		}
2850
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2988
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2851 2989
 		{
2852 2990
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2853 2991
 		}
@@ -2857,8 +2995,7 @@  discard block
 block discarded – undo
2857 2995
 		{
2858 2996
 			$context['provider'] = 'enchant';
2859 2997
 			return $enchant_link;
2860
-		}
2861
-		else
2998
+		} else
2862 2999
 		{
2863 3000
 			// Free up any resources used...
2864 3001
 			@enchant_broker_free($context['enchant_broker']);
@@ -2879,8 +3016,9 @@  discard block
 block discarded – undo
2879 3016
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2880 3017
 
2881 3018
 		// Most people don't have anything but English installed... So we use English as a last resort.
2882
-		if (!$pspell_link)
2883
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3019
+		if (!$pspell_link) {
3020
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		}
2884 3022
 
2885 3023
 		error_reporting($old);
2886 3024
 		ob_end_clean();
@@ -2920,8 +3058,7 @@  discard block
 block discarded – undo
2920 3058
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2921 3059
 		}
2922 3060
 		return enchant_dict_check($dict, $word);
2923
-	}
2924
-	elseif ($context['provider'] == 'pspell')
3061
+	} elseif ($context['provider'] == 'pspell')
2925 3062
 	{
2926 3063
 		return pspell_check($dict, $word);
2927 3064
 	}
@@ -2957,13 +3094,11 @@  discard block
 block discarded – undo
2957 3094
 			}
2958 3095
 
2959 3096
 			return $suggestions;
2960
-		}
2961
-		else
3097
+		} else
2962 3098
 		{
2963 3099
 			return enchant_dict_suggest($dict, $word);
2964 3100
 		}
2965
-	}
2966
-	elseif ($context['provider'] == 'pspell')
3101
+	} elseif ($context['provider'] == 'pspell')
2967 3102
 	{
2968 3103
 		return pspell_suggest($dict, $word);
2969 3104
 	}
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 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
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -154,11 +157,12 @@  discard block
 block discarded – undo
154 157
 				'data' => array(
155 158
 					'function' => function($news)
156 159
 					{
157
-						if (is_numeric($news['id']))
158
-							return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
160
+						if (is_numeric($news['id'])) {
161
+													return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
159 162
 							<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
160
-						else
161
-							return $news['unparsed'];
163
+						} else {
164
+													return $news['unparsed'];
165
+						}
162 166
 					},
163 167
 					'style' => 'width: 50%;',
164 168
 				),
@@ -183,10 +187,11 @@  discard block
 block discarded – undo
183 187
 				'data' => array(
184 188
 					'function' => function($news)
185 189
 					{
186
-						if (is_numeric($news['id']))
187
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">';
188
-						else
189
-							return '';
190
+						if (is_numeric($news['id'])) {
191
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">';
192
+						} else {
193
+													return '';
194
+						}
190 195
 					},
191 196
 					'class' => 'centercol',
192 197
 				),
@@ -280,12 +285,13 @@  discard block
 block discarded – undo
280 285
 
281 286
 	$admin_current_news = array();
282 287
 	// Ready the current news.
283
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
284
-		$admin_current_news[$id] = array(
288
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
289
+			$admin_current_news[$id] = array(
285 290
 			'id' => $id,
286 291
 			'unparsed' => un_preparsecode($line),
287 292
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
288 293
 		);
294
+	}
289 295
 
290 296
 	$admin_current_news['last'] = array(
291 297
 		'id' => 'last',
@@ -352,10 +358,11 @@  discard block
 block discarded – undo
352 358
 			'member_count' => 0,
353 359
 		);
354 360
 
355
-		if ($row['min_posts'] == -1)
356
-			$normalGroups[$row['id_group']] = $row['id_group'];
357
-		else
358
-			$postGroups[$row['id_group']] = $row['id_group'];
361
+		if ($row['min_posts'] == -1) {
362
+					$normalGroups[$row['id_group']] = $row['id_group'];
363
+		} else {
364
+					$postGroups[$row['id_group']] = $row['id_group'];
365
+		}
359 366
 	}
360 367
 	$smcFunc['db_free_result']($request);
361 368
 
@@ -371,8 +378,9 @@  discard block
 block discarded – undo
371 378
 				'post_group_list' => $postGroups,
372 379
 			)
373 380
 		);
374
-		while ($row = $smcFunc['db_fetch_assoc']($query))
375
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
381
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
382
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
383
+		}
376 384
 		$smcFunc['db_free_result']($query);
377 385
 	}
378 386
 
@@ -388,8 +396,9 @@  discard block
 block discarded – undo
388 396
 				'normal_group_list' => $normalGroups,
389 397
 			)
390 398
 		);
391
-		while ($row = $smcFunc['db_fetch_assoc']($query))
392
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
399
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
400
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
401
+		}
393 402
 		$smcFunc['db_free_result']($query);
394 403
 
395 404
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -406,8 +415,9 @@  discard block
 block discarded – undo
406 415
 				'blank_string' => '',
407 416
 			)
408 417
 		);
409
-		while ($row = $smcFunc['db_fetch_assoc']($query))
410
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
418
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
419
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
420
+		}
411 421
 		$smcFunc['db_free_result']($query);
412 422
 	}
413 423
 
@@ -458,10 +468,11 @@  discard block
 block discarded – undo
458 468
 	{
459 469
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
460 470
 
461
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
462
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
463
-		elseif (!empty($_REQUEST['xml']))
464
-			continue;
471
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
472
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
473
+		} elseif (!empty($_REQUEST['xml'])) {
474
+					continue;
475
+		}
465 476
 
466 477
 		preparsecode($context[$key]);
467 478
 		if ($html)
@@ -540,10 +551,12 @@  discard block
 block discarded – undo
540 551
 
541 552
 	// Start by finding any members!
542 553
 	$toClean = array();
543
-	if (!empty($_POST['members']))
544
-		$toClean[] = 'members';
545
-	if (!empty($_POST['exclude_members']))
546
-		$toClean[] = 'exclude_members';
554
+	if (!empty($_POST['members'])) {
555
+			$toClean[] = 'members';
556
+	}
557
+	if (!empty($_POST['exclude_members'])) {
558
+			$toClean[] = 'exclude_members';
559
+	}
547 560
 	if (!empty($toClean))
548 561
 	{
549 562
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -555,11 +568,13 @@  discard block
 block discarded – undo
555 568
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
556 569
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
557 570
 
558
-			foreach ($_POST[$type] as $index => $member)
559
-				if (strlen(trim($member)) > 0)
571
+			foreach ($_POST[$type] as $index => $member) {
572
+							if (strlen(trim($member)) > 0)
560 573
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
561
-				else
562
-					unset($_POST[$type][$index]);
574
+			}
575
+				else {
576
+									unset($_POST[$type][$index]);
577
+				}
563 578
 
564 579
 			// Find the members
565 580
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -569,16 +584,18 @@  discard block
 block discarded – undo
569 584
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
570 585
 	{
571 586
 		$members = array();
572
-		foreach ($_POST['member_list'] as $member_id)
573
-			$members[] = (int) $member_id;
587
+		foreach ($_POST['member_list'] as $member_id) {
588
+					$members[] = (int) $member_id;
589
+		}
574 590
 		$_POST['members'] = implode(',', $members);
575 591
 	}
576 592
 
577 593
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
578 594
 	{
579 595
 		$members = array();
580
-		foreach ($_POST['exclude_member_list'] as $member_id)
581
-			$members[] = (int) $member_id;
596
+		foreach ($_POST['exclude_member_list'] as $member_id) {
597
+					$members[] = (int) $member_id;
598
+		}
582 599
 		$_POST['exclude_members'] = implode(',', $members);
583 600
 	}
584 601
 
@@ -602,8 +619,9 @@  discard block
 block discarded – undo
602 619
 			'current_time' => time(),
603 620
 		)
604 621
 	);
605
-	while ($row = $smcFunc['db_fetch_assoc']($request))
606
-		$context['recipients']['exclude_members'][] = $row['id_member'];
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$context['recipients']['exclude_members'][] = $row['id_member'];
624
+	}
607 625
 	$smcFunc['db_free_result']($request);
608 626
 
609 627
 	$request = $smcFunc['db_query']('', '
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
639 657
 			$condition_array_params
640 658
 		);
641
-		while ($row = $smcFunc['db_fetch_assoc']($request))
642
-			$context['recipients']['exclude_members'][] = $row['id_member'];
659
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
660
+					$context['recipients']['exclude_members'][] = $row['id_member'];
661
+		}
643 662
 		$smcFunc['db_free_result']($request);
644 663
 	}
645 664
 
@@ -657,10 +676,11 @@  discard block
 block discarded – undo
657 676
 		);
658 677
 		while ($row = $smcFunc['db_fetch_assoc']($request))
659 678
 		{
660
-			if (in_array(3, $context['recipients']))
661
-				$context['recipients']['exclude_members'][] = $row['identifier'];
662
-			else
663
-				$context['recipients']['members'][] = $row['identifier'];
679
+			if (in_array(3, $context['recipients'])) {
680
+							$context['recipients']['exclude_members'][] = $row['identifier'];
681
+			} else {
682
+							$context['recipients']['members'][] = $row['identifier'];
683
+			}
664 684
 		}
665 685
 		$smcFunc['db_free_result']($request);
666 686
 	}
@@ -707,8 +727,9 @@  discard block
 block discarded – undo
707 727
 	$num_at_once = 1000;
708 728
 
709 729
 	// If by PM's I suggest we half the above number.
710
-	if (!empty($_POST['send_pm']))
711
-		$num_at_once /= 2;
730
+	if (!empty($_POST['send_pm'])) {
731
+			$num_at_once /= 2;
732
+	}
712 733
 
713 734
 	checkSession();
714 735
 
@@ -731,8 +752,7 @@  discard block
 block discarded – undo
731 752
 		);
732 753
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
733 754
 		$smcFunc['db_free_result']($request);
734
-	}
735
-	else
755
+	} else
736 756
 	{
737 757
 		$context['total_members'] = (int) $_REQUEST['total_members'];
738 758
 	}
@@ -750,32 +770,35 @@  discard block
 block discarded – undo
750 770
 	if (!empty($_POST['exclude_members']))
751 771
 	{
752 772
 		$members = explode(',', $_POST['exclude_members']);
753
-		foreach ($members as $member)
754
-			if ($member >= $context['start'])
773
+		foreach ($members as $member) {
774
+					if ($member >= $context['start'])
755 775
 				$context['recipients']['exclude_members'][] = (int) $member;
776
+		}
756 777
 	}
757 778
 
758 779
 	// What about members we *must* do?
759 780
 	if (!empty($_POST['members']))
760 781
 	{
761 782
 		$members = explode(',', $_POST['members']);
762
-		foreach ($members as $member)
763
-			if ($member >= $context['start'])
783
+		foreach ($members as $member) {
784
+					if ($member >= $context['start'])
764 785
 				$context['recipients']['members'][] = (int) $member;
786
+		}
765 787
 	}
766 788
 	// Cleaning groups is simple - although deal with both checkbox and commas.
767 789
 	if (isset($_POST['groups']))
768 790
 	{
769 791
 		if (is_array($_POST['groups']))
770 792
 		{
771
-			foreach ($_POST['groups'] as $group => $dummy)
772
-				$context['recipients']['groups'][] = (int) $group;
773
-		}
774
-		else
793
+			foreach ($_POST['groups'] as $group => $dummy) {
794
+							$context['recipients']['groups'][] = (int) $group;
795
+			}
796
+		} else
775 797
 		{
776 798
 			$groups = explode(',', $_POST['groups']);
777
-			foreach ($groups as $group)
778
-				$context['recipients']['groups'][] = (int) $group;
799
+			foreach ($groups as $group) {
800
+							$context['recipients']['groups'][] = (int) $group;
801
+			}
779 802
 		}
780 803
 	}
781 804
 	// Same for excluded groups
@@ -783,15 +806,17 @@  discard block
 block discarded – undo
783 806
 	{
784 807
 		if (is_array($_POST['exclude_groups']))
785 808
 		{
786
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
787
-				$context['recipients']['exclude_groups'][] = (int) $group;
809
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
810
+							$context['recipients']['exclude_groups'][] = (int) $group;
811
+			}
788 812
 		}
789 813
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
790 814
 		elseif ($_POST['exclude_groups'] != '')
791 815
 		{
792 816
 			$groups = explode(',', $_POST['exclude_groups']);
793
-			foreach ($groups as $group)
794
-				$context['recipients']['exclude_groups'][] = (int) $group;
817
+			foreach ($groups as $group) {
818
+							$context['recipients']['exclude_groups'][] = (int) $group;
819
+			}
795 820
 		}
796 821
 	}
797 822
 	// Finally - emails!
@@ -801,14 +826,16 @@  discard block
 block discarded – undo
801 826
 		foreach ($addressed as $curmem)
802 827
 		{
803 828
 			$curmem = trim($curmem);
804
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
805
-				$context['recipients']['emails'][$curmem] = $curmem;
829
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
830
+							$context['recipients']['emails'][$curmem] = $curmem;
831
+			}
806 832
 		}
807 833
 	}
808 834
 
809 835
 	// If we're only cleaning drop out here.
810
-	if ($clean_only)
811
-		return;
836
+	if ($clean_only) {
837
+			return;
838
+	}
812 839
 
813 840
 	require_once($sourcedir . '/Subs-Post.php');
814 841
 
@@ -824,16 +851,18 @@  discard block
 block discarded – undo
824 851
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
825 852
 	{
826 853
 		// Prepare the message for HTML.
827
-		if (!empty($_POST['parse_html']))
828
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
854
+		if (!empty($_POST['parse_html'])) {
855
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
856
+		}
829 857
 
830 858
 		// This is here to prevent spam filters from tagging this as spam.
831 859
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
832 860
 		{
833
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
834
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
835
-			else
836
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
861
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
862
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
863
+			} else {
864
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
865
+			}
837 866
 		}
838 867
 	}
839 868
 
@@ -887,15 +916,17 @@  discard block
 block discarded – undo
887 916
 	foreach ($context['recipients']['emails'] as $k => $email)
888 917
 	{
889 918
 		// Done as many as we can?
890
-		if ($i >= $num_at_once)
891
-			break;
919
+		if ($i >= $num_at_once) {
920
+					break;
921
+		}
892 922
 
893 923
 		// Don't sent it twice!
894 924
 		unset($context['recipients']['emails'][$k]);
895 925
 
896 926
 		// Dammit - can't PM emails!
897
-		if ($context['send_pm'])
898
-			continue;
927
+		if ($context['send_pm']) {
928
+					continue;
929
+		}
899 930
 
900 931
 		$to_member = array(
901 932
 			$email,
@@ -929,8 +960,9 @@  discard block
 block discarded – undo
929 960
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
930 961
 				}
931 962
 			}
932
-			if (!empty($queryBuild))
933
-			$sendQuery .= implode(' OR ', $queryBuild);
963
+			if (!empty($queryBuild)) {
964
+						$sendQuery .= implode(' OR ', $queryBuild);
965
+			}
934 966
 		}
935 967
 		if (!empty($context['recipients']['members']))
936 968
 		{
@@ -949,8 +981,9 @@  discard block
 block discarded – undo
949 981
 		}
950 982
 
951 983
 		// Anything to exclude?
952
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
953
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
984
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
985
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
986
+		}
954 987
 		if (!empty($context['recipients']['exclude_members']))
955 988
 		{
956 989
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -986,21 +1019,24 @@  discard block
 block discarded – undo
986 1019
 		foreach ($rows as $row)
987 1020
 		{
988 1021
 			// Force them to have it?
989
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
990
-				continue;
1022
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1023
+							continue;
1024
+			}
991 1025
 
992 1026
 			// What groups are we looking at here?
993
-			if (empty($row['additional_groups']))
994
-				$groups = array($row['id_group'], $row['id_post_group']);
995
-			else
996
-				$groups = array_merge(
1027
+			if (empty($row['additional_groups'])) {
1028
+							$groups = array($row['id_group'], $row['id_post_group']);
1029
+			} else {
1030
+							$groups = array_merge(
997 1031
 					array($row['id_group'], $row['id_post_group']),
998 1032
 					explode(',', $row['additional_groups'])
999 1033
 				);
1034
+			}
1000 1035
 
1001 1036
 			// Excluded groups?
1002
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1003
-				continue;
1037
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1038
+							continue;
1039
+			}
1004 1040
 
1005 1041
 			// We might need this
1006 1042
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1023,10 +1059,11 @@  discard block
 block discarded – undo
1023 1059
 				), $_POST['subject']);
1024 1060
 
1025 1061
 			// Send the actual email - or a PM!
1026
-			if (!$context['send_pm'])
1027
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1028
-			else
1029
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1062
+			if (!$context['send_pm']) {
1063
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1064
+			} else {
1065
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1066
+			}
1030 1067
 		}
1031 1068
 	}
1032 1069
 
@@ -1076,8 +1113,9 @@  discard block
 block discarded – undo
1076 1113
 
1077 1114
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1078 1115
 
1079
-	if ($return_config)
1080
-		return $config_vars;
1116
+	if ($return_config) {
1117
+			return $config_vars;
1118
+	}
1081 1119
 
1082 1120
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1083 1121
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 1 patch
Braces   +267 added lines, -200 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
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$id_topic = $smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$id_topic = $smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -821,6 +856,7 @@  discard block
 block discarded – undo
821 856
 				array('id_topic'),
822 857
 				1
823 858
 			);
859
+		}
824 860
 
825 861
 		// Capture the ID of the new topic...
826 862
 		$topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic;
@@ -858,22 +894,24 @@  discard block
 block discarded – undo
858 894
 			);
859 895
 
860 896
 			// Mark recycled topic as read.
861
-			if (!$user_info['is_guest'])
862
-				$smcFunc['db_insert']('replace',
897
+			if (!$user_info['is_guest']) {
898
+							$smcFunc['db_insert']('replace',
863 899
 					'{db_prefix}log_topics',
864 900
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
865 901
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
866 902
 					array('id_topic', 'id_member')
867 903
 				);
904
+			}
868 905
 
869 906
 			// Mark recycle board as seen, if it was marked as seen before.
870
-			if (!empty($isRead) && !$user_info['is_guest'])
871
-				$smcFunc['db_insert']('replace',
907
+			if (!empty($isRead) && !$user_info['is_guest']) {
908
+							$smcFunc['db_insert']('replace',
872 909
 					'{db_prefix}log_boards',
873 910
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
874 911
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
875 912
 					array('id_board', 'id_member')
876 913
 				);
914
+			}
877 915
 
878 916
 			// Add one topic and post to the recycle bin board.
879 917
 			$smcFunc['db_query']('', '
@@ -891,8 +929,8 @@  discard block
 block discarded – undo
891 929
 			);
892 930
 
893 931
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
894
-			if (!empty($id_recycle_topic))
895
-				$smcFunc['db_query']('', '
932
+			if (!empty($id_recycle_topic)) {
933
+							$smcFunc['db_query']('', '
896 934
 					UPDATE {db_prefix}topics
897 935
 					SET num_replies = num_replies + 1' .
898 936
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -903,6 +941,7 @@  discard block
 block discarded – undo
903 941
 						'id_merged_msg' => $message,
904 942
 					)
905 943
 				);
944
+			}
906 945
 
907 946
 			// Make sure this message isn't getting deleted later on.
908 947
 			$recycle = true;
@@ -912,8 +951,8 @@  discard block
 block discarded – undo
912 951
 		}
913 952
 
914 953
 		// If it wasn't approved don't keep it in the queue.
915
-		if (!$row['approved'])
916
-			$smcFunc['db_query']('', '
954
+		if (!$row['approved']) {
955
+					$smcFunc['db_query']('', '
917 956
 				DELETE FROM {db_prefix}approval_queue
918 957
 				WHERE id_msg = {int:id_msg}
919 958
 					AND id_attach = {int:id_attach}',
@@ -922,6 +961,7 @@  discard block
 block discarded – undo
922 961
 					'id_attach' => 0,
923 962
 				)
924 963
 			);
964
+		}
925 965
 	}
926 966
 
927 967
 	$smcFunc['db_query']('', '
@@ -939,8 +979,9 @@  discard block
 block discarded – undo
939 979
 
940 980
 	// If the poster was registered and the board this message was on incremented
941 981
 	// the member's posts when it was posted, decrease his or her post count.
942
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
943
-		updateMemberData($row['id_member'], array('posts' => '-'));
982
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
983
+			updateMemberData($row['id_member'], array('posts' => '-'));
984
+	}
944 985
 
945 986
 	// Only remove posts if they're not recycled.
946 987
 	if (!$recycle)
@@ -948,8 +989,9 @@  discard block
 block discarded – undo
948 989
 		// Callback for search APIs to do their thing
949 990
 		require_once($sourcedir . '/Search.php');
950 991
 		$searchAPI = findSearchAPI();
951
-		if ($searchAPI->supportsMethod('postRemoved'))
952
-			$searchAPI->postRemoved($message);
992
+		if ($searchAPI->supportsMethod('postRemoved')) {
993
+					$searchAPI->postRemoved($message);
994
+		}
953 995
 
954 996
 		// Remove the message!
955 997
 		$smcFunc['db_query']('', '
@@ -964,8 +1006,8 @@  discard block
 block discarded – undo
964 1006
 		{
965 1007
 			$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
966 1008
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
967
-			if (!empty($words))
968
-				$smcFunc['db_query']('', '
1009
+			if (!empty($words)) {
1010
+							$smcFunc['db_query']('', '
969 1011
 					DELETE FROM {db_prefix}log_search_words
970 1012
 					WHERE id_word IN ({array_int:word_list})
971 1013
 						AND id_msg = {int:id_msg}',
@@ -974,6 +1016,7 @@  discard block
 block discarded – undo
974 1016
 						'id_msg' => $message,
975 1017
 					)
976 1018
 				);
1019
+			}
977 1020
 		}
978 1021
 
979 1022
 		// Delete attachment(s) if they exist.
@@ -997,10 +1040,11 @@  discard block
 block discarded – undo
997 1040
 
998 1041
 	// And now to update the last message of each board we messed with.
999 1042
 	require_once($sourcedir . '/Subs-Post.php');
1000
-	if ($recycle)
1001
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1002
-	else
1003
-		updateLastMessages($row['id_board']);
1043
+	if ($recycle) {
1044
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1045
+	} else {
1046
+			updateLastMessages($row['id_board']);
1047
+	}
1004 1048
 
1005 1049
 	// Close any moderation reports for this message.
1006 1050
 	$smcFunc['db_query']('', '
@@ -1033,8 +1077,9 @@  discard block
 block discarded – undo
1033 1077
 	checkSession('get');
1034 1078
 
1035 1079
 	// Is recycled board enabled?
1036
-	if (empty($modSettings['recycle_enable']))
1037
-		fatal_lang_error('restored_disabled', 'critical');
1080
+	if (empty($modSettings['recycle_enable'])) {
1081
+			fatal_lang_error('restored_disabled', 'critical');
1082
+	}
1038 1083
 
1039 1084
 	// Can we be in here?
1040 1085
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1049,8 +1094,9 @@  discard block
 block discarded – undo
1049 1094
 	if (!empty($_REQUEST['msgs']))
1050 1095
 	{
1051 1096
 		$msgs = explode(',', $_REQUEST['msgs']);
1052
-		foreach ($msgs as $k => $msg)
1053
-			$msgs[$k] = (int) $msg;
1097
+		foreach ($msgs as $k => $msg) {
1098
+					$msgs[$k] = (int) $msg;
1099
+		}
1054 1100
 
1055 1101
 		// Get the id_previous_board and id_previous_topic.
1056 1102
 		$request = $smcFunc['db_query']('', '
@@ -1084,8 +1130,8 @@  discard block
 block discarded – undo
1084 1130
 			}
1085 1131
 
1086 1132
 			$previous_topics[] = $row['id_previous_topic'];
1087
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1088
-				$actioned_messages[$row['id_previous_topic']] = array(
1133
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1134
+							$actioned_messages[$row['id_previous_topic']] = array(
1089 1135
 					'msgs' => array(),
1090 1136
 					'count_posts' => $row['count_posts'],
1091 1137
 					'subject' => $row['subject'],
@@ -1095,17 +1141,20 @@  discard block
 block discarded – undo
1095 1141
 					'current_board' => $row['id_board'],
1096 1142
 					'members' => array(),
1097 1143
 				);
1144
+			}
1098 1145
 
1099 1146
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1100
-			if ($row['id_member'])
1101
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1147
+			if ($row['id_member']) {
1148
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1149
+			}
1102 1150
 		}
1103 1151
 		$smcFunc['db_free_result']($request);
1104 1152
 
1105 1153
 		// Check for topics we are going to fully restore.
1106
-		foreach ($actioned_messages as $topic => $data)
1107
-			if (in_array($topic, $topics_to_restore))
1154
+		foreach ($actioned_messages as $topic => $data) {
1155
+					if (in_array($topic, $topics_to_restore))
1108 1156
 				unset($actioned_messages[$topic]);
1157
+		}
1109 1158
 
1110 1159
 		// Load any previous topics to check they exist.
1111 1160
 		if (!empty($previous_topics))
@@ -1120,11 +1169,12 @@  discard block
 block discarded – undo
1120 1169
 				)
1121 1170
 			);
1122 1171
 			$previous_topics = array();
1123
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1124
-				$previous_topics[$row['id_topic']] = array(
1172
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1173
+							$previous_topics[$row['id_topic']] = array(
1125 1174
 					'board' => $row['id_board'],
1126 1175
 					'subject' => $row['subject'],
1127 1176
 				);
1177
+			}
1128 1178
 			$smcFunc['db_free_result']($request);
1129 1179
 		}
1130 1180
 
@@ -1146,11 +1196,11 @@  discard block
 block discarded – undo
1146 1196
 				// Log em.
1147 1197
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1148 1198
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1149
-			}
1150
-			else
1199
+			} else
1151 1200
 			{
1152
-				foreach ($data['msgs'] as $msg)
1153
-					$unfound_messages[$msg['id']] = $msg['subject'];
1201
+				foreach ($data['msgs'] as $msg) {
1202
+									$unfound_messages[$msg['id']] = $msg['subject'];
1203
+				}
1154 1204
 			}
1155 1205
 		}
1156 1206
 	}
@@ -1159,8 +1209,9 @@  discard block
 block discarded – undo
1159 1209
 	if (!empty($_REQUEST['topics']))
1160 1210
 	{
1161 1211
 		$topics = explode(',', $_REQUEST['topics']);
1162
-		foreach ($topics as $id)
1163
-			$topics_to_restore[] = (int) $id;
1212
+		foreach ($topics as $id) {
1213
+					$topics_to_restore[] = (int) $id;
1214
+		}
1164 1215
 	}
1165 1216
 
1166 1217
 	if (!empty($topics_to_restore))
@@ -1214,8 +1265,9 @@  discard block
 block discarded – undo
1214 1265
 					)
1215 1266
 				);
1216 1267
 
1217
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1218
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1268
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1269
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1270
+				}
1219 1271
 				$smcFunc['db_free_result']($request2);
1220 1272
 			}
1221 1273
 
@@ -1226,8 +1278,9 @@  discard block
 block discarded – undo
1226 1278
 	}
1227 1279
 
1228 1280
 	// Didn't find some things?
1229
-	if (!empty($unfound_messages))
1230
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1281
+	if (!empty($unfound_messages)) {
1282
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1283
+	}
1231 1284
 
1232 1285
 	// Just send them to the index if they get here.
1233 1286
 	redirectexit();
@@ -1247,12 +1300,14 @@  discard block
 block discarded – undo
1247 1300
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1248 1301
 
1249 1302
 	// Is it an array?
1250
-	if (!is_array($msgs))
1251
-		$msgs = array($msgs);
1303
+	if (!is_array($msgs)) {
1304
+			$msgs = array($msgs);
1305
+	}
1252 1306
 
1253 1307
 	// Lets make sure they are int.
1254
-	foreach ($msgs as $key => $msg)
1255
-		$msgs[$key] = (int) $msg;
1308
+	foreach ($msgs as $key => $msg) {
1309
+			$msgs[$key] = (int) $msg;
1310
+	}
1256 1311
 
1257 1312
 	// Get the source information.
1258 1313
 	$request = $smcFunc['db_query']('', '
@@ -1295,8 +1350,9 @@  discard block
 block discarded – undo
1295 1350
 			)
1296 1351
 		);
1297 1352
 
1298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1299
-			updateMemberData($row['id_member'], array('posts' => '+'));
1353
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1354
+					updateMemberData($row['id_member'], array('posts' => '+'));
1355
+		}
1300 1356
 	}
1301 1357
 
1302 1358
 	// Time to move the messages.
@@ -1332,13 +1388,15 @@  discard block
 block discarded – undo
1332 1388
 	);
1333 1389
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1334 1390
 	{
1335
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1336
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1391
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1392
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1393
+		}
1337 1394
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1338
-		if (!$row['approved'])
1339
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1340
-		else
1341
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1395
+		if (!$row['approved']) {
1396
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1397
+		} else {
1398
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1399
+		}
1342 1400
 	}
1343 1401
 	$smcFunc['db_free_result']($request);
1344 1402
 
@@ -1397,13 +1455,15 @@  discard block
 block discarded – undo
1397 1455
 		);
1398 1456
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1399 1457
 		{
1400
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1401
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1458
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1459
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1460
+			}
1402 1461
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1403
-			if (!$row['approved'])
1404
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1405
-			else
1406
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1462
+			if (!$row['approved']) {
1463
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1464
+			} else {
1465
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1466
+			}
1407 1467
 		}
1408 1468
 		$smcFunc['db_free_result']($request);
1409 1469
 
@@ -1467,10 +1527,12 @@  discard block
 block discarded – undo
1467 1527
 
1468 1528
 	// Subject cache?
1469 1529
 	$cache_updates = array();
1470
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1471
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1472
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1473
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1530
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1531
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1532
+	}
1533
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1534
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1535
+	}
1474 1536
 
1475 1537
 	if (!empty($cache_updates))
1476 1538
 	{
@@ -1482,8 +1544,9 @@  discard block
 block discarded – undo
1482 1544
 				'first_messages' => $cache_updates,
1483 1545
 			)
1484 1546
 		);
1485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1486
-			updateStats('subject', $row['id_topic'], $row['subject']);
1547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1548
+					updateStats('subject', $row['id_topic'], $row['subject']);
1549
+		}
1487 1550
 		$smcFunc['db_free_result']($request);
1488 1551
 	}
1489 1552
 
@@ -1499,22 +1562,26 @@  discard block
 block discarded – undo
1499 1562
 	global $modSettings, $board, $scripturl, $context;
1500 1563
 
1501 1564
 	// No recycle no need to go further
1502
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1503
-		return false;
1565
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1566
+			return false;
1567
+	}
1504 1568
 
1505 1569
 	// If it's confirmed go on and delete (from recycle)
1506
-	if (isset($_GET['confirm_delete']))
1507
-		return true;
1570
+	if (isset($_GET['confirm_delete'])) {
1571
+			return true;
1572
+	}
1508 1573
 
1509
-	if (empty($board))
1510
-		return false;
1574
+	if (empty($board)) {
1575
+			return false;
1576
+	}
1511 1577
 
1512
-	if ($modSettings['recycle_board'] != $board)
1513
-		return true;
1514
-	elseif (isset($_REQUEST['msg']))
1515
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1516
-	else
1517
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1578
+	if ($modSettings['recycle_board'] != $board) {
1579
+			return true;
1580
+	} elseif (isset($_REQUEST['msg'])) {
1581
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1582
+	} else {
1583
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1584
+	}
1518 1585
 
1519 1586
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1520 1587
 }
Please login to merge, or discard this patch.
Sources/Subs-MessageIndex.php 1 patch
Braces   +13 added lines, -10 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
  * Generates the query to determine the list of available boards for a user
@@ -25,8 +26,9 @@  discard block
 block discarded – undo
25 26
 {
26 27
 	global $smcFunc, $sourcedir;
27 28
 
28
-	if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards']))
29
-		trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR);
29
+	if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards'])) {
30
+			trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR);
31
+	}
30 32
 
31 33
 	$where = array();
32 34
 	$where_parameters = array();
@@ -42,11 +44,11 @@  discard block
 block discarded – undo
42 44
 		$where_parameters['included_boards'] = $boardListOptions['included_boards'];
43 45
 	}
44 46
 
45
-	if (!empty($boardListOptions['ignore_boards']))
46
-		$where[] = '{query_wanna_see_board}';
47
-
48
-	elseif (!empty($boardListOptions['use_permissions']))
49
-		$where[] = '{query_see_board}';
47
+	if (!empty($boardListOptions['ignore_boards'])) {
48
+			$where[] = '{query_wanna_see_board}';
49
+	} elseif (!empty($boardListOptions['use_permissions'])) {
50
+			$where[] = '{query_see_board}';
51
+	}
50 52
 
51 53
 	if (!empty($boardListOptions['not_redirection']))
52 54
 	{
@@ -68,12 +70,13 @@  discard block
 block discarded – undo
68 70
 	{
69 71
 		while ($row = $smcFunc['db_fetch_assoc']($request))
70 72
 		{
71
-			if (!isset($return_value[$row['id_cat']]))
72
-				$return_value[$row['id_cat']] = array(
73
+			if (!isset($return_value[$row['id_cat']])) {
74
+							$return_value[$row['id_cat']] = array(
73 75
 					'id' => $row['id_cat'],
74 76
 					'name' => $row['cat_name'],
75 77
 					'boards' => array(),
76 78
 				);
79
+			}
77 80
 
78 81
 			$return_value[$row['id_cat']]['boards'][$row['id_board']] = array(
79 82
 				'id' => $row['id_board'],
Please login to merge, or discard this patch.
Sources/Class-CacheAPI.php 1 patch
Braces   +13 added lines, -9 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
@@ -183,8 +184,9 @@  discard block
 block discarded – undo
183 184
 	{
184 185
 		global $cache_enable;
185 186
 
186
-		if ($test)
187
-			return true;
187
+		if ($test) {
188
+					return true;
189
+		}
188 190
 		return !empty($cache_enable);
189 191
 	}
190 192
 
@@ -203,10 +205,11 @@  discard block
 block discarded – undo
203 205
 		global $boardurl, $cachedir;
204 206
 
205 207
 		// Set the default if no prefix was specified.
206
-		if (empty($prefix))
207
-			$this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-';
208
-		else
209
-			$this->prefix = $prefix;
208
+		if (empty($prefix)) {
209
+					$this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-';
210
+		} else {
211
+					$this->prefix = $prefix;
212
+		}
210 213
 
211 214
 		return true;
212 215
 	}
@@ -269,8 +272,9 @@  discard block
 block discarded – undo
269 272
 
270 273
 		// Invalidate cache, to be sure!
271 274
 		// ... as long as index.php can be modified, anyway.
272
-		if (is_writable($cachedir . '/' . 'index.php'))
273
-			@touch($cachedir . '/' . 'index.php');
275
+		if (is_writable($cachedir . '/' . 'index.php')) {
276
+					@touch($cachedir . '/' . 'index.php');
277
+		}
274 278
 
275 279
 		return true;
276 280
 	}
Please login to merge, or discard this patch.
Sources/Class-Package.php 1 patch
Braces   +266 added lines, -199 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 xmlArray
@@ -65,8 +66,9 @@  discard block
 block discarded – undo
65 66
 		}
66 67
 
67 68
 		// Is the input an array? (ie. passed from file()?)
68
-		if (is_array($data))
69
-			$data = implode('', $data);
69
+		if (is_array($data)) {
70
+					$data = implode('', $data);
71
+		}
70 72
 
71 73
 		// Remove any xml declaration or doctype, and parse out comments and CDATA.
72 74
 		$data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data)));
@@ -101,8 +103,9 @@  discard block
 block discarded – undo
101 103
 		// Get the element, in array form.
102 104
 		$array = $this->path($path);
103 105
 
104
-		if ($array === false)
105
-			return false;
106
+		if ($array === false) {
107
+					return false;
108
+		}
106 109
 
107 110
 		// Getting elements into this is a bit complicated...
108 111
 		if ($get_elements && !is_string($array))
@@ -113,8 +116,9 @@  discard block
 block discarded – undo
113 116
 			foreach ($array->array as $val)
114 117
 			{
115 118
 				// Skip the name and any attributes.
116
-				if (is_array($val))
117
-					$temp .= $this->_xml($val, null);
119
+				if (is_array($val)) {
120
+									$temp .= $this->_xml($val, null);
121
+				}
118 122
 			}
119 123
 
120 124
 			// Just get the XML data and then take out the CDATAs.
@@ -156,32 +160,35 @@  discard block
 block discarded – undo
156 160
 			elseif (substr($el, 0, 1) == '@')
157 161
 			{
158 162
 				// It simplifies things if the attribute is already there ;).
159
-				if (isset($array[$el]))
160
-					return $array[$el];
161
-				else
163
+				if (isset($array[$el])) {
164
+									return $array[$el];
165
+				} else
162 166
 				{
163 167
 					$trace = debug_backtrace();
164 168
 					$i = 0;
165
-					while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this))
166
-						$i++;
169
+					while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) {
170
+											$i++;
171
+					}
167 172
 					$debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')';
168 173
 
169 174
 					// Cause an error.
170
-					if ($this->debug_level & E_NOTICE)
171
-						trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE);
175
+					if ($this->debug_level & E_NOTICE) {
176
+											trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE);
177
+					}
172 178
 					return false;
173 179
 				}
180
+			} else {
181
+							$lvl = null;
174 182
 			}
175
-			else
176
-				$lvl = null;
177 183
 
178 184
 			// Find this element.
179 185
 			$array = $this->_path($array, $el, $lvl);
180 186
 		}
181 187
 
182 188
 		// Clean up after $lvl, for $return_full.
183
-		if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']'))
184
-			$array = array('name' => $el . '[]', $array);
189
+		if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) {
190
+					$array = array('name' => $el . '[]', $array);
191
+		}
185 192
 
186 193
 		// Create the right type of class...
187 194
 		$newClass = get_class($this);
@@ -216,10 +223,11 @@  discard block
 block discarded – undo
216 223
 				$el = substr($el, 0, strpos($el, '['));
217 224
 			}
218 225
 			// Find an attribute.
219
-			elseif (substr($el, 0, 1) == '@')
220
-				return isset($array[$el]);
221
-			else
222
-				$lvl = null;
226
+			elseif (substr($el, 0, 1) == '@') {
227
+							return isset($array[$el]);
228
+			} else {
229
+							$lvl = null;
230
+			}
223 231
 
224 232
 			// Find this element.
225 233
 			$array = $this->_path($array, $el, $lvl, true);
@@ -244,8 +252,9 @@  discard block
 block discarded – undo
244 252
 		$i = 0;
245 253
 		foreach ($temp->array as $item)
246 254
 		{
247
-			if (is_array($item))
248
-				$i++;
255
+			if (is_array($item)) {
256
+							$i++;
257
+			}
249 258
 		}
250 259
 
251 260
 		return $i;
@@ -269,8 +278,9 @@  discard block
 block discarded – undo
269 278
 		foreach ($xml->array as $val)
270 279
 		{
271 280
 			// Skip these, they aren't elements.
272
-			if (!is_array($val) || $val['name'] == '!')
273
-				continue;
281
+			if (!is_array($val) || $val['name'] == '!') {
282
+							continue;
283
+			}
274 284
 
275 285
 			// Create the right type of class...
276 286
 			$newClass = get_class($this);
@@ -297,14 +307,16 @@  discard block
 block discarded – undo
297 307
 			$path = $this->path($path);
298 308
 
299 309
 			// The path was not found
300
-			if ($path === false)
301
-				return false;
310
+			if ($path === false) {
311
+							return false;
312
+			}
302 313
 
303 314
 			$path = $path->array;
304 315
 		}
305 316
 		// Just use the current array.
306
-		else
307
-			$path = $this->array;
317
+		else {
318
+					$path = $this->array;
319
+		}
308 320
 
309 321
 		// Add the xml declaration to the front.
310 322
 		return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0);
@@ -326,14 +338,16 @@  discard block
 block discarded – undo
326 338
 			$path = $this->path($path);
327 339
 
328 340
 			// The path was not found
329
-			if ($path === false)
330
-				return false;
341
+			if ($path === false) {
342
+							return false;
343
+			}
331 344
 
332 345
 			$path = $path->array;
333 346
 		}
334 347
 		// No, so just use the current array.
335
-		else
336
-			$path = $this->array;
348
+		else {
349
+					$path = $this->array;
350
+		}
337 351
 
338 352
 		return $this->_array($path);
339 353
 	}
@@ -355,8 +369,9 @@  discard block
 block discarded – undo
355 369
 		{
356 370
 			// Find and remove the next tag.
357 371
 			preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match);
358
-			if (isset($match[0]))
359
-				$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1);
372
+			if (isset($match[0])) {
373
+							$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1);
374
+			}
360 375
 
361 376
 			// Didn't find a tag?  Keep looping....
362 377
 			if (!isset($match[1]) || $match[1] == '')
@@ -367,11 +382,12 @@  discard block
 block discarded – undo
367 382
 					$text_value = $this->_from_cdata($data);
368 383
 					$data = '';
369 384
 
370
-					if ($text_value != '')
371
-						$current[] = array(
385
+					if ($text_value != '') {
386
+											$current[] = array(
372 387
 							'name' => '!',
373 388
 							'value' => $text_value
374 389
 						);
390
+					}
375 391
 				}
376 392
 				// If the < isn't immediately next to the current position... more data.
377 393
 				elseif (strpos($data, '<') > 0)
@@ -379,11 +395,12 @@  discard block
 block discarded – undo
379 395
 					$text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<')));
380 396
 					$data = substr($data, strpos($data, '<'));
381 397
 
382
-					if ($text_value != '')
383
-						$current[] = array(
398
+					if ($text_value != '') {
399
+											$current[] = array(
384 400
 							'name' => '!',
385 401
 							'value' => $text_value
386 402
 						);
403
+					}
387 404
 				}
388 405
 				// If we're looking at a </something> with no start, kill it.
389 406
 				elseif (strpos($data, '<') !== false && strpos($data, '<') == 0)
@@ -393,22 +410,23 @@  discard block
 block discarded – undo
393 410
 						$text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1)));
394 411
 						$data = substr($data, strpos($data, '<', 1));
395 412
 
396
-						if ($text_value != '')
397
-							$current[] = array(
413
+						if ($text_value != '') {
414
+													$current[] = array(
398 415
 								'name' => '!',
399 416
 								'value' => $text_value
400 417
 							);
401
-					}
402
-					else
418
+						}
419
+					} else
403 420
 					{
404 421
 						$text_value = $this->_from_cdata($data);
405 422
 						$data = '';
406 423
 
407
-						if ($text_value != '')
408
-							$current[] = array(
424
+						if ($text_value != '') {
425
+													$current[] = array(
409 426
 								'name' => '!',
410 427
 								'value' => $text_value
411 428
 							);
429
+						}
412 430
 					}
413 431
 				}
414 432
 
@@ -425,8 +443,9 @@  discard block
 block discarded – undo
425 443
 			{
426 444
 				// Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way.
427 445
 				$last_tag_end = strpos($data, '</' . $match[1] . '>');
428
-				if ($last_tag_end === false)
429
-					continue;
446
+				if ($last_tag_end === false) {
447
+									continue;
448
+				}
430 449
 
431 450
 				$offset = 0;
432 451
 				while (1 == 1)
@@ -434,16 +453,17 @@  discard block
 block discarded – undo
434 453
 					// Where is the next start tag?
435 454
 					$next_tag_start = strpos($data, '<' . $match[1], $offset);
436 455
 					// If the next start tag is after the last end tag then we've found the right close.
437
-					if ($next_tag_start === false || $next_tag_start > $last_tag_end)
438
-						break;
456
+					if ($next_tag_start === false || $next_tag_start > $last_tag_end) {
457
+											break;
458
+					}
439 459
 
440 460
 					// If not then find the next ending tag.
441 461
 					$next_tag_end = strpos($data, '</' . $match[1] . '>', $offset);
442 462
 
443 463
 					// Didn't find one? Then just use the last and sod it.
444
-					if ($next_tag_end === false)
445
-						break;
446
-					else
464
+					if ($next_tag_end === false) {
465
+											break;
466
+					} else
447 467
 					{
448 468
 						$last_tag_end = $next_tag_end;
449 469
 						$offset = $next_tag_start + 1;
@@ -457,16 +477,17 @@  discard block
 block discarded – undo
457 477
 				if (!empty($inner_match))
458 478
 				{
459 479
 					// Parse the inner data.
460
-					if (strpos($inner_match, '<') !== false)
461
-						$el += $this->_parse($inner_match);
462
-					elseif (trim($inner_match) != '')
480
+					if (strpos($inner_match, '<') !== false) {
481
+											$el += $this->_parse($inner_match);
482
+					} elseif (trim($inner_match) != '')
463 483
 					{
464 484
 						$text_value = $this->_from_cdata($inner_match);
465
-						if ($text_value != '')
466
-							$el[] = array(
485
+						if ($text_value != '') {
486
+													$el[] = array(
467 487
 								'name' => '!',
468 488
 								'value' => $text_value
469 489
 							);
490
+						}
470 491
 					}
471 492
 				}
472 493
 			}
@@ -478,8 +499,9 @@  discard block
 block discarded – undo
478 499
 				preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER);
479 500
 
480 501
 				// Set them as @attribute-name.
481
-				foreach ($attr as $match_attr)
482
-					$el['@' . $match_attr[1]] = $match_attr[2];
502
+				foreach ($attr as $match_attr) {
503
+									$el['@' . $match_attr[1]] = $match_attr[2];
504
+				}
483 505
 			}
484 506
 		}
485 507
 
@@ -503,16 +525,18 @@  discard block
 block discarded – undo
503 525
 		if (is_array($array) && !isset($array['name']))
504 526
 		{
505 527
 			$temp = '';
506
-			foreach ($array as $val)
507
-				$temp .= $this->_xml($val, $indent);
528
+			foreach ($array as $val) {
529
+							$temp .= $this->_xml($val, $indent);
530
+			}
508 531
 			return $temp;
509 532
 		}
510 533
 
511 534
 		// This is just text!
512
-		if ($array['name'] == '!')
513
-			return $indentation . '<![CDATA[' . $array['value'] . ']]>';
514
-		elseif (substr($array['name'], -2) == '[]')
515
-			$array['name'] = substr($array['name'], 0, -2);
535
+		if ($array['name'] == '!') {
536
+					return $indentation . '<![CDATA[' . $array['value'] . ']]>';
537
+		} elseif (substr($array['name'], -2) == '[]') {
538
+					$array['name'] = substr($array['name'], 0, -2);
539
+		}
516 540
 
517 541
 		// Start the element.
518 542
 		$output = $indentation . '<' . $array['name'];
@@ -523,9 +547,9 @@  discard block
 block discarded – undo
523 547
 		// Run through and recursively output all the elements or attrbutes inside this.
524 548
 		foreach ($array as $k => $v)
525 549
 		{
526
-			if (substr($k, 0, 1) == '@')
527
-				$output .= ' ' . substr($k, 1) . '="' . $v . '"';
528
-			elseif (is_array($v))
550
+			if (substr($k, 0, 1) == '@') {
551
+							$output .= ' ' . substr($k, 1) . '="' . $v . '"';
552
+			} elseif (is_array($v))
529 553
 			{
530 554
 				$output_el .= $this->_xml($v, $indent === null ? null : $indent + 1);
531 555
 				$inside_elements = true;
@@ -533,10 +557,11 @@  discard block
 block discarded – undo
533 557
 		}
534 558
 
535 559
 		// Indent, if necessary.... then close the tag.
536
-		if ($inside_elements)
537
-			$output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>';
538
-		else
539
-			$output .= ' />';
560
+		if ($inside_elements) {
561
+					$output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>';
562
+		} else {
563
+					$output .= ' />';
564
+		}
540 565
 
541 566
 		return $output;
542 567
 	}
@@ -553,19 +578,22 @@  discard block
 block discarded – undo
553 578
 		$text = '';
554 579
 		foreach ($array as $value)
555 580
 		{
556
-			if (!is_array($value) || !isset($value['name']))
557
-				continue;
581
+			if (!is_array($value) || !isset($value['name'])) {
582
+							continue;
583
+			}
558 584
 
559
-			if ($value['name'] == '!')
560
-				$text .= $value['value'];
561
-			else
562
-				$return[$value['name']] = $this->_array($value);
585
+			if ($value['name'] == '!') {
586
+							$text .= $value['value'];
587
+			} else {
588
+							$return[$value['name']] = $this->_array($value);
589
+			}
563 590
 		}
564 591
 
565
-		if (empty($return))
566
-			return $text;
567
-		else
568
-			return $return;
592
+		if (empty($return)) {
593
+					return $text;
594
+		} else {
595
+					return $return;
596
+		}
569 597
 	}
570 598
 
571 599
 	/**
@@ -583,24 +611,28 @@  discard block
 block discarded – undo
583 611
 		foreach ($parts as $part)
584 612
 		{
585 613
 			// Handle XML comments.
586
-			if (!$inCdata && $part === '<!--')
587
-				$inComment = true;
588
-			if ($inComment && $part === '-->')
589
-				$inComment = false;
590
-			elseif ($inComment)
591
-				continue;
614
+			if (!$inCdata && $part === '<!--') {
615
+							$inComment = true;
616
+			}
617
+			if ($inComment && $part === '-->') {
618
+							$inComment = false;
619
+			} elseif ($inComment) {
620
+							continue;
621
+			}
592 622
 
593 623
 			// Handle Cdata blocks.
594
-			elseif (!$inComment && $part === '<![CDATA[')
595
-				$inCdata = true;
596
-			elseif ($inCdata && $part === ']]>')
597
-				$inCdata = false;
598
-			elseif ($inCdata)
599
-				$output .= htmlentities($part, ENT_QUOTES);
624
+			elseif (!$inComment && $part === '<![CDATA[') {
625
+							$inCdata = true;
626
+			} elseif ($inCdata && $part === ']]>') {
627
+							$inCdata = false;
628
+			} elseif ($inCdata) {
629
+							$output .= htmlentities($part, ENT_QUOTES);
630
+			}
600 631
 
601 632
 			// Everything else is kept as is.
602
-			else
603
-				$output .= $part;
633
+			else {
634
+							$output .= $part;
635
+			}
604 636
 		}
605 637
 
606 638
 		return $output;
@@ -635,22 +667,26 @@  discard block
 block discarded – undo
635 667
 	protected function _fetch($array)
636 668
 	{
637 669
 		// Don't return anything if this is just a string.
638
-		if (is_string($array))
639
-			return '';
670
+		if (is_string($array)) {
671
+					return '';
672
+		}
640 673
 
641 674
 		$temp = '';
642 675
 		foreach ($array as $text)
643 676
 		{
644 677
 			// This means it's most likely an attribute or the name itself.
645
-			if (!isset($text['name']))
646
-				continue;
678
+			if (!isset($text['name'])) {
679
+							continue;
680
+			}
647 681
 
648 682
 			// This is text!
649
-			if ($text['name'] == '!')
650
-				$temp .= $text['value'];
683
+			if ($text['name'] == '!') {
684
+							$temp .= $text['value'];
685
+			}
651 686
 			// Another element - dive in ;).
652
-			else
653
-				$temp .= $this->_fetch($text);
687
+			else {
688
+							$temp .= $this->_fetch($text);
689
+			}
654 690
 		}
655 691
 
656 692
 		// Return all the bits and pieces we've put together.
@@ -669,12 +705,14 @@  discard block
 block discarded – undo
669 705
 	protected function _path($array, $path, $level, $no_error = false)
670 706
 	{
671 707
 		// Is $array even an array?  It might be false!
672
-		if (!is_array($array))
673
-			return false;
708
+		if (!is_array($array)) {
709
+					return false;
710
+		}
674 711
 
675 712
 		// Asking for *no* path?
676
-		if ($path == '' || $path == '.')
677
-			return $array;
713
+		if ($path == '' || $path == '.') {
714
+					return $array;
715
+		}
678 716
 		$paths = explode('|', $path);
679 717
 
680 718
 		// A * means all elements of any name.
@@ -685,16 +723,18 @@  discard block
 block discarded – undo
685 723
 		// Check each element.
686 724
 		foreach ($array as $value)
687 725
 		{
688
-			if (!is_array($value) || $value['name'] === '!')
689
-				continue;
726
+			if (!is_array($value) || $value['name'] === '!') {
727
+							continue;
728
+			}
690 729
 
691 730
 			if ($show_all || in_array($value['name'], $paths))
692 731
 			{
693 732
 				// Skip elements before "the one".
694
-				if ($level !== null && $level > 0)
695
-					$level--;
696
-				else
697
-					$results[] = $value;
733
+				if ($level !== null && $level > 0) {
734
+									$level--;
735
+				} else {
736
+									$results[] = $value;
737
+				}
698 738
 			}
699 739
 		}
700 740
 
@@ -703,21 +743,25 @@  discard block
 block discarded – undo
703 743
 		{
704 744
 			$trace = debug_backtrace();
705 745
 			$i = 0;
706
-			while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this))
707
-				$i++;
746
+			while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) {
747
+							$i++;
748
+			}
708 749
 			$debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'];
709 750
 
710 751
 			// Cause an error.
711
-			if ($this->debug_level & E_NOTICE && !$no_error)
712
-				trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE);
752
+			if ($this->debug_level & E_NOTICE && !$no_error) {
753
+							trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE);
754
+			}
713 755
 			return false;
714 756
 		}
715 757
 		// Only one result.
716
-		elseif (count($results) == 1 || $level !== null)
717
-			return $results[0];
758
+		elseif (count($results) == 1 || $level !== null) {
759
+					return $results[0];
760
+		}
718 761
 		// Return the result set.
719
-		else
720
-			return $results + array('name' => $path . '[]');
762
+		else {
763
+					return $results + array('name' => $path . '[]');
764
+		}
721 765
 	}
722 766
 }
723 767
 
@@ -764,8 +808,9 @@  discard block
 block discarded – undo
764 808
 		$this->error = false;
765 809
 		$this->pasv = array();
766 810
 
767
-		if ($ftp_server !== null)
768
-			$this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
811
+		if ($ftp_server !== null) {
812
+					$this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
813
+		}
769 814
 	}
770 815
 
771 816
 	/**
@@ -778,14 +823,16 @@  discard block
 block discarded – undo
778 823
 	 */
779 824
 	public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
780 825
 	{
781
-		if (strpos($ftp_server, 'ftp://') === 0)
782
-			$ftp_server = substr($ftp_server, 6);
783
-		elseif (strpos($ftp_server, 'ftps://') === 0)
784
-			$ftp_server = 'ssl://' . substr($ftp_server, 7);
785
-		if (strpos($ftp_server, 'http://') === 0)
786
-			$ftp_server = substr($ftp_server, 7);
787
-		elseif (strpos($ftp_server, 'https://') === 0)
788
-			$ftp_server = substr($ftp_server, 8);
826
+		if (strpos($ftp_server, 'ftp://') === 0) {
827
+					$ftp_server = substr($ftp_server, 6);
828
+		} elseif (strpos($ftp_server, 'ftps://') === 0) {
829
+					$ftp_server = 'ssl://' . substr($ftp_server, 7);
830
+		}
831
+		if (strpos($ftp_server, 'http://') === 0) {
832
+					$ftp_server = substr($ftp_server, 7);
833
+		} elseif (strpos($ftp_server, 'https://') === 0) {
834
+					$ftp_server = substr($ftp_server, 8);
835
+		}
789 836
 		$ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
790 837
 
791 838
 		// Connect to the FTP server.
@@ -834,12 +881,14 @@  discard block
 block discarded – undo
834 881
 	 */
835 882
 	public function chdir($ftp_path)
836 883
 	{
837
-		if (!is_resource($this->connection))
838
-			return false;
884
+		if (!is_resource($this->connection)) {
885
+					return false;
886
+		}
839 887
 
840 888
 		// No slash on the end, please...
841
-		if ($ftp_path !== '/' && substr($ftp_path, -1) === '/')
842
-			$ftp_path = substr($ftp_path, 0, -1);
889
+		if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') {
890
+					$ftp_path = substr($ftp_path, 0, -1);
891
+		}
843 892
 
844 893
 		fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
845 894
 		if (!$this->check_response(250))
@@ -860,11 +909,13 @@  discard block
 block discarded – undo
860 909
 	 */
861 910
 	public function chmod($ftp_file, $chmod)
862 911
 	{
863
-		if (!is_resource($this->connection))
864
-			return false;
912
+		if (!is_resource($this->connection)) {
913
+					return false;
914
+		}
865 915
 
866
-		if ($ftp_file == '')
867
-			$ftp_file = '.';
916
+		if ($ftp_file == '') {
917
+					$ftp_file = '.';
918
+		}
868 919
 
869 920
 		// Do we have a file or a dir?
870 921
 		$is_dir = is_dir($ftp_file);
@@ -880,9 +931,7 @@  discard block
 block discarded – undo
880 931
 			{
881 932
 				$is_writable = true;
882 933
 				break;
883
-			}
884
-
885
-			else
934
+			} else
886 935
 			{
887 936
 				// Convert the chmod value from octal (0777) to text ("777").
888 937
 				fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n");
@@ -905,8 +954,9 @@  discard block
 block discarded – undo
905 954
 	public function unlink($ftp_file)
906 955
 	{
907 956
 		// We are actually connected, right?
908
-		if (!is_resource($this->connection))
909
-			return false;
957
+		if (!is_resource($this->connection)) {
958
+					return false;
959
+		}
910 960
 
911 961
 		// Delete file X.
912 962
 		fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
@@ -935,9 +985,9 @@  discard block
 block discarded – undo
935 985
 	{
936 986
 		// Wait for a response that isn't continued with -, but don't wait too long.
937 987
 		$time = time();
938
-		do
939
-			$this->last_message = fgets($this->connection, 1024);
940
-		while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5);
988
+		do {
989
+					$this->last_message = fgets($this->connection, 1024);
990
+		} while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5);
941 991
 
942 992
 		// Was the desired response returned?
943 993
 		return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
@@ -951,15 +1001,16 @@  discard block
 block discarded – undo
951 1001
 	public function passive()
952 1002
 	{
953 1003
 		// We can't create a passive data connection without a primary one first being there.
954
-		if (!is_resource($this->connection))
955
-			return false;
1004
+		if (!is_resource($this->connection)) {
1005
+					return false;
1006
+		}
956 1007
 
957 1008
 		// Request a passive connection - this means, we'll talk to you, you don't talk to us.
958 1009
 		@fwrite($this->connection, 'PASV' . "\r\n");
959 1010
 		$time = time();
960
-		do
961
-			$response = fgets($this->connection, 1024);
962
-		while (strpos($response, ' ', 3) !== 3 && time() - $time < 5);
1011
+		do {
1012
+					$response = fgets($this->connection, 1024);
1013
+		} while (strpos($response, ' ', 3) !== 3 && time() - $time < 5);
963 1014
 
964 1015
 		// If it's not 227, we weren't given an IP and port, which means it failed.
965 1016
 		if (strpos($response, '227 ') !== 0)
@@ -990,12 +1041,14 @@  discard block
 block discarded – undo
990 1041
 	public function create_file($ftp_file)
991 1042
 	{
992 1043
 		// First, we have to be connected... very important.
993
-		if (!is_resource($this->connection))
994
-			return false;
1044
+		if (!is_resource($this->connection)) {
1045
+					return false;
1046
+		}
995 1047
 
996 1048
 		// I'd like one passive mode, please!
997
-		if (!$this->passive())
998
-			return false;
1049
+		if (!$this->passive()) {
1050
+					return false;
1051
+		}
999 1052
 
1000 1053
 		// Seems logical enough, so far...
1001 1054
 		fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
@@ -1030,12 +1083,14 @@  discard block
 block discarded – undo
1030 1083
 	public function list_dir($ftp_path = '', $search = false)
1031 1084
 	{
1032 1085
 		// Are we even connected...?
1033
-		if (!is_resource($this->connection))
1034
-			return false;
1086
+		if (!is_resource($this->connection)) {
1087
+					return false;
1088
+		}
1035 1089
 
1036 1090
 		// Passive... non-agressive...
1037
-		if (!$this->passive())
1038
-			return false;
1091
+		if (!$this->passive()) {
1092
+					return false;
1093
+		}
1039 1094
 
1040 1095
 		// Get the listing!
1041 1096
 		fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
@@ -1051,8 +1106,9 @@  discard block
 block discarded – undo
1051 1106
 
1052 1107
 		// Read in the file listing.
1053 1108
 		$data = '';
1054
-		while (!feof($fp))
1055
-			$data .= fread($fp, 4096);
1109
+		while (!feof($fp)) {
1110
+					$data .= fread($fp, 4096);
1111
+		}
1056 1112
 		fclose($fp);
1057 1113
 
1058 1114
 		// Everything go okay?
@@ -1074,21 +1130,23 @@  discard block
 block discarded – undo
1074 1130
 	 */
1075 1131
 	public function locate($file, $listing = null)
1076 1132
 	{
1077
-		if ($listing === null)
1078
-			$listing = $this->list_dir('', true);
1133
+		if ($listing === null) {
1134
+					$listing = $this->list_dir('', true);
1135
+		}
1079 1136
 		$listing = explode("\n", $listing);
1080 1137
 
1081 1138
 		@fwrite($this->connection, 'PWD' . "\r\n");
1082 1139
 		$time = time();
1083
-		do
1084
-			$response = fgets($this->connection, 1024);
1085
-		while ($response[3] != ' ' && time() - $time < 5);
1140
+		do {
1141
+					$response = fgets($this->connection, 1024);
1142
+		} while ($response[3] != ' ' && time() - $time < 5);
1086 1143
 
1087 1144
 		// Check for 257!
1088
-		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
1089
-			$current_dir = strtr($match[1], array('""' => '"'));
1090
-		else
1091
-			$current_dir = '';
1145
+		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) {
1146
+					$current_dir = strtr($match[1], array('""' => '"'));
1147
+		} else {
1148
+					$current_dir = '';
1149
+		}
1092 1150
 
1093 1151
 		for ($i = 0, $n = count($listing); $i < $n; $i++)
1094 1152
 		{
@@ -1101,12 +1159,15 @@  discard block
 block discarded – undo
1101 1159
 			// Okay, this file's name is:
1102 1160
 			$listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
1103 1161
 
1104
-			if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
1105
-				return $listing[$i];
1106
-			if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
1107
-				return $listing[$i];
1108
-			if (basename($listing[$i]) == $file || $listing[$i] == $file)
1109
-				return $listing[$i];
1162
+			if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) {
1163
+							return $listing[$i];
1164
+			}
1165
+			if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) {
1166
+							return $listing[$i];
1167
+			}
1168
+			if (basename($listing[$i]) == $file || $listing[$i] == $file) {
1169
+							return $listing[$i];
1170
+			}
1110 1171
 		}
1111 1172
 
1112 1173
 		return false;
@@ -1121,8 +1182,9 @@  discard block
 block discarded – undo
1121 1182
 	public function create_dir($ftp_dir)
1122 1183
 	{
1123 1184
 		// We must be connected to the server to do something.
1124
-		if (!is_resource($this->connection))
1125
-			return false;
1185
+		if (!is_resource($this->connection)) {
1186
+					return false;
1187
+		}
1126 1188
 
1127 1189
 		// Make this new beautiful directory!
1128 1190
 		fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
@@ -1154,35 +1216,40 @@  discard block
 block discarded – undo
1154 1216
 
1155 1217
 				$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
1156 1218
 
1157
-				if (substr($path, -1) == '/')
1158
-					$path = substr($path, 0, -1);
1219
+				if (substr($path, -1) == '/') {
1220
+									$path = substr($path, 0, -1);
1221
+				}
1159 1222
 
1160
-				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
1161
-					$path .= dirname($_SERVER['PHP_SELF']);
1223
+				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) {
1224
+									$path .= dirname($_SERVER['PHP_SELF']);
1225
+				}
1226
+			} elseif (strpos($filesystem_path, '/var/www/') === 0) {
1227
+							$path = substr($filesystem_path, 8);
1228
+			} else {
1229
+							$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1162 1230
 			}
1163
-			elseif (strpos($filesystem_path, '/var/www/') === 0)
1164
-				$path = substr($filesystem_path, 8);
1165
-			else
1166
-				$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1231
+		} else {
1232
+					$path = '';
1167 1233
 		}
1168
-		else
1169
-			$path = '';
1170 1234
 
1171 1235
 		if (is_resource($this->connection) && $this->list_dir($path) == '')
1172 1236
 		{
1173 1237
 			$data = $this->list_dir('', true);
1174 1238
 
1175
-			if ($lookup_file === null)
1176
-				$lookup_file = $_SERVER['PHP_SELF'];
1239
+			if ($lookup_file === null) {
1240
+							$lookup_file = $_SERVER['PHP_SELF'];
1241
+			}
1177 1242
 
1178 1243
 			$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
1179
-			if ($found_path == false)
1180
-				$found_path = dirname($this->locate(basename($lookup_file)));
1181
-			if ($found_path != false)
1182
-				$path = $found_path;
1244
+			if ($found_path == false) {
1245
+							$found_path = dirname($this->locate(basename($lookup_file)));
1246
+			}
1247
+			if ($found_path != false) {
1248
+							$path = $found_path;
1249
+			}
1250
+		} elseif (is_resource($this->connection)) {
1251
+					$found_path = true;
1183 1252
 		}
1184
-		elseif (is_resource($this->connection))
1185
-			$found_path = true;
1186 1253
 
1187 1254
 		return array($username, $path, isset($found_path));
1188 1255
 	}
Please login to merge, or discard this patch.
Sources/ManageSearchEngines.php 1 patch
Braces   +109 added lines, -77 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
  * Entry point for this section.
@@ -38,8 +39,7 @@  discard block
 block discarded – undo
38 39
 			'stats' => 'SpiderStats',
39 40
 		);
40 41
 		$default = 'stats';
41
-	}
42
-	else
42
+	} else
43 43
 	{
44 44
 		$subActions = array(
45 45
 			'settings' => 'ManageSearchEngineSettings',
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		{
91 91
 			disabledState = document.getElementById(\'spider_mode\').value == 0;';
92 92
 
93
-	foreach ($config_vars as $variable)
94
-		if ($variable[1] != 'spider_mode')
93
+	foreach ($config_vars as $variable) {
94
+			if ($variable[1] != 'spider_mode')
95 95
 			$javascript_function .= '
96 96
 			if (document.getElementById(\'' . $variable[1] . '\'))
97 97
 				document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;';
98
+	}
98 99
 
99 100
 	$javascript_function .= '
100 101
 		}
@@ -102,8 +103,9 @@  discard block
 block discarded – undo
102 103
 
103 104
 	call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars));
104 105
 
105
-	if ($return_config)
106
-		return $config_vars;
106
+	if ($return_config) {
107
+			return $config_vars;
108
+	}
107 109
 
108 110
 	// We need to load the groups for the spider group thingy.
109 111
 	$request = $smcFunc['db_query']('', '
@@ -116,13 +118,15 @@  discard block
 block discarded – undo
116 118
 			'moderator_group' => 3,
117 119
 		)
118 120
 	);
119
-	while ($row = $smcFunc['db_fetch_assoc']($request))
120
-		$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
121
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
122
+			$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
123
+	}
121 124
 	$smcFunc['db_free_result']($request);
122 125
 
123 126
 	// Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here!
124
-	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']]))
125
-		$_POST['spider_group'] = 0;
127
+	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) {
128
+			$_POST['spider_group'] = 0;
129
+	}
126 130
 
127 131
 	// We'll want this for our easy save.
128 132
 	require_once($sourcedir . '/ManageServer.php');
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
 	}
167 171
 
168 172
 	// Are we adding a new one?
169
-	if (!empty($_POST['addSpider']))
170
-		return EditSpider();
173
+	if (!empty($_POST['addSpider'])) {
174
+			return EditSpider();
175
+	}
171 176
 	// User pressed the 'remove selection button'.
172 177
 	elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove']))
173 178
 	{
@@ -175,8 +180,9 @@  discard block
 block discarded – undo
175 180
 		validateToken('admin-ser');
176 181
 
177 182
 		// Make sure every entry is a proper integer.
178
-		foreach ($_POST['remove'] as $index => $spider_id)
179
-			$_POST['remove'][(int) $index] = (int) $spider_id;
183
+		foreach ($_POST['remove'] as $index => $spider_id) {
184
+					$_POST['remove'][(int) $index] = (int) $spider_id;
185
+		}
180 186
 
181 187
 		// Delete them all!
182 188
 		$smcFunc['db_query']('', '
@@ -215,8 +221,9 @@  discard block
 block discarded – undo
215 221
 	);
216 222
 
217 223
 	$context['spider_last_seen'] = array();
218
-	while ($row = $smcFunc['db_fetch_assoc']($request))
219
-		$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
224
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
225
+			$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
226
+	}
220 227
 	$smcFunc['db_free_result']($request);
221 228
 
222 229
 	createToken('admin-ser');
@@ -346,8 +353,9 @@  discard block
 block discarded – undo
346 353
 		)
347 354
 	);
348 355
 	$spiders = array();
349
-	while ($row = $smcFunc['db_fetch_assoc']($request))
350
-		$spiders[$row['id_spider']] = $row;
356
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
357
+			$spiders[$row['id_spider']] = $row;
358
+	}
351 359
 	$smcFunc['db_free_result']($request);
352 360
 
353 361
 	return $spiders;
@@ -397,14 +405,15 @@  discard block
 block discarded – undo
397 405
 		foreach ($ip_sets as $set)
398 406
 		{
399 407
 			$test = ip2range(trim($set));
400
-			if (!empty($test))
401
-				$ips[] = $set;
408
+			if (!empty($test)) {
409
+							$ips[] = $set;
410
+			}
402 411
 		}
403 412
 		$ips = implode(',', $ips);
404 413
 
405 414
 		// Goes in as it is...
406
-		if ($context['id_spider'])
407
-			$smcFunc['db_query']('', '
415
+		if ($context['id_spider']) {
416
+					$smcFunc['db_query']('', '
408 417
 				UPDATE {db_prefix}spiders
409 418
 				SET spider_name = {string:spider_name}, user_agent = {string:spider_agent},
410 419
 					ip_info = {string:ip_info}
@@ -416,8 +425,8 @@  discard block
 block discarded – undo
416 425
 					'ip_info' => $ips,
417 426
 				)
418 427
 			);
419
-		else
420
-			$smcFunc['db_insert']('insert',
428
+		} else {
429
+					$smcFunc['db_insert']('insert',
421 430
 				'{db_prefix}spiders',
422 431
 				array(
423 432
 					'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string',
@@ -427,6 +436,7 @@  discard block
 block discarded – undo
427 436
 				),
428 437
 				array('id_spider')
429 438
 			);
439
+		}
430 440
 
431 441
 
432 442
 		cache_put_data('spider_search', null);
@@ -454,13 +464,14 @@  discard block
 block discarded – undo
454 464
 				'current_spider' => $context['id_spider'],
455 465
 			)
456 466
 		);
457
-		if ($row = $smcFunc['db_fetch_assoc']($request))
458
-			$context['spider'] = array(
467
+		if ($row = $smcFunc['db_fetch_assoc']($request)) {
468
+					$context['spider'] = array(
459 469
 				'id' => $row['id_spider'],
460 470
 				'name' => $row['spider_name'],
461 471
 				'agent' => $row['user_agent'],
462 472
 				'ip_info' => $row['ip_info'],
463 473
 			);
474
+		}
464 475
 		$smcFunc['db_free_result']($request);
465 476
 	}
466 477
 
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 {
478 489
 	global $modSettings, $smcFunc;
479 490
 
480
-	if (isset($_SESSION['id_robot']))
481
-		unset($_SESSION['id_robot']);
491
+	if (isset($_SESSION['id_robot'])) {
492
+			unset($_SESSION['id_robot']);
493
+	}
482 494
 	$_SESSION['robot_check'] = time();
483 495
 
484 496
 	// We cache the spider data for ten minutes if we can.
@@ -492,15 +504,17 @@  discard block
 block discarded – undo
492 504
 			)
493 505
 		);
494 506
 		$spider_data = array();
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$spider_data[] = $row;
507
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
508
+					$spider_data[] = $row;
509
+		}
497 510
 		$smcFunc['db_free_result']($request);
498 511
 
499 512
 		cache_put_data('spider_search', $spider_data, 600);
500 513
 	}
501 514
 
502
-	if (empty($spider_data))
503
-		return false;
515
+	if (empty($spider_data)) {
516
+			return false;
517
+	}
504 518
 
505 519
 	// Only do these bits once.
506 520
 	$ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
@@ -508,33 +522,38 @@  discard block
 block discarded – undo
508 522
 	foreach ($spider_data as $spider)
509 523
 	{
510 524
 		// User agent is easy.
511
-		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false)
512
-			$_SESSION['id_robot'] = $spider['id_spider'];
525
+		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) {
526
+					$_SESSION['id_robot'] = $spider['id_spider'];
527
+		}
513 528
 		// IP stuff is harder.
514 529
 		elseif ($_SERVER['REMOTE_ADDR'])
515 530
 		{
516 531
 			$ips = explode(',', $spider['ip_info']);
517 532
 			foreach ($ips as $ip)
518 533
 			{
519
-				if ($ip === '')
520
-					continue;
534
+				if ($ip === '') {
535
+									continue;
536
+				}
521 537
 
522 538
 				$ip = ip2range($ip);
523 539
 				if (!empty($ip))
524 540
 				{
525
-					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR']))
526
-						$_SESSION['id_robot'] = $spider['id_spider'];
541
+					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) {
542
+											$_SESSION['id_robot'] = $spider['id_spider'];
543
+					}
527 544
 				}
528 545
 			}
529 546
 		}
530 547
 
531
-		if (isset($_SESSION['id_robot']))
532
-			break;
548
+		if (isset($_SESSION['id_robot'])) {
549
+					break;
550
+		}
533 551
 	}
534 552
 
535 553
 	// If this is low server tracking then log the spider here as opposed to the main logging function.
536
-	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot']))
537
-		logSpider();
554
+	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) {
555
+			logSpider();
556
+	}
538 557
 
539 558
 	return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
540 559
 }
@@ -548,8 +567,9 @@  discard block
 block discarded – undo
548 567
 {
549 568
 	global $smcFunc, $modSettings, $context;
550 569
 
551
-	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot']))
552
-		return;
570
+	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) {
571
+			return;
572
+	}
553 573
 
554 574
 	// Attempt to update today's entry.
555 575
 	if ($modSettings['spider_mode'] == 1)
@@ -590,9 +610,9 @@  discard block
 block discarded – undo
590 610
 			$url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
591 611
 			unset($url['sesc'], $url[$context['session_var']]);
592 612
 			$url = json_encode($url);
613
+		} else {
614
+					$url = '';
593 615
 		}
594
-		else
595
-			$url = '';
596 616
 
597 617
 		$smcFunc['db_insert']('insert',
598 618
 			'{db_prefix}log_spider_hits',
@@ -620,12 +640,14 @@  discard block
 block discarded – undo
620 640
 		)
621 641
 	);
622 642
 	$spider_hits = array();
623
-	while ($row = $smcFunc['db_fetch_assoc']($request))
624
-		$spider_hits[] = $row;
643
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
644
+			$spider_hits[] = $row;
645
+	}
625 646
 	$smcFunc['db_free_result']($request);
626 647
 
627
-	if (empty($spider_hits))
628
-		return;
648
+	if (empty($spider_hits)) {
649
+			return;
650
+	}
629 651
 
630 652
 	// Attempt to update the master data.
631 653
 	$stat_inserts = array();
@@ -646,18 +668,20 @@  discard block
 block discarded – undo
646 668
 				'hits' => $stat['num_hits'],
647 669
 			)
648 670
 		);
649
-		if ($smcFunc['db_affected_rows']() == 0)
650
-			$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
671
+		if ($smcFunc['db_affected_rows']() == 0) {
672
+					$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
673
+		}
651 674
 	}
652 675
 
653 676
 	// New stats?
654
-	if (!empty($stat_inserts))
655
-		$smcFunc['db_insert']('ignore',
677
+	if (!empty($stat_inserts)) {
678
+			$smcFunc['db_insert']('ignore',
656 679
 			'{db_prefix}log_spider_stats',
657 680
 			array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'),
658 681
 			$stat_inserts,
659 682
 			array('stat_date', 'id_spider')
660 683
 		);
684
+	}
661 685
 
662 686
 	// All processed.
663 687
 	$smcFunc['db_query']('', '
@@ -700,8 +724,7 @@  discard block
 block discarded – undo
700 724
 					'delete_period' => $deleteTime,
701 725
 				)
702 726
 			);
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			// Deleting all of them
707 730
 			$smcFunc['db_query']('', '
@@ -791,10 +814,11 @@  discard block
 block discarded – undo
791 814
 		foreach ($context['spider_logs']['rows'] as $k => $row)
792 815
 		{
793 816
 			// Feature disabled?
794
-			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3)
795
-				$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
796
-			else
797
-				$urls[$k] = array($row['data']['viewing']['value'], -1);
817
+			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) {
818
+							$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
819
+			} else {
820
+							$urls[$k] = array($row['data']['viewing']['value'], -1);
821
+			}
798 822
 		}
799 823
 
800 824
 		// Now stick in the new URLs.
@@ -836,8 +860,9 @@  discard block
 block discarded – undo
836 860
 		)
837 861
 	);
838 862
 	$spider_logs = array();
839
-	while ($row = $smcFunc['db_fetch_assoc']($request))
840
-		$spider_logs[] = $row;
863
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
864
+			$spider_logs[] = $row;
865
+	}
841 866
 	$smcFunc['db_free_result']($request);
842 867
 
843 868
 	return $spider_logs;
@@ -913,14 +938,18 @@  discard block
 block discarded – undo
913 938
 
914 939
 	// Prepare the dates for the drop down.
915 940
 	$date_choices = array();
916
-	for ($y = $min_year; $y <= $max_year; $y++)
917
-		for ($m = 1; $m <= 12; $m++)
941
+	for ($y = $min_year; $y <= $max_year; $y++) {
942
+			for ($m = 1;
943
+	}
944
+	$m <= 12; $m++)
918 945
 		{
919 946
 			// This doesn't count?
920
-			if ($y == $min_year && $m < $min_month)
921
-				continue;
922
-			if ($y == $max_year && $m > $max_month)
923
-				break;
947
+			if ($y == $min_year && $m < $min_month) {
948
+							continue;
949
+			}
950
+			if ($y == $max_year && $m > $max_month) {
951
+							break;
952
+			}
924 953
 
925 954
 			$date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y;
926 955
 		}
@@ -933,13 +962,14 @@  discard block
 block discarded – undo
933 962
 		' . $txt['spider_stats_select_month'] . ':
934 963
 		<select name="new_date" onchange="document.spider_stat_list.submit();">';
935 964
 
936
-	if (empty($date_choices))
937
-		$date_select .= '
965
+	if (empty($date_choices)) {
966
+			$date_select .= '
938 967
 			<option></option>';
939
-	else
940
-		foreach ($date_choices as $id => $text)
968
+	} else {
969
+			foreach ($date_choices as $id => $text)
941 970
 			$date_select .= '
942 971
 			<option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>';
972
+	}
943 973
 
944 974
 	$date_select .= '
945 975
 		</select>
@@ -1063,8 +1093,9 @@  discard block
 block discarded – undo
1063 1093
 		)
1064 1094
 	);
1065 1095
 	$spider_stats = array();
1066
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1067
-		$spider_stats[] = $row;
1096
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1097
+			$spider_stats[] = $row;
1098
+	}
1068 1099
 	$smcFunc['db_free_result']($request);
1069 1100
 
1070 1101
 	return $spider_stats;
@@ -1105,8 +1136,9 @@  discard block
 block discarded – undo
1105 1136
 		array()
1106 1137
 	);
1107 1138
 	$spiders = array();
1108
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1109
-		$spiders[$row['id_spider']] = $row['spider_name'];
1139
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1140
+			$spiders[$row['id_spider']] = $row['spider_name'];
1141
+	}
1110 1142
 	$smcFunc['db_free_result']($request);
1111 1143
 
1112 1144
 	updateSettings(array('spider_name_cache' => json_encode($spiders)));
Please login to merge, or discard this patch.
Sources/DbSearch-mysql.php 1 patch
Braces   +13 added lines, -10 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
  *  Add the file functions to the $smcFunc array.
@@ -23,14 +24,15 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') {
28
+			$smcFunc += array(
28 29
 			'db_search_query' => 'smf_db_query',
29 30
 			'db_search_support' => 'smf_db_search_support',
30 31
 			'db_create_word_search' => 'smf_db_create_word_search',
31 32
 			'db_support_ignore' => true,
32 33
 		);
33
-}
34
+	}
35
+	}
34 36
 
35 37
 /**
36 38
  * This function will tell you whether this database type supports this search type.
@@ -54,12 +56,13 @@  discard block
 block discarded – undo
54 56
 {
55 57
 	global $smcFunc;
56 58
 
57
-	if ($size == 'small')
58
-		$size = 'smallint(5)';
59
-	elseif ($size == 'medium')
60
-		$size = 'mediumint(8)';
61
-	else
62
-		$size = 'int(10)';
59
+	if ($size == 'small') {
60
+			$size = 'smallint(5)';
61
+	} elseif ($size == 'medium') {
62
+			$size = 'mediumint(8)';
63
+	} else {
64
+			$size = 'int(10)';
65
+	}
63 66
 
64 67
 	$smcFunc['db_query']('', '
65 68
 		CREATE TABLE {db_prefix}log_search_words (
Please login to merge, or discard this patch.
Sources/Search.php 1 patch
Braces   +414 added lines, -307 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
 // This defines two version types for checking the API's are compatible with this version of SMF.
20 21
 $GLOBALS['search_versions'] = array(
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir;
40 41
 
41 42
 	// Is the load average too high to allow searching just now?
42
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
43
-		fatal_lang_error('loadavg_search_disabled', false);
43
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
44
+			fatal_lang_error('loadavg_search_disabled', false);
45
+	}
44 46
 
45 47
 	loadLanguage('Search');
46 48
 	// Don't load this in XML mode.
@@ -88,23 +90,30 @@  discard block
 block discarded – undo
88 90
 			@list ($k, $v) = explode('|\'|', $data);
89 91
 			$context['search_params'][$k] = $v;
90 92
 		}
91
-		if (isset($context['search_params']['brd']))
92
-			$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
93
+		if (isset($context['search_params']['brd'])) {
94
+					$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
95
+		}
93 96
 	}
94 97
 
95
-	if (isset($_REQUEST['search']))
96
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
98
+	if (isset($_REQUEST['search'])) {
99
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
100
+	}
97 101
 
98
-	if (isset($context['search_params']['search']))
99
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
100
-	if (isset($context['search_params']['userspec']))
101
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
102
-	if (!empty($context['search_params']['searchtype']))
103
-		$context['search_params']['searchtype'] = 2;
104
-	if (!empty($context['search_params']['minage']))
105
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
106
-	if (!empty($context['search_params']['maxage']))
107
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
102
+	if (isset($context['search_params']['search'])) {
103
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
104
+	}
105
+	if (isset($context['search_params']['userspec'])) {
106
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
107
+	}
108
+	if (!empty($context['search_params']['searchtype'])) {
109
+			$context['search_params']['searchtype'] = 2;
110
+	}
111
+	if (!empty($context['search_params']['minage'])) {
112
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
113
+	}
114
+	if (!empty($context['search_params']['maxage'])) {
115
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
116
+	}
108 117
 
109 118
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
110 119
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
@@ -116,11 +125,13 @@  discard block
 block discarded – undo
116 125
 		$context['search_errors']['messages'] = array();
117 126
 		foreach ($context['search_errors'] as $search_error => $dummy)
118 127
 		{
119
-			if ($search_error === 'messages')
120
-				continue;
128
+			if ($search_error === 'messages') {
129
+							continue;
130
+			}
121 131
 
122
-			if ($search_error == 'string_too_long')
123
-				$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
132
+			if ($search_error == 'string_too_long') {
133
+							$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
134
+			}
124 135
 
125 136
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
126 137
 		}
@@ -143,12 +154,13 @@  discard block
 block discarded – undo
143 154
 	while ($row = $smcFunc['db_fetch_assoc']($request))
144 155
 	{
145 156
 		// This category hasn't been set up yet..
146
-		if (!isset($context['categories'][$row['id_cat']]))
147
-			$context['categories'][$row['id_cat']] = array(
157
+		if (!isset($context['categories'][$row['id_cat']])) {
158
+					$context['categories'][$row['id_cat']] = array(
148 159
 				'id' => $row['id_cat'],
149 160
 				'name' => $row['cat_name'],
150 161
 				'boards' => array()
151 162
 			);
163
+		}
152 164
 
153 165
 		// Set this board up, and let the template know when it's a child.  (indent them..)
154 166
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -159,8 +171,9 @@  discard block
 block discarded – undo
159 171
 		);
160 172
 
161 173
 		// If a board wasn't checked that probably should have been ensure the board selection is selected, yo!
162
-		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board']))
163
-			$context['boards_check_all'] = false;
174
+		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) {
175
+					$context['boards_check_all'] = false;
176
+		}
164 177
 	}
165 178
 	$smcFunc['db_free_result']($request);
166 179
 
@@ -182,18 +195,20 @@  discard block
 block discarded – undo
182 195
 	}
183 196
 
184 197
 	$max_boards = ceil(count($temp_boards) / 2);
185
-	if ($max_boards == 1)
186
-		$max_boards = 2;
198
+	if ($max_boards == 1) {
199
+			$max_boards = 2;
200
+	}
187 201
 
188 202
 	// Now, alternate them so they can be shown left and right ;).
189 203
 	$context['board_columns'] = array();
190 204
 	for ($i = 0; $i < $max_boards; $i++)
191 205
 	{
192 206
 		$context['board_columns'][] = $temp_boards[$i];
193
-		if (isset($temp_boards[$i + $max_boards]))
194
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
195
-		else
196
-			$context['board_columns'][] = array();
207
+		if (isset($temp_boards[$i + $max_boards])) {
208
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
209
+		} else {
210
+					$context['board_columns'][] = array();
211
+		}
197 212
 	}
198 213
 
199 214
 	if (!empty($_REQUEST['topic']))
@@ -225,8 +240,9 @@  discard block
 block discarded – undo
225 240
 			)
226 241
 		);
227 242
 
228
-		if ($smcFunc['db_num_rows']($request) == 0)
229
-			fatal_lang_error('topic_gone', false);
243
+		if ($smcFunc['db_num_rows']($request) == 0) {
244
+					fatal_lang_error('topic_gone', false);
245
+		}
230 246
 
231 247
 		list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request);
232 248
 		$smcFunc['db_free_result']($request);
@@ -256,11 +272,13 @@  discard block
 block discarded – undo
256 272
 	global $excludedWords, $participants, $smcFunc;
257 273
 
258 274
 	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
259
-	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
260
-		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
275
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') {
276
+			redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
277
+	}
261 278
 
262
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
263
-		fatal_lang_error('loadavg_search_disabled', false);
279
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
280
+			fatal_lang_error('loadavg_search_disabled', false);
281
+	}
264 282
 
265 283
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
266 284
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -307,8 +325,9 @@  discard block
 block discarded – undo
307 325
 	}
308 326
 
309 327
 	// Zero weight.  Weightless :P.
310
-	if (empty($weight_total))
311
-		fatal_lang_error('search_invalid_weights');
328
+	if (empty($weight_total)) {
329
+			fatal_lang_error('search_invalid_weights');
330
+	}
312 331
 
313 332
 	// These vars don't require an interface, they're just here for tweaking.
314 333
 	$recentPercentage = 0.30;
@@ -326,11 +345,13 @@  discard block
 block discarded – undo
326 345
 	$context['search_string_limit'] = 100;
327 346
 
328 347
 	loadLanguage('Search');
329
-	if (!isset($_REQUEST['xml']))
330
-		loadTemplate('Search');
348
+	if (!isset($_REQUEST['xml'])) {
349
+			loadTemplate('Search');
350
+	}
331 351
 	//If we're doing XML we need to use the results template regardless really.
332
-	else
333
-		$context['sub_template'] = 'results';
352
+	else {
353
+			$context['sub_template'] = 'results';
354
+	}
334 355
 
335 356
 	// Are you allowed?
336 357
 	isAllowedTo('search_posts');
@@ -363,34 +384,39 @@  discard block
 block discarded – undo
363 384
 			$search_params[$k] = $v;
364 385
 		}
365 386
 
366
-		if (isset($search_params['brd']))
367
-			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
387
+		if (isset($search_params['brd'])) {
388
+					$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
389
+		}
368 390
 	}
369 391
 
370 392
 	// Store whether simple search was used (needed if the user wants to do another query).
371
-	if (!isset($search_params['advanced']))
372
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
393
+	if (!isset($search_params['advanced'])) {
394
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
395
+	}
373 396
 
374 397
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
375
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
376
-		$search_params['searchtype'] = 2;
398
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
399
+			$search_params['searchtype'] = 2;
400
+	}
377 401
 
378 402
 	// Minimum age of messages. Default to zero (don't set param in that case).
379
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
380
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
403
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
404
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
405
+	}
381 406
 
382 407
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
383
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999))
384
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
408
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) {
409
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
410
+	}
385 411
 
386 412
 	// Searching a specific topic?
387 413
 	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
388 414
 	{
389 415
 		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
390 416
 		$search_params['show_complete'] = true;
417
+	} elseif (!empty($search_params['topic'])) {
418
+			$search_params['topic'] = (int) $search_params['topic'];
391 419
 	}
392
-	elseif (!empty($search_params['topic']))
393
-		$search_params['topic'] = (int) $search_params['topic'];
394 420
 
395 421
 	if (!empty($search_params['minage']) || !empty($search_params['maxage']))
396 422
 	{
@@ -408,19 +434,21 @@  discard block
 block discarded – undo
408 434
 			)
409 435
 		);
410 436
 		list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request);
411
-		if ($minMsgID < 0 || $maxMsgID < 0)
412
-			$context['search_errors']['no_messages_in_time_frame'] = true;
437
+		if ($minMsgID < 0 || $maxMsgID < 0) {
438
+					$context['search_errors']['no_messages_in_time_frame'] = true;
439
+		}
413 440
 		$smcFunc['db_free_result']($request);
414 441
 	}
415 442
 
416 443
 	// Default the user name to a wildcard matching every user (*).
417
-	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
418
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
444
+	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
445
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
446
+	}
419 447
 
420 448
 	// If there's no specific user, then don't mention it in the main query.
421
-	if (empty($search_params['userspec']))
422
-		$userQuery = '';
423
-	else
449
+	if (empty($search_params['userspec'])) {
450
+			$userQuery = '';
451
+	} else
424 452
 	{
425 453
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
426 454
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -432,19 +460,21 @@  discard block
 block discarded – undo
432 460
 		{
433 461
 			$possible_users[$k] = trim($possible_users[$k]);
434 462
 
435
-			if (strlen($possible_users[$k]) == 0)
436
-				unset($possible_users[$k]);
463
+			if (strlen($possible_users[$k]) == 0) {
464
+							unset($possible_users[$k]);
465
+			}
437 466
 		}
438 467
 
439 468
 		// Create a list of database-escaped search names.
440 469
 		$realNameMatches = array();
441
-		foreach ($possible_users as $possible_user)
442
-			$realNameMatches[] = $smcFunc['db_quote'](
470
+		foreach ($possible_users as $possible_user) {
471
+					$realNameMatches[] = $smcFunc['db_quote'](
443 472
 				'{string:possible_user}',
444 473
 				array(
445 474
 					'possible_user' => $possible_user
446 475
 				)
447 476
 			);
477
+		}
448 478
 
449 479
 		// Retrieve a list of possible members.
450 480
 		$request = $smcFunc['db_query']('', '
@@ -456,9 +486,9 @@  discard block
 block discarded – undo
456 486
 			)
457 487
 		);
458 488
 		// Simply do nothing if there're too many members matching the criteria.
459
-		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
460
-			$userQuery = '';
461
-		elseif ($smcFunc['db_num_rows']($request) == 0)
489
+		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
490
+					$userQuery = '';
491
+		} elseif ($smcFunc['db_num_rows']($request) == 0)
462 492
 		{
463 493
 			$userQuery = $smcFunc['db_quote'](
464 494
 				'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})',
@@ -467,12 +497,12 @@  discard block
 block discarded – undo
467 497
 					'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches),
468 498
 				)
469 499
 			);
470
-		}
471
-		else
500
+		} else
472 501
 		{
473 502
 			$memberlist = array();
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$memberlist[] = $row['id_member'];
503
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
504
+							$memberlist[] = $row['id_member'];
505
+			}
476 506
 			$userQuery = $smcFunc['db_quote'](
477 507
 				'(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))',
478 508
 				array(
@@ -486,22 +516,25 @@  discard block
 block discarded – undo
486 516
 	}
487 517
 
488 518
 	// If the boards were passed by URL (params=), temporarily put them back in $_REQUEST.
489
-	if (!empty($search_params['brd']) && is_array($search_params['brd']))
490
-		$_REQUEST['brd'] = $search_params['brd'];
519
+	if (!empty($search_params['brd']) && is_array($search_params['brd'])) {
520
+			$_REQUEST['brd'] = $search_params['brd'];
521
+	}
491 522
 
492 523
 	// Ensure that brd is an array.
493 524
 	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
494 525
 	{
495
-		if (!empty($_REQUEST['brd']))
496
-			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
497
-		else
498
-			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
526
+		if (!empty($_REQUEST['brd'])) {
527
+					$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
528
+		} else {
529
+					$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
530
+		}
499 531
 	}
500 532
 
501 533
 	// Make sure all boards are integers.
502
-	if (!empty($_REQUEST['brd']))
503
-		foreach ($_REQUEST['brd'] as $id => $brd)
534
+	if (!empty($_REQUEST['brd'])) {
535
+			foreach ($_REQUEST['brd'] as $id => $brd)
504 536
 			$_REQUEST['brd'][$id] = (int) $brd;
537
+	}
505 538
 
506 539
 	// Special case for boards: searching just one topic?
507 540
 	if (!empty($search_params['topic']))
@@ -520,17 +553,18 @@  discard block
 block discarded – undo
520 553
 			)
521 554
 		);
522 555
 
523
-		if ($smcFunc['db_num_rows']($request) == 0)
524
-			fatal_lang_error('topic_gone', false);
556
+		if ($smcFunc['db_num_rows']($request) == 0) {
557
+					fatal_lang_error('topic_gone', false);
558
+		}
525 559
 
526 560
 		$search_params['brd'] = array();
527 561
 		list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request);
528 562
 		$smcFunc['db_free_result']($request);
529 563
 	}
530 564
 	// Select all boards you've selected AND are allowed to see.
531
-	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
532
-		$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
533
-	else
565
+	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) {
566
+			$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
567
+	} else
534 568
 	{
535 569
 		$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
536 570
 		$request = $smcFunc['db_query']('', '
@@ -548,19 +582,22 @@  discard block
 block discarded – undo
548 582
 			)
549 583
 		);
550 584
 		$search_params['brd'] = array();
551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
552
-			$search_params['brd'][] = $row['id_board'];
585
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
586
+					$search_params['brd'][] = $row['id_board'];
587
+		}
553 588
 		$smcFunc['db_free_result']($request);
554 589
 
555 590
 		// This error should pro'bly only happen for hackers.
556
-		if (empty($search_params['brd']))
557
-			$context['search_errors']['no_boards_selected'] = true;
591
+		if (empty($search_params['brd'])) {
592
+					$context['search_errors']['no_boards_selected'] = true;
593
+		}
558 594
 	}
559 595
 
560 596
 	if (count($search_params['brd']) != 0)
561 597
 	{
562
-		foreach ($search_params['brd'] as $k => $v)
563
-			$search_params['brd'][$k] = (int) $v;
598
+		foreach ($search_params['brd'] as $k => $v) {
599
+					$search_params['brd'][$k] = (int) $v;
600
+		}
564 601
 
565 602
 		// If we've selected all boards, this parameter can be left empty.
566 603
 		$request = $smcFunc['db_query']('', '
@@ -574,15 +611,16 @@  discard block
 block discarded – undo
574 611
 		list ($num_boards) = $smcFunc['db_fetch_row']($request);
575 612
 		$smcFunc['db_free_result']($request);
576 613
 
577
-		if (count($search_params['brd']) == $num_boards)
614
+		if (count($search_params['brd']) == $num_boards) {
615
+					$boardQuery = '';
616
+		} elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) {
617
+					$boardQuery = '!= ' . $modSettings['recycle_board'];
618
+		} else {
619
+					$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
620
+		}
621
+	} else {
578 622
 			$boardQuery = '';
579
-		elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd']))
580
-			$boardQuery = '!= ' . $modSettings['recycle_board'];
581
-		else
582
-			$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
583 623
 	}
584
-	else
585
-		$boardQuery = '';
586 624
 
587 625
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
588 626
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
@@ -596,11 +634,13 @@  discard block
 block discarded – undo
596 634
 		'id_msg',
597 635
 	);
598 636
 	call_integration_hook('integrate_search_sort_columns', array(&$sort_columns));
599
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
600
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
637
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
638
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
639
+	}
601 640
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance';
602
-	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies')
603
-		$search_params['sort'] = 'id_msg';
641
+	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') {
642
+			$search_params['sort'] = 'id_msg';
643
+	}
604 644
 
605 645
 	// Sorting direction: descending unless stated otherwise.
606 646
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
@@ -624,17 +664,19 @@  discard block
 block discarded – undo
624 664
 	// What are we searching for?
625 665
 	if (empty($search_params['search']))
626 666
 	{
627
-		if (isset($_GET['search']))
628
-			$search_params['search'] = un_htmlspecialchars($_GET['search']);
629
-		elseif (isset($_POST['search']))
630
-			$search_params['search'] = $_POST['search'];
631
-		else
632
-			$search_params['search'] = '';
667
+		if (isset($_GET['search'])) {
668
+					$search_params['search'] = un_htmlspecialchars($_GET['search']);
669
+		} elseif (isset($_POST['search'])) {
670
+					$search_params['search'] = $_POST['search'];
671
+		} else {
672
+					$search_params['search'] = '';
673
+		}
633 674
 	}
634 675
 
635 676
 	// Nothing??
636
-	if (!isset($search_params['search']) || $search_params['search'] == '')
637
-		$context['search_errors']['invalid_search_string'] = true;
677
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
678
+			$context['search_errors']['invalid_search_string'] = true;
679
+	}
638 680
 	// Too long?
639 681
 	elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit'])
640 682
 	{
@@ -648,8 +690,9 @@  discard block
 block discarded – undo
648 690
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));
649 691
 
650 692
 	// This (hidden) setting will do fulltext searching in the most basic way.
651
-	if (!empty($modSettings['search_simple_fulltext']))
652
-		$stripped_query = strtr($stripped_query, array('"' => ''));
693
+	if (!empty($modSettings['search_simple_fulltext'])) {
694
+			$stripped_query = strtr($stripped_query, array('"' => ''));
695
+	}
653 696
 
654 697
 	$no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1;
655 698
 
@@ -672,8 +715,9 @@  discard block
 block discarded – undo
672 715
 	{
673 716
 		if ($word === '-')
674 717
 		{
675
-			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
676
-				$excludedWords[] = $word;
718
+			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
719
+							$excludedWords[] = $word;
720
+			}
677 721
 			unset($phraseArray[$index]);
678 722
 		}
679 723
 	}
@@ -683,8 +727,9 @@  discard block
 block discarded – undo
683 727
 	{
684 728
 		if (strpos(trim($word), '-') === 0)
685 729
 		{
686
-			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
687
-				$excludedWords[] = $word;
730
+			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
731
+							$excludedWords[] = $word;
732
+			}
688 733
 			unset($wordArray[$index]);
689 734
 		}
690 735
 	}
@@ -697,8 +742,9 @@  discard block
 block discarded – undo
697 742
 	foreach ($searchArray as $index => $value)
698 743
 	{
699 744
 		// Skip anything practically empty.
700
-		if (($searchArray[$index] = trim($value, '-_\' ')) === '')
701
-			unset($searchArray[$index]);
745
+		if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
746
+					unset($searchArray[$index]);
747
+		}
702 748
 		// Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing.
703 749
 		elseif (in_array($searchArray[$index], $blacklisted_words))
704 750
 		{
@@ -716,31 +762,37 @@  discard block
 block discarded – undo
716 762
 
717 763
 	// Create an array of replacements for highlighting.
718 764
 	$context['mark'] = array();
719
-	foreach ($searchArray as $word)
720
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
765
+	foreach ($searchArray as $word) {
766
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
767
+	}
721 768
 
722 769
 	// Initialize two arrays storing the words that have to be searched for.
723 770
 	$orParts = array();
724 771
 	$searchWords = array();
725 772
 
726 773
 	// Make sure at least one word is being searched for.
727
-	if (empty($searchArray))
728
-		$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
774
+	if (empty($searchArray)) {
775
+			$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
776
+	}
729 777
 	// All words/sentences must match.
730
-	elseif (empty($search_params['searchtype']))
731
-		$orParts[0] = $searchArray;
778
+	elseif (empty($search_params['searchtype'])) {
779
+			$orParts[0] = $searchArray;
780
+	}
732 781
 	// Any word/sentence must match.
733
-	else
734
-		foreach ($searchArray as $index => $value)
782
+	else {
783
+			foreach ($searchArray as $index => $value)
735 784
 			$orParts[$index] = array($value);
785
+	}
736 786
 
737 787
 	// Don't allow duplicate error messages if one string is too short.
738
-	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string']))
739
-		unset($context['search_errors']['invalid_search_string']);
788
+	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) {
789
+			unset($context['search_errors']['invalid_search_string']);
790
+	}
740 791
 	// Make sure the excluded words are in all or-branches.
741
-	foreach ($orParts as $orIndex => $andParts)
742
-		foreach ($excludedWords as $word)
792
+	foreach ($orParts as $orIndex => $andParts) {
793
+			foreach ($excludedWords as $word)
743 794
 			$orParts[$orIndex][] = $word;
795
+	}
744 796
 
745 797
 	// Determine the or-branches and the fulltext search words.
746 798
 	foreach ($orParts as $orIndex => $andParts)
@@ -754,8 +806,9 @@  discard block
 block discarded – undo
754 806
 		);
755 807
 
756 808
 		// Sort the indexed words (large words -> small words -> excluded words).
757
-		if ($searchAPI->supportsMethod('searchSort'))
758
-			usort($orParts[$orIndex], 'searchSort');
809
+		if ($searchAPI->supportsMethod('searchSort')) {
810
+					usort($orParts[$orIndex], 'searchSort');
811
+		}
759 812
 
760 813
 		foreach ($orParts[$orIndex] as $word)
761 814
 		{
@@ -767,15 +820,17 @@  discard block
 block discarded – undo
767 820
 			if (!$is_excluded || count($subjectWords) === 1)
768 821
 			{
769 822
 				$searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords);
770
-				if ($is_excluded)
771
-					$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
823
+				if ($is_excluded) {
824
+									$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
825
+				}
826
+			} else {
827
+							$excludedPhrases[] = $word;
772 828
 			}
773
-			else
774
-				$excludedPhrases[] = $word;
775 829
 
776 830
 			// Have we got indexes to prepare?
777
-			if ($searchAPI->supportsMethod('prepareIndexes'))
778
-				$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
831
+			if ($searchAPI->supportsMethod('prepareIndexes')) {
832
+							$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
833
+			}
779 834
 		}
780 835
 
781 836
 		// Search_force_index requires all AND parts to have at least one fulltext word.
@@ -783,8 +838,7 @@  discard block
 block discarded – undo
783 838
 		{
784 839
 			$context['search_errors']['query_not_specific_enough'] = true;
785 840
 			break;
786
-		}
787
-		elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
841
+		} elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
788 842
 		{
789 843
 			$context['search_errors']['query_not_specific_enough'] = true;
790 844
 			break;
@@ -812,8 +866,9 @@  discard block
 block discarded – undo
812 866
 		$found_misspelling = false;
813 867
 		foreach ($searchArray as $word)
814 868
 		{
815
-			if (empty($link))
816
-				continue;
869
+			if (empty($link)) {
870
+							continue;
871
+			}
817 872
 
818 873
 			// Don't check phrases.
819 874
 			if (preg_match('~^\w+$~', $word) === 0)
@@ -828,8 +883,7 @@  discard block
 block discarded – undo
828 883
 				$did_you_mean['search'][] = $word;
829 884
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
830 885
 				continue;
831
-			}
832
-			elseif (spell_check($link, $word))
886
+			} elseif (spell_check($link, $word))
833 887
 			{
834 888
 				$did_you_mean['search'][] = $word;
835 889
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -840,11 +894,13 @@  discard block
 block discarded – undo
840 894
 			foreach ($suggestions as $i => $s)
841 895
 			{
842 896
 				// Search is case insensitive.
843
-				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
844
-					unset($suggestions[$i]);
897
+				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) {
898
+									unset($suggestions[$i]);
899
+				}
845 900
 				// Plus, don't suggest something the user thinks is rude!
846
-				elseif ($suggestions[$i] != censorText($s))
847
-					unset($suggestions[$i]);
901
+				elseif ($suggestions[$i] != censorText($s)) {
902
+									unset($suggestions[$i]);
903
+				}
848 904
 			}
849 905
 
850 906
 			// Anything found?  If so, correct it!
@@ -854,8 +910,7 @@  discard block
 block discarded – undo
854 910
 				$did_you_mean['search'][] = $suggestions[0];
855 911
 				$did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
856 912
 				$found_misspelling = true;
857
-			}
858
-			else
913
+			} else
859 914
 			{
860 915
 				$did_you_mean['search'][] = $word;
861 916
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -872,8 +927,7 @@  discard block
 block discarded – undo
872 927
 				{
873 928
 					$temp_excluded['search'][] = '-"' . $word . '"';
874 929
 					$temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
875
-				}
876
-				else
930
+				} else
877 931
 				{
878 932
 					$temp_excluded['search'][] = '-' . $word;
879 933
 					$temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
@@ -885,11 +939,13 @@  discard block
 block discarded – undo
885 939
 
886 940
 			$temp_params = $search_params;
887 941
 			$temp_params['search'] = implode(' ', $did_you_mean['search']);
888
-			if (isset($temp_params['brd']))
889
-				$temp_params['brd'] = implode(',', $temp_params['brd']);
942
+			if (isset($temp_params['brd'])) {
943
+							$temp_params['brd'] = implode(',', $temp_params['brd']);
944
+			}
890 945
 			$context['params'] = array();
891
-			foreach ($temp_params as $k => $v)
892
-				$context['did_you_mean_params'][] = $k . '|\'|' . $v;
946
+			foreach ($temp_params as $k => $v) {
947
+							$context['did_you_mean_params'][] = $k . '|\'|' . $v;
948
+			}
893 949
 			$context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
894 950
 			$context['did_you_mean'] = implode(' ', $did_you_mean['display']);
895 951
 		}
@@ -897,18 +953,20 @@  discard block
 block discarded – undo
897 953
 
898 954
 	// Let the user adjust the search query, should they wish?
899 955
 	$context['search_params'] = $search_params;
900
-	if (isset($context['search_params']['search']))
901
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
902
-	if (isset($context['search_params']['userspec']))
903
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
956
+	if (isset($context['search_params']['search'])) {
957
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
958
+	}
959
+	if (isset($context['search_params']['userspec'])) {
960
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
961
+	}
904 962
 
905 963
 	// Do we have captcha enabled?
906 964
 	if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']))
907 965
 	{
908 966
 		// If we come from another search box tone down the error...
909
-		if (!isset($_REQUEST['search_vv']))
910
-			$context['search_errors']['need_verification_code'] = true;
911
-		else
967
+		if (!isset($_REQUEST['search_vv'])) {
968
+					$context['search_errors']['need_verification_code'] = true;
969
+		} else
912 970
 		{
913 971
 			require_once($sourcedir . '/Subs-Editor.php');
914 972
 			$verificationOptions = array(
@@ -918,12 +976,14 @@  discard block
 block discarded – undo
918 976
 
919 977
 			if (is_array($context['require_verification']))
920 978
 			{
921
-				foreach ($context['require_verification'] as $error)
922
-					$context['search_errors'][$error] = true;
979
+				foreach ($context['require_verification'] as $error) {
980
+									$context['search_errors'][$error] = true;
981
+				}
923 982
 			}
924 983
 			// Don't keep asking for it - they've proven themselves worthy.
925
-			else
926
-				$_SESSION['ss_vv_passed'] = true;
984
+			else {
985
+							$_SESSION['ss_vv_passed'] = true;
986
+			}
927 987
 		}
928 988
 	}
929 989
 
@@ -931,19 +991,22 @@  discard block
 block discarded – undo
931 991
 
932 992
 	// All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below.
933 993
 	$temp_params = $search_params;
934
-	if (isset($temp_params['brd']))
935
-		$temp_params['brd'] = implode(',', $temp_params['brd']);
994
+	if (isset($temp_params['brd'])) {
995
+			$temp_params['brd'] = implode(',', $temp_params['brd']);
996
+	}
936 997
 	$context['params'] = array();
937
-	foreach ($temp_params as $k => $v)
938
-		$context['params'][] = $k . '|\'|' . $v;
998
+	foreach ($temp_params as $k => $v) {
999
+			$context['params'][] = $k . '|\'|' . $v;
1000
+	}
939 1001
 
940 1002
 	if (!empty($context['params']))
941 1003
 	{
942 1004
 		// Due to old IE's 2083 character limit, we have to compress long search strings
943 1005
 		$params = @gzcompress(implode('|"|', $context['params']));
944 1006
 		// Gzcompress failed, use try non-gz
945
-		if (empty($params))
946
-			$params = implode('|"|', $context['params']);
1007
+		if (empty($params)) {
1008
+					$params = implode('|"|', $context['params']);
1009
+		}
947 1010
 		// Base64 encode, then replace +/= with uri safe ones that can be reverted
948 1011
 		$context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params));
949 1012
 	}
@@ -969,8 +1032,9 @@  discard block
 block discarded – undo
969 1032
 	}
970 1033
 
971 1034
 	// Spam me not, Spam-a-lot?
972
-	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])
973
-		spamProtection('search');
1035
+	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) {
1036
+			spamProtection('search');
1037
+	}
974 1038
 	// Store the last search string to allow pages of results to be browsed.
975 1039
 	$_SESSION['last_ss'] = $search_params['search'];
976 1040
 
@@ -1030,8 +1094,9 @@  discard block
 block discarded – undo
1030 1094
 						'where' => array(),
1031 1095
 					);
1032 1096
 
1033
-					if ($modSettings['postmod_active'])
1034
-						$subject_query['where'][] = 't.approved = {int:is_approved}';
1097
+					if ($modSettings['postmod_active']) {
1098
+											$subject_query['where'][] = 't.approved = {int:is_approved}';
1099
+					}
1035 1100
 
1036 1101
 					$numTables = 0;
1037 1102
 					$prev_join = 0;
@@ -1043,8 +1108,7 @@  discard block
 block discarded – undo
1043 1108
 						{
1044 1109
 							$subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)';
1045 1110
 							$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1046
-						}
1047
-						else
1111
+						} else
1048 1112
 						{
1049 1113
 							$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1050 1114
 							$subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}');
@@ -1062,14 +1126,18 @@  discard block
 block discarded – undo
1062 1126
 						}
1063 1127
 						$subject_query['where'][] = $userQuery;
1064 1128
 					}
1065
-					if (!empty($search_params['topic']))
1066
-						$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1067
-					if (!empty($minMsgID))
1068
-						$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1069
-					if (!empty($maxMsgID))
1070
-						$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1071
-					if (!empty($boardQuery))
1072
-						$subject_query['where'][] = 't.id_board ' . $boardQuery;
1129
+					if (!empty($search_params['topic'])) {
1130
+											$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1131
+					}
1132
+					if (!empty($minMsgID)) {
1133
+											$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1134
+					}
1135
+					if (!empty($maxMsgID)) {
1136
+											$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1137
+					}
1138
+					if (!empty($boardQuery)) {
1139
+											$subject_query['where'][] = 't.id_board ' . $boardQuery;
1140
+					}
1073 1141
 					if (!empty($excludedPhrases))
1074 1142
 					{
1075 1143
 						if ($subject_query['from'] != '{db_prefix}messages AS m')
@@ -1089,8 +1157,9 @@  discard block
 block discarded – undo
1089 1157
 					foreach ($weight_factors as $type => $value)
1090 1158
 					{
1091 1159
 						$relevance .= $weight[$type];
1092
-						if (!empty($value['results']))
1093
-							$relevance .= ' * ' . $value['results'];
1160
+						if (!empty($value['results'])) {
1161
+													$relevance .= ' * ' . $value['results'];
1162
+						}
1094 1163
 						$relevance .= ' + ';
1095 1164
 					}
1096 1165
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1128,20 +1197,23 @@  discard block
 block discarded – undo
1128 1197
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1129 1198
 						{
1130 1199
 							// No duplicates!
1131
-							if (isset($inserts[$row[1]]))
1132
-								continue;
1200
+							if (isset($inserts[$row[1]])) {
1201
+															continue;
1202
+							}
1133 1203
 
1134
-							foreach ($row as $key => $value)
1135
-								$inserts[$row[1]][] = (int) $row[$key];
1204
+							foreach ($row as $key => $value) {
1205
+															$inserts[$row[1]][] = (int) $row[$key];
1206
+							}
1136 1207
 						}
1137 1208
 						$smcFunc['db_free_result']($ignoreRequest);
1138 1209
 						$numSubjectResults = count($inserts);
1210
+					} else {
1211
+											$numSubjectResults += $smcFunc['db_affected_rows']();
1139 1212
 					}
1140
-					else
1141
-						$numSubjectResults += $smcFunc['db_affected_rows']();
1142 1213
 
1143
-					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1144
-						break;
1214
+					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1215
+											break;
1216
+					}
1145 1217
 				}
1146 1218
 
1147 1219
 				// If there's data to be inserted for non-IGNORE databases do it here!
@@ -1156,8 +1228,7 @@  discard block
 block discarded – undo
1156 1228
 				}
1157 1229
 
1158 1230
 				$_SESSION['search_cache']['num_results'] = $numSubjectResults;
1159
-			}
1160
-			else
1231
+			} else
1161 1232
 			{
1162 1233
 				$main_query = array(
1163 1234
 					'select' => array(
@@ -1189,8 +1260,7 @@  discard block
 block discarded – undo
1189 1260
 					$main_query['weights'] = $weight_factors;
1190 1261
 
1191 1262
 					$main_query['group_by'][] = 't.id_topic';
1192
-				}
1193
-				else
1263
+				} else
1194 1264
 				{
1195 1265
 					// This is outrageous!
1196 1266
 					$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
@@ -1211,8 +1281,9 @@  discard block
 block discarded – undo
1211 1281
 						$main_query['where'][] = 't.id_topic = {int:topic}';
1212 1282
 						$main_query['parameters']['topic'] = $search_params['topic'];
1213 1283
 					}
1214
-					if (!empty($search_params['show_complete']))
1215
-						$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1284
+					if (!empty($search_params['show_complete'])) {
1285
+											$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1286
+					}
1216 1287
 				}
1217 1288
 
1218 1289
 				// *** Get the subject results.
@@ -1239,14 +1310,15 @@  discard block
 block discarded – undo
1239 1310
 					) !== false;
1240 1311
 
1241 1312
 					// Clean up some previous cache.
1242
-					if (!$createTemporary)
1243
-						$smcFunc['db_search_query']('delete_log_search_topics', '
1313
+					if (!$createTemporary) {
1314
+											$smcFunc['db_search_query']('delete_log_search_topics', '
1244 1315
 							DELETE FROM {db_prefix}log_search_topics
1245 1316
 							WHERE id_search = {int:search_id}',
1246 1317
 							array(
1247 1318
 								'search_id' => $_SESSION['search_cache']['id_search'],
1248 1319
 							)
1249 1320
 						);
1321
+					}
1250 1322
 
1251 1323
 					foreach ($searchWords as $orIndex => $words)
1252 1324
 					{
@@ -1278,8 +1350,7 @@  discard block
 block discarded – undo
1278 1350
 								$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1279 1351
 								$subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}';
1280 1352
 								$subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]';
1281
-							}
1282
-							else
1353
+							} else
1283 1354
 							{
1284 1355
 								$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1285 1356
 								$subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}';
@@ -1334,8 +1405,9 @@  discard block
 block discarded – undo
1334 1405
 						call_integration_hook('integrate_subject_search_query', array(&$subject_query));
1335 1406
 
1336 1407
 						// Nothing to search for?
1337
-						if (empty($subject_query['where']))
1338
-							continue;
1408
+						if (empty($subject_query['where'])) {
1409
+													continue;
1410
+						}
1339 1411
 
1340 1412
 						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1341 1413
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
@@ -1358,19 +1430,21 @@  discard block
 block discarded – undo
1358 1430
 							{
1359 1431
 								$ind = $createTemporary ? 0 : 1;
1360 1432
 								// No duplicates!
1361
-								if (isset($inserts[$row[$ind]]))
1362
-									continue;
1433
+								if (isset($inserts[$row[$ind]])) {
1434
+																	continue;
1435
+								}
1363 1436
 
1364 1437
 								$inserts[$row[$ind]] = $row;
1365 1438
 							}
1366 1439
 							$smcFunc['db_free_result']($ignoreRequest);
1367 1440
 							$numSubjectResults = count($inserts);
1441
+						} else {
1442
+													$numSubjectResults += $smcFunc['db_affected_rows']();
1368 1443
 						}
1369
-						else
1370
-							$numSubjectResults += $smcFunc['db_affected_rows']();
1371 1444
 
1372
-						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1373
-							break;
1445
+						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1446
+													break;
1447
+						}
1374 1448
 					}
1375 1449
 
1376 1450
 					// Got some non-MySQL data to plonk in?
@@ -1388,8 +1462,9 @@  discard block
 block discarded – undo
1388 1462
 					{
1389 1463
 						$main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END';
1390 1464
 						$main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)';
1391
-						if (!$createTemporary)
1392
-							$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1465
+						if (!$createTemporary) {
1466
+													$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1467
+						}
1393 1468
 					}
1394 1469
 				}
1395 1470
 
@@ -1417,14 +1492,15 @@  discard block
 block discarded – undo
1417 1492
 					) !== false;
1418 1493
 
1419 1494
 					// Clear, all clear!
1420
-					if (!$createTemporary)
1421
-						$smcFunc['db_search_query']('delete_log_search_messages', '
1495
+					if (!$createTemporary) {
1496
+											$smcFunc['db_search_query']('delete_log_search_messages', '
1422 1497
 							DELETE FROM {db_prefix}log_search_messages
1423 1498
 							WHERE id_search = {int:id_search}',
1424 1499
 							array(
1425 1500
 								'id_search' => $_SESSION['search_cache']['id_search'],
1426 1501
 							)
1427 1502
 						);
1503
+					}
1428 1504
 
1429 1505
 					foreach ($searchWords as $orIndex => $words)
1430 1506
 					{
@@ -1458,19 +1534,21 @@  discard block
 block discarded – undo
1458 1534
 								while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1459 1535
 								{
1460 1536
 									// No duplicates!
1461
-									if (isset($inserts[$row[0]]))
1462
-										continue;
1537
+									if (isset($inserts[$row[0]])) {
1538
+																			continue;
1539
+									}
1463 1540
 
1464 1541
 									$inserts[$row[0]] = $row;
1465 1542
 								}
1466 1543
 								$smcFunc['db_free_result']($ignoreRequest);
1467 1544
 								$indexedResults = count($inserts);
1545
+							} else {
1546
+															$indexedResults += $smcFunc['db_affected_rows']();
1468 1547
 							}
1469
-							else
1470
-								$indexedResults += $smcFunc['db_affected_rows']();
1471 1548
 
1472
-							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults)
1473
-								break;
1549
+							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) {
1550
+															break;
1551
+							}
1474 1552
 						}
1475 1553
 					}
1476 1554
 
@@ -1490,8 +1568,7 @@  discard block
 block discarded – undo
1490 1568
 						$context['search_errors']['query_not_specific_enough'] = true;
1491 1569
 						$_REQUEST['params'] = $context['params'];
1492 1570
 						return PlushSearch1();
1493
-					}
1494
-					elseif (!empty($indexedResults))
1571
+					} elseif (!empty($indexedResults))
1495 1572
 					{
1496 1573
 						$main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)';
1497 1574
 						if (!$createTemporary)
@@ -1513,15 +1590,18 @@  discard block
 block discarded – undo
1513 1590
 						foreach ($words['all_words'] as $regularWord)
1514 1591
 						{
1515 1592
 							$where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1516
-							if (in_array($regularWord, $excludedWords))
1517
-								$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1593
+							if (in_array($regularWord, $excludedWords)) {
1594
+															$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1595
+							}
1518 1596
 							$main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
1519 1597
 						}
1520
-						if (!empty($where))
1521
-							$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1598
+						if (!empty($where)) {
1599
+													$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1600
+						}
1601
+					}
1602
+					if (!empty($orWhere)) {
1603
+											$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1522 1604
 					}
1523
-					if (!empty($orWhere))
1524
-						$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1525 1605
 
1526 1606
 					if (!empty($userQuery))
1527 1607
 					{
@@ -1559,8 +1639,9 @@  discard block
 block discarded – undo
1559 1639
 					foreach ($main_query['weights'] as $type => $value)
1560 1640
 					{
1561 1641
 						$relevance .= $weight[$type];
1562
-						if (!empty($value['search']))
1563
-							$relevance .= ' * ' . $value['search'];
1642
+						if (!empty($value['search'])) {
1643
+													$relevance .= ' * ' . $value['search'];
1644
+						}
1564 1645
 						$relevance .= ' + ';
1565 1646
 						$new_weight_total += $weight[$type];
1566 1647
 					}
@@ -1591,11 +1672,13 @@  discard block
 block discarded – undo
1591 1672
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1592 1673
 						{
1593 1674
 							// No duplicates!
1594
-							if (isset($inserts[$row[2]]))
1595
-								continue;
1675
+							if (isset($inserts[$row[2]])) {
1676
+															continue;
1677
+							}
1596 1678
 
1597
-							foreach ($row as $key => $value)
1598
-								$inserts[$row[2]][] = (int) $row[$key];
1679
+							foreach ($row as $key => $value) {
1680
+															$inserts[$row[2]][] = (int) $row[$key];
1681
+							}
1599 1682
 						}
1600 1683
 						$smcFunc['db_free_result']($ignoreRequest);
1601 1684
 
@@ -1603,8 +1686,9 @@  discard block
 block discarded – undo
1603 1686
 						if (!empty($inserts))
1604 1687
 						{
1605 1688
 							$query_columns = array();
1606
-							foreach ($main_query['select'] as $k => $v)
1607
-								$query_columns[$k] = 'int';
1689
+							foreach ($main_query['select'] as $k => $v) {
1690
+															$query_columns[$k] = 'int';
1691
+							}
1608 1692
 
1609 1693
 							$smcFunc['db_insert']('',
1610 1694
 								'{db_prefix}log_search_results',
@@ -1614,21 +1698,23 @@  discard block
 block discarded – undo
1614 1698
 							);
1615 1699
 						}
1616 1700
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1701
+					} else {
1702
+											$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1617 1703
 					}
1618
-					else
1619
-						$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1620 1704
 				}
1621 1705
 
1622 1706
 				// Insert subject-only matches.
1623 1707
 				if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0)
1624 1708
 				{
1625 1709
 					$relevance = '1000 * (';
1626
-					foreach ($weight_factors as $type => $value)
1627
-						if (isset($value['results']))
1710
+					foreach ($weight_factors as $type => $value) {
1711
+											if (isset($value['results']))
1628 1712
 						{
1629 1713
 							$relevance .= $weight[$type];
1630
-							if (!empty($value['results']))
1631
-								$relevance .= ' * ' . $value['results'];
1714
+					}
1715
+							if (!empty($value['results'])) {
1716
+															$relevance .= ' * ' . $value['results'];
1717
+							}
1632 1718
 							$relevance .= ' + ';
1633 1719
 						}
1634 1720
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1662,8 +1748,9 @@  discard block
 block discarded – undo
1662 1748
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1663 1749
 						{
1664 1750
 							// No duplicates!
1665
-							if (isset($usedIDs[$row[1]]))
1666
-								continue;
1751
+							if (isset($usedIDs[$row[1]])) {
1752
+															continue;
1753
+							}
1667 1754
 
1668 1755
 							$usedIDs[$row[1]] = true;
1669 1756
 							$inserts[] = $row;
@@ -1681,12 +1768,12 @@  discard block
 block discarded – undo
1681 1768
 							);
1682 1769
 						}
1683 1770
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1771
+					} else {
1772
+											$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1684 1773
 					}
1685
-					else
1686
-						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1774
+				} elseif ($_SESSION['search_cache']['num_results'] == -1) {
1775
+									$_SESSION['search_cache']['num_results'] = 0;
1687 1776
 				}
1688
-				elseif ($_SESSION['search_cache']['num_results'] == -1)
1689
-					$_SESSION['search_cache']['num_results'] = 0;
1690 1777
 			}
1691 1778
 		}
1692 1779
 
@@ -1756,14 +1843,16 @@  discard block
 block discarded – undo
1756 1843
 			)
1757 1844
 		);
1758 1845
 		$posters = array();
1759
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1760
-			$posters[] = $row['id_member'];
1846
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1847
+					$posters[] = $row['id_member'];
1848
+		}
1761 1849
 		$smcFunc['db_free_result']($request);
1762 1850
 
1763 1851
 		call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters));
1764 1852
 
1765
-		if (!empty($posters))
1766
-			loadMemberData(array_unique($posters));
1853
+		if (!empty($posters)) {
1854
+					loadMemberData(array_unique($posters));
1855
+		}
1767 1856
 
1768 1857
 		// Get the messages out for the callback - select enough that it can be made to look just like Display.
1769 1858
 		$messages_request = $smcFunc['db_query']('', '
@@ -1797,8 +1886,9 @@  discard block
 block discarded – undo
1797 1886
 		);
1798 1887
 
1799 1888
 		// If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore.
1800
-		if ($smcFunc['db_num_rows']($messages_request) == 0)
1801
-			$context['topics'] = array();
1889
+		if ($smcFunc['db_num_rows']($messages_request) == 0) {
1890
+					$context['topics'] = array();
1891
+		}
1802 1892
 
1803 1893
 		// If we want to know who participated in what then load this now.
1804 1894
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
@@ -1816,8 +1906,9 @@  discard block
 block discarded – undo
1816 1906
 					'limit' => count($participants),
1817 1907
 				)
1818 1908
 			);
1819
-			while ($row = $smcFunc['db_fetch_assoc']($result))
1820
-				$participants[$row['id_topic']] = true;
1909
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
1910
+							$participants[$row['id_topic']] = true;
1911
+			}
1821 1912
 			$smcFunc['db_free_result']($result);
1822 1913
 		}
1823 1914
 	}
@@ -1826,15 +1917,17 @@  discard block
 block discarded – undo
1826 1917
 	$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false);
1827 1918
 
1828 1919
 	// Consider the search complete!
1829
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1830
-		cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1920
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1921
+			cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1922
+	}
1831 1923
 
1832 1924
 	$context['key_words'] = &$searchArray;
1833 1925
 
1834 1926
 	// Setup the default topic icons... for checking they exist and the like!
1835 1927
 	$context['icon_sources'] = array();
1836
-	foreach ($context['stable_icons'] as $icon)
1837
-		$context['icon_sources'][$icon] = 'images_url';
1928
+	foreach ($context['stable_icons'] as $icon) {
1929
+			$context['icon_sources'][$icon] = 'images_url';
1930
+	}
1838 1931
 
1839 1932
 	$context['sub_template'] = 'results';
1840 1933
 	$context['page_title'] = $txt['search_results'];
@@ -1865,26 +1958,31 @@  discard block
 block discarded – undo
1865 1958
 	global $boards_can, $participants, $smcFunc;
1866 1959
 	static $recycle_board = null;
1867 1960
 
1868
-	if ($recycle_board === null)
1869
-		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1961
+	if ($recycle_board === null) {
1962
+			$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1963
+	}
1870 1964
 
1871 1965
 	// Remember which message this is.  (ie. reply #83)
1872 1966
 	static $counter = null;
1873
-	if ($counter == null || $reset)
1874
-		$counter = $_REQUEST['start'] + 1;
1967
+	if ($counter == null || $reset) {
1968
+			$counter = $_REQUEST['start'] + 1;
1969
+	}
1875 1970
 
1876 1971
 	// If the query returned false, bail.
1877
-	if ($messages_request == false)
1878
-		return false;
1972
+	if ($messages_request == false) {
1973
+			return false;
1974
+	}
1879 1975
 
1880 1976
 	// Start from the beginning...
1881
-	if ($reset)
1882
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1977
+	if ($reset) {
1978
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1979
+	}
1883 1980
 
1884 1981
 	// Attempt to get the next message.
1885 1982
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1886
-	if (!$message)
1887
-		return false;
1983
+	if (!$message) {
1984
+			return false;
1985
+	}
1888 1986
 
1889 1987
 	// Can't have an empty subject can we?
1890 1988
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1923,9 +2021,9 @@  discard block
 block discarded – undo
1923 2021
 
1924 2022
 		if ($smcFunc['strlen']($message['body']) > $charLimit)
1925 2023
 		{
1926
-			if (empty($context['key_words']))
1927
-				$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
1928
-			else
2024
+			if (empty($context['key_words'])) {
2025
+							$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
2026
+			} else
1929 2027
 			{
1930 2028
 				$matchString = '';
1931 2029
 				$force_partial_word = false;
@@ -1934,18 +2032,20 @@  discard block
 block discarded – undo
1934 2032
 					$keyword = un_htmlspecialchars($keyword);
1935 2033
 					$keyword = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
1936 2034
 
1937
-					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
1938
-						$force_partial_word = true;
2035
+					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) {
2036
+											$force_partial_word = true;
2037
+					}
1939 2038
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
1940 2039
 				}
1941 2040
 				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
1942 2041
 
1943 2042
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br>' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
1944 2043
 
1945
-				if (empty($modSettings['search_method']) || $force_partial_word)
1946
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
1947
-				else
1948
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2044
+				if (empty($modSettings['search_method']) || $force_partial_word) {
2045
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2046
+				} else {
2047
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2048
+				}
1949 2049
 
1950 2050
 				$message['body'] = '';
1951 2051
 				foreach ($matches[0] as $index => $match)
@@ -1958,8 +2058,7 @@  discard block
 block discarded – undo
1958 2058
 			// Re-fix the international characters.
1959 2059
 			$message['body'] = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
1960 2060
 		}
1961
-	}
1962
-	else
2061
+	} else
1963 2062
 	{
1964 2063
 		// Run BBC interpreter on the message.
1965 2064
 		$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
@@ -1978,21 +2077,26 @@  discard block
 block discarded – undo
1978 2077
 	// Sadly, we need to check the icon ain't broke.
1979 2078
 	if (!empty($modSettings['messageIconChecks_enable']))
1980 2079
 	{
1981
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1982
-			$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1983
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1984
-			$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1985
-		if (!isset($context['icon_sources'][$message['icon']]))
1986
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1987
-	}
1988
-	else
2080
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2081
+					$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
2082
+		}
2083
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2084
+					$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
2085
+		}
2086
+		if (!isset($context['icon_sources'][$message['icon']])) {
2087
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
2088
+		}
2089
+	} else
1989 2090
 	{
1990
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1991
-			$context['icon_sources'][$message['first_icon']] = 'images_url';
1992
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1993
-			$context['icon_sources'][$message['last_icon']] = 'images_url';
1994
-		if (!isset($context['icon_sources'][$message['icon']]))
1995
-			$context['icon_sources'][$message['icon']] = 'images_url';
2091
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2092
+					$context['icon_sources'][$message['first_icon']] = 'images_url';
2093
+		}
2094
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2095
+					$context['icon_sources'][$message['last_icon']] = 'images_url';
2096
+		}
2097
+		if (!isset($context['icon_sources'][$message['icon']])) {
2098
+					$context['icon_sources'][$message['icon']] = 'images_url';
2099
+		}
1996 2100
 	}
1997 2101
 
1998 2102
 	// Do we have quote tag enabled?
@@ -2002,12 +2106,14 @@  discard block
 block discarded – undo
2002 2106
 	$colorClass = 'windowbg';
2003 2107
 
2004 2108
 	// Sticky topics should get a different color, too.
2005
-	if ($message['is_sticky'])
2006
-		$colorClass .= ' sticky';
2109
+	if ($message['is_sticky']) {
2110
+			$colorClass .= ' sticky';
2111
+	}
2007 2112
 
2008 2113
 	// Locked topics get special treatment as well.
2009
-	if ($message['locked'])
2010
-		$colorClass .= ' locked';
2114
+	if ($message['locked']) {
2115
+			$colorClass .= ' locked';
2116
+	}
2011 2117
 
2012 2118
 	$output = array_merge($context['topics'][$message['id_msg']], array(
2013 2119
 		'id' => $message['id_topic'],
@@ -2151,8 +2257,9 @@  discard block
 block discarded – undo
2151 2257
 
2152 2258
 	// Load up the search API we are going to use.
2153 2259
 	$modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
2154
-	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'))
2155
-		fatal_lang_error('search_api_missing');
2260
+	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) {
2261
+			fatal_lang_error('search_api_missing');
2262
+	}
2156 2263
 	require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php');
2157 2264
 
2158 2265
 	// Create an instance of the search API and check it is valid for this version of SMF.
Please login to merge, or discard this patch.