Completed
Push — release-2.1 ( 3bcfde...9b1f72 )
by Michael
18:23 queued 11:46
created
Sources/Subs-Sound.php 1 patch
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(header('HTTP/1.1 400 Bad Request'));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(header('HTTP/1.1 400 Bad Request'));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -41,16 +43,19 @@  discard block
 block discarded – undo
41 43
 	mt_srand(end(unpack('n', md5($word . session_id()))));
42 44
 
43 45
 	// Try to see if there's a sound font in the user's language.
44
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
45
-		$sound_language = $user_info['language'];
46
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
47
+			$sound_language = $user_info['language'];
48
+	}
46 49
 
47 50
 	// English should be there.
48
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
49
-		$sound_language = 'english';
51
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
52
+			$sound_language = 'english';
53
+	}
50 54
 
51 55
 	// Guess not...
52
-	else
53
-		return false;
56
+	else {
57
+			return false;
58
+	}
54 59
 
55 60
 	// File names are in lower case so lets make sure that we are only using a lower case string
56 61
 	$word = strtolower($word);
@@ -60,20 +65,25 @@  discard block
 block discarded – undo
60 65
 	for ($i = 0; $i < strlen($word); $i++)
61 66
 	{
62 67
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
63
-		if (strpos($sound_letter, 'data') === false)
64
-			return false;
68
+		if (strpos($sound_letter, 'data') === false) {
69
+					return false;
70
+		}
65 71
 
66 72
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
67 73
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
68 74
 		{
69
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
70
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
71
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
75
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
76
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
77
+			}
78
+			$k < $m; $k++) {
79
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
80
+					}
72 81
 			break;
73 82
 
74 83
 			case 1:
75
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
76
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
84
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
85
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
86
+				}
77 87
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
78 88
 			break;
79 89
 
@@ -81,10 +91,12 @@  discard block
 block discarded – undo
81 91
 				$shift = 0;
82 92
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
83 93
 				{
84
-					if (mt_rand(0, 10) === 0)
85
-						$shift += mt_rand(-3, 3);
86
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
87
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
94
+					if (mt_rand(0, 10) === 0) {
95
+											$shift += mt_rand(-3, 3);
96
+					}
97
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
98
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
99
+					}
88 100
 				}
89 101
 			break;
90 102
 
Please login to merge, or discard this patch.
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 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 	$message = preg_replace('~\.{100,}~', '...', $message);
47 48
 
48 49
 	// Trim off trailing quotes - these often happen by accident.
49
-	while (substr($message, -7) == '[quote]')
50
-		$message = substr($message, 0, -7);
51
-	while (substr($message, 0, 8) == '[/quote]')
52
-		$message = substr($message, 8);
50
+	while (substr($message, -7) == '[quote]') {
51
+			$message = substr($message, 0, -7);
52
+	}
53
+	while (substr($message, 0, 8) == '[/quote]') {
54
+			$message = substr($message, 8);
55
+	}
53 56
 
54 57
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
55 58
 	$in_tag = false;
56 59
 	$had_tag = false;
57 60
 	$codeopen = 0;
58
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
59
-		foreach ($matches[0] as $index => $dummy)
61
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
62
+			foreach ($matches[0] as $index => $dummy)
60 63
 		{
61 64
 			// Closing?
62 65
 			if (!empty($matches[2][$index]))
@@ -64,6 +67,7 @@  discard block
 block discarded – undo
64 67
 				// If it's closing and we're not in a tag we need to open it...
65 68
 				if (!$in_tag)
66 69
 					$codeopen = true;
70
+	}
67 71
 				// Either way we ain't in one any more.
68 72
 				$in_tag = false;
69 73
 			}
@@ -72,17 +76,20 @@  discard block
 block discarded – undo
72 76
 			{
73 77
 				$had_tag = true;
74 78
 				// If we're in a tag don't do nought!
75
-				if (!$in_tag)
76
-					$in_tag = true;
79
+				if (!$in_tag) {
80
+									$in_tag = true;
81
+				}
77 82
 			}
78 83
 		}
79 84
 
80 85
 	// If we have an open tag, close it.
81
-	if ($in_tag)
82
-		$message .= '[/code]';
86
+	if ($in_tag) {
87
+			$message .= '[/code]';
88
+	}
83 89
 	// Open any ones that need to be open, only if we've never had a tag.
84
-	if ($codeopen && !$had_tag)
85
-		$message = '[code]' . $message;
90
+	if ($codeopen && !$had_tag) {
91
+			$message = '[code]' . $message;
92
+	}
86 93
 
87 94
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
88 95
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +115,26 @@  discard block
 block discarded – undo
108 115
 	fixTags($message);
109 116
 
110 117
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
118
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
119
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
120
+	} else {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
122
+	}
115 123
 
116 124
 	if (!$previewing && strpos($message, '[html]') !== false)
117 125
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
126
+		if (allowedTo('admin_forum')) {
127
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 128
 				return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
129
+		}
121 130
 			}, $message);
122 131
 
123 132
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 133
 		else
125 134
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
135
+			while (strpos($message, '[html]') !== false) {
136
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			}
128 138
 		}
129 139
 	}
130 140
 
@@ -146,10 +156,12 @@  discard block
 block discarded – undo
146 156
 
147 157
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 158
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
159
+	if ($list_close - $list_open > 0) {
160
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
161
+	}
162
+	if ($list_open - $list_close > 0) {
163
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
164
+	}
153 165
 
154 166
 	$mistake_fixes = array(
155 167
 		// Find [table]s not followed by [tr].
@@ -198,8 +210,9 @@  discard block
 block discarded – undo
198 210
 	);
199 211
 
200 212
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
213
+	for ($j = 0; $j < 3; $j++) {
214
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	}
203 216
 
204 217
 	// Remove empty bbc from the sections outside the code tags
205 218
 	$allowedEmpty = array(
@@ -209,24 +222,28 @@  discard block
 block discarded – undo
209 222
 
210 223
 	require_once($sourcedir . '/Subs.php');
211 224
 
212
-	foreach (($codes = parse_bbc(false)) as $code)
213
-		if (!in_array($code['tag'], $allowedEmpty))
225
+	foreach (($codes = parse_bbc(false)) as $code) {
226
+			if (!in_array($code['tag'], $allowedEmpty))
214 227
 			$alltags[] = $code['tag'];
228
+	}
215 229
 
216 230
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
217 231
 
218
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
219
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
232
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
233
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	}
220 235
 
221 236
 	// Restore code blocks
222
-	if (!empty($code_tags))
223
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
237
+	if (!empty($code_tags)) {
238
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	}
224 240
 
225 241
 	// Restore white space entities
226
-	if (!$previewing)
227
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
228
-	else
229
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
242
+	if (!$previewing) {
243
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	} else {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	}
230 247
 
231 248
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
232 249
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
270 287
 	}, $message);
271 288
 
272
-	if (!empty($code_tags))
273
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
289
+	if (!empty($code_tags)) {
290
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	}
274 292
 
275 293
 	// Change breaks back to \n's and &nsbp; back to spaces.
276 294
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -351,8 +369,9 @@  discard block
 block discarded – undo
351 369
 	);
352 370
 
353 371
 	// Fix each type of tag.
354
-	foreach ($fixArray as $param)
355
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
372
+	foreach ($fixArray as $param) {
373
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	}
356 375
 
357 376
 	// Now fix possible security problems with images loading links automatically...
358 377
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -388,16 +407,19 @@  discard block
 block discarded – undo
388 407
 					$desired_height = $height;
389 408
 				}
390 409
 				// Scale it to the width...
391
-				elseif (empty($desired_width) && !empty($height))
392
-					$desired_width = (int) (($desired_height * $width) / $height);
410
+				elseif (empty($desired_width) && !empty($height)) {
411
+									$desired_width = (int) (($desired_height * $width) / $height);
412
+				}
393 413
 				// Scale if to the height.
394
-				elseif (!empty($width))
395
-					$desired_height = (int) (($desired_width * $height) / $width);
414
+				elseif (!empty($width)) {
415
+									$desired_height = (int) (($desired_width * $height) / $width);
416
+				}
396 417
 			}
397 418
 
398 419
 			// If the width and height are fine, just continue along...
399
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
400
-				continue;
420
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
421
+							continue;
422
+			}
401 423
 
402 424
 			// Too bad, it's too wide.  Make it as wide as the maximum.
403 425
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -417,8 +439,9 @@  discard block
 block discarded – undo
417 439
 		}
418 440
 
419 441
 		// If any img tags were actually changed...
420
-		if (!empty($replaces))
421
-			$message = strtr($message, $replaces);
442
+		if (!empty($replaces)) {
443
+					$message = strtr($message, $replaces);
444
+		}
422 445
 	}
423 446
 }
424 447
 
@@ -437,10 +460,11 @@  discard block
 block discarded – undo
437 460
 {
438 461
 	global $boardurl, $scripturl;
439 462
 
440
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
441
-		$domain_url = $match[1];
442
-	else
443
-		$domain_url = $boardurl . '/';
463
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
464
+			$domain_url = $match[1];
465
+	} else {
466
+			$domain_url = $boardurl . '/';
467
+	}
444 468
 
445 469
 	$replaces = array();
446 470
 
@@ -448,11 +472,11 @@  discard block
 block discarded – undo
448 472
 	{
449 473
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
450 474
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
475
+	} elseif ($hasEqualSign) {
476
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} else {
478
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
451 479
 	}
452
-	elseif ($hasEqualSign)
453
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
454
-	else
455
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
456 480
 
457 481
 	foreach ($matches[0] as $k => $dummy)
458 482
 	{
@@ -465,49 +489,53 @@  discard block
 block discarded – undo
465 489
 		foreach ($protocols as $protocol)
466 490
 		{
467 491
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
468
-			if ($found)
469
-				break;
492
+			if ($found) {
493
+							break;
494
+			}
470 495
 		}
471 496
 
472 497
 		if (!$found && $protocols[0] == 'http')
473 498
 		{
474
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
475
-				$replace = $domain_url . $replace;
476
-			elseif (substr($replace, 0, 1) == '?')
477
-				$replace = $scripturl . $replace;
478
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
499
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
500
+							$replace = $domain_url . $replace;
501
+			} elseif (substr($replace, 0, 1) == '?') {
502
+							$replace = $scripturl . $replace;
503
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
479 504
 			{
480 505
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
481 506
 				$this_tag = 'iurl';
482 507
 				$this_close = 'iurl';
508
+			} elseif (substr($replace, 0, 2) != '//') {
509
+							$replace = $protocols[0] . '://' . $replace;
483 510
 			}
484
-			elseif (substr($replace, 0, 2) != '//')
485
-				$replace = $protocols[0] . '://' . $replace;
486
-		}
487
-		elseif (!$found && $protocols[0] == 'ftp')
488
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
489
-		elseif (!$found)
490
-			$replace = $protocols[0] . '://' . $replace;
491
-
492
-		if ($hasEqualSign && $embeddedUrl)
493
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
494
-		elseif ($hasEqualSign)
495
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
496
-		elseif ($embeddedUrl)
497
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
498
-		else
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
511
+		} elseif (!$found && $protocols[0] == 'ftp') {
512
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
513
+		} elseif (!$found) {
514
+					$replace = $protocols[0] . '://' . $replace;
515
+		}
516
+
517
+		if ($hasEqualSign && $embeddedUrl) {
518
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
519
+		} elseif ($hasEqualSign) {
520
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
521
+		} elseif ($embeddedUrl) {
522
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
523
+		} else {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
525
+		}
500 526
 	}
501 527
 
502 528
 	foreach ($replaces as $k => $v)
503 529
 	{
504
-		if ($k == $v)
505
-			unset($replaces[$k]);
530
+		if ($k == $v) {
531
+					unset($replaces[$k]);
532
+		}
506 533
 	}
507 534
 
508
-	if (!empty($replaces))
509
-		$message = strtr($message, $replaces);
510
-}
535
+	if (!empty($replaces)) {
536
+			$message = strtr($message, $replaces);
537
+	}
538
+	}
511 539
 
512 540
 /**
513 541
  * This function sends an email to the specified recipient(s).
@@ -551,8 +579,9 @@  discard block
 block discarded – undo
551 579
 	}
552 580
 
553 581
 	// Nothing left? Nothing else to do
554
-	if (empty($to_array))
555
-		return true;
582
+	if (empty($to_array)) {
583
+			return true;
584
+	}
556 585
 
557 586
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
558 587
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -569,15 +598,17 @@  discard block
 block discarded – undo
569 598
 		}
570 599
 
571 600
 		// Call this function recursively for the hotmail addresses.
572
-		if (!empty($hotmail_to))
573
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
601
+		if (!empty($hotmail_to)) {
602
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		}
574 604
 
575 605
 		// The remaining addresses no longer need the fix.
576 606
 		$hotmail_fix = false;
577 607
 
578 608
 		// No other addresses left? Return instantly.
579
-		if (empty($to_array))
580
-			return $mail_result;
609
+		if (empty($to_array)) {
610
+					return $mail_result;
611
+		}
581 612
 	}
582 613
 
583 614
 	// Get rid of entities.
@@ -602,13 +633,15 @@  discard block
 block discarded – undo
602 633
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
603 634
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
604 635
 
605
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
606
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
636
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
637
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	}
607 639
 	$headers .= 'X-Mailer: SMF' . $line_break;
608 640
 
609 641
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
610
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
611
-		return false;
642
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
643
+			return false;
644
+	}
612 645
 
613 646
 	// Save the original message...
614 647
 	$orig_message = $message;
@@ -657,17 +690,19 @@  discard block
 block discarded – undo
657 690
 	}
658 691
 
659 692
 	// Are we using the mail queue, if so this is where we butt in...
660
-	if ($priority != 0)
661
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
693
+	if ($priority != 0) {
694
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	}
662 696
 
663 697
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
664 698
 	elseif (!empty($modSettings['mail_limit']))
665 699
 	{
666 700
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
667
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
668
-			$new_queue_stat = time() . '|' . 1;
669
-		else
670
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
701
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
702
+					$new_queue_stat = time() . '|' . 1;
703
+		} else {
704
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
705
+		}
671 706
 
672 707
 		updateSettings(array('mail_recent' => $new_queue_stat));
673 708
 	}
@@ -692,12 +727,13 @@  discard block
 block discarded – undo
692 727
 
693 728
 			// Wait, wait, I'm still sending here!
694 729
 			@set_time_limit(300);
695
-			if (function_exists('apache_reset_timeout'))
696
-				@apache_reset_timeout();
730
+			if (function_exists('apache_reset_timeout')) {
731
+							@apache_reset_timeout();
732
+			}
697 733
 		}
734
+	} else {
735
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
698 736
 	}
699
-	else
700
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
701 737
 
702 738
 	// Everything go smoothly?
703 739
 	return $mail_result;
@@ -723,8 +759,9 @@  discard block
 block discarded – undo
723 759
 	static $cur_insert = array();
724 760
 	static $cur_insert_len = 0;
725 761
 
726
-	if ($cur_insert_len == 0)
727
-		$cur_insert = array();
762
+	if ($cur_insert_len == 0) {
763
+			$cur_insert = array();
764
+	}
728 765
 
729 766
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
730 767
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -799,8 +836,9 @@  discard block
 block discarded – undo
799 836
 	}
800 837
 
801 838
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
802
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
803
-		return AddMailQueue(true);
839
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
840
+			return AddMailQueue(true);
841
+	}
804 842
 
805 843
 	return true;
806 844
 }
@@ -833,23 +871,26 @@  discard block
 block discarded – undo
833 871
 		'sent' => array()
834 872
 	);
835 873
 
836
-	if ($from === null)
837
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
838 876
 			'id' => $user_info['id'],
839 877
 			'name' => $user_info['name'],
840 878
 			'username' => $user_info['username']
841 879
 		);
880
+	}
842 881
 
843 882
 	// This is the one that will go in their inbox.
844 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
845 884
 	preparsecode($htmlmessage);
846 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
847
-	if ($smcFunc['strlen']($htmlsubject) > 100)
848
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
849 889
 
850 890
 	// Make sure is an array
851
-	if (!is_array($recipients))
852
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
853 894
 
854 895
 	// Integrated PMs
855 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -877,21 +918,23 @@  discard block
 block discarded – undo
877 918
 				'usernames' => array_keys($usernames),
878 919
 			)
879 920
 		);
880
-		while ($row = $smcFunc['db_fetch_assoc']($request))
881
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
882 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
883 925
 		$smcFunc['db_free_result']($request);
884 926
 
885 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
886
-		foreach ($recipients as $rec_type => $rec)
887
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
888 930
 			{
889 931
 				if (is_numeric($recipients[$rec_type][$id]))
890 932
 					continue;
933
+		}
891 934
 
892
-				if (!empty($usernames[$member]))
893
-					$recipients[$rec_type][$id] = $usernames[$member];
894
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
895 938
 				{
896 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
897 940
 					unset($recipients[$rec_type][$id]);
@@ -930,8 +973,9 @@  discard block
 block discarded – undo
930 973
 		foreach ($criteria as $criterium)
931 974
 		{
932 975
 			$match = false;
933
-			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))
934
-				$delete = true;
976
+			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)) {
977
+							$delete = true;
978
+			}
935 979
 			// If we're adding and one criteria don't match then we stop!
936 980
 			elseif (!$row['is_or'])
937 981
 			{
@@ -939,8 +983,9 @@  discard block
 block discarded – undo
939 983
 				break;
940 984
 			}
941 985
 		}
942
-		if ($delete)
943
-			$deletes[$row['id_member']] = 1;
986
+		if ($delete) {
987
+					$deletes[$row['id_member']] = 1;
988
+		}
944 989
 	}
945 990
 	$smcFunc['db_free_result']($request);
946 991
 
@@ -955,8 +1000,9 @@  discard block
 block discarded – undo
955 1000
 			array(
956 1001
 			)
957 1002
 		);
958
-		while ($row = $smcFunc['db_fetch_assoc']($request))
959
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1003
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1004
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1005
+		}
960 1006
 		$smcFunc['db_free_result']($request);
961 1007
 	}
962 1008
 
@@ -964,8 +1010,9 @@  discard block
 block discarded – undo
964 1010
 	require_once($sourcedir . '/Subs-Members.php');
965 1011
 	$pmReadGroups = groupsAllowedTo('pm_read');
966 1012
 
967
-	if (empty($modSettings['permission_enable_deny']))
968
-		$pmReadGroups['denied'] = array();
1013
+	if (empty($modSettings['permission_enable_deny'])) {
1014
+			$pmReadGroups['denied'] = array();
1015
+	}
969 1016
 
970 1017
 	// Load their alert preferences
971 1018
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -997,8 +1044,9 @@  discard block
 block discarded – undo
997 1044
 	while ($row = $smcFunc['db_fetch_assoc']($request))
998 1045
 	{
999 1046
 		// Don't do anything for members to be deleted!
1000
-		if (isset($deletes[$row['id_member']]))
1001
-			continue;
1047
+		if (isset($deletes[$row['id_member']])) {
1048
+					continue;
1049
+		}
1002 1050
 
1003 1051
 		// Load the preferences for this member (if any)
1004 1052
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1019,8 +1067,9 @@  discard block
 block discarded – undo
1019 1067
 		{
1020 1068
 			foreach ($groups as $id)
1021 1069
 			{
1022
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1023
-					$message_limit = $message_limit_cache[$id];
1070
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1071
+									$message_limit = $message_limit_cache[$id];
1072
+				}
1024 1073
 			}
1025 1074
 
1026 1075
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1068,8 +1117,9 @@  discard block
 block discarded – undo
1068 1117
 	$smcFunc['db_free_result']($request);
1069 1118
 
1070 1119
 	// Only 'send' the message if there are any recipients left.
1071
-	if (empty($all_to))
1072
-		return $log;
1120
+	if (empty($all_to)) {
1121
+			return $log;
1122
+	}
1073 1123
 
1074 1124
 	// Insert the message itself and then grab the last insert id.
1075 1125
 	$smcFunc['db_insert']('',
@@ -1090,8 +1140,8 @@  discard block
 block discarded – undo
1090 1140
 	if (!empty($id_pm))
1091 1141
 	{
1092 1142
 		// If this is new we need to set it part of it's own conversation.
1093
-		if (empty($pm_head))
1094
-			$smcFunc['db_query']('', '
1143
+		if (empty($pm_head)) {
1144
+					$smcFunc['db_query']('', '
1095 1145
 				UPDATE {db_prefix}personal_messages
1096 1146
 				SET id_pm_head = {int:id_pm_head}
1097 1147
 				WHERE id_pm = {int:id_pm_head}',
@@ -1099,6 +1149,7 @@  discard block
 block discarded – undo
1099 1149
 					'id_pm_head' => $id_pm,
1100 1150
 				)
1101 1151
 			);
1152
+		}
1102 1153
 
1103 1154
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1104 1155
 		$smcFunc['db_query']('', '
@@ -1114,8 +1165,9 @@  discard block
 block discarded – undo
1114 1165
 		foreach ($all_to as $to)
1115 1166
 		{
1116 1167
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1117
-			if (!in_array($to, $recipients['bcc']))
1118
-				$to_list[] = $to;
1168
+			if (!in_array($to, $recipients['bcc'])) {
1169
+							$to_list[] = $to;
1170
+			}
1119 1171
 		}
1120 1172
 
1121 1173
 		$smcFunc['db_insert']('insert',
@@ -1133,9 +1185,9 @@  discard block
 block discarded – undo
1133 1185
 	{
1134 1186
 		censorText($message);
1135 1187
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1188
+	} else {
1189
+			$message = '';
1136 1190
 	}
1137
-	else
1138
-		$message = '';
1139 1191
 
1140 1192
 	$to_names = array();
1141 1193
 	if (count($to_list) > 1)
@@ -1148,8 +1200,9 @@  discard block
 block discarded – undo
1148 1200
 				'to_members' => $to_list,
1149 1201
 			)
1150 1202
 		);
1151
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1152
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1203
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1204
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1205
+		}
1153 1206
 		$smcFunc['db_free_result']($request);
1154 1207
 	}
1155 1208
 	$replacements = array(
@@ -1177,11 +1230,13 @@  discard block
 block discarded – undo
1177 1230
 	loadLanguage('index+PersonalMessage');
1178 1231
 
1179 1232
 	// Add one to their unread and read message counts.
1180
-	foreach ($all_to as $k => $id)
1181
-		if (isset($deletes[$id]))
1233
+	foreach ($all_to as $k => $id) {
1234
+			if (isset($deletes[$id]))
1182 1235
 			unset($all_to[$k]);
1183
-	if (!empty($all_to))
1184
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1237
+	if (!empty($all_to)) {
1238
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1239
+	}
1185 1240
 
1186 1241
 	return $log;
1187 1242
 }
@@ -1211,15 +1266,17 @@  discard block
 block discarded – undo
1211 1266
 		// Let's, for now, assume there are only &#021;'ish characters.
1212 1267
 		$simple = true;
1213 1268
 
1214
-		foreach ($matches[1] as $entity)
1215
-			if ($entity > 128)
1269
+		foreach ($matches[1] as $entity) {
1270
+					if ($entity > 128)
1216 1271
 				$simple = false;
1272
+		}
1217 1273
 		unset($matches);
1218 1274
 
1219
-		if ($simple)
1220
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1275
+		if ($simple) {
1276
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1221 1277
 			{
1222 1278
 				return chr("$m[1]");
1279
+		}
1223 1280
 			}, $string);
1224 1281
 		else
1225 1282
 		{
@@ -1227,8 +1284,9 @@  discard block
 block discarded – undo
1227 1284
 			if (!$context['utf8'] && function_exists('iconv'))
1228 1285
 			{
1229 1286
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1230
-				if ($newstring)
1231
-					$string = $newstring;
1287
+				if ($newstring) {
1288
+									$string = $newstring;
1289
+				}
1232 1290
 			}
1233 1291
 
1234 1292
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1244,23 +1302,25 @@  discard block
 block discarded – undo
1244 1302
 		if (!$context['utf8'] && function_exists('iconv'))
1245 1303
 		{
1246 1304
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1247
-			if ($newstring)
1248
-				$string = $newstring;
1305
+			if ($newstring) {
1306
+							$string = $newstring;
1307
+			}
1249 1308
 		}
1250 1309
 
1251 1310
 		$entityConvert = function($m)
1252 1311
 		{
1253 1312
 			$c = $m[1];
1254
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1255
-				return $c;
1256
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1259
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1260
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1261
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1262
-			else
1263
-				return "";
1313
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1314
+							return $c;
1315
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1316
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1317
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1318
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1319
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1320
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1321
+			} else {
1322
+							return "";
1323
+			}
1264 1324
 		};
1265 1325
 
1266 1326
 		// Convert all 'special' characters to HTML entities.
@@ -1274,19 +1334,20 @@  discard block
 block discarded – undo
1274 1334
 		$string = base64_encode($string);
1275 1335
 
1276 1336
 		// Show the characterset and the transfer-encoding for header strings.
1277
-		if ($with_charset)
1278
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1337
+		if ($with_charset) {
1338
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1339
+		}
1279 1340
 
1280 1341
 		// Break it up in lines (mail body).
1281
-		else
1282
-			$string = chunk_split($string, 76, $line_break);
1342
+		else {
1343
+					$string = chunk_split($string, 76, $line_break);
1344
+		}
1283 1345
 
1284 1346
 		return array($charset, $string, 'base64');
1347
+	} else {
1348
+			return array($charset, $string, '7bit');
1349
+	}
1285 1350
 	}
1286
-
1287
-	else
1288
-		return array($charset, $string, '7bit');
1289
-}
1290 1351
 
1291 1352
 /**
1292 1353
  * Sends mail, like mail() but over SMTP.
@@ -1310,8 +1371,9 @@  discard block
 block discarded – undo
1310 1371
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1311 1372
 	{
1312 1373
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1313
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1314
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1374
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1375
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1376
+		}
1315 1377
 
1316 1378
 		if ($socket)
1317 1379
 		{
@@ -1332,8 +1394,9 @@  discard block
 block discarded – undo
1332 1394
 		// Maybe we can still save this?  The port might be wrong.
1333 1395
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1334 1396
 		{
1335
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1336
-				log_error($txt['smtp_port_ssl']);
1397
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1398
+							log_error($txt['smtp_port_ssl']);
1399
+			}
1337 1400
 		}
1338 1401
 
1339 1402
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1345,20 +1408,23 @@  discard block
 block discarded – undo
1345 1408
 	}
1346 1409
 
1347 1410
 	// Wait for a response of 220, without "-" continuer.
1348
-	if (!server_parse(null, $socket, '220'))
1349
-		return false;
1411
+	if (!server_parse(null, $socket, '220')) {
1412
+			return false;
1413
+	}
1350 1414
 
1351 1415
 	// Try and determine the servers name, fall back to the mail servers if not found
1352 1416
 	$helo = false;
1353
-	if (function_exists('gethostname') && gethostname() !== false)
1354
-		$helo = gethostname();
1355
-	elseif (function_exists('php_uname'))
1356
-		$helo = php_uname('n');
1357
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1358
-		$helo = $_SERVER['SERVER_NAME'];
1417
+	if (function_exists('gethostname') && gethostname() !== false) {
1418
+			$helo = gethostname();
1419
+	} elseif (function_exists('php_uname')) {
1420
+			$helo = php_uname('n');
1421
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1422
+			$helo = $_SERVER['SERVER_NAME'];
1423
+	}
1359 1424
 
1360
-	if (empty($helo))
1361
-		$helo = $modSettings['smtp_host'];
1425
+	if (empty($helo)) {
1426
+			$helo = $modSettings['smtp_host'];
1427
+	}
1362 1428
 
1363 1429
 	// SMTP = 1, SMTP - STARTTLS = 2
1364 1430
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1370,33 +1436,39 @@  discard block
 block discarded – undo
1370 1436
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1371 1437
 			{
1372 1438
 				// Send STARTTLS to enable encryption
1373
-				if (!server_parse('STARTTLS', $socket, '220'))
1374
-					return false;
1439
+				if (!server_parse('STARTTLS', $socket, '220')) {
1440
+									return false;
1441
+				}
1375 1442
 				// Enable the encryption
1376
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1377
-					return false;
1443
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1444
+									return false;
1445
+				}
1378 1446
 				// Send the EHLO command again
1379
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1380
-					return false;
1447
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1448
+									return false;
1449
+				}
1381 1450
 			}
1382 1451
 
1383
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1384
-				return false;
1452
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1453
+							return false;
1454
+			}
1385 1455
 			// Send the username and password, encoded.
1386
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1387
-				return false;
1456
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1457
+							return false;
1458
+			}
1388 1459
 			// The password is already encoded ;)
1389
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1390
-				return false;
1460
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1461
+							return false;
1462
+			}
1463
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1464
+					return false;
1391 1465
 		}
1392
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1393
-			return false;
1394
-	}
1395
-	else
1466
+	} else
1396 1467
 	{
1397 1468
 		// Just say "helo".
1398
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1399
-			return false;
1469
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1470
+					return false;
1471
+		}
1400 1472
 	}
1401 1473
 
1402 1474
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1409,31 +1481,38 @@  discard block
 block discarded – undo
1409 1481
 		// Reset the connection to send another email.
1410 1482
 		if ($i != 0)
1411 1483
 		{
1412
-			if (!server_parse('RSET', $socket, '250'))
1413
-				return false;
1484
+			if (!server_parse('RSET', $socket, '250')) {
1485
+							return false;
1486
+			}
1414 1487
 		}
1415 1488
 
1416 1489
 		// From, to, and then start the data...
1417
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1420
-			return false;
1421
-		if (!server_parse('DATA', $socket, '354'))
1422
-			return false;
1490
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1494
+					return false;
1495
+		}
1496
+		if (!server_parse('DATA', $socket, '354')) {
1497
+					return false;
1498
+		}
1423 1499
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1424
-		if (strlen($mail_to) > 0)
1425
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1500
+		if (strlen($mail_to) > 0) {
1501
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1502
+		}
1426 1503
 		fputs($socket, $headers . "\r\n\r\n");
1427 1504
 		fputs($socket, $message . "\r\n");
1428 1505
 
1429 1506
 		// Send a ., or in other words "end of data".
1430
-		if (!server_parse('.', $socket, '250'))
1431
-			return false;
1507
+		if (!server_parse('.', $socket, '250')) {
1508
+					return false;
1509
+		}
1432 1510
 
1433 1511
 		// Almost done, almost done... don't stop me just yet!
1434 1512
 		@set_time_limit(300);
1435
-		if (function_exists('apache_reset_timeout'))
1436
-			@apache_reset_timeout();
1513
+		if (function_exists('apache_reset_timeout')) {
1514
+					@apache_reset_timeout();
1515
+		}
1437 1516
 	}
1438 1517
 	fputs($socket, 'QUIT' . "\r\n");
1439 1518
 	fclose($socket);
@@ -1457,8 +1536,9 @@  discard block
 block discarded – undo
1457 1536
 {
1458 1537
 	global $txt;
1459 1538
 
1460
-	if ($message !== null)
1461
-		fputs($socket, $message . "\r\n");
1539
+	if ($message !== null) {
1540
+			fputs($socket, $message . "\r\n");
1541
+	}
1462 1542
 
1463 1543
 	// No response yet.
1464 1544
 	$server_response = '';
@@ -1474,8 +1554,9 @@  discard block
 block discarded – undo
1474 1554
 		$response .= $server_response;
1475 1555
 	}
1476 1556
 
1477
-	if ($code === null)
1478
-		return substr($server_response, 0, 3);
1557
+	if ($code === null) {
1558
+			return substr($server_response, 0, 3);
1559
+	}
1479 1560
 
1480 1561
 	if (substr($server_response, 0, 3) != $code)
1481 1562
 	{
@@ -1505,8 +1586,9 @@  discard block
 block discarded – undo
1505 1586
 	// Create a pspell or enchant dictionary resource
1506 1587
 	$dict = spell_init();
1507 1588
 
1508
-	if (!isset($_POST['spellstring']) || !$dict)
1509
-		die;
1589
+	if (!isset($_POST['spellstring']) || !$dict) {
1590
+			die;
1591
+	}
1510 1592
 
1511 1593
 	// Construct a bit of Javascript code.
1512 1594
 	$context['spell_js'] = '
@@ -1524,8 +1606,9 @@  discard block
 block discarded – undo
1524 1606
 		$check_word = explode('|', $alphas[$i]);
1525 1607
 
1526 1608
 		// If the word is a known word, or spelled right...
1527
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1528
-			continue;
1609
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1610
+					continue;
1611
+		}
1529 1612
 
1530 1613
 		// Find the word, and move up the "last occurrence" to here.
1531 1614
 		$found_words = true;
@@ -1539,20 +1622,23 @@  discard block
 block discarded – undo
1539 1622
 		if (!empty($suggestions))
1540 1623
 		{
1541 1624
 			// But first check they aren't going to be censored - no naughty words!
1542
-			foreach ($suggestions as $k => $word)
1543
-				if ($suggestions[$k] != censorText($word))
1625
+			foreach ($suggestions as $k => $word) {
1626
+							if ($suggestions[$k] != censorText($word))
1544 1627
 					unset($suggestions[$k]);
1628
+			}
1545 1629
 
1546
-			if (!empty($suggestions))
1547
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1630
+			if (!empty($suggestions)) {
1631
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1632
+			}
1548 1633
 		}
1549 1634
 
1550 1635
 		$context['spell_js'] .= ']),';
1551 1636
 	}
1552 1637
 
1553 1638
 	// If words were found, take off the last comma.
1554
-	if ($found_words)
1555
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1639
+	if ($found_words) {
1640
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1641
+	}
1556 1642
 
1557 1643
 	$context['spell_js'] .= '
1558 1644
 		);';
@@ -1587,11 +1673,13 @@  discard block
 block discarded – undo
1587 1673
 	global $user_info, $smcFunc;
1588 1674
 
1589 1675
 	// Can't do it if there's no topics.
1590
-	if (empty($topics))
1591
-		return;
1676
+	if (empty($topics)) {
1677
+			return;
1678
+	}
1592 1679
 	// It must be an array - it must!
1593
-	if (!is_array($topics))
1594
-		$topics = array($topics);
1680
+	if (!is_array($topics)) {
1681
+			$topics = array($topics);
1682
+	}
1595 1683
 
1596 1684
 	// Get the subject and body...
1597 1685
 	$result = $smcFunc['db_query']('', '
@@ -1639,14 +1727,15 @@  discard block
 block discarded – undo
1639 1727
 	}
1640 1728
 	$smcFunc['db_free_result']($result);
1641 1729
 
1642
-	if (!empty($task_rows))
1643
-		$smcFunc['db_insert']('',
1730
+	if (!empty($task_rows)) {
1731
+			$smcFunc['db_insert']('',
1644 1732
 			'{db_prefix}background_tasks',
1645 1733
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1646 1734
 			$task_rows,
1647 1735
 			array('id_task')
1648 1736
 		);
1649
-}
1737
+	}
1738
+	}
1650 1739
 
1651 1740
 /**
1652 1741
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1684,9 +1773,9 @@  discard block
 block discarded – undo
1684 1773
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1685 1774
 
1686 1775
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1687
-	if (!$modSettings['postmod_active'])
1688
-		$topicOptions['is_approved'] = true;
1689
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1776
+	if (!$modSettings['postmod_active']) {
1777
+			$topicOptions['is_approved'] = true;
1778
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1690 1779
 	{
1691 1780
 		$request = $smcFunc['db_query']('', '
1692 1781
 			SELECT approved
@@ -1709,8 +1798,7 @@  discard block
 block discarded – undo
1709 1798
 			$posterOptions['id'] = 0;
1710 1799
 			$posterOptions['name'] = $txt['guest_title'];
1711 1800
 			$posterOptions['email'] = '';
1712
-		}
1713
-		elseif ($posterOptions['id'] != $user_info['id'])
1801
+		} elseif ($posterOptions['id'] != $user_info['id'])
1714 1802
 		{
1715 1803
 			$request = $smcFunc['db_query']('', '
1716 1804
 				SELECT member_name, email_address
@@ -1728,12 +1816,11 @@  discard block
 block discarded – undo
1728 1816
 				$posterOptions['id'] = 0;
1729 1817
 				$posterOptions['name'] = $txt['guest_title'];
1730 1818
 				$posterOptions['email'] = '';
1819
+			} else {
1820
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1731 1821
 			}
1732
-			else
1733
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1734 1822
 			$smcFunc['db_free_result']($request);
1735
-		}
1736
-		else
1823
+		} else
1737 1824
 		{
1738 1825
 			$posterOptions['name'] = $user_info['name'];
1739 1826
 			$posterOptions['email'] = $user_info['email'];
@@ -1743,8 +1830,9 @@  discard block
 block discarded – undo
1743 1830
 	if (!empty($modSettings['enable_mentions']))
1744 1831
 	{
1745 1832
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1746
-		if (!empty($msgOptions['mentioned_members']))
1747
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1833
+		if (!empty($msgOptions['mentioned_members'])) {
1834
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1835
+		}
1748 1836
 	}
1749 1837
 
1750 1838
 	// It's do or die time: forget any user aborts!
@@ -1777,12 +1865,13 @@  discard block
 block discarded – undo
1777 1865
 	$msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg');
1778 1866
 
1779 1867
 	// Something went wrong creating the message...
1780
-	if (empty($msgOptions['id']))
1781
-		return false;
1868
+	if (empty($msgOptions['id'])) {
1869
+			return false;
1870
+	}
1782 1871
 
1783 1872
 	// Fix the attachments.
1784
-	if (!empty($msgOptions['attachments']))
1785
-		$smcFunc['db_query']('', '
1873
+	if (!empty($msgOptions['attachments'])) {
1874
+			$smcFunc['db_query']('', '
1786 1875
 			UPDATE {db_prefix}attachments
1787 1876
 			SET id_msg = {int:id_msg}
1788 1877
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1791,6 +1880,7 @@  discard block
 block discarded – undo
1791 1880
 				'id_msg' => $msgOptions['id'],
1792 1881
 			)
1793 1882
 		);
1883
+	}
1794 1884
 
1795 1885
 	// What if we want to export new posts out to a CMS?
1796 1886
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1868,20 +1958,23 @@  discard block
 block discarded – undo
1868 1958
 			'counter_increment' => 1,
1869 1959
 		);
1870 1960
 		$topics_columns = array();
1871
-		if ($msgOptions['approved'])
1872
-			$topics_columns = array(
1961
+		if ($msgOptions['approved']) {
1962
+					$topics_columns = array(
1873 1963
 				'id_member_updated = {int:poster_id}',
1874 1964
 				'id_last_msg = {int:id_msg}',
1875 1965
 				'num_replies = num_replies + {int:counter_increment}',
1876 1966
 			);
1877
-		else
1878
-			$topics_columns = array(
1967
+		} else {
1968
+					$topics_columns = array(
1879 1969
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1880 1970
 			);
1881
-		if ($topicOptions['lock_mode'] !== null)
1882
-			$topics_columns[] = 'locked = {int:locked}';
1883
-		if ($topicOptions['sticky_mode'] !== null)
1884
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1971
+		}
1972
+		if ($topicOptions['lock_mode'] !== null) {
1973
+					$topics_columns[] = 'locked = {int:locked}';
1974
+		}
1975
+		if ($topicOptions['sticky_mode'] !== null) {
1976
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1977
+		}
1885 1978
 
1886 1979
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1887 1980
 
@@ -1910,8 +2003,8 @@  discard block
 block discarded – undo
1910 2003
 	);
1911 2004
 
1912 2005
 	// Increase the number of posts and topics on the board.
1913
-	if ($msgOptions['approved'])
1914
-		$smcFunc['db_query']('', '
2006
+	if ($msgOptions['approved']) {
2007
+			$smcFunc['db_query']('', '
1915 2008
 			UPDATE {db_prefix}boards
1916 2009
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1917 2010
 			WHERE id_board = {int:id_board}',
@@ -1919,7 +2012,7 @@  discard block
 block discarded – undo
1919 2012
 				'id_board' => $topicOptions['board'],
1920 2013
 			)
1921 2014
 		);
1922
-	else
2015
+	} else
1923 2016
 	{
1924 2017
 		$smcFunc['db_query']('', '
1925 2018
 			UPDATE {db_prefix}boards
@@ -1989,8 +2082,8 @@  discard block
 block discarded – undo
1989 2082
 		}
1990 2083
 	}
1991 2084
 
1992
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1993
-		$smcFunc['db_insert']('',
2085
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2086
+			$smcFunc['db_insert']('',
1994 2087
 			'{db_prefix}background_tasks',
1995 2088
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1996 2089
 			array(
@@ -2002,19 +2095,22 @@  discard block
 block discarded – undo
2002 2095
 			),
2003 2096
 			array('id_task')
2004 2097
 		);
2098
+	}
2005 2099
 
2006 2100
 	// If there's a custom search index, it may need updating...
2007 2101
 	require_once($sourcedir . '/Search.php');
2008 2102
 	$searchAPI = findSearchAPI();
2009
-	if (is_callable(array($searchAPI, 'postCreated')))
2010
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2104
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2105
+	}
2011 2106
 
2012 2107
 	// Increase the post counter for the user that created the post.
2013 2108
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2014 2109
 	{
2015 2110
 		// Are you the one that happened to create this post?
2016
-		if ($user_info['id'] == $posterOptions['id'])
2017
-			$user_info['posts']++;
2111
+		if ($user_info['id'] == $posterOptions['id']) {
2112
+					$user_info['posts']++;
2113
+		}
2018 2114
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2019 2115
 	}
2020 2116
 
@@ -2022,19 +2118,21 @@  discard block
 block discarded – undo
2022 2118
 	$_SESSION['last_read_topic'] = 0;
2023 2119
 
2024 2120
 	// Better safe than sorry.
2025
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2026
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2122
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2123
+	}
2027 2124
 
2028 2125
 	// Update all the stats so everyone knows about this new topic and message.
2029 2126
 	updateStats('message', true, $msgOptions['id']);
2030 2127
 
2031 2128
 	// Update the last message on the board assuming it's approved AND the topic is.
2032
-	if ($msgOptions['approved'])
2033
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	if ($msgOptions['approved']) {
2130
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2131
+	}
2034 2132
 
2035 2133
 	// Queue createPost background notification
2036
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2037
-		$smcFunc['db_insert']('',
2134
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2135
+			$smcFunc['db_insert']('',
2038 2136
 			'{db_prefix}background_tasks',
2039 2137
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2040 2138
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
@@ -2045,6 +2143,7 @@  discard block
 block discarded – undo
2045 2143
 			)), 0),
2046 2144
 			array('id_task')
2047 2145
 		);
2146
+	}
2048 2147
 
2049 2148
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2050 2149
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2071,14 +2170,18 @@  discard block
 block discarded – undo
2071 2170
 
2072 2171
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2073 2172
 	$messages_columns = array();
2074
-	if (isset($posterOptions['name']))
2075
-		$messages_columns['poster_name'] = $posterOptions['name'];
2076
-	if (isset($posterOptions['email']))
2077
-		$messages_columns['poster_email'] = $posterOptions['email'];
2078
-	if (isset($msgOptions['icon']))
2079
-		$messages_columns['icon'] = $msgOptions['icon'];
2080
-	if (isset($msgOptions['subject']))
2081
-		$messages_columns['subject'] = $msgOptions['subject'];
2173
+	if (isset($posterOptions['name'])) {
2174
+			$messages_columns['poster_name'] = $posterOptions['name'];
2175
+	}
2176
+	if (isset($posterOptions['email'])) {
2177
+			$messages_columns['poster_email'] = $posterOptions['email'];
2178
+	}
2179
+	if (isset($msgOptions['icon'])) {
2180
+			$messages_columns['icon'] = $msgOptions['icon'];
2181
+	}
2182
+	if (isset($msgOptions['subject'])) {
2183
+			$messages_columns['subject'] = $msgOptions['subject'];
2184
+	}
2082 2185
 	if (isset($msgOptions['body']))
2083 2186
 	{
2084 2187
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2105,8 +2208,9 @@  discard block
 block discarded – undo
2105 2208
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2106 2209
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2107 2210
 	}
2108
-	if (isset($msgOptions['smileys_enabled']))
2109
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	if (isset($msgOptions['smileys_enabled'])) {
2212
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2213
+	}
2110 2214
 
2111 2215
 	// Which columns need to be ints?
2112 2216
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2124,23 +2228,27 @@  discard block
 block discarded – undo
2124 2228
 		{
2125 2229
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2126 2230
 
2127
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2128
-				foreach ($match[1] as $i => $oldID)
2231
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2232
+							foreach ($match[1] as $i => $oldID)
2129 2233
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2234
+			}
2130 2235
 
2131
-			if (empty($modSettings['search_custom_index_config']))
2132
-				unset($msgOptions['old_body']);
2236
+			if (empty($modSettings['search_custom_index_config'])) {
2237
+							unset($msgOptions['old_body']);
2238
+			}
2133 2239
 		}
2134 2240
 
2135 2241
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2136 2242
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2137 2243
 
2138 2244
 		// Remove the poster.
2139
-		if (isset($mentions[$user_info['id']]))
2140
-			unset($mentions[$user_info['id']]);
2245
+		if (isset($mentions[$user_info['id']])) {
2246
+					unset($mentions[$user_info['id']]);
2247
+		}
2141 2248
 
2142
-		if (isset($oldmentions[$user_info['id']]))
2143
-			unset($oldmentions[$user_info['id']]);
2249
+		if (isset($oldmentions[$user_info['id']])) {
2250
+					unset($oldmentions[$user_info['id']]);
2251
+		}
2144 2252
 
2145 2253
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2146 2254
 		{
@@ -2170,8 +2278,9 @@  discard block
 block discarded – undo
2170 2278
 	}
2171 2279
 
2172 2280
 	// Nothing to do?
2173
-	if (empty($messages_columns))
2174
-		return true;
2281
+	if (empty($messages_columns)) {
2282
+			return true;
2283
+	}
2175 2284
 
2176 2285
 	// Change the post.
2177 2286
 	$smcFunc['db_query']('', '
@@ -2232,8 +2341,9 @@  discard block
 block discarded – undo
2232 2341
 	// If there's a custom search index, it needs to be modified...
2233 2342
 	require_once($sourcedir . '/Search.php');
2234 2343
 	$searchAPI = findSearchAPI();
2235
-	if (is_callable(array($searchAPI, 'postModified')))
2236
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	if (is_callable(array($searchAPI, 'postModified'))) {
2345
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2346
+	}
2237 2347
 
2238 2348
 	if (isset($msgOptions['subject']))
2239 2349
 	{
@@ -2247,14 +2357,16 @@  discard block
 block discarded – undo
2247 2357
 				'id_first_msg' => $msgOptions['id'],
2248 2358
 			)
2249 2359
 		);
2250
-		if ($smcFunc['db_num_rows']($request) == 1)
2251
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		if ($smcFunc['db_num_rows']($request) == 1) {
2361
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2362
+		}
2252 2363
 		$smcFunc['db_free_result']($request);
2253 2364
 	}
2254 2365
 
2255 2366
 	// Finally, if we are setting the approved state we need to do much more work :(
2256
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2257
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2368
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2369
+	}
2258 2370
 
2259 2371
 	return true;
2260 2372
 }
@@ -2271,11 +2383,13 @@  discard block
 block discarded – undo
2271 2383
 {
2272 2384
 	global $smcFunc;
2273 2385
 
2274
-	if (!is_array($msgs))
2275
-		$msgs = array($msgs);
2386
+	if (!is_array($msgs)) {
2387
+			$msgs = array($msgs);
2388
+	}
2276 2389
 
2277
-	if (empty($msgs))
2278
-		return false;
2390
+	if (empty($msgs)) {
2391
+			return false;
2392
+	}
2279 2393
 
2280 2394
 	// May as well start at the beginning, working out *what* we need to change.
2281 2395
 	$request = $smcFunc['db_query']('', '
@@ -2307,20 +2421,22 @@  discard block
 block discarded – undo
2307 2421
 		$topics[] = $row['id_topic'];
2308 2422
 
2309 2423
 		// Ensure our change array exists already.
2310
-		if (!isset($topic_changes[$row['id_topic']]))
2311
-			$topic_changes[$row['id_topic']] = array(
2424
+		if (!isset($topic_changes[$row['id_topic']])) {
2425
+					$topic_changes[$row['id_topic']] = array(
2312 2426
 				'id_last_msg' => $row['id_last_msg'],
2313 2427
 				'approved' => $row['topic_approved'],
2314 2428
 				'replies' => 0,
2315 2429
 				'unapproved_posts' => 0,
2316 2430
 			);
2317
-		if (!isset($board_changes[$row['id_board']]))
2318
-			$board_changes[$row['id_board']] = array(
2431
+		}
2432
+		if (!isset($board_changes[$row['id_board']])) {
2433
+					$board_changes[$row['id_board']] = array(
2319 2434
 				'posts' => 0,
2320 2435
 				'topics' => 0,
2321 2436
 				'unapproved_posts' => 0,
2322 2437
 				'unapproved_topics' => 0,
2323 2438
 			);
2439
+		}
2324 2440
 
2325 2441
 		// If it's the first message then the topic state changes!
2326 2442
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2341,14 +2457,13 @@  discard block
 block discarded – undo
2341 2457
 				'poster' => $row['id_member'],
2342 2458
 				'new_topic' => true,
2343 2459
 			);
2344
-		}
2345
-		else
2460
+		} else
2346 2461
 		{
2347 2462
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2348 2463
 
2349 2464
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2350
-			if ($row['id_msg'] > $row['id_last_msg'])
2351
-				$notification_posts[$row['id_topic']] = array(
2465
+			if ($row['id_msg'] > $row['id_last_msg']) {
2466
+							$notification_posts[$row['id_topic']] = array(
2352 2467
 					'id' => $row['id_msg'],
2353 2468
 					'body' => $row['body'],
2354 2469
 					'subject' => $row['subject'],
@@ -2359,28 +2474,33 @@  discard block
 block discarded – undo
2359 2474
 					'new_topic' => false,
2360 2475
 					'msg' => $row['id_msg'],
2361 2476
 				);
2477
+			}
2362 2478
 		}
2363 2479
 
2364 2480
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2365
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2366
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2482
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2483
+		}
2367 2484
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2368
-		elseif (!$approve)
2369
-			// Default to the first message and then we'll override in a bit ;)
2485
+		elseif (!$approve) {
2486
+					// Default to the first message and then we'll override in a bit ;)
2370 2487
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2488
+		}
2371 2489
 
2372 2490
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2373 2491
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2374 2492
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2375 2493
 
2376 2494
 		// Post count for the user?
2377
-		if ($row['id_member'] && empty($row['count_posts']))
2378
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		if ($row['id_member'] && empty($row['count_posts'])) {
2496
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2497
+		}
2379 2498
 	}
2380 2499
 	$smcFunc['db_free_result']($request);
2381 2500
 
2382
-	if (empty($msgs))
2383
-		return;
2501
+	if (empty($msgs)) {
2502
+			return;
2503
+	}
2384 2504
 
2385 2505
 	// Now we have the differences make the changes, first the easy one.
2386 2506
 	$smcFunc['db_query']('', '
@@ -2407,14 +2527,15 @@  discard block
 block discarded – undo
2407 2527
 				'approved' => 1,
2408 2528
 			)
2409 2529
 		);
2410
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2411
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2531
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2532
+		}
2412 2533
 		$smcFunc['db_free_result']($request);
2413 2534
 	}
2414 2535
 
2415 2536
 	// ... next the topics...
2416
-	foreach ($topic_changes as $id => $changes)
2417
-		$smcFunc['db_query']('', '
2537
+	foreach ($topic_changes as $id => $changes) {
2538
+			$smcFunc['db_query']('', '
2418 2539
 			UPDATE {db_prefix}topics
2419 2540
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2420 2541
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2427,10 +2548,11 @@  discard block
 block discarded – undo
2427 2548
 				'id_topic' => $id,
2428 2549
 			)
2429 2550
 		);
2551
+	}
2430 2552
 
2431 2553
 	// ... finally the boards...
2432
-	foreach ($board_changes as $id => $changes)
2433
-		$smcFunc['db_query']('', '
2554
+	foreach ($board_changes as $id => $changes) {
2555
+			$smcFunc['db_query']('', '
2434 2556
 			UPDATE {db_prefix}boards
2435 2557
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2436 2558
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2443,13 +2565,14 @@  discard block
 block discarded – undo
2443 2565
 				'id_board' => $id,
2444 2566
 			)
2445 2567
 		);
2568
+	}
2446 2569
 
2447 2570
 	// Finally, least importantly, notifications!
2448 2571
 	if ($approve)
2449 2572
 	{
2450 2573
 		$task_rows = array();
2451
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2452
-			$task_rows[] = array(
2574
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2575
+					$task_rows[] = array(
2453 2576
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
2454 2577
 					'msgOptions' => array(
2455 2578
 						'id' => $topic['msg'],
@@ -2467,14 +2590,16 @@  discard block
 block discarded – undo
2467 2590
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2468 2591
 				)), 0
2469 2592
 			);
2593
+		}
2470 2594
 
2471
-		if ($notify)
2472
-			$smcFunc['db_insert']('',
2595
+		if ($notify) {
2596
+					$smcFunc['db_insert']('',
2473 2597
 				'{db_prefix}background_tasks',
2474 2598
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2475 2599
 				$task_rows,
2476 2600
 				array('id_task')
2477 2601
 			);
2602
+		}
2478 2603
 
2479 2604
 		$smcFunc['db_query']('', '
2480 2605
 			DELETE FROM {db_prefix}approval_queue
@@ -2490,8 +2615,9 @@  discard block
 block discarded – undo
2490 2615
 	else
2491 2616
 	{
2492 2617
 		$msgInserts = array();
2493
-		foreach ($msgs as $msg)
2494
-			$msgInserts[] = array($msg);
2618
+		foreach ($msgs as $msg) {
2619
+					$msgInserts[] = array($msg);
2620
+		}
2495 2621
 
2496 2622
 		$smcFunc['db_insert']('ignore',
2497 2623
 			'{db_prefix}approval_queue',
@@ -2505,9 +2631,10 @@  discard block
 block discarded – undo
2505 2631
 	updateLastMessages(array_keys($board_changes));
2506 2632
 
2507 2633
 	// Post count for the members?
2508
-	if (!empty($member_post_changes))
2509
-		foreach ($member_post_changes as $id_member => $count_change)
2634
+	if (!empty($member_post_changes)) {
2635
+			foreach ($member_post_changes as $id_member => $count_change)
2510 2636
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2637
+	}
2511 2638
 
2512 2639
 	return true;
2513 2640
 }
@@ -2524,11 +2651,13 @@  discard block
 block discarded – undo
2524 2651
 {
2525 2652
 	global $smcFunc;
2526 2653
 
2527
-	if (!is_array($topics))
2528
-		$topics = array($topics);
2654
+	if (!is_array($topics)) {
2655
+			$topics = array($topics);
2656
+	}
2529 2657
 
2530
-	if (empty($topics))
2531
-		return false;
2658
+	if (empty($topics)) {
2659
+			return false;
2660
+	}
2532 2661
 
2533 2662
 	$approve_type = $approve ? 0 : 1;
2534 2663
 
@@ -2544,8 +2673,9 @@  discard block
 block discarded – undo
2544 2673
 		)
2545 2674
 	);
2546 2675
 	$msgs = array();
2547
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2548
-		$msgs[] = $row['id_msg'];
2676
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2677
+			$msgs[] = $row['id_msg'];
2678
+	}
2549 2679
 	$smcFunc['db_free_result']($request);
2550 2680
 
2551 2681
 	return approvePosts($msgs, $approve);
@@ -2568,11 +2698,13 @@  discard block
 block discarded – undo
2568 2698
 	global $board_info, $board, $smcFunc;
2569 2699
 
2570 2700
 	// Please - let's be sane.
2571
-	if (empty($setboards))
2572
-		return false;
2701
+	if (empty($setboards)) {
2702
+			return false;
2703
+	}
2573 2704
 
2574
-	if (!is_array($setboards))
2575
-		$setboards = array($setboards);
2705
+	if (!is_array($setboards)) {
2706
+			$setboards = array($setboards);
2707
+	}
2576 2708
 
2577 2709
 	// If we don't know the id_msg we need to find it.
2578 2710
 	if (!$id_msg)
@@ -2590,15 +2722,16 @@  discard block
 block discarded – undo
2590 2722
 			)
2591 2723
 		);
2592 2724
 		$lastMsg = array();
2593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2594
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2726
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2727
+		}
2595 2728
 		$smcFunc['db_free_result']($request);
2596
-	}
2597
-	else
2729
+	} else
2598 2730
 	{
2599 2731
 		// Just to note - there should only be one board passed if we are doing this.
2600
-		foreach ($setboards as $id_board)
2601
-			$lastMsg[$id_board] = $id_msg;
2732
+		foreach ($setboards as $id_board) {
2733
+					$lastMsg[$id_board] = $id_msg;
2734
+		}
2602 2735
 	}
2603 2736
 
2604 2737
 	$parent_boards = array();
@@ -2613,10 +2746,11 @@  discard block
 block discarded – undo
2613 2746
 			$lastModified[$id_board] = 0;
2614 2747
 		}
2615 2748
 
2616
-		if (!empty($board) && $id_board == $board)
2617
-			$parents = $board_info['parent_boards'];
2618
-		else
2619
-			$parents = getBoardParents($id_board);
2749
+		if (!empty($board) && $id_board == $board) {
2750
+					$parents = $board_info['parent_boards'];
2751
+		} else {
2752
+					$parents = getBoardParents($id_board);
2753
+		}
2620 2754
 
2621 2755
 		// Ignore any parents on the top child level.
2622 2756
 		// @todo Why?
@@ -2625,10 +2759,11 @@  discard block
 block discarded – undo
2625 2759
 			if ($parent['level'] != 0)
2626 2760
 			{
2627 2761
 				// If we're already doing this one as a board, is this a higher last modified?
2628
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2629
-					$lastModified[$id] = $lastModified[$id_board];
2630
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2631
-					$parent_boards[$id] = $lastModified[$id_board];
2762
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2763
+									$lastModified[$id] = $lastModified[$id_board];
2764
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2765
+									$parent_boards[$id] = $lastModified[$id_board];
2766
+				}
2632 2767
 			}
2633 2768
 		}
2634 2769
 	}
@@ -2641,23 +2776,24 @@  discard block
 block discarded – undo
2641 2776
 	// Finally, to save on queries make the changes...
2642 2777
 	foreach ($parent_boards as $id => $msg)
2643 2778
 	{
2644
-		if (!isset($parent_updates[$msg]))
2645
-			$parent_updates[$msg] = array($id);
2646
-		else
2647
-			$parent_updates[$msg][] = $id;
2779
+		if (!isset($parent_updates[$msg])) {
2780
+					$parent_updates[$msg] = array($id);
2781
+		} else {
2782
+					$parent_updates[$msg][] = $id;
2783
+		}
2648 2784
 	}
2649 2785
 
2650 2786
 	foreach ($lastMsg as $id => $msg)
2651 2787
 	{
2652
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2653
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2788
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2789
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2654 2790
 				'id' => $msg,
2655 2791
 				'updated' => $lastModified[$id],
2656 2792
 				'boards' => array($id)
2657 2793
 			);
2658
-
2659
-		else
2660
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		} else {
2795
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2796
+		}
2661 2797
 	}
2662 2798
 
2663 2799
 	// Now commit the changes!
@@ -2749,11 +2885,13 @@  discard block
 block discarded – undo
2749 2885
 	global $txt, $mbname, $scripturl, $settings;
2750 2886
 
2751 2887
 	// First things first, load up the email templates language file, if we need to.
2752
-	if ($loadLang)
2753
-		loadLanguage('EmailTemplates', $lang);
2888
+	if ($loadLang) {
2889
+			loadLanguage('EmailTemplates', $lang);
2890
+	}
2754 2891
 
2755
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2756
-		fatal_lang_error('email_no_template', 'template', array($template));
2892
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2893
+			fatal_lang_error('email_no_template', 'template', array($template));
2894
+	}
2757 2895
 
2758 2896
 	$ret = array(
2759 2897
 		'subject' => $txt[$template . '_subject'],
@@ -2803,17 +2941,18 @@  discard block
 block discarded – undo
2803 2941
 function user_info_callback($matches)
2804 2942
 {
2805 2943
 	global $user_info;
2806
-	if (empty($matches[1]))
2807
-		return '';
2944
+	if (empty($matches[1])) {
2945
+			return '';
2946
+	}
2808 2947
 
2809 2948
 	$use_ref = true;
2810 2949
 	$ref = &$user_info;
2811 2950
 
2812 2951
 	foreach (explode('.', $matches[1]) as $index)
2813 2952
 	{
2814
-		if ($use_ref && isset($ref[$index]))
2815
-			$ref = &$ref[$index];
2816
-		else
2953
+		if ($use_ref && isset($ref[$index])) {
2954
+					$ref = &$ref[$index];
2955
+		} else
2817 2956
 		{
2818 2957
 			$use_ref = false;
2819 2958
 			break;
@@ -2850,8 +2989,7 @@  discard block
 block discarded – undo
2850 2989
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2851 2990
 		{
2852 2991
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2853
-		}
2854
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2992
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2855 2993
 		{
2856 2994
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2857 2995
 		}
@@ -2861,8 +2999,7 @@  discard block
 block discarded – undo
2861 2999
 		{
2862 3000
 			$context['provider'] = 'enchant';
2863 3001
 			return $enchant_link;
2864
-		}
2865
-		else
3002
+		} else
2866 3003
 		{
2867 3004
 			// Free up any resources used...
2868 3005
 			@enchant_broker_free($context['enchant_broker']);
@@ -2883,8 +3020,9 @@  discard block
 block discarded – undo
2883 3020
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2884 3021
 
2885 3022
 		// Most people don't have anything but English installed... So we use English as a last resort.
2886
-		if (!$pspell_link)
2887
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		if (!$pspell_link) {
3024
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3025
+		}
2888 3026
 
2889 3027
 		error_reporting($old);
2890 3028
 		ob_end_clean();
@@ -2924,8 +3062,7 @@  discard block
 block discarded – undo
2924 3062
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2925 3063
 		}
2926 3064
 		return enchant_dict_check($dict, $word);
2927
-	}
2928
-	elseif ($context['provider'] == 'pspell')
3065
+	} elseif ($context['provider'] == 'pspell')
2929 3066
 	{
2930 3067
 		return pspell_check($dict, $word);
2931 3068
 	}
@@ -2961,13 +3098,11 @@  discard block
 block discarded – undo
2961 3098
 			}
2962 3099
 
2963 3100
 			return $suggestions;
2964
-		}
2965
-		else
3101
+		} else
2966 3102
 		{
2967 3103
 			return enchant_dict_suggest($dict, $word);
2968 3104
 		}
2969
-	}
2970
-	elseif ($context['provider'] == 'pspell')
3105
+	} elseif ($context['provider'] == 'pspell')
2971 3106
 	{
2972 3107
 		return pspell_suggest($dict, $word);
2973 3108
 	}
Please login to merge, or discard this patch.
Sources/Packages.php 1 patch
Braces   +599 added lines, -484 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is the notoriously defunct package manager..... :/.
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
 	);
58 59
 
59 60
 	// Work out exactly who it is we are calling.
60
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
61
-		$context['sub_action'] = $_REQUEST['sa'];
62
-	else
63
-		$context['sub_action'] = 'browse';
61
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
62
+			$context['sub_action'] = $_REQUEST['sa'];
63
+	} else {
64
+			$context['sub_action'] = 'browse';
65
+	}
64 66
 
65 67
 	// Set up some tabs...
66 68
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -82,8 +84,9 @@  discard block
 block discarded – undo
82 84
 		),
83 85
 	);
84 86
 
85
-	if ($context['sub_action'] == 'browse')
86
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
87
+	if ($context['sub_action'] == 'browse') {
88
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
89
+	}
87 90
 
88 91
 	call_integration_hook('integrate_manage_packages', array(&$subActions));
89 92
 
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings;
100 103
 
101 104
 	// You have to specify a file!!
102
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
103
-		redirectexit('action=admin;area=packages');
105
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
106
+			redirectexit('action=admin;area=packages');
107
+	}
104 108
 	$context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']);
105 109
 
106 110
 	// Do we have an existing id, for uninstalls and the like.
@@ -112,8 +116,9 @@  discard block
 block discarded – undo
112 116
 	create_chmod_control();
113 117
 
114 118
 	// Make sure temp directory exists and is empty.
115
-	if (file_exists($packagesdir . '/temp'))
116
-		deltree($packagesdir . '/temp', false);
119
+	if (file_exists($packagesdir . '/temp')) {
120
+			deltree($packagesdir . '/temp', false);
121
+	}
117 122
 
118 123
 	if (!mktree($packagesdir . '/temp', 0755))
119 124
 	{
@@ -124,8 +129,9 @@  discard block
 block discarded – undo
124 129
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
125 130
 
126 131
 			deltree($packagesdir . '/temp', false);
127
-			if (!mktree($packagesdir . '/temp', 0777))
128
-				fatal_lang_error('package_cant_download', false);
132
+			if (!mktree($packagesdir . '/temp', 0777)) {
133
+							fatal_lang_error('package_cant_download', false);
134
+			}
129 135
 		}
130 136
 	}
131 137
 
@@ -151,25 +157,26 @@  discard block
 block discarded – undo
151 157
 	{
152 158
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
153 159
 
154
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
155
-			foreach ($context['extracted_files'] as $file)
160
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
161
+					foreach ($context['extracted_files'] as $file)
156 162
 				if (basename($file['filename']) == 'package-info.xml')
157 163
 				{
158 164
 					$context['base_path'] = dirname($file['filename']) . '/';
165
+		}
159 166
 					break;
160 167
 				}
161 168
 
162
-		if (!isset($context['base_path']))
163
-			$context['base_path'] = '';
164
-	}
165
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
169
+		if (!isset($context['base_path'])) {
170
+					$context['base_path'] = '';
171
+		}
172
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
166 173
 	{
167 174
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
168 175
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
169 176
 		$context['base_path'] = '';
177
+	} else {
178
+			fatal_lang_error('no_access', false);
170 179
 	}
171
-	else
172
-		fatal_lang_error('no_access', false);
173 180
 
174 181
 	// Load up any custom themes we may want to install into...
175 182
 	$request = $smcFunc['db_query']('', '
@@ -185,15 +192,17 @@  discard block
 block discarded – undo
185 192
 		)
186 193
 	);
187 194
 	$theme_paths = array();
188
-	while ($row = $smcFunc['db_fetch_assoc']($request))
189
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
197
+	}
190 198
 	$smcFunc['db_free_result']($request);
191 199
 
192 200
 	// Get the package info...
193 201
 	$packageInfo = getPackageInfo($context['filename']);
194 202
 
195
-	if (!is_array($packageInfo))
196
-		fatal_lang_error($packageInfo);
203
+	if (!is_array($packageInfo)) {
204
+			fatal_lang_error($packageInfo);
205
+	}
197 206
 
198 207
 	$packageInfo['filename'] = $context['filename'];
199 208
 	$context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
@@ -227,18 +236,19 @@  discard block
 block discarded – undo
227 236
 	$smcFunc['db_free_result']($request);
228 237
 
229 238
 	$context['database_changes'] = array();
230
-	if (isset($packageInfo['uninstall']['database']))
231
-		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
232
-	elseif (!empty($db_changes))
239
+	if (isset($packageInfo['uninstall']['database'])) {
240
+			$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
241
+	} elseif (!empty($db_changes))
233 242
 	{
234 243
 		foreach ($db_changes as $change)
235 244
 		{
236
-			if (isset($change[2]) && isset($txt['package_db_' . $change[0]]))
237
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
238
-			elseif (isset($txt['package_db_' . $change[0]]))
239
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
240
-			else
241
-				$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
245
+			if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
246
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
247
+			} elseif (isset($txt['package_db_' . $change[0]])) {
248
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
249
+			} else {
250
+							$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
251
+			}
242 252
 		}
243 253
 	}
244 254
 
@@ -265,31 +275,33 @@  discard block
 block discarded – undo
265 275
 		$context['themes_locked'] = true;
266 276
 
267 277
 		// Only let them uninstall themes it was installed into.
268
-		foreach ($theme_paths as $id => $data)
269
-			if ($id != 1 && !in_array($id, $old_themes))
278
+		foreach ($theme_paths as $id => $data) {
279
+					if ($id != 1 && !in_array($id, $old_themes))
270 280
 				unset($theme_paths[$id]);
271
-	}
272
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
281
+		}
282
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
273 283
 	{
274 284
 		// Look for an upgrade...
275 285
 		$actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
276 286
 
277 287
 		// There was no upgrade....
278
-		if (empty($actions))
279
-			$context['is_installed'] = true;
280
-		else
288
+		if (empty($actions)) {
289
+					$context['is_installed'] = true;
290
+		} else
281 291
 		{
282 292
 			// Otherwise they can only upgrade themes from the first time around.
283
-			foreach ($theme_paths as $id => $data)
284
-				if ($id != 1 && !in_array($id, $old_themes))
293
+			foreach ($theme_paths as $id => $data) {
294
+							if ($id != 1 && !in_array($id, $old_themes))
285 295
 					unset($theme_paths[$id]);
296
+			}
286 297
 		}
298
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
299
+			$context['is_installed'] = true;
287 300
 	}
288
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
289
-		$context['is_installed'] = true;
290 301
 
291
-	if (!isset($old_version) || $context['is_installed'])
292
-		$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
302
+	if (!isset($old_version) || $context['is_installed']) {
303
+			$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
304
+	}
293 305
 
294 306
 	$context['actions'] = array();
295 307
 	$context['ftp_needed'] = false;
@@ -297,8 +309,9 @@  discard block
 block discarded – undo
297 309
 	$chmod_files = array();
298 310
 
299 311
 	// no actions found, return so we can display an error
300
-	if (empty($actions))
301
-		return;
312
+	if (empty($actions)) {
313
+			return;
314
+	}
302 315
 
303 316
 	// This will hold data about anything that can be installed in other themes.
304 317
 	$themeFinds = array(
@@ -317,14 +330,14 @@  discard block
 block discarded – undo
317 330
 		{
318 331
 			$chmod_files[] = $action['filename'];
319 332
 			continue;
320
-		}
321
-		elseif ($action['type'] == 'readme' || $action['type'] == 'license')
333
+		} elseif ($action['type'] == 'readme' || $action['type'] == 'license')
322 334
 		{
323 335
 			$type = 'package_' . $action['type'];
324
-			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
325
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
326
-			elseif (file_exists($action['filename']))
327
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
336
+			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
337
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
338
+			} elseif (file_exists($action['filename'])) {
339
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
340
+			}
328 341
 
329 342
 			if (!empty($action['parse_bbc']))
330 343
 			{
@@ -332,24 +345,24 @@  discard block
 block discarded – undo
332 345
 				$context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]);
333 346
 				preparsecode($context[$type]);
334 347
 				$context[$type] = parse_bbc($context[$type]);
348
+			} else {
349
+							$context[$type] = nl2br($context[$type]);
335 350
 			}
336
-			else
337
-				$context[$type] = nl2br($context[$type]);
338 351
 
339 352
 			continue;
340 353
 		}
341 354
 		// Don't show redirects.
342
-		elseif ($action['type'] == 'redirect')
343
-			continue;
344
-		elseif ($action['type'] == 'error')
355
+		elseif ($action['type'] == 'redirect') {
356
+					continue;
357
+		} elseif ($action['type'] == 'error')
345 358
 		{
346 359
 			$context['has_failure'] = true;
347
-			if (isset($action['error_msg']) && isset($action['error_var']))
348
-				$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
349
-			elseif (isset($action['error_msg']))
350
-				$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
351
-		}
352
-		elseif ($action['type'] == 'modification')
360
+			if (isset($action['error_msg']) && isset($action['error_var'])) {
361
+							$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
362
+			} elseif (isset($action['error_msg'])) {
363
+							$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
364
+			}
365
+		} elseif ($action['type'] == 'modification')
353 366
 		{
354 367
 			if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
355 368
 			{
@@ -361,52 +374,54 @@  discard block
 block discarded – undo
361 374
 					'description' => $txt['package_action_missing'],
362 375
 					'failed' => true,
363 376
 				);
364
-			}
365
-			else
377
+			} else
366 378
 			{
367 379
 
368
-				if ($action['boardmod'])
369
-					$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
370
-				else
371
-					$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
380
+				if ($action['boardmod']) {
381
+									$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
382
+				} else {
383
+									$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
384
+				}
372 385
 
373
-				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-')
374
-					$mod_actions[0]['filename'] = $action['filename'];
386
+				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
387
+									$mod_actions[0]['filename'] = $action['filename'];
388
+				}
375 389
 
376 390
 				foreach ($mod_actions as $key => $mod_action)
377 391
 				{
378 392
 					// Lets get the last section of the file name.
379
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
380
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
381
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
382
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
383
-					else
384
-						$actual_filename = $key;
385
-
386
-					if ($mod_action['type'] == 'opened')
387
-						$failed = false;
388
-					elseif ($mod_action['type'] == 'failure')
393
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
394
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
395
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
396
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
397
+					} else {
398
+											$actual_filename = $key;
399
+					}
400
+
401
+					if ($mod_action['type'] == 'opened') {
402
+											$failed = false;
403
+					} elseif ($mod_action['type'] == 'failure')
389 404
 					{
390
-						if (empty($mod_action['is_custom']))
391
-							$context['has_failure'] = true;
405
+						if (empty($mod_action['is_custom'])) {
406
+													$context['has_failure'] = true;
407
+						}
392 408
 						$failed = true;
393
-					}
394
-					elseif ($mod_action['type'] == 'chmod')
409
+					} elseif ($mod_action['type'] == 'chmod')
395 410
 					{
396 411
 						$chmod_files[] = $mod_action['filename'];
397
-					}
398
-					elseif ($mod_action['type'] == 'saved')
412
+					} elseif ($mod_action['type'] == 'saved')
399 413
 					{
400 414
 						if (!empty($mod_action['is_custom']))
401 415
 						{
402
-							if (!isset($context['theme_actions'][$mod_action['is_custom']]))
403
-								$context['theme_actions'][$mod_action['is_custom']] = array(
416
+							if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
417
+															$context['theme_actions'][$mod_action['is_custom']] = array(
404 418
 									'name' => $theme_paths[$mod_action['is_custom']]['name'],
405 419
 									'actions' => array(),
406 420
 									'has_failure' => $failed,
407 421
 								);
408
-							else
409
-								$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
422
+							} else {
423
+															$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
424
+							}
410 425
 
411 426
 							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array(
412 427
 								'type' => $txt['execute_modification'],
@@ -414,8 +429,7 @@  discard block
 block discarded – undo
414 429
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
415 430
 								'failed' => $failed,
416 431
 							);
417
-						}
418
-						elseif (!isset($context['actions'][$actual_filename]))
432
+						} elseif (!isset($context['actions'][$actual_filename]))
419 433
 						{
420 434
 							$context['actions'][$actual_filename] = array(
421 435
 								'type' => $txt['execute_modification'],
@@ -423,22 +437,19 @@  discard block
 block discarded – undo
423 437
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
424 438
 								'failed' => $failed,
425 439
 							);
426
-						}
427
-						else
440
+						} else
428 441
 						{
429 442
 								$context['actions'][$actual_filename]['failed'] |= $failed;
430 443
 								$context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
431 444
 						}
432
-					}
433
-					elseif ($mod_action['type'] == 'skipping')
445
+					} elseif ($mod_action['type'] == 'skipping')
434 446
 					{
435 447
 						$context['actions'][$actual_filename] = array(
436 448
 							'type' => $txt['execute_modification'],
437 449
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
438 450
 							'description' => $txt['package_action_skipping']
439 451
 						);
440
-					}
441
-					elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
452
+					} elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
442 453
 					{
443 454
 						$context['has_failure'] = true;
444 455
 						$context['actions'][$actual_filename] = array(
@@ -447,32 +458,33 @@  discard block
 block discarded – undo
447 458
 							'description' => $txt['package_action_missing'],
448 459
 							'failed' => true,
449 460
 						);
450
-					}
451
-					elseif ($mod_action['type'] == 'error')
452
-						$context['actions'][$actual_filename] = array(
461
+					} elseif ($mod_action['type'] == 'error') {
462
+											$context['actions'][$actual_filename] = array(
453 463
 							'type' => $txt['execute_modification'],
454 464
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
455 465
 							'description' => $txt['package_action_error'],
456 466
 							'failed' => true,
457 467
 						);
468
+					}
458 469
 				}
459 470
 
460 471
 				// We need to loop again just to get the operations down correctly.
461 472
 				foreach ($mod_actions as $operation_key => $mod_action)
462 473
 				{
463 474
 					// Lets get the last section of the file name.
464
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
465
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
466
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
467
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
468
-					else
469
-						$actual_filename = $key;
475
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
476
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
477
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
478
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
479
+					} else {
480
+											$actual_filename = $key;
481
+					}
470 482
 
471 483
 					// We just need it for actual parse changes.
472 484
 					if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod')))
473 485
 					{
474
-						if (empty($mod_action['is_custom']))
475
-							$context['actions'][$actual_filename]['operations'][] = array(
486
+						if (empty($mod_action['is_custom'])) {
487
+													$context['actions'][$actual_filename]['operations'][] = array(
476 488
 								'type' => $txt['execute_modification'],
477 489
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
478 490
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -483,10 +495,11 @@  discard block
 block discarded – undo
483 495
 								'failed' => $mod_action['failed'],
484 496
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
485 497
 							);
498
+						}
486 499
 
487 500
 						// Themes are under the saved type.
488
-						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']]))
489
-							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
501
+						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
502
+													$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
490 503
 								'type' => $txt['execute_modification'],
491 504
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
492 505
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -497,59 +510,55 @@  discard block
 block discarded – undo
497 510
 								'failed' => $mod_action['failed'],
498 511
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
499 512
 							);
513
+						}
500 514
 					}
501 515
 				}
502 516
 			}
503
-		}
504
-		elseif ($action['type'] == 'code')
517
+		} elseif ($action['type'] == 'code')
505 518
 		{
506 519
 			$thisAction = array(
507 520
 				'type' => $txt['execute_code'],
508 521
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
509 522
 			);
510
-		}
511
-		elseif ($action['type'] == 'database')
523
+		} elseif ($action['type'] == 'database')
512 524
 		{
513 525
 			$thisAction = array(
514 526
 				'type' => $txt['execute_database_changes'],
515 527
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
516 528
 			);
517
-		}
518
-		elseif (in_array($action['type'], array('create-dir', 'create-file')))
529
+		} elseif (in_array($action['type'], array('create-dir', 'create-file')))
519 530
 		{
520 531
 			$thisAction = array(
521 532
 				'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']),
522 533
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
523 534
 			);
524
-		}
525
-		elseif ($action['type'] == 'hook')
535
+		} elseif ($action['type'] == 'hook')
526 536
 		{
527 537
 			$action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
528 538
 
529
-			if (!isset($action['hook'], $action['function']))
530
-				$context['has_failure'] = true;
539
+			if (!isset($action['hook'], $action['function'])) {
540
+							$context['has_failure'] = true;
541
+			}
531 542
 
532 543
 			$thisAction = array(
533 544
 				'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'],
534 545
 				'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])),
535 546
 			);
536
-		}
537
-		elseif ($action['type'] == 'credits')
547
+		} elseif ($action['type'] == 'credits')
538 548
 		{
539 549
 			$thisAction = array(
540 550
 				'type' => $txt['execute_credits_add'],
541 551
 				'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])),
542 552
 			);
543
-		}
544
-		elseif ($action['type'] == 'requires')
553
+		} elseif ($action['type'] == 'requires')
545 554
 		{
546 555
 			$installed = false;
547 556
 			$version = true;
548 557
 
549 558
 			// package missing required values?
550
-			if (!isset($action['id']))
551
-				$context['has_failure'] = true;
552
-			else
559
+			if (!isset($action['id'])) {
560
+							$context['has_failure'] = true;
561
+			} else
553 562
 			{
554 563
 				// See if this dependancy is installed
555 564
 				$request = $smcFunc['db_query']('', '
@@ -565,8 +574,9 @@  discard block
 block discarded – undo
565 574
 					)
566 575
 				);
567 576
 				$installed = ($smcFunc['db_num_rows']($request) !== 0);
568
-				if ($installed)
569
-					list ($version) = $smcFunc['db_fetch_row']($request);
577
+				if ($installed) {
578
+									list ($version) = $smcFunc['db_fetch_row']($request);
579
+				}
570 580
 				$smcFunc['db_free_result']($request);
571 581
 
572 582
 				// do a version level check (if requested) in the most basic way
@@ -581,8 +591,7 @@  discard block
 block discarded – undo
581 591
 				'type' => $txt['package_requires'],
582 592
 				'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''),
583 593
 			);
584
-		}
585
-		elseif (in_array($action['type'], array('require-dir', 'require-file')))
594
+		} elseif (in_array($action['type'], array('require-dir', 'require-file')))
586 595
 		{
587 596
 			// Do this one...
588 597
 			$thisAction = array(
@@ -596,26 +605,29 @@  discard block
 block discarded – undo
596 605
 				// Is the action already stated?
597 606
 				$theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
598 607
 				// If it's not auto do we think we have something we can act upon?
599
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
600
-					$theme_action = '';
608
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
609
+									$theme_action = '';
610
+				}
601 611
 				// ... or if it's auto do we even want to do anything?
602
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
603
-					$theme_action = '';
612
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
613
+									$theme_action = '';
614
+				}
604 615
 
605 616
 				// So, we still want to do something?
606
-				if ($theme_action != '')
607
-					$themeFinds['candidates'][] = $action;
617
+				if ($theme_action != '') {
618
+									$themeFinds['candidates'][] = $action;
619
+				}
608 620
 				// Otherwise is this is going into another theme record it.
609
-				elseif ($matches[1] == 'themes_dir')
610
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
621
+				elseif ($matches[1] == 'themes_dir') {
622
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
623
+				}
611 624
 			}
612
-		}
613
-		elseif (in_array($action['type'], array('move-dir', 'move-file')))
614
-			$thisAction = array(
625
+		} elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
626
+					$thisAction = array(
615 627
 				'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']),
616 628
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
617 629
 			);
618
-		elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
630
+		} elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
619 631
 		{
620 632
 			$thisAction = array(
621 633
 				'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']),
@@ -631,30 +643,36 @@  discard block
 block discarded – undo
631 643
 				$action['unparsed_destination'] = $action['unparsed_filename'];
632 644
 
633 645
 				// If it's not auto do we think we have something we can act upon?
634
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
635
-					$theme_action = '';
646
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
647
+									$theme_action = '';
648
+				}
636 649
 				// ... or if it's auto do we even want to do anything?
637
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
638
-					$theme_action = '';
650
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
651
+									$theme_action = '';
652
+				}
639 653
 
640 654
 				// So, we still want to do something?
641
-				if ($theme_action != '')
642
-					$themeFinds['candidates'][] = $action;
655
+				if ($theme_action != '') {
656
+									$themeFinds['candidates'][] = $action;
657
+				}
643 658
 				// Otherwise is this is going into another theme record it.
644
-				elseif ($matches[1] == 'themes_dir')
645
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
659
+				elseif ($matches[1] == 'themes_dir') {
660
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
661
+				}
646 662
 			}
647 663
 		}
648 664
 
649
-		if (empty($thisAction))
650
-			continue;
665
+		if (empty($thisAction)) {
666
+					continue;
667
+		}
651 668
 
652 669
 		if (!in_array($action['type'], array('hook', 'credits')))
653 670
 		{
654
-			if ($context['uninstalling'])
655
-				$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
656
-			else
657
-				$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
671
+			if ($context['uninstalling']) {
672
+							$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
673
+			} else {
674
+							$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
675
+			}
658 676
 		}
659 677
 
660 678
 		// Don't fail if a file/directory we're trying to create doesn't exist...
@@ -669,8 +687,9 @@  discard block
 block discarded – undo
669 687
 		}
670 688
 
671 689
 		// @todo None given?
672
-		if (empty($thisAction['description']))
673
-			$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
690
+		if (empty($thisAction['description'])) {
691
+					$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
692
+		}
674 693
 
675 694
 		$context['actions'][] = $thisAction;
676 695
 	}
@@ -683,18 +702,21 @@  discard block
 block discarded – undo
683 702
 			// Get the part of the file we'll be dealing with.
684 703
 			preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
685 704
 
686
-			if ($matches[1] == 'imagesdir')
687
-				$path = '/' . basename($settings['default_images_url']);
688
-			elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir')
689
-				$path = '/languages';
690
-			else
691
-				$path = '';
705
+			if ($matches[1] == 'imagesdir') {
706
+							$path = '/' . basename($settings['default_images_url']);
707
+			} elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
708
+							$path = '/languages';
709
+			} else {
710
+							$path = '';
711
+			}
692 712
 
693
-			if (!empty($matches[3]))
694
-				$path .= $matches[3];
713
+			if (!empty($matches[3])) {
714
+							$path .= $matches[3];
715
+			}
695 716
 
696
-			if (!$context['uninstalling'])
697
-				$path .= '/' . basename($action_data['filename']);
717
+			if (!$context['uninstalling']) {
718
+							$path .= '/' . basename($action_data['filename']);
719
+			}
698 720
 
699 721
 			// Loop through each custom theme to note it's candidacy!
700 722
 			foreach ($theme_paths as $id => $theme_data)
@@ -710,36 +732,40 @@  discard block
 block discarded – undo
710 732
 						if (!mktree(dirname($real_path), false))
711 733
 						{
712 734
 							$temp = dirname($real_path);
713
-							while (!file_exists($temp) && strlen($temp) > 1)
714
-								$temp = dirname($temp);
735
+							while (!file_exists($temp) && strlen($temp) > 1) {
736
+															$temp = dirname($temp);
737
+							}
715 738
 							$chmod_files[] = $temp;
716 739
 						}
717 740
 
718
-						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path))))
719
-							$chmod_files[] = $real_path;
741
+						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
742
+													$chmod_files[] = $real_path;
743
+						}
720 744
 
721
-						if (!isset($context['theme_actions'][$id]))
722
-							$context['theme_actions'][$id] = array(
745
+						if (!isset($context['theme_actions'][$id])) {
746
+													$context['theme_actions'][$id] = array(
723 747
 								'name' => $theme_data['name'],
724 748
 								'actions' => array(),
725 749
 							);
750
+						}
726 751
 
727
-						if ($context['uninstalling'])
728
-							$context['theme_actions'][$id]['actions'][] = array(
752
+						if ($context['uninstalling']) {
753
+													$context['theme_actions'][$id]['actions'][] = array(
729 754
 								'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
730 755
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
731 756
 								'description' => '',
732 757
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))),
733 758
 								'not_mod' => true,
734 759
 							);
735
-						else
736
-							$context['theme_actions'][$id]['actions'][] = array(
760
+						} else {
761
+													$context['theme_actions'][$id]['actions'][] = array(
737 762
 								'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
738 763
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
739 764
 								'description' => '',
740 765
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))),
741 766
 								'not_mod' => true,
742 767
 							);
768
+						}
743 769
 					}
744 770
 				}
745 771
 			}
@@ -749,8 +775,9 @@  discard block
 block discarded – undo
749 775
 	// Trash the cache... which will also check permissions for us!
750 776
 	package_flush_cache(true);
751 777
 
752
-	if (file_exists($packagesdir . '/temp'))
753
-		deltree($packagesdir . '/temp');
778
+	if (file_exists($packagesdir . '/temp')) {
779
+			deltree($packagesdir . '/temp');
780
+	}
754 781
 
755 782
 	if (!empty($chmod_files))
756 783
 	{
@@ -775,8 +802,9 @@  discard block
 block discarded – undo
775 802
 	checkSession();
776 803
 
777 804
 	// If there's no file, what are we installing?
778
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
779
-		redirectexit('action=admin;area=packages');
805
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
806
+			redirectexit('action=admin;area=packages');
807
+	}
780 808
 	$context['filename'] = $_REQUEST['package'];
781 809
 
782 810
 	// If this is an uninstall, we'll have an id.
@@ -797,51 +825,55 @@  discard block
 block discarded – undo
797 825
 
798 826
 	$context['sub_template'] = 'extract_package';
799 827
 
800
-	if (!file_exists($packagesdir . '/' . $context['filename']))
801
-		fatal_lang_error('package_no_file', false);
828
+	if (!file_exists($packagesdir . '/' . $context['filename'])) {
829
+			fatal_lang_error('package_no_file', false);
830
+	}
802 831
 
803 832
 	// Load up the package FTP information?
804 833
 	create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
805 834
 
806 835
 	// Make sure temp directory exists and is empty!
807
-	if (file_exists($packagesdir . '/temp'))
808
-		deltree($packagesdir . '/temp', false);
809
-	else
810
-		mktree($packagesdir . '/temp', 0777);
836
+	if (file_exists($packagesdir . '/temp')) {
837
+			deltree($packagesdir . '/temp', false);
838
+	} else {
839
+			mktree($packagesdir . '/temp', 0777);
840
+	}
811 841
 
812 842
 	// Let the unpacker do the work.
813 843
 	if (is_file($packagesdir . '/' . $context['filename']))
814 844
 	{
815 845
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
816 846
 
817
-		if (!file_exists($packagesdir . '/temp/package-info.xml'))
818
-			foreach ($context['extracted_files'] as $file)
847
+		if (!file_exists($packagesdir . '/temp/package-info.xml')) {
848
+					foreach ($context['extracted_files'] as $file)
819 849
 				if (basename($file['filename']) == 'package-info.xml')
820 850
 				{
821 851
 					$context['base_path'] = dirname($file['filename']) . '/';
852
+		}
822 853
 					break;
823 854
 				}
824 855
 
825
-		if (!isset($context['base_path']))
826
-			$context['base_path'] = '';
827
-	}
828
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
856
+		if (!isset($context['base_path'])) {
857
+					$context['base_path'] = '';
858
+		}
859
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
829 860
 	{
830 861
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
831 862
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
832 863
 		$context['base_path'] = '';
864
+	} else {
865
+			fatal_lang_error('no_access', false);
833 866
 	}
834
-	else
835
-		fatal_lang_error('no_access', false);
836 867
 
837 868
 	// Are we installing this into any custom themes?
838 869
 	$custom_themes = array(1);
839 870
 	$known_themes = explode(',', $modSettings['knownThemes']);
840 871
 	if (!empty($_POST['custom_theme']))
841 872
 	{
842
-		foreach ($_POST['custom_theme'] as $tid)
843
-			if (in_array($tid, $known_themes))
873
+		foreach ($_POST['custom_theme'] as $tid) {
874
+					if (in_array($tid, $known_themes))
844 875
 				$custom_themes[] = (int) $tid;
876
+		}
845 877
 	}
846 878
 
847 879
 	// Now load up the paths of the themes that we need to know about.
@@ -858,8 +890,9 @@  discard block
 block discarded – undo
858 890
 	);
859 891
 	$theme_paths = array();
860 892
 	$themes_installed = array(1);
861
-	while ($row = $smcFunc['db_fetch_assoc']($request))
862
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
895
+	}
863 896
 	$smcFunc['db_free_result']($request);
864 897
 
865 898
 	// Are there any theme copying that we want to take place?
@@ -871,11 +904,13 @@  discard block
 block discarded – undo
871 904
 	{
872 905
 		foreach ($_POST['theme_changes'] as $change)
873 906
 		{
874
-			if (empty($change))
875
-				continue;
907
+			if (empty($change)) {
908
+							continue;
909
+			}
876 910
 			$theme_data = smf_json_decode(base64_decode($change), true);
877
-			if (empty($theme_data['type']))
878
-				continue;
911
+			if (empty($theme_data['type'])) {
912
+							continue;
913
+			}
879 914
 
880 915
 			$themes_installed[] = $theme_data['id'];
881 916
 			$context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
@@ -884,8 +919,9 @@  discard block
 block discarded – undo
884 919
 
885 920
 	// Get the package info...
886 921
 	$packageInfo = getPackageInfo($context['filename']);
887
-	if (!is_array($packageInfo))
888
-		fatal_lang_error($packageInfo);
922
+	if (!is_array($packageInfo)) {
923
+			fatal_lang_error($packageInfo);
924
+	}
889 925
 
890 926
 	$packageInfo['filename'] = $context['filename'];
891 927
 
@@ -897,8 +933,9 @@  discard block
 block discarded – undo
897 933
 	{
898 934
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
899 935
 		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
900
-		if (!$result)
901
-			fatal_lang_error('could_not_package_backup', false);
936
+		if (!$result) {
937
+					fatal_lang_error('could_not_package_backup', false);
938
+		}
902 939
 	}
903 940
 
904 941
 	// The mod isn't installed.... unless proven otherwise.
@@ -938,35 +975,38 @@  discard block
 block discarded – undo
938 975
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
939 976
 
940 977
 		// Gadzooks!  There's no uninstaller at all!?
941
-		if (empty($install_log))
942
-			fatal_lang_error('package_uninstall_cannot', false);
978
+		if (empty($install_log)) {
979
+					fatal_lang_error('package_uninstall_cannot', false);
980
+		}
943 981
 
944 982
 		// They can only uninstall from what it was originally installed into.
945
-		foreach ($theme_paths as $id => $data)
946
-			if ($id != 1 && !in_array($id, $old_themes))
983
+		foreach ($theme_paths as $id => $data) {
984
+					if ($id != 1 && !in_array($id, $old_themes))
947 985
 				unset($theme_paths[$id]);
948
-	}
949
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
986
+		}
987
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
950 988
 	{
951 989
 		// Look for an upgrade...
952 990
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
953 991
 
954 992
 		// There was no upgrade....
955
-		if (empty($install_log))
956
-			$context['is_installed'] = true;
957
-		else
993
+		if (empty($install_log)) {
994
+					$context['is_installed'] = true;
995
+		} else
958 996
 		{
959 997
 			// Upgrade previous themes only!
960
-			foreach ($theme_paths as $id => $data)
961
-				if ($id != 1 && !in_array($id, $old_themes))
998
+			foreach ($theme_paths as $id => $data) {
999
+							if ($id != 1 && !in_array($id, $old_themes))
962 1000
 					unset($theme_paths[$id]);
1001
+			}
963 1002
 		}
1003
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
1004
+			$context['is_installed'] = true;
964 1005
 	}
965
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
966
-		$context['is_installed'] = true;
967 1006
 
968
-	if (!isset($old_version) || $context['is_installed'])
969
-		$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1007
+	if (!isset($old_version) || $context['is_installed']) {
1008
+			$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1009
+	}
970 1010
 
971 1011
 	$context['install_finished'] = false;
972 1012
 
@@ -983,37 +1023,39 @@  discard block
 block discarded – undo
983 1023
 
984 1024
 			if ($action['type'] == 'modification' && !empty($action['filename']))
985 1025
 			{
986
-				if ($action['boardmod'])
987
-					$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
988
-				else
989
-					$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1026
+				if ($action['boardmod']) {
1027
+									$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1028
+				} else {
1029
+									$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1030
+				}
990 1031
 
991 1032
 				// Any errors worth noting?
992 1033
 				foreach ($mod_actions as $key => $action)
993 1034
 				{
994
-					if ($action['type'] == 'failure')
995
-						$failed_steps[] = array(
1035
+					if ($action['type'] == 'failure') {
1036
+											$failed_steps[] = array(
996 1037
 							'file' => $action['filename'],
997 1038
 							'large_step' => $failed_count,
998 1039
 							'sub_step' => $key,
999 1040
 							'theme' => 1,
1000 1041
 						);
1042
+					}
1001 1043
 
1002 1044
 					// Gather the themes we installed into.
1003
-					if (!empty($action['is_custom']))
1004
-						$themes_installed[] = $action['is_custom'];
1045
+					if (!empty($action['is_custom'])) {
1046
+											$themes_installed[] = $action['is_custom'];
1047
+					}
1005 1048
 				}
1006
-			}
1007
-			elseif ($action['type'] == 'code' && !empty($action['filename']))
1049
+			} elseif ($action['type'] == 'code' && !empty($action['filename']))
1008 1050
 			{
1009 1051
 				// This is just here as reference for what is available.
1010 1052
 				global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
1011 1053
 
1012 1054
 				// Now include the file and be done with it ;).
1013
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1014
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1015
-			}
1016
-			elseif ($action['type'] == 'credits')
1055
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1056
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1057
+				}
1058
+			} elseif ($action['type'] == 'credits')
1017 1059
 			{
1018 1060
 				// Time to build the billboard
1019 1061
 				$credits_tag = array(
@@ -1023,13 +1065,13 @@  discard block
 block discarded – undo
1023 1065
 					'copyright' => $action['copyright'],
1024 1066
 					'title' => $action['title'],
1025 1067
 				);
1026
-			}
1027
-			elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1068
+			} elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1028 1069
 			{
1029
-				if ($action['reverse'])
1030
-					remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1031
-				else
1032
-					add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1070
+				if ($action['reverse']) {
1071
+									remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1072
+				} else {
1073
+									add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1074
+				}
1033 1075
 			}
1034 1076
 			// Only do the database changes on uninstall if requested.
1035 1077
 			elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes'])))
@@ -1042,8 +1084,9 @@  discard block
 block discarded – undo
1042 1084
 				db_extend('packages');
1043 1085
 
1044 1086
 				// Let the file work its magic ;)
1045
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1046
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1087
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1088
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1089
+				}
1047 1090
 			}
1048 1091
 			// Handle a redirect...
1049 1092
 			elseif ($action['type'] == 'redirect' && !empty($action['redirect_url']))
@@ -1125,8 +1168,9 @@  discard block
 block discarded – undo
1125 1168
 			reloadSettings();
1126 1169
 
1127 1170
 			// Any db changes from older version?
1128
-			if (!empty($old_db_changes))
1129
-				$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1171
+			if (!empty($old_db_changes)) {
1172
+							$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1173
+			}
1130 1174
 
1131 1175
 			// If there are some database changes we might want to remove then filter them out.
1132 1176
 			if (!empty($db_package_log))
@@ -1142,22 +1186,24 @@  discard block
 block discarded – undo
1142 1186
 				 */
1143 1187
 				function sort_table_first($a, $b)
1144 1188
 				{
1145
-					if ($a[0] == $b[0])
1146
-						return 0;
1189
+					if ($a[0] == $b[0]) {
1190
+											return 0;
1191
+					}
1147 1192
 					return $a[0] == 'remove_table' ? -1 : 1;
1148 1193
 				}
1149 1194
 				usort($db_package_log, 'sort_table_first');
1150 1195
 				foreach ($db_package_log as $k => $log)
1151 1196
 				{
1152
-					if ($log[0] == 'remove_table')
1153
-						$tables[] = $log[1];
1154
-					elseif (in_array($log[1], $tables))
1155
-						unset($db_package_log[$k]);
1197
+					if ($log[0] == 'remove_table') {
1198
+											$tables[] = $log[1];
1199
+					} elseif (in_array($log[1], $tables)) {
1200
+											unset($db_package_log[$k]);
1201
+					}
1156 1202
 				}
1157 1203
 				$db_changes = json_encode($db_package_log);
1204
+			} else {
1205
+							$db_changes = '';
1158 1206
 			}
1159
-			else
1160
-				$db_changes = '';
1161 1207
 
1162 1208
 			// What themes did we actually install?
1163 1209
 			$themes_installed = array_unique($themes_installed);
@@ -1206,18 +1252,20 @@  discard block
 block discarded – undo
1206 1252
 
1207 1253
 		foreach ($db_changes as $change)
1208 1254
 		{
1209
-			if ($change[0] == 'remove_table' && isset($change[1]))
1210
-				$smcFunc['db_drop_table']($change[1]);
1211
-			elseif ($change[0] == 'remove_column' && isset($change[2]))
1212
-				$smcFunc['db_remove_column']($change[1], $change[2]);
1213
-			elseif ($change[0] == 'remove_index' && isset($change[2]))
1214
-				$smcFunc['db_remove_index']($change[1], $change[2]);
1255
+			if ($change[0] == 'remove_table' && isset($change[1])) {
1256
+							$smcFunc['db_drop_table']($change[1]);
1257
+			} elseif ($change[0] == 'remove_column' && isset($change[2])) {
1258
+							$smcFunc['db_remove_column']($change[1], $change[2]);
1259
+			} elseif ($change[0] == 'remove_index' && isset($change[2])) {
1260
+							$smcFunc['db_remove_index']($change[1], $change[2]);
1261
+			}
1215 1262
 		}
1216 1263
 	}
1217 1264
 
1218 1265
 	// Clean house... get rid of the evidence ;).
1219
-	if (file_exists($packagesdir . '/temp'))
1220
-		deltree($packagesdir . '/temp');
1266
+	if (file_exists($packagesdir . '/temp')) {
1267
+			deltree($packagesdir . '/temp');
1268
+	}
1221 1269
 
1222 1270
 	// Log what we just did.
1223 1271
 	logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
@@ -1239,8 +1287,9 @@  discard block
 block discarded – undo
1239 1287
 	require_once($sourcedir . '/Subs-Package.php');
1240 1288
 
1241 1289
 	// No package?  Show him or her the door.
1242
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1243
-		redirectexit('action=admin;area=packages');
1290
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1291
+			redirectexit('action=admin;area=packages');
1292
+	}
1244 1293
 
1245 1294
 	$context['linktree'][] = array(
1246 1295
 		'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'],
@@ -1253,11 +1302,12 @@  discard block
 block discarded – undo
1253 1302
 	$context['filename'] = $_REQUEST['package'];
1254 1303
 
1255 1304
 	// Let the unpacker do the work.
1256
-	if (is_file($packagesdir . '/' . $context['filename']))
1257
-		$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1258
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1259
-		$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1260
-}
1305
+	if (is_file($packagesdir . '/' . $context['filename'])) {
1306
+			$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1307
+	} elseif (is_dir($packagesdir . '/' . $context['filename'])) {
1308
+			$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1309
+	}
1310
+	}
1261 1311
 
1262 1312
 /**
1263 1313
  * Display one of the files in a package.
@@ -1269,22 +1319,25 @@  discard block
 block discarded – undo
1269 1319
 	require_once($sourcedir . '/Subs-Package.php');
1270 1320
 
1271 1321
 	// No package?  Show him or her the door.
1272
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1273
-		redirectexit('action=admin;area=packages');
1322
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1323
+			redirectexit('action=admin;area=packages');
1324
+	}
1274 1325
 
1275 1326
 	// No file?  Show him or her the door.
1276
-	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '')
1277
-		redirectexit('action=admin;area=packages');
1327
+	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
1328
+			redirectexit('action=admin;area=packages');
1329
+	}
1278 1330
 
1279 1331
 	$_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_')));
1280 1332
 	$_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']);
1281 1333
 
1282 1334
 	if (isset($_REQUEST['raw']))
1283 1335
 	{
1284
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1285
-			echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1286
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1287
-			echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1336
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1337
+					echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1338
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1339
+					echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1340
+		}
1288 1341
 
1289 1342
 		obExit(false);
1290 1343
 	}
@@ -1301,17 +1354,19 @@  discard block
 block discarded – undo
1301 1354
 	$context['filename'] = $_REQUEST['file'];
1302 1355
 
1303 1356
 	// Let the unpacker do the work.... but make sure we handle images properly.
1304
-	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png')))
1305
-		$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1306
-	else
1357
+	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
1358
+			$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1359
+	} else
1307 1360
 	{
1308
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1309
-			$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1310
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1311
-			$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1361
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1362
+					$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1363
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1364
+					$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1365
+		}
1312 1366
 
1313
-		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php')
1314
-			$context['filedata'] = highlight_php_code($context['filedata']);
1367
+		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
1368
+					$context['filedata'] = highlight_php_code($context['filedata']);
1369
+		}
1315 1370
 	}
1316 1371
 }
1317 1372
 
@@ -1326,8 +1381,9 @@  discard block
 block discarded – undo
1326 1381
 	checkSession('get');
1327 1382
 
1328 1383
 	// Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
1329
-	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups')
1330
-		redirectexit('action=admin;area=packages;sa=browse');
1384
+	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') {
1385
+			redirectexit('action=admin;area=packages;sa=browse');
1386
+	}
1331 1387
 	$_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
1332 1388
 
1333 1389
 	// Can't delete what's not there.
@@ -1335,9 +1391,9 @@  discard block
 block discarded – undo
1335 1391
 	{
1336 1392
 		create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
1337 1393
 
1338
-		if (is_dir($packagesdir . '/' . $_GET['package']))
1339
-			deltree($packagesdir . '/' . $_GET['package']);
1340
-		else
1394
+		if (is_dir($packagesdir . '/' . $_GET['package'])) {
1395
+					deltree($packagesdir . '/' . $_GET['package']);
1396
+		} else
1341 1397
 		{
1342 1398
 			smf_chmod($packagesdir . '/' . $_GET['package'], 0777);
1343 1399
 			unlink($packagesdir . '/' . $_GET['package']);
@@ -1385,8 +1441,9 @@  discard block
 block discarded – undo
1385 1441
 					'data' => array(
1386 1442
 						'function' => function($package_md5) use ($type, &$context)
1387 1443
 						{
1388
-							if (isset($context['available_' . $type . ''][$package_md5]))
1389
-								return $context['available_' . $type . ''][$package_md5]['sort_id'];
1444
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1445
+															return $context['available_' . $type . ''][$package_md5]['sort_id'];
1446
+							}
1390 1447
 						},
1391 1448
 					),
1392 1449
 					'sort' => array(
@@ -1402,8 +1459,9 @@  discard block
 block discarded – undo
1402 1459
 					'data' => array(
1403 1460
 						'function' => function($package_md5) use ($type, &$context)
1404 1461
 						{
1405
-							if (isset($context['available_' . $type . ''][$package_md5]))
1406
-								return $context['available_' . $type . ''][$package_md5]['name'];
1462
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1463
+															return $context['available_' . $type . ''][$package_md5]['name'];
1464
+							}
1407 1465
 						},
1408 1466
 					),
1409 1467
 					'sort' => array(
@@ -1418,8 +1476,9 @@  discard block
 block discarded – undo
1418 1476
 					'data' => array(
1419 1477
 						'function' => function($package_md5) use ($type, &$context)
1420 1478
 						{
1421
-							if (isset($context['available_' . $type . ''][$package_md5]))
1422
-								return $context['available_' . $type . ''][$package_md5]['version'];
1479
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1480
+															return $context['available_' . $type . ''][$package_md5]['version'];
1481
+							}
1423 1482
 						},
1424 1483
 					),
1425 1484
 					'sort' => array(
@@ -1434,8 +1493,9 @@  discard block
 block discarded – undo
1434 1493
 					'data' => array(
1435 1494
 						'function' => function($package_md5) use ($type, $txt, &$context)
1436 1495
 						{
1437
-							if (isset($context['available_' . $type . ''][$package_md5]))
1438
-								return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1496
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1497
+															return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1498
+							}
1439 1499
 						},
1440 1500
 						'class' => 'smalltext',
1441 1501
 					),
@@ -1451,28 +1511,30 @@  discard block
 block discarded – undo
1451 1511
 					'data' => array(
1452 1512
 						'function' => function($package_md5) use ($type, &$context, $scripturl, $txt)
1453 1513
 						{
1454
-							if (!isset($context['available_' . $type . ''][$package_md5]))
1455
-								return '';
1514
+							if (!isset($context['available_' . $type . ''][$package_md5])) {
1515
+															return '';
1516
+							}
1456 1517
 
1457 1518
 							// Rewrite shortcut
1458 1519
 							$package = $context['available_' . $type . ''][$package_md5];
1459 1520
 							$return = '';
1460 1521
 
1461
-							if ($package['can_uninstall'])
1462
-								$return = '
1522
+							if ($package['can_uninstall']) {
1523
+															$return = '
1463 1524
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>';
1464
-							elseif ($package['can_emulate_uninstall'])
1465
-								$return = '
1525
+							} elseif ($package['can_emulate_uninstall']) {
1526
+															$return = '
1466 1527
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>';
1467
-							elseif ($package['can_upgrade'])
1468
-								$return = '
1528
+							} elseif ($package['can_upgrade']) {
1529
+															$return = '
1469 1530
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>';
1470
-							elseif ($package['can_install'])
1471
-								$return = '
1531
+							} elseif ($package['can_install']) {
1532
+															$return = '
1472 1533
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>';
1473
-							elseif ($package['can_emulate_install'])
1474
-								$return = '
1534
+							} elseif ($package['can_emulate_install']) {
1535
+															$return = '
1475 1536
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>';
1537
+							}
1476 1538
 
1477 1539
 							return $return . '
1478 1540
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a>
@@ -1537,12 +1599,14 @@  discard block
 block discarded – undo
1537 1599
 	static $packages, $installed_mods;
1538 1600
 
1539 1601
 	// Start things up
1540
-	if (!isset($packages[$params]))
1541
-		$packages[$params] = array();
1602
+	if (!isset($packages[$params])) {
1603
+			$packages[$params] = array();
1604
+	}
1542 1605
 
1543 1606
 	// We need the packages directory to be writable for this.
1544
-	if (!@is_writable($packagesdir))
1545
-		create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1607
+	if (!@is_writable($packagesdir)) {
1608
+			create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1609
+	}
1546 1610
 
1547 1611
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1548 1612
 
@@ -1550,41 +1614,44 @@  discard block
 block discarded – undo
1550 1614
 	if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version)
1551 1615
 	{
1552 1616
 		unset($_SESSION['version_emulate']);
1553
-	}
1554
-	elseif (isset($_GET['version_emulate']))
1617
+	} elseif (isset($_GET['version_emulate']))
1555 1618
 	{
1556
-		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate']))
1557
-			unset($_SESSION['version_emulate']);
1558
-		elseif ($_GET['version_emulate'] !== 0)
1559
-			$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1619
+		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) {
1620
+					unset($_SESSION['version_emulate']);
1621
+		} elseif ($_GET['version_emulate'] !== 0) {
1622
+					$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1623
+		}
1560 1624
 	}
1561 1625
 	if (!empty($_SESSION['version_emulate']))
1562 1626
 	{
1563 1627
 		$context['forum_version'] = 'SMF ' . $_SESSION['version_emulate'];
1564 1628
 		$the_version = $_SESSION['version_emulate'];
1565 1629
 	}
1566
-	if (isset($_SESSION['single_version_emulate']))
1567
-		unset($_SESSION['single_version_emulate']);
1630
+	if (isset($_SESSION['single_version_emulate'])) {
1631
+			unset($_SESSION['single_version_emulate']);
1632
+	}
1568 1633
 
1569 1634
 	if (empty($installed_mods))
1570 1635
 	{
1571 1636
 		$instmods = loadInstalledPackages();
1572 1637
 		$installed_mods = array();
1573 1638
 		// Look through the list of installed mods...
1574
-		foreach ($instmods as $installed_mod)
1575
-			$installed_mods[$installed_mod['package_id']] = array(
1639
+		foreach ($instmods as $installed_mod) {
1640
+					$installed_mods[$installed_mod['package_id']] = array(
1576 1641
 				'id' => $installed_mod['id'],
1577 1642
 				'version' => $installed_mod['version'],
1578 1643
 				'time_installed' => $installed_mod['time_installed'],
1579 1644
 			);
1645
+		}
1580 1646
 
1581 1647
 		// Get a list of all the ids installed, so the latest packages won't include already installed ones.
1582 1648
 		$context['installed_mods'] = array_keys($installed_mods);
1583 1649
 	}
1584 1650
 
1585
-	if (empty($packages))
1586
-		foreach ($context['modification_types'] as $type)
1651
+	if (empty($packages)) {
1652
+			foreach ($context['modification_types'] as $type)
1587 1653
 			$packages[$type] = array();
1654
+	}
1588 1655
 
1589 1656
 	if ($dir = @opendir($packagesdir))
1590 1657
 	{
@@ -1600,50 +1667,56 @@  discard block
 block discarded – undo
1600 1667
 
1601 1668
 		while ($package = readdir($dir))
1602 1669
 		{
1603
-			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
1604
-				continue;
1670
+			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
1671
+							continue;
1672
+			}
1605 1673
 
1606 1674
 			$skip = false;
1607
-			foreach ($context['modification_types'] as $type)
1608
-				if (isset($context['available_' . $type][md5($package)]))
1675
+			foreach ($context['modification_types'] as $type) {
1676
+							if (isset($context['available_' . $type][md5($package)]))
1609 1677
 					$skip = true;
1678
+			}
1610 1679
 
1611
-			if ($skip)
1612
-				continue;
1680
+			if ($skip) {
1681
+							continue;
1682
+			}
1613 1683
 
1614 1684
 			// Skip directories or files that are named the same.
1615 1685
 			if (is_dir($packagesdir . '/' . $package))
1616 1686
 			{
1617
-				if (in_array($package, $dirs))
1618
-					continue;
1687
+				if (in_array($package, $dirs)) {
1688
+									continue;
1689
+				}
1619 1690
 				$dirs[] = $package;
1620
-			}
1621
-			elseif (substr(strtolower($package), -7) == '.tar.gz')
1691
+			} elseif (substr(strtolower($package), -7) == '.tar.gz')
1622 1692
 			{
1623
-				if (in_array(substr($package, 0, -7), $dirs))
1624
-					continue;
1693
+				if (in_array(substr($package, 0, -7), $dirs)) {
1694
+									continue;
1695
+				}
1625 1696
 				$dirs[] = substr($package, 0, -7);
1626
-			}
1627
-			elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1697
+			} elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1628 1698
 			{
1629
-				if (in_array(substr($package, 0, -4), $dirs))
1630
-					continue;
1699
+				if (in_array(substr($package, 0, -4), $dirs)) {
1700
+									continue;
1701
+				}
1631 1702
 				$dirs[] = substr($package, 0, -4);
1632 1703
 			}
1633 1704
 
1634 1705
 			$packageInfo = getPackageInfo($package);
1635
-			if (!is_array($packageInfo))
1636
-				continue;
1706
+			if (!is_array($packageInfo)) {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (!empty($packageInfo))
1639 1711
 			{
1640 1712
 				$packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0;
1641 1713
 				$packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0;
1642 1714
 
1643
-				if (!isset($sort_id[$packageInfo['type']]))
1644
-					$packageInfo['sort_id'] = $sort_id['unknown'];
1645
-				else
1646
-					$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1715
+				if (!isset($sort_id[$packageInfo['type']])) {
1716
+									$packageInfo['sort_id'] = $sort_id['unknown'];
1717
+				} else {
1718
+									$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1719
+				}
1647 1720
 
1648 1721
 				$packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]);
1649 1722
 				$packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']);
@@ -1692,10 +1765,11 @@  discard block
 block discarded – undo
1692 1765
 					foreach ($upgrades as $upgrade)
1693 1766
 					{
1694 1767
 						// Even if it is for this SMF, is it for the installed version of the mod?
1695
-						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for')))
1696
-							if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1768
+						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) {
1769
+													if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1697 1770
 							{
1698 1771
 								$packageInfo['can_upgrade'] = true;
1772
+						}
1699 1773
 								break;
1700 1774
 							}
1701 1775
 					}
@@ -1772,10 +1846,11 @@  discard block
 block discarded – undo
1772 1846
 
1773 1847
 	if (isset($_GET['type']) && $_GET['type'] == $params)
1774 1848
 	{
1775
-		if (isset($_GET['desc']))
1776
-			krsort($packages[$params]);
1777
-		else
1778
-			ksort($packages[$params]);
1849
+		if (isset($_GET['desc'])) {
1850
+					krsort($packages[$params]);
1851
+		} else {
1852
+					ksort($packages[$params]);
1853
+		}
1779 1854
 	}
1780 1855
 
1781 1856
 	return $packages[$params];
@@ -1804,10 +1879,11 @@  discard block
 block discarded – undo
1804 1879
 		redirectexit('action=admin;area=packages;sa=options');
1805 1880
 	}
1806 1881
 
1807
-	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1808
-		$default_username = $match[1];
1809
-	else
1810
-		$default_username = '';
1882
+	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) {
1883
+			$default_username = $match[1];
1884
+	} else {
1885
+			$default_username = '';
1886
+	}
1811 1887
 
1812 1888
 	$context['page_title'] = $txt['package_settings'];
1813 1889
 	$context['sub_template'] = 'install_options';
@@ -1836,8 +1912,9 @@  discard block
 block discarded – undo
1836 1912
 	isAllowedTo('admin_forum');
1837 1913
 
1838 1914
 	// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
1839
-	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key']))
1840
-		fatal_lang_error('operation_invalid', 'general');
1915
+	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
1916
+			fatal_lang_error('operation_invalid', 'general');
1917
+	}
1841 1918
 
1842 1919
 	// Load the required file.
1843 1920
 	require_once($sourcedir . '/Subs-Package.php');
@@ -1853,18 +1930,19 @@  discard block
 block discarded – undo
1853 1930
 	{
1854 1931
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1855 1932
 
1856
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
1857
-			foreach ($context['extracted_files'] as $file)
1933
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
1934
+					foreach ($context['extracted_files'] as $file)
1858 1935
 				if (basename($file['filename']) == 'package-info.xml')
1859 1936
 				{
1860 1937
 					$context['base_path'] = dirname($file['filename']) . '/';
1938
+		}
1861 1939
 					break;
1862 1940
 				}
1863 1941
 
1864
-		if (!isset($context['base_path']))
1865
-			$context['base_path'] = '';
1866
-	}
1867
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1942
+		if (!isset($context['base_path'])) {
1943
+					$context['base_path'] = '';
1944
+		}
1945
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
1868 1946
 	{
1869 1947
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1870 1948
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
@@ -1885,8 +1963,9 @@  discard block
 block discarded – undo
1885 1963
 		)
1886 1964
 	);
1887 1965
 	$theme_paths = array();
1888
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1889
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1968
+	}
1890 1969
 	$smcFunc['db_free_result']($request);
1891 1970
 
1892 1971
 	// If we're viewing uninstall operations, only consider themes that
@@ -1911,19 +1990,21 @@  discard block
 block discarded – undo
1911 1990
 				list ($old_themes) = $smcFunc['db_fetch_row']($request);
1912 1991
 				$old_themes = explode(',', $old_themes);
1913 1992
 
1914
-				foreach ($theme_paths as $id => $data)
1915
-					if ($id != 1 && !in_array($id, $old_themes))
1993
+				foreach ($theme_paths as $id => $data) {
1994
+									if ($id != 1 && !in_array($id, $old_themes))
1916 1995
 						unset($theme_paths[$id]);
1996
+				}
1917 1997
 			}
1918 1998
 			$smcFunc['db_free_result']($request);
1919 1999
 		}
1920 2000
 	}
1921 2001
 
1922 2002
 	// Boardmod?
1923
-	if (isset($_REQUEST['boardmod']))
1924
-		$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
1925
-	else
1926
-		$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2003
+	if (isset($_REQUEST['boardmod'])) {
2004
+			$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2005
+	} else {
2006
+			$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2007
+	}
1927 2008
 
1928 2009
 	// Ok lets get the content of the file.
1929 2010
 	$context['operations'] = array(
@@ -1979,9 +2060,9 @@  discard block
 block discarded – undo
1979 2060
 			'path' => $detect_path,
1980 2061
 			'form_elements_only' => true,
1981 2062
 		);
2063
+	} else {
2064
+			$context['ftp_connected'] = true;
1982 2065
 	}
1983
-	else
1984
-		$context['ftp_connected'] = true;
1985 2066
 
1986 2067
 	// Define the template.
1987 2068
 	$context['page_title'] = $txt['package_file_perms'];
@@ -2094,18 +2175,19 @@  discard block
 block discarded – undo
2094 2175
 	{
2095 2176
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2096 2177
 
2097
-		if (!is_array($modSettings['attachmentUploadDir']))
2098
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2178
+		if (!is_array($modSettings['attachmentUploadDir'])) {
2179
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2180
+		}
2099 2181
 
2100 2182
 		// @todo Should we suggest non-current directories be read only?
2101
-		foreach ($modSettings['attachmentUploadDir'] as $dir)
2102
-			$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2183
+		foreach ($modSettings['attachmentUploadDir'] as $dir) {
2184
+					$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2103 2185
 			'type' => 'dir',
2104 2186
 			'writable_on' => 'restrictive',
2105 2187
 		);
2188
+		}
2106 2189
 
2107
-	}
2108
-	elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2190
+	} elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2109 2191
 	{
2110 2192
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2111 2193
 		$context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array(
@@ -2155,8 +2237,8 @@  discard block
 block discarded – undo
2155 2237
 	);
2156 2238
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2239
 	{
2158
-		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes'))
2159
-			$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2240
+		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) {
2241
+					$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2160 2242
 				'type' => 'dir_recursive',
2161 2243
 				'list_contents' => true,
2162 2244
 				'contents' => array(
@@ -2166,7 +2248,7 @@  discard block
 block discarded – undo
2166 2248
 					),
2167 2249
 				),
2168 2250
 			);
2169
-		else
2251
+		} else
2170 2252
 		{
2171 2253
 			$context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array(
2172 2254
 				'type' => 'dir_recursive',
@@ -2183,28 +2265,33 @@  discard block
 block discarded – undo
2183 2265
 	$smcFunc['db_free_result']($request);
2184 2266
 
2185 2267
 	// If we're submitting then let's move on to another function to keep things cleaner..
2186
-	if (isset($_POST['action_changes']))
2187
-		return PackagePermissionsAction();
2268
+	if (isset($_POST['action_changes'])) {
2269
+			return PackagePermissionsAction();
2270
+	}
2188 2271
 
2189 2272
 	$context['look_for'] = array();
2190 2273
 	// Are we looking for a particular tree - normally an expansion?
2191
-	if (!empty($_REQUEST['find']))
2192
-		$context['look_for'][] = base64_decode($_REQUEST['find']);
2274
+	if (!empty($_REQUEST['find'])) {
2275
+			$context['look_for'][] = base64_decode($_REQUEST['find']);
2276
+	}
2193 2277
 	// Only that tree?
2194 2278
 	$context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : '';
2195
-	if ($context['only_find'])
2196
-		$context['look_for'][] = $context['only_find'];
2279
+	if ($context['only_find']) {
2280
+			$context['look_for'][] = $context['only_find'];
2281
+	}
2197 2282
 
2198 2283
 	// Have we got a load of back-catalogue trees to expand from a submit etc?
2199 2284
 	if (!empty($_GET['back_look']))
2200 2285
 	{
2201 2286
 		$potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true);
2202
-		foreach ($potententialTrees as $tree)
2203
-			$context['look_for'][] = $tree;
2287
+		foreach ($potententialTrees as $tree) {
2288
+					$context['look_for'][] = $tree;
2289
+		}
2204 2290
 	}
2205 2291
 	// ... maybe posted?
2206
-	if (!empty($_POST['back_look']))
2207
-		$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2292
+	if (!empty($_POST['back_look'])) {
2293
+			$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2294
+	}
2208 2295
 
2209 2296
 	$context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15)));
2210 2297
 
@@ -2243,9 +2330,9 @@  discard block
 block discarded – undo
2243 2330
 				'chmod' => @is_writable($path),
2244 2331
 				'perms' => @fileperms($path),
2245 2332
 			);
2333
+		} else {
2334
+					unset($context['file_tree'][$path]);
2246 2335
 		}
2247
-		else
2248
-			unset($context['file_tree'][$path]);
2249 2336
 	}
2250 2337
 
2251 2338
 	// Is this actually xml?
@@ -2269,22 +2356,25 @@  discard block
 block discarded – undo
2269 2356
 	global $context;
2270 2357
 
2271 2358
 	$isLikelyPath = false;
2272
-	foreach ($context['look_for'] as $possiblePath)
2273
-		if (substr($possiblePath, 0, strlen($path)) == $path)
2359
+	foreach ($context['look_for'] as $possiblePath) {
2360
+			if (substr($possiblePath, 0, strlen($path)) == $path)
2274 2361
 			$isLikelyPath = true;
2362
+	}
2275 2363
 
2276 2364
 	// Is this where we stop?
2277
-	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath)
2278
-		return;
2279
-	elseif ($level > $context['default_level'] && !$isLikelyPath)
2280
-		return;
2365
+	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) {
2366
+			return;
2367
+	} elseif ($level > $context['default_level'] && !$isLikelyPath) {
2368
+			return;
2369
+	}
2281 2370
 
2282 2371
 	// Are we actually interested in saving this data?
2283 2372
 	$save_data = empty($context['only_find']) || $context['only_find'] == $path;
2284 2373
 
2285 2374
 	// @todo Shouldn't happen - but better error message?
2286
-	if (!is_dir($path))
2287
-		fatal_lang_error('no_access', false);
2375
+	if (!is_dir($path)) {
2376
+			fatal_lang_error('no_access', false);
2377
+	}
2288 2378
 
2289 2379
 	// This is where we put stuff we've found for sorting.
2290 2380
 	$foundData = array(
@@ -2299,11 +2389,13 @@  discard block
 block discarded – undo
2299 2389
 		if (is_file($path . '/' . $entry))
2300 2390
 		{
2301 2391
 			// Are we listing PHP files in this directory?
2302
-			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php')
2303
-				$foundData['files'][$entry] = true;
2392
+			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') {
2393
+							$foundData['files'][$entry] = true;
2394
+			}
2304 2395
 			// A file we were looking for.
2305
-			elseif ($save_data && isset($data['contents'][$entry]))
2306
-				$foundData['files'][$entry] = true;
2396
+			elseif ($save_data && isset($data['contents'][$entry])) {
2397
+							$foundData['files'][$entry] = true;
2398
+			}
2307 2399
 		}
2308 2400
 		// It's a directory - we're interested one way or another, probably...
2309 2401
 		elseif ($entry != '.' && $entry != '..')
@@ -2311,32 +2403,36 @@  discard block
 block discarded – undo
2311 2403
 			// Going further?
2312 2404
 			if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
2313 2405
 			{
2314
-				if (!isset($data['contents'][$entry]))
2315
-					$foundData['folders'][$entry] = 'dir_recursive';
2316
-				else
2317
-					$foundData['folders'][$entry] = true;
2406
+				if (!isset($data['contents'][$entry])) {
2407
+									$foundData['folders'][$entry] = 'dir_recursive';
2408
+				} else {
2409
+									$foundData['folders'][$entry] = true;
2410
+				}
2318 2411
 
2319 2412
 				// If this wasn't expected inherit the recusiveness...
2320
-				if (!isset($data['contents'][$entry]))
2321
-					// We need to do this as we will be going all recursive.
2413
+				if (!isset($data['contents'][$entry])) {
2414
+									// We need to do this as we will be going all recursive.
2322 2415
 					$data['contents'][$entry] = array(
2323 2416
 						'type' => 'dir_recursive',
2324 2417
 					);
2418
+				}
2325 2419
 
2326 2420
 				// Actually do the recursive stuff...
2327 2421
 				fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1);
2328 2422
 			}
2329 2423
 			// Maybe it is a folder we are not descending into.
2330
-			elseif (isset($data['contents'][$entry]))
2331
-				$foundData['folders'][$entry] = true;
2424
+			elseif (isset($data['contents'][$entry])) {
2425
+							$foundData['folders'][$entry] = true;
2426
+			}
2332 2427
 			// Otherwise we stop here.
2333 2428
 		}
2334 2429
 	}
2335 2430
 	closedir($dh);
2336 2431
 
2337 2432
 	// Nothing to see here?
2338
-	if (!$save_data)
2339
-		return;
2433
+	if (!$save_data) {
2434
+			return;
2435
+	}
2340 2436
 
2341 2437
 	// Now actually add the data, starting with the folders.
2342 2438
 	ksort($foundData['folders']);
@@ -2348,8 +2444,9 @@  discard block
 block discarded – undo
2348 2444
 				'perms' => @fileperms($path . '/' . $folder),
2349 2445
 			),
2350 2446
 		);
2351
-		if ($type !== true)
2352
-			$additional_data['type'] = $type;
2447
+		if ($type !== true) {
2448
+					$additional_data['type'] = $type;
2449
+		}
2353 2450
 
2354 2451
 		// If there's an offset ignore any folders in XML mode.
2355 2452
 		if (isset($_GET['xml']) && $context['file_offset'] == 0)
@@ -2368,13 +2465,13 @@  discard block
 block discarded – undo
2368 2465
 				),
2369 2466
 				'value' => $folder,
2370 2467
 			);
2371
-		}
2372
-		elseif (!isset($_GET['xml']))
2468
+		} elseif (!isset($_GET['xml']))
2373 2469
 		{
2374
-			if (isset($data['contents'][$folder]))
2375
-				$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2376
-			else
2377
-				$data['contents'][$folder] = $additional_data;
2470
+			if (isset($data['contents'][$folder])) {
2471
+							$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2472
+			} else {
2473
+							$data['contents'][$folder] = $additional_data;
2474
+			}
2378 2475
 		}
2379 2476
 	}
2380 2477
 
@@ -2386,11 +2483,13 @@  discard block
 block discarded – undo
2386 2483
 		$counter++;
2387 2484
 
2388 2485
 		// Have we reached our offset?
2389
-		if ($context['file_offset'] > $counter)
2390
-			continue;
2486
+		if ($context['file_offset'] > $counter) {
2487
+					continue;
2488
+		}
2391 2489
 		// Gone too far?
2392
-		if ($counter > ($context['file_offset'] + $context['file_limit']))
2393
-			continue;
2490
+		if ($counter > ($context['file_offset'] + $context['file_limit'])) {
2491
+					continue;
2492
+		}
2394 2493
 
2395 2494
 		$additional_data = array(
2396 2495
 			'perms' => array(
@@ -2416,13 +2515,13 @@  discard block
 block discarded – undo
2416 2515
 				),
2417 2516
 				'value' => $file,
2418 2517
 			);
2419
-		}
2420
-		elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2518
+		} elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2421 2519
 		{
2422
-			if (isset($data['contents'][$file]))
2423
-				$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2424
-			else
2425
-				$data['contents'][$file] = $additional_data;
2520
+			if (isset($data['contents'][$file])) {
2521
+							$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2522
+			} else {
2523
+							$data['contents'][$file] = $additional_data;
2524
+			}
2426 2525
 		}
2427 2526
 	}
2428 2527
 }
@@ -2444,8 +2543,9 @@  discard block
 block discarded – undo
2444 2543
 	$context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array();
2445 2544
 
2446 2545
 	// Skipping use of FTP?
2447
-	if (empty($package_ftp))
2448
-		$context['skip_ftp'] = true;
2546
+	if (empty($package_ftp)) {
2547
+			$context['skip_ftp'] = true;
2548
+	}
2449 2549
 
2450 2550
 	// We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place.
2451 2551
 	if ($context['method'] == 'individual')
@@ -2455,8 +2555,9 @@  discard block
 block discarded – undo
2455 2555
 		$context['custom_value'] = (int) $_POST['custom_value'];
2456 2556
 
2457 2557
 		// Continuing?
2458
-		if (isset($_POST['toProcess']))
2459
-			$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2558
+		if (isset($_POST['toProcess'])) {
2559
+					$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2560
+		}
2460 2561
 
2461 2562
 		if (isset($_POST['permStatus']))
2462 2563
 		{
@@ -2465,22 +2566,27 @@  discard block
 block discarded – undo
2465 2566
 			foreach ($_POST['permStatus'] as $path => $status)
2466 2567
 			{
2467 2568
 				// Nothing to see here?
2468
-				if ($status == 'no_change')
2469
-					continue;
2569
+				if ($status == 'no_change') {
2570
+									continue;
2571
+				}
2470 2572
 				$legal = false;
2471
-				foreach ($legal_roots as $root)
2472
-					if (substr($path, 0, strlen($root)) == $root)
2573
+				foreach ($legal_roots as $root) {
2574
+									if (substr($path, 0, strlen($root)) == $root)
2473 2575
 						$legal = true;
2576
+				}
2474 2577
 
2475
-				if (!$legal)
2476
-					continue;
2578
+				if (!$legal) {
2579
+									continue;
2580
+				}
2477 2581
 
2478 2582
 				// Check it exists.
2479
-				if (!file_exists($path))
2480
-					continue;
2583
+				if (!file_exists($path)) {
2584
+									continue;
2585
+				}
2481 2586
 
2482
-				if ($status == 'custom')
2483
-					$validate_custom = true;
2587
+				if ($status == 'custom') {
2588
+									$validate_custom = true;
2589
+				}
2484 2590
 
2485 2591
 				// Now add it.
2486 2592
 				$context['to_process'][$path] = $status;
@@ -2490,17 +2596,20 @@  discard block
 block discarded – undo
2490 2596
 			// Make sure the chmod status is valid?
2491 2597
 			if ($validate_custom)
2492 2598
 			{
2493
-				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false)
2494
-					fatal_error($txt['chmod_value_invalid']);
2599
+				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) {
2600
+									fatal_error($txt['chmod_value_invalid']);
2601
+				}
2495 2602
 			}
2496 2603
 
2497 2604
 			// Nothing to do?
2498
-			if (empty($context['to_process']))
2499
-				redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2605
+			if (empty($context['to_process'])) {
2606
+							redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2607
+			}
2500 2608
 		}
2501 2609
 		// Should never get here,
2502
-		else
2503
-			fatal_lang_error('no_access', false);
2610
+		else {
2611
+					fatal_lang_error('no_access', false);
2612
+		}
2504 2613
 
2505 2614
 		// Setup the custom value.
2506 2615
 		$custom_value = octdec('0' . $context['custom_value']);
@@ -2508,26 +2617,27 @@  discard block
 block discarded – undo
2508 2617
 		// Start processing items.
2509 2618
 		foreach ($context['to_process'] as $path => $status)
2510 2619
 		{
2511
-			if (in_array($status, array('execute', 'writable', 'read')))
2512
-				package_chmod($path, $status);
2513
-			elseif ($status == 'custom' && !empty($custom_value))
2620
+			if (in_array($status, array('execute', 'writable', 'read'))) {
2621
+							package_chmod($path, $status);
2622
+			} elseif ($status == 'custom' && !empty($custom_value))
2514 2623
 			{
2515 2624
 				// Use FTP if we have it.
2516 2625
 				if (!empty($package_ftp) && !empty($_SESSION['pack_ftp']))
2517 2626
 				{
2518 2627
 					$ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => ''));
2519 2628
 					$package_ftp->chmod($ftp_file, $custom_value);
2629
+				} else {
2630
+									smf_chmod($path, $custom_value);
2520 2631
 				}
2521
-				else
2522
-					smf_chmod($path, $custom_value);
2523 2632
 			}
2524 2633
 
2525 2634
 			// This fish is fried...
2526 2635
 			unset($context['to_process'][$path]);
2527 2636
 
2528 2637
 			// See if we're out of time?
2529
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2530
-				return false;
2638
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2639
+							return false;
2640
+			}
2531 2641
 		}
2532 2642
 	}
2533 2643
 	// If predefined this is a little different.
@@ -2595,23 +2705,27 @@  discard block
 block discarded – undo
2595 2705
 			{
2596 2706
 				global $context;
2597 2707
 
2598
-				if (!empty($data['writable_on']))
2599
-					if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2708
+				if (!empty($data['writable_on'])) {
2709
+									if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2600 2710
 						$context['special_files'][$path] = 1;
2711
+				}
2601 2712
 
2602
-				if (!empty($data['contents']))
2603
-					foreach ($data['contents'] as $name => $contents)
2713
+				if (!empty($data['contents'])) {
2714
+									foreach ($data['contents'] as $name => $contents)
2604 2715
 						build_special_files__recursive($path . '/' . $name, $contents);
2716
+				}
2605 2717
 			}
2606 2718
 
2607
-			foreach ($context['file_tree'] as $path => $data)
2608
-				build_special_files__recursive($path, $data);
2719
+			foreach ($context['file_tree'] as $path => $data) {
2720
+							build_special_files__recursive($path, $data);
2721
+			}
2609 2722
 		}
2610 2723
 		// Free doesn't need special files.
2611
-		elseif ($context['predefined_type'] == 'free')
2612
-			$context['special_files'] = array();
2613
-		else
2614
-			$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2724
+		elseif ($context['predefined_type'] == 'free') {
2725
+					$context['special_files'] = array();
2726
+		} else {
2727
+					$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2728
+		}
2615 2729
 
2616 2730
 		// Now we definitely know where we are, we need to go through again doing the chmod!
2617 2731
 		foreach ($context['directory_list'] as $path => $dummy)
@@ -2656,8 +2770,9 @@  discard block
 block discarded – undo
2656 2770
 			unset($context['directory_list'][$path]);
2657 2771
 
2658 2772
 			// See if we're out of time?
2659
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2660
-				return false;
2773
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2774
+							return false;
2775
+			}
2661 2776
 		}
2662 2777
 	}
2663 2778
 
Please login to merge, or discard this patch.
Sources/MessageIndex.php 1 patch
Braces   +264 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -257,8 +270,9 @@  discard block
 block discarded – undo
257 270
 	$context['sort_direction'] = $ascending ? 'up' : 'down';
258 271
 	$txt['starter'] = $txt['started_by'];
259 272
 
260
-	foreach ($sort_methods as $key => $val)
261
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
273
+	foreach ($sort_methods as $key => $val) {
274
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
275
+	}
262 276
 
263 277
 	// Calculate the fastest way to get the topics.
264 278
 	$start = (int) $_REQUEST['start'];
@@ -268,14 +282,15 @@  discard block
 block discarded – undo
268 282
 		$fake_ascending = true;
269 283
 		$maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex;
270 284
 		$start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex;
285
+	} else {
286
+			$fake_ascending = false;
271 287
 	}
272
-	else
273
-		$fake_ascending = false;
274 288
 
275 289
 	// Setup the default topic icons...
276 290
 	$context['icon_sources'] = array();
277
-	foreach ($context['stable_icons'] as $icon)
278
-		$context['icon_sources'][$icon] = 'images_url';
291
+	foreach ($context['stable_icons'] as $icon) {
292
+			$context['icon_sources'][$icon] = 'images_url';
293
+	}
279 294
 
280 295
 	$topic_ids = array();
281 296
 	$context['topics'] = array();
@@ -306,8 +321,9 @@  discard block
 block discarded – undo
306 321
 			)
307 322
 		);
308 323
 		$topic_ids = array();
309
-		while ($row = $smcFunc['db_fetch_assoc']($request))
310
-			$topic_ids[] = $row['id_topic'];
324
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
325
+					$topic_ids[] = $row['id_topic'];
326
+		}
311 327
 	}
312 328
 
313 329
 	// Grab the appropriate topic information...
@@ -363,11 +379,13 @@  discard block
 block discarded – undo
363 379
 		// Begin 'printing' the message index for current board.
364 380
 		while ($row = $smcFunc['db_fetch_assoc']($result))
365 381
 		{
366
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
367
-				continue;
382
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
383
+							continue;
384
+			}
368 385
 
369
-			if (!$pre_query)
370
-				$topic_ids[] = $row['id_topic'];
386
+			if (!$pre_query) {
387
+							$topic_ids[] = $row['id_topic'];
388
+			}
371 389
 
372 390
 			// Reference the main color class.
373 391
 			$colorClass = 'windowbg';
@@ -377,8 +395,9 @@  discard block
 block discarded – undo
377 395
 			{
378 396
 				// Limit them to $modSettings['preview_characters'] characters
379 397
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
380
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
381
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
398
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
399
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
400
+				}
382 401
 
383 402
 				// Censor the subject and message preview.
384 403
 				censorText($row['first_subject']);
@@ -389,27 +408,27 @@  discard block
 block discarded – undo
389 408
 				{
390 409
 					$row['last_subject'] = $row['first_subject'];
391 410
 					$row['last_body'] = $row['first_body'];
392
-				}
393
-				else
411
+				} else
394 412
 				{
395 413
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
396
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
397
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
414
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
415
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
416
+					}
398 417
 
399 418
 					censorText($row['last_subject']);
400 419
 					censorText($row['last_body']);
401 420
 				}
402
-			}
403
-			else
421
+			} else
404 422
 			{
405 423
 				$row['first_body'] = '';
406 424
 				$row['last_body'] = '';
407 425
 				censorText($row['first_subject']);
408 426
 
409
-				if ($row['id_first_msg'] == $row['id_last_msg'])
410
-					$row['last_subject'] = $row['first_subject'];
411
-				else
412
-					censorText($row['last_subject']);
427
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
428
+									$row['last_subject'] = $row['first_subject'];
429
+				} else {
430
+									censorText($row['last_subject']);
431
+				}
413 432
 			}
414 433
 
415 434
 			// Decide how many pages the topic should have.
@@ -420,42 +439,50 @@  discard block
 block discarded – undo
420 439
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
421 440
 
422 441
 				// If we can use all, show all.
423
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
424
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
442
+				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
443
+									$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
444
+				}
445
+			} else {
446
+							$pages = '';
425 447
 			}
426
-			else
427
-				$pages = '';
428 448
 
429 449
 			// We need to check the topic icons exist...
430 450
 			if (!empty($modSettings['messageIconChecks_enable']))
431 451
 			{
432
-				if (!isset($context['icon_sources'][$row['first_icon']]))
433
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
434
-				if (!isset($context['icon_sources'][$row['last_icon']]))
435
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
436
-			}
437
-			else
452
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
453
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
454
+				}
455
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
456
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
457
+				}
458
+			} else
438 459
 			{
439
-				if (!isset($context['icon_sources'][$row['first_icon']]))
440
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
441
-				if (!isset($context['icon_sources'][$row['last_icon']]))
442
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
460
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
461
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
462
+				}
463
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
464
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
465
+				}
443 466
 			}
444 467
 
445
-			if (!empty($board_info['recycle']))
446
-				$row['first_icon'] = 'recycled';
468
+			if (!empty($board_info['recycle'])) {
469
+							$row['first_icon'] = 'recycled';
470
+			}
447 471
 
448 472
 			// Is this topic pending approval, or does it have any posts pending approval?
449
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
450
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
473
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
474
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
475
+			}
451 476
 
452 477
 			// Sticky topics should get a different color, too.
453
-			if ($row['is_sticky'])
454
-				$colorClass .= ' sticky';
478
+			if ($row['is_sticky']) {
479
+							$colorClass .= ' sticky';
480
+			}
455 481
 
456 482
 			// Locked topics get special treatment as well.
457
-			if ($row['locked'])
458
-				$colorClass .= ' locked';
483
+			if ($row['locked']) {
484
+							$colorClass .= ' locked';
485
+			}
459 486
 
460 487
 			// 'Print' the topic info.
461 488
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -536,8 +563,9 @@  discard block
 block discarded – undo
536 563
 		$smcFunc['db_free_result']($result);
537 564
 
538 565
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
539
-		if ($fake_ascending)
540
-			$context['topics'] = array_reverse($context['topics'], true);
566
+		if ($fake_ascending) {
567
+					$context['topics'] = array_reverse($context['topics'], true);
568
+		}
541 569
 
542 570
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids))
543 571
 		{
@@ -554,8 +582,9 @@  discard block
 block discarded – undo
554 582
 					'limit' => count($topic_ids),
555 583
 				)
556 584
 			);
557
-			while ($row = $smcFunc['db_fetch_assoc']($result))
558
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
585
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
586
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
587
+			}
559 588
 			$smcFunc['db_free_result']($result);
560 589
 		}
561 590
 	}
@@ -580,9 +609,9 @@  discard block
 block discarded – undo
580 609
 		// Can we restore topics?
581 610
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
582 611
 
583
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
584
-			$context['can_move_any'] = true;
585
-		else
612
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
613
+					$context['can_move_any'] = true;
614
+		} else
586 615
 		{
587 616
 			// We'll use this in a minute
588 617
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -609,11 +638,13 @@  discard block
 block discarded – undo
609 638
 		}
610 639
 
611 640
 		// Can we use quick moderation checkboxes?
612
-		if ($options['display_quick_mod'] == 1)
613
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
641
+		if ($options['display_quick_mod'] == 1) {
642
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
643
+		}
614 644
 		// Or the icons?
615
-		else
616
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
645
+		else {
646
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
647
+		}
617 648
 	}
618 649
 
619 650
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -647,13 +678,15 @@  discard block
 block discarded – undo
647 678
 			);
648 679
 
649 680
 			// We've seen all these boards now!
650
-			foreach ($board_info['parent_boards'] as $k => $dummy)
651
-				if (isset($_SESSION['topicseen_cache'][$k]))
681
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
682
+							if (isset($_SESSION['topicseen_cache'][$k]))
652 683
 					unset($_SESSION['topicseen_cache'][$k]);
684
+			}
653 685
 		}
654 686
 
655
-		if (isset($_SESSION['topicseen_cache'][$board]))
656
-			unset($_SESSION['topicseen_cache'][$board]);
687
+		if (isset($_SESSION['topicseen_cache'][$board])) {
688
+					unset($_SESSION['topicseen_cache'][$board]);
689
+		}
657 690
 
658 691
 		$request = $smcFunc['db_query']('', '
659 692
 			SELECT id_topic, id_board, sent
@@ -675,8 +708,9 @@  discard block
 block discarded – undo
675 708
 				$context['is_marked_notify'] = true;
676 709
 				$board_sent = $row['sent'];
677 710
 			}
678
-			if (!empty($row['id_topic']))
679
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
711
+			if (!empty($row['id_topic'])) {
712
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
713
+			}
680 714
 		}
681 715
 		$smcFunc['db_free_result']($request);
682 716
 
@@ -700,8 +734,7 @@  discard block
 block discarded – undo
700 734
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
701 735
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
702 736
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
703
-	}
704
-	else
737
+	} else
705 738
 	{
706 739
 		$context['is_marked_notify'] = false;
707 740
 		$context['board_notification_mode'] = 1;
@@ -714,23 +747,27 @@  discard block
 block discarded – undo
714 747
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
715 748
 
716 749
 	// Don't want to show this forever...
717
-	if ($context['becomesUnapproved'])
718
-		unset($_SESSION['becomesUnapproved']);
750
+	if ($context['becomesUnapproved']) {
751
+			unset($_SESSION['becomesUnapproved']);
752
+	}
719 753
 
720 754
 	// Build the message index button array.
721 755
 	$context['normal_buttons'] = array();
722 756
 	
723
-	if ($context['can_post_new'])
724
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
757
+	if ($context['can_post_new']) {
758
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
759
+	}
725 760
 	
726
-	if ($context['can_post_poll'])
727
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
761
+	if ($context['can_post_poll']) {
762
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
763
+	}
728 764
 	
729
-	if (!$context['user']['is_logged'])
730
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
765
+	if (!$context['user']['is_logged']) {
766
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
767
+	}
731 768
 
732
-	if ($context['can_mark_notify'])
733
-		$context['normal_buttons']['notify'] = array(
769
+	if ($context['can_mark_notify']) {
770
+			$context['normal_buttons']['notify'] = array(
734 771
 			'lang' => true,
735 772
 			'text' => 'notify_board_' . $context['board_notification_mode'],
736 773
 			'sub_buttons' => array(
@@ -748,6 +785,7 @@  discard block
 block discarded – undo
748 785
 				),
749 786
 			),
750 787
 		);
788
+	}
751 789
 
752 790
 	// Javascript for inline editing.
753 791
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -769,18 +807,21 @@  discard block
 block discarded – undo
769 807
 	checkSession('request');
770 808
 
771 809
 	// Lets go straight to the restore area.
772
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
773
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
810
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
811
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
812
+	}
774 813
 
775
-	if (isset($_SESSION['topicseen_cache']))
776
-		$_SESSION['topicseen_cache'] = array();
814
+	if (isset($_SESSION['topicseen_cache'])) {
815
+			$_SESSION['topicseen_cache'] = array();
816
+	}
777 817
 
778 818
 	// This is going to be needed to send off the notifications and for updateLastMessages().
779 819
 	require_once($sourcedir . '/Subs-Post.php');
780 820
 
781 821
 	// Remember the last board they moved things to.
782
-	if (isset($_REQUEST['move_to']))
783
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
822
+	if (isset($_REQUEST['move_to'])) {
823
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
824
+	}
784 825
 
785 826
 	// Only a few possible actions.
786 827
 	$possibleActions = array();
@@ -800,8 +841,7 @@  discard block
 block discarded – undo
800 841
 		);
801 842
 
802 843
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
803
-	}
804
-	else
844
+	} else
805 845
 	{
806 846
 		/**
807 847
 		 * @todo Ugly. There's no getting around this, is there?
@@ -819,8 +859,7 @@  discard block
 block discarded – undo
819 859
 		if (!empty($board))
820 860
 		{
821 861
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
822
-		}
823
-		else
862
+		} else
824 863
 		{
825 864
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
826 865
 		}
@@ -831,55 +870,67 @@  discard block
 block discarded – undo
831 870
 		}
832 871
 	}
833 872
 
834
-	if (!$user_info['is_guest'])
835
-		$possibleActions[] = 'markread';
836
-	if (!empty($boards_can['make_sticky']))
837
-		$possibleActions[] = 'sticky';
838
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
839
-		$possibleActions[] = 'move';
840
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
841
-		$possibleActions[] = 'remove';
842
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
843
-		$possibleActions[] = 'lock';
844
-	if (!empty($boards_can['merge_any']))
845
-		$possibleActions[] = 'merge';
846
-	if (!empty($boards_can['approve_posts']))
847
-		$possibleActions[] = 'approve';
873
+	if (!$user_info['is_guest']) {
874
+			$possibleActions[] = 'markread';
875
+	}
876
+	if (!empty($boards_can['make_sticky'])) {
877
+			$possibleActions[] = 'sticky';
878
+	}
879
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
880
+			$possibleActions[] = 'move';
881
+	}
882
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
883
+			$possibleActions[] = 'remove';
884
+	}
885
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
886
+			$possibleActions[] = 'lock';
887
+	}
888
+	if (!empty($boards_can['merge_any'])) {
889
+			$possibleActions[] = 'merge';
890
+	}
891
+	if (!empty($boards_can['approve_posts'])) {
892
+			$possibleActions[] = 'approve';
893
+	}
848 894
 
849 895
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
850 896
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
851 897
 	if (!empty($_REQUEST['topics']))
852 898
 	{
853 899
 		// If the action isn't valid, just quit now.
854
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
855
-			redirectexit($redirect_url);
900
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
901
+					redirectexit($redirect_url);
902
+		}
856 903
 
857 904
 		// Merge requires all topics as one parameter and can be done at once.
858 905
 		if ($_REQUEST['qaction'] == 'merge')
859 906
 		{
860 907
 			// Merge requires at least two topics.
861
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
862
-				redirectexit($redirect_url);
908
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
909
+							redirectexit($redirect_url);
910
+			}
863 911
 
864 912
 			require_once($sourcedir . '/SplitTopics.php');
865 913
 			return MergeExecute($_REQUEST['topics']);
866 914
 		}
867 915
 
868 916
 		// Just convert to the other method, to make it easier.
869
-		foreach ($_REQUEST['topics'] as $topic)
870
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
917
+		foreach ($_REQUEST['topics'] as $topic) {
918
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
919
+		}
871 920
 	}
872 921
 
873 922
 	// Weird... how'd you get here?
874
-	if (empty($_REQUEST['actions']))
875
-		redirectexit($redirect_url);
923
+	if (empty($_REQUEST['actions'])) {
924
+			redirectexit($redirect_url);
925
+	}
876 926
 
877 927
 	// Validate each action.
878 928
 	$temp = array();
879 929
 	foreach ($_REQUEST['actions'] as $topic => $action)
880 930
 	{
881
-		if (in_array($action, $possibleActions))
882
-			$temp[(int) $topic] = $action;
931
+		if (in_array($action, $possibleActions)) {
932
+					$temp[(int) $topic] = $action;
933
+		}
883 934
 	}
884 935
 	$_REQUEST['actions'] = $temp;
885 936
 
@@ -900,27 +951,31 @@  discard block
 block discarded – undo
900 951
 		{
901 952
 			if (!empty($board))
902 953
 			{
903
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
904
-					unset($_REQUEST['actions'][$row['id_topic']]);
905
-			}
906
-			else
954
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
955
+									unset($_REQUEST['actions'][$row['id_topic']]);
956
+				}
957
+			} else
907 958
 			{
908 959
 				// Don't allow them to act on unapproved posts they can't see...
909
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
910
-					unset($_REQUEST['actions'][$row['id_topic']]);
960
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
961
+									unset($_REQUEST['actions'][$row['id_topic']]);
962
+				}
911 963
 				// Goodness, this is fun.  We need to validate the action.
912
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
913
-					unset($_REQUEST['actions'][$row['id_topic']]);
914
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
915
-					unset($_REQUEST['actions'][$row['id_topic']]);
916
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
917
-					unset($_REQUEST['actions'][$row['id_topic']]);
964
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
965
+									unset($_REQUEST['actions'][$row['id_topic']]);
966
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
967
+									unset($_REQUEST['actions'][$row['id_topic']]);
968
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
969
+									unset($_REQUEST['actions'][$row['id_topic']]);
970
+				}
918 971
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
919
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
920
-					unset($_REQUEST['actions'][$row['id_topic']]);
972
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
973
+									unset($_REQUEST['actions'][$row['id_topic']]);
974
+				}
921 975
 				// If the topic is approved then you need permission to approve the posts within.
922
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
923
-					unset($_REQUEST['actions'][$row['id_topic']]);
976
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
977
+									unset($_REQUEST['actions'][$row['id_topic']]);
978
+				}
924 979
 			}
925 980
 		}
926 981
 		$smcFunc['db_free_result']($request);
@@ -938,11 +993,11 @@  discard block
 block discarded – undo
938 993
 	{
939 994
 		$topic = (int) $topic;
940 995
 
941
-		if ($action == 'markread')
942
-			$markCache[] = $topic;
943
-		elseif ($action == 'sticky')
944
-			$stickyCache[] = $topic;
945
-		elseif ($action == 'move')
996
+		if ($action == 'markread') {
997
+					$markCache[] = $topic;
998
+		} elseif ($action == 'sticky') {
999
+					$stickyCache[] = $topic;
1000
+		} elseif ($action == 'move')
946 1001
 		{
947 1002
 			require_once($sourcedir . '/MoveTopic.php');
948 1003
 			moveTopicConcurrence();
@@ -950,23 +1005,25 @@  discard block
 block discarded – undo
950 1005
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
951 1006
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
952 1007
 
953
-			if (empty($moveCache[1][$topic]))
954
-				continue;
1008
+			if (empty($moveCache[1][$topic])) {
1009
+							continue;
1010
+			}
955 1011
 
956 1012
 			$moveCache[0][] = $topic;
1013
+		} elseif ($action == 'remove') {
1014
+					$removeCache[] = $topic;
1015
+		} elseif ($action == 'lock') {
1016
+					$lockCache[] = $topic;
1017
+		} elseif ($action == 'approve') {
1018
+					$approveCache[] = $topic;
957 1019
 		}
958
-		elseif ($action == 'remove')
959
-			$removeCache[] = $topic;
960
-		elseif ($action == 'lock')
961
-			$lockCache[] = $topic;
962
-		elseif ($action == 'approve')
963
-			$approveCache[] = $topic;
964 1020
 	}
965 1021
 
966
-	if (empty($board))
967
-		$affectedBoards = array();
968
-	else
969
-		$affectedBoards = array($board => array(0, 0));
1022
+	if (empty($board)) {
1023
+			$affectedBoards = array();
1024
+	} else {
1025
+			$affectedBoards = array($board => array(0, 0));
1026
+	}
970 1027
 
971 1028
 	// Do all the stickies...
972 1029
 	if (!empty($stickyCache))
@@ -1026,14 +1083,16 @@  discard block
 block discarded – undo
1026 1083
 		{
1027 1084
 			$to = $moveCache[1][$row['id_topic']];
1028 1085
 
1029
-			if (empty($to))
1030
-				continue;
1086
+			if (empty($to)) {
1087
+							continue;
1088
+			}
1031 1089
 
1032 1090
 			// Does this topic's board count the posts or not?
1033 1091
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1034 1092
 
1035
-			if (!isset($moveTos[$to]))
1036
-				$moveTos[$to] = array();
1093
+			if (!isset($moveTos[$to])) {
1094
+							$moveTos[$to] = array();
1095
+			}
1037 1096
 
1038 1097
 			$moveTos[$to][] = $row['id_topic'];
1039 1098
 
@@ -1047,8 +1106,9 @@  discard block
 block discarded – undo
1047 1106
 		require_once($sourcedir . '/MoveTopic.php');
1048 1107
 
1049 1108
 		// Do the actual moves...
1050
-		foreach ($moveTos as $to => $topics)
1051
-			moveTopics($topics, $to);
1109
+		foreach ($moveTos as $to => $topics) {
1110
+					moveTopics($topics, $to);
1111
+		}
1052 1112
 
1053 1113
 		// Does the post counts need to be updated?
1054 1114
 		if (!empty($moveTos))
@@ -1097,20 +1157,23 @@  discard block
 block discarded – undo
1097 1157
 
1098 1158
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1099 1159
 				{
1100
-					if (!isset($members[$row['id_member']]))
1101
-						$members[$row['id_member']] = 0;
1160
+					if (!isset($members[$row['id_member']])) {
1161
+											$members[$row['id_member']] = 0;
1162
+					}
1102 1163
 
1103
-					if ($topicRecounts[$row['id_topic']] === '+')
1104
-						$members[$row['id_member']] += 1;
1105
-					else
1106
-						$members[$row['id_member']] -= 1;
1164
+					if ($topicRecounts[$row['id_topic']] === '+') {
1165
+											$members[$row['id_member']] += 1;
1166
+					} else {
1167
+											$members[$row['id_member']] -= 1;
1168
+					}
1107 1169
 				}
1108 1170
 
1109 1171
 				$smcFunc['db_free_result']($request);
1110 1172
 
1111 1173
 				// And now update them member's post counts
1112
-				foreach ($members as $id_member => $post_adj)
1113
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1174
+				foreach ($members as $id_member => $post_adj) {
1175
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1176
+				}
1114 1177
 
1115 1178
 			}
1116 1179
 		}
@@ -1190,8 +1253,9 @@  discard block
 block discarded – undo
1190 1253
 			approveTopics($approveCache);
1191 1254
 
1192 1255
 			// Time for some logging!
1193
-			foreach ($approveCache as $topic)
1194
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1256
+			foreach ($approveCache as $topic) {
1257
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1258
+			}
1195 1259
 		}
1196 1260
 	}
1197 1261
 
@@ -1226,8 +1290,7 @@  discard block
 block discarded – undo
1226 1290
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1227 1291
 			}
1228 1292
 			$smcFunc['db_free_result']($result);
1229
-		}
1230
-		else
1293
+		} else
1231 1294
 		{
1232 1295
 			$result = $smcFunc['db_query']('', '
1233 1296
 				SELECT id_topic, locked, id_board
@@ -1277,13 +1340,15 @@  discard block
 block discarded – undo
1277 1340
 			)
1278 1341
 		);
1279 1342
 		$logged_topics = array();
1280
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1281
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1343
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1344
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1345
+		}
1282 1346
 		$smcFunc['db_free_result']($request);
1283 1347
 
1284 1348
 		$markArray = array();
1285
-		foreach ($markCache as $topic)
1286
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1349
+		foreach ($markCache as $topic) {
1350
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1351
+		}
1287 1352
 
1288 1353
 		$smcFunc['db_insert']('replace',
1289 1354
 			'{db_prefix}log_topics',
@@ -1296,8 +1361,9 @@  discard block
 block discarded – undo
1296 1361
 	foreach ($moveCache as $topic)
1297 1362
 	{
1298 1363
 		// Didn't actually move anything!
1299
-		if (!isset($topic[0]))
1300
-			break;
1364
+		if (!isset($topic[0])) {
1365
+					break;
1366
+		}
1301 1367
 
1302 1368
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1303 1369
 		sendNotifications($topic[0], 'move');
@@ -1319,8 +1385,9 @@  discard block
 block discarded – undo
1319 1385
 		'calendar_updated' => time(),
1320 1386
 	));
1321 1387
 
1322
-	if (!empty($affectedBoards))
1323
-		updateLastMessages(array_keys($affectedBoards));
1388
+	if (!empty($affectedBoards)) {
1389
+			updateLastMessages(array_keys($affectedBoards));
1390
+	}
1324 1391
 
1325 1392
 	redirectexit($redirect_url);
1326 1393
 }
Please login to merge, or discard this patch.