Completed
Pull Request — release-2.1 (#3807)
by Martyn
07:05
created
Sources/ManageErrors.php 1 patch
Braces   +49 added lines, -38 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
  * View the forum's error log.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 
36 38
 	// Check for the administrative permission to do this.
37 39
 	isAllowedTo('admin_forum');
@@ -85,8 +87,8 @@  discard block
 block discarded – undo
85 87
 	);
86 88
 
87 89
 	// Set up the filtering...
88
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
89
-		$filter = array(
90
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
91
+			$filter = array(
90 92
 			'variable' => $_GET['filter'],
91 93
 			'value' => array(
92 94
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -94,10 +96,12 @@  discard block
 block discarded – undo
94 96
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
95 97
 			'entity' => $filters[$_GET['filter']]['txt']
96 98
 		);
99
+	}
97 100
 
98 101
 	// Deleting, are we?
99
-	if (isset($_POST['delall']) || isset($_POST['delete']))
100
-		deleteErrors();
102
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
103
+			deleteErrors();
104
+	}
101 105
 
102 106
 	// Just how many errors are there?
103 107
 	$result = $smcFunc['db_query']('', '
@@ -112,12 +116,14 @@  discard block
 block discarded – undo
112 116
 	$smcFunc['db_free_result']($result);
113 117
 
114 118
 	// If this filter is empty...
115
-	if ($num_errors == 0 && isset($filter))
116
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
119
+	if ($num_errors == 0 && isset($filter)) {
120
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
121
+	}
117 122
 
118 123
 	// Clean up start.
119
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
120
-		$_GET['start'] = 0;
124
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
125
+			$_GET['start'] = 0;
126
+	}
121 127
 
122 128
 	// Do we want to reverse error listing?
123 129
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -127,9 +133,9 @@  discard block
 block discarded – undo
127 133
 	$context['start'] = $_GET['start'];
128 134
 
129 135
 	// Update the error count
130
-	if (!isset($filter))
131
-		$context['num_errors'] = $num_errors;
132
-	else
136
+	if (!isset($filter)) {
137
+			$context['num_errors'] = $num_errors;
138
+	} else
133 139
 	{
134 140
 		// We want all errors, not just the number of filtered messages...
135 141
 		$query = $smcFunc['db_query']('', '
@@ -161,8 +167,9 @@  discard block
 block discarded – undo
161 167
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
162 168
 	{
163 169
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
164
-		if ($search_message == $filter['value']['sql'])
165
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
170
+		if ($search_message == $filter['value']['sql']) {
171
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
172
+		}
166 173
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
167 174
 
168 175
 		$context['errors'][$row['id_error']] = array(
@@ -221,8 +228,9 @@  discard block
 block discarded – undo
221 228
 				'members' => count($members),
222 229
 			)
223 230
 		);
224
-		while ($row = $smcFunc['db_fetch_assoc']($request))
225
-			$members[$row['id_member']] = $row;
231
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
232
+					$members[$row['id_member']] = $row;
233
+		}
226 234
 		$smcFunc['db_free_result']($request);
227 235
 
228 236
 		// This is a guest...
@@ -254,20 +262,18 @@  discard block
 block discarded – undo
254 262
 			$id = $filter['value']['sql'];
255 263
 			loadMemberData($id, false, 'minimal');
256 264
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
257
-		}
258
-		elseif ($filter['variable'] == 'url')
259
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
260
-		elseif ($filter['variable'] == 'message')
265
+		} elseif ($filter['variable'] == 'url') {
266
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
267
+		} elseif ($filter['variable'] == 'message')
261 268
 		{
262 269
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
263 270
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
264
-		}
265
-		elseif ($filter['variable'] == 'error_type')
271
+		} elseif ($filter['variable'] == 'error_type')
266 272
 		{
267 273
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
274
+		} else {
275
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
268 276
 		}
269
-		else
270
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
271 277
 	}
272 278
 
273 279
 	$context['error_types'] = array();
@@ -308,10 +314,11 @@  discard block
 block discarded – undo
308 314
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
309 315
 
310 316
 	// Finally, work out what is the last tab!
311
-	if (isset($context['error_types'][$sum]))
312
-		$context['error_types'][$sum]['is_last'] = true;
313
-	else
314
-		$context['error_types']['all']['is_last'] = true;
317
+	if (isset($context['error_types'][$sum])) {
318
+			$context['error_types'][$sum]['is_last'] = true;
319
+	} else {
320
+			$context['error_types']['all']['is_last'] = true;
321
+	}
315 322
 
316 323
 	// And this is pretty basic ;).
317 324
 	$context['page_title'] = $txt['errlog'];
@@ -337,21 +344,23 @@  discard block
 block discarded – undo
337 344
 	validateToken('admin-el');
338 345
 
339 346
 	// Delete all or just some?
340
-	if (isset($_POST['delall']) && !isset($filter))
341
-		$smcFunc['db_query']('truncate_table', '
347
+	if (isset($_POST['delall']) && !isset($filter)) {
348
+			$smcFunc['db_query']('truncate_table', '
342 349
 			TRUNCATE {db_prefix}log_errors',
343 350
 			array(
344 351
 			)
345 352
 		);
353
+	}
346 354
 	// Deleting all with a filter?
347
-	elseif (isset($_POST['delall']) && isset($filter))
348
-		$smcFunc['db_query']('', '
355
+	elseif (isset($_POST['delall']) && isset($filter)) {
356
+			$smcFunc['db_query']('', '
349 357
 			DELETE FROM {db_prefix}log_errors
350 358
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
351 359
 			array(
352 360
 				'filter' => $filter['value']['sql'],
353 361
 			)
354 362
 		);
363
+	}
355 364
 	// Just specific errors?
356 365
 	elseif (!empty($_POST['delete']))
357 366
 	{
@@ -397,15 +406,17 @@  discard block
 block discarded – undo
397 406
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
398 407
 
399 408
 	// Make sure the file we are looking for is one they are allowed to look at
400
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
401
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
409
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
410
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
411
+	}
402 412
 
403 413
 	// get the min and max lines
404 414
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
405 415
 	$max = $line + 21; // One additional line to make everything work out correctly
406 416
 
407
-	if ($max <= 0 || $min >= $max)
408
-		fatal_lang_error('error_bad_line');
417
+	if ($max <= 0 || $min >= $max) {
418
+			fatal_lang_error('error_bad_line');
419
+	}
409 420
 
410 421
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
411 422
 
Please login to merge, or discard this patch.
Sources/News.php 1 patch
Braces   +239 added lines, -185 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
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -53,8 +55,9 @@  discard block
 block discarded – undo
53 55
 	if (!empty($_REQUEST['c']) && empty($board))
54 56
 	{
55 57
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
56
-		foreach ($_REQUEST['c'] as $i => $c)
57
-			$_REQUEST['c'][$i] = (int) $c;
58
+		foreach ($_REQUEST['c'] as $i => $c) {
59
+					$_REQUEST['c'][$i] = (int) $c;
60
+		}
58 61
 
59 62
 		if (count($_REQUEST['c']) == 1)
60 63
 		{
@@ -90,18 +93,20 @@  discard block
 block discarded – undo
90 93
 		}
91 94
 		$smcFunc['db_free_result']($request);
92 95
 
93
-		if (!empty($boards))
94
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
96
+		if (!empty($boards)) {
97
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
98
+		}
95 99
 
96 100
 		// Try to limit the number of messages we look through.
97
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
98
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
99
-	}
100
-	elseif (!empty($_REQUEST['boards']))
101
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
102
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
103
+		}
104
+	} elseif (!empty($_REQUEST['boards']))
101 105
 	{
102 106
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
103
-		foreach ($_REQUEST['boards'] as $i => $b)
104
-			$_REQUEST['boards'][$i] = (int) $b;
107
+		foreach ($_REQUEST['boards'] as $i => $b) {
108
+					$_REQUEST['boards'][$i] = (int) $b;
109
+		}
105 110
 
106 111
 		$request = $smcFunc['db_query']('', '
107 112
 			SELECT b.id_board, b.num_posts, b.name
@@ -117,29 +122,32 @@  discard block
 block discarded – undo
117 122
 
118 123
 		// Either the board specified doesn't exist or you have no access.
119 124
 		$num_boards = $smcFunc['db_num_rows']($request);
120
-		if ($num_boards == 0)
121
-			fatal_lang_error('no_board');
125
+		if ($num_boards == 0) {
126
+					fatal_lang_error('no_board');
127
+		}
122 128
 
123 129
 		$total_posts = 0;
124 130
 		$boards = array();
125 131
 		while ($row = $smcFunc['db_fetch_assoc']($request))
126 132
 		{
127
-			if ($num_boards == 1)
128
-				$feed_title = ' - ' . strip_tags($row['name']);
133
+			if ($num_boards == 1) {
134
+							$feed_title = ' - ' . strip_tags($row['name']);
135
+			}
129 136
 
130 137
 			$boards[] = $row['id_board'];
131 138
 			$total_posts += $row['num_posts'];
132 139
 		}
133 140
 		$smcFunc['db_free_result']($request);
134 141
 
135
-		if (!empty($boards))
136
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
142
+		if (!empty($boards)) {
143
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
144
+		}
137 145
 
138 146
 		// The more boards, the more we're going to look through...
139
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
140
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
141
-	}
142
-	elseif (!empty($board))
147
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
148
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
149
+		}
150
+	} elseif (!empty($board))
143 151
 	{
144 152
 		$request = $smcFunc['db_query']('', '
145 153
 			SELECT num_posts
@@ -158,10 +166,10 @@  discard block
 block discarded – undo
158 166
 		$query_this_board = 'b.id_board = ' . $board;
159 167
 
160 168
 		// Try to look through just a few messages, if at all possible.
161
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
162
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
163
-	}
164
-	else
169
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
170
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
171
+		}
172
+	} else
165 173
 	{
166 174
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
167 175
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -184,30 +192,35 @@  discard block
 block discarded – undo
184 192
 	// Easy adding of sub actions
185 193
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
186 194
 
187
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
188
-		$_GET['sa'] = 'recent';
195
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
196
+			$_GET['sa'] = 'recent';
197
+	}
189 198
 
190 199
 	// We only want some information, not all of it.
191 200
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
192
-	foreach (array('board', 'boards', 'c') as $var)
193
-		if (isset($_REQUEST[$var]))
201
+	foreach (array('board', 'boards', 'c') as $var) {
202
+			if (isset($_REQUEST[$var]))
194 203
 			$cachekey[] = $_REQUEST[$var];
204
+	}
195 205
 	$cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
196 206
 	$cache_t = microtime();
197 207
 
198 208
 	// Get the associative array representing the xml.
199
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
200
-		$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
209
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
210
+			$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
211
+	}
201 212
 	if (empty($xml))
202 213
 	{
203 214
 		$call = call_helper($subActions[$_GET['sa']][0], true);
204 215
 
205
-		if (!empty($call))
206
-			$xml = call_user_func($call, $xml_format);
216
+		if (!empty($call)) {
217
+					$xml = call_user_func($call, $xml_format);
218
+		}
207 219
 
208 220
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
209
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
210
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
221
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
222
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
223
+		}
211 224
 	}
212 225
 
213 226
 	$feed_title = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_title) ? $feed_title : '');
@@ -218,19 +231,21 @@  discard block
 block discarded – undo
218 231
 
219 232
 	// This is an xml file....
220 233
 	ob_end_clean();
221
-	if (!empty($modSettings['enableCompressedOutput']))
222
-		@ob_start('ob_gzhandler');
223
-	else
224
-		ob_start();
234
+	if (!empty($modSettings['enableCompressedOutput'])) {
235
+			@ob_start('ob_gzhandler');
236
+	} else {
237
+			ob_start();
238
+	}
225 239
 
226
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
227
-		header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
228
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
229
-		header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
230
-	elseif ($xml_format == 'atom')
231
-		header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
232
-	elseif ($xml_format == 'rdf')
233
-		header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
240
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
241
+			header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
242
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
243
+			header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
244
+	} elseif ($xml_format == 'atom') {
245
+			header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
246
+	} elseif ($xml_format == 'rdf') {
247
+			header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
248
+	}
234 249
 
235 250
 	// First, output the xml header.
236 251
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -247,8 +262,9 @@  discard block
 block discarded – undo
247 262
 		<description>', cdata_parse(strip_tags($txt['xml_rss_desc'])), '</description>';
248 263
 
249 264
 		// RSS2 calls for this.
250
-		if ($xml_format == 'rss2')
251
-			echo '<atom:link rel="self" type="application/rss+xml" href="', $scripturl, '?action=.xml', !empty($_GET['sa']) ? ';sa=' . $_GET['sa'] : '', ';type=rss2" />';
265
+		if ($xml_format == 'rss2') {
266
+					echo '<atom:link rel="self" type="application/rss+xml" href="', $scripturl, '?action=.xml', !empty($_GET['sa']) ? ';sa=' . $_GET['sa'] : '', ';type=rss2" />';
267
+		}
252 268
 
253 269
 		// Output all of the associative array, start indenting with 2 tabs, and name everything "item".
254 270
 		dumpTags($xml, 2, 'item', $xml_format);
@@ -257,12 +273,12 @@  discard block
 block discarded – undo
257 273
 		echo '
258 274
 	</channel>
259 275
 </rss>';
260
-	}
261
-	elseif ($xml_format == 'atom')
276
+	} elseif ($xml_format == 'atom')
262 277
 	{
263
-		foreach ($_REQUEST as $var => $val)
264
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
278
+		foreach ($_REQUEST as $var => $val) {
279
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
265 280
 				$url_parts[] = $var . '=' . (is_array($_REQUEST[$var]) ? implode(',', $_REQUEST[$var]) : $_REQUEST[$var]);
281
+		}
266 282
 
267 283
 		echo '
268 284
 <feed xmlns="http://www.w3.org/2005/Atom">
@@ -283,8 +299,7 @@  discard block
 block discarded – undo
283 299
 
284 300
 		echo '
285 301
 </feed>';
286
-	}
287
-	elseif ($xml_format == 'rdf')
302
+	} elseif ($xml_format == 'rdf')
288 303
 	{
289 304
 		echo '
290 305
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
@@ -295,9 +310,10 @@  discard block
 block discarded – undo
295 310
 		<items>
296 311
 			<rdf:Seq>';
297 312
 
298
-		foreach ($xml as $item)
299
-			echo '
313
+		foreach ($xml as $item) {
314
+					echo '
300 315
 				<rdf:li rdf:resource="', $item['link'], '" />';
316
+		}
301 317
 
302 318
 		echo '
303 319
 			</rdf:Seq>
@@ -337,13 +353,15 @@  discard block
 block discarded – undo
337 353
 {
338 354
 	global $modSettings, $context, $scripturl;
339 355
 
340
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
341
-		return $val;
356
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
357
+			return $val;
358
+	}
342 359
 
343 360
 	call_integration_hook('integrate_fix_url', array(&$val));
344 361
 
345
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
346
-		return $val;
362
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
363
+			return $val;
364
+	}
347 365
 
348 366
 	$val = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function ($m) use ($scripturl)
349 367
 		{
@@ -365,8 +383,9 @@  discard block
 block discarded – undo
365 383
 	global $smcFunc;
366 384
 
367 385
 	// Do we even need to do this?
368
-	if (strpbrk($data, '<>&') == false)
369
-		return $data;
386
+	if (strpbrk($data, '<>&') == false) {
387
+			return $data;
388
+	}
370 389
 
371 390
 	$cdata = '<![CDATA[';
372 391
 
@@ -376,49 +395,55 @@  discard block
 block discarded – undo
376 395
 			$smcFunc['strpos']($data, '&', $pos),
377 396
 			$smcFunc['strpos']($data, ']', $pos),
378 397
 		);
379
-		if ($ns != '')
380
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
398
+		if ($ns != '') {
399
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
400
+		}
381 401
 		foreach ($positions as $k => $dummy)
382 402
 		{
383
-			if ($dummy === false)
384
-				unset($positions[$k]);
403
+			if ($dummy === false) {
404
+							unset($positions[$k]);
405
+			}
385 406
 		}
386 407
 
387 408
 		$old = $pos;
388 409
 		$pos = empty($positions) ? $n : min($positions);
389 410
 
390
-		if ($pos - $old > 0)
391
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
392
-		if ($pos >= $n)
393
-			break;
411
+		if ($pos - $old > 0) {
412
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
413
+		}
414
+		if ($pos >= $n) {
415
+					break;
416
+		}
394 417
 
395 418
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
396 419
 		{
397 420
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
398
-			if ($pos2 === false)
399
-				$pos2 = $n;
400
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
401
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
402
-			else
403
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
421
+			if ($pos2 === false) {
422
+							$pos2 = $n;
423
+			}
424
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
425
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
426
+			} else {
427
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
428
+			}
404 429
 			$pos = $pos2 + 1;
405
-		}
406
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
430
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
407 431
 		{
408 432
 			$cdata .= ']]>&#093;<![CDATA[';
409 433
 			$pos++;
410
-		}
411
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
434
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
412 435
 		{
413 436
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
414
-			if ($pos2 === false)
415
-				$pos2 = $n;
437
+			if ($pos2 === false) {
438
+							$pos2 = $n;
439
+			}
416 440
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
417 441
 
418
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
419
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
420
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
421
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
442
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
443
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
444
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
445
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
446
+			}
422 447
 
423 448
 			$pos = $pos2 + 1;
424 449
 		}
@@ -456,19 +481,22 @@  discard block
 block discarded – undo
456 481
 		'gender',
457 482
 		'blurb',
458 483
 	);
459
-	if ($xml_format != 'atom')
460
-		$keysToCdata[] = 'category';
484
+	if ($xml_format != 'atom') {
485
+			$keysToCdata[] = 'category';
486
+	}
461 487
 
462 488
 	// For every array in the data...
463 489
 	foreach ($data as $key => $val)
464 490
 	{
465 491
 		// Skip it, it's been set to null.
466
-		if ($val === null)
467
-			continue;
492
+		if ($val === null) {
493
+					continue;
494
+		}
468 495
 
469 496
 		// If the value should maybe be CDATA, do that now.
470
-		if (!is_array($val) && in_array($key, $keysToCdata))
471
-			$val = cdata_parse($val);
497
+		if (!is_array($val) && in_array($key, $keysToCdata)) {
498
+					$val = cdata_parse($val);
499
+		}
472 500
 
473 501
 		// If a tag was passed, use it instead of the key.
474 502
 		$key = isset($tag) ? $tag : $key;
@@ -484,11 +512,11 @@  discard block
 block discarded – undo
484 512
 		}
485 513
 
486 514
 		// If it's empty/0/nothing simply output an empty tag.
487
-		if ($val == '')
488
-			echo '<', $key, ' />';
489
-		elseif ($xml_format == 'atom' && $key == 'category')
490
-			echo '<', $key, ' term="', $val, '" />';
491
-		else
515
+		if ($val == '') {
516
+					echo '<', $key, ' />';
517
+		} elseif ($xml_format == 'atom' && $key == 'category') {
518
+					echo '<', $key, ' term="', $val, '" />';
519
+		} else
492 520
 		{
493 521
 			// Beginning tag.
494 522
 			if ($xml_format == 'rdf' && $key == 'item' && isset($val['link']))
@@ -496,11 +524,11 @@  discard block
 block discarded – undo
496 524
 				echo '<', $key, ' rdf:about="', fix_possible_url($val['link']), '">';
497 525
 				echo "\n", str_repeat("\t", $i + 1);
498 526
 				echo '<dc:format>text/html</dc:format>';
527
+			} elseif ($xml_format == 'atom' && $key == 'summary') {
528
+							echo '<', $key, ' type="html">';
529
+			} else {
530
+							echo '<', $key, '>';
499 531
 			}
500
-			elseif ($xml_format == 'atom' && $key == 'summary')
501
-				echo '<', $key, ' type="html">';
502
-			else
503
-				echo '<', $key, '>';
504 532
 
505 533
 			// The element's value.
506 534
 			if (is_array($val))
@@ -510,11 +538,13 @@  discard block
 block discarded – undo
510 538
 				echo "\n", str_repeat("\t", $i);
511 539
 			}
512 540
 			// A string with returns in it.... show this as a multiline element.
513
-			elseif (strpos($val, "\n") !== false || preg_match('~<br ?/?' . '>~', $val) !== false)
514
-				echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i);
541
+			elseif (strpos($val, "\n") !== false || preg_match('~<br ?/?' . '>~', $val) !== false) {
542
+							echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i);
543
+			}
515 544
 			// A simple string.
516
-			else
517
-				echo fix_possible_url($val);
545
+			else {
546
+							echo fix_possible_url($val);
547
+			}
518 548
 
519 549
 			// Ending tag.
520 550
 			echo '</', $key, '>';
@@ -534,8 +564,9 @@  discard block
 block discarded – undo
534 564
 {
535 565
 	global $scripturl, $smcFunc;
536 566
 
537
-	if (!allowedTo('view_mlist'))
538
-		return array();
567
+	if (!allowedTo('view_mlist')) {
568
+			return array();
569
+	}
539 570
 
540 571
 	// Find the most recent members.
541 572
 	$request = $smcFunc['db_query']('', '
@@ -551,35 +582,37 @@  discard block
 block discarded – undo
551 582
 	while ($row = $smcFunc['db_fetch_assoc']($request))
552 583
 	{
553 584
 		// Make the data look rss-ish.
554
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
555
-			$data[] = array(
585
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
586
+					$data[] = array(
556 587
 				'title' => $row['real_name'],
557 588
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
558 589
 				'comments' => $scripturl . '?action=pm;sa=send;u=' . $row['id_member'],
559 590
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['date_registered']),
560 591
 				'guid' => $scripturl . '?action=profile;u=' . $row['id_member'],
561 592
 			);
562
-		elseif ($xml_format == 'rdf')
563
-			$data[] = array(
593
+		} elseif ($xml_format == 'rdf') {
594
+					$data[] = array(
564 595
 				'title' => $row['real_name'],
565 596
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
566 597
 			);
567
-		elseif ($xml_format == 'atom')
568
-			$data[] = array(
598
+		} elseif ($xml_format == 'atom') {
599
+					$data[] = array(
569 600
 				'title' => $row['real_name'],
570 601
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
571 602
 				'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['date_registered']),
572 603
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['last_login']),
573 604
 				'id' => $scripturl . '?action=profile;u=' . $row['id_member'],
574 605
 			);
606
+		}
575 607
 		// More logical format for the data, but harder to apply.
576
-		else
577
-			$data[] = array(
608
+		else {
609
+					$data[] = array(
578 610
 				'name' => $row['real_name'],
579 611
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['date_registered']))),
580 612
 				'id' => $row['id_member'],
581 613
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member']
582 614
 			);
615
+		}
583 616
 	}
584 617
 	$smcFunc['db_free_result']($request);
585 618
 
@@ -640,22 +673,24 @@  discard block
 block discarded – undo
640 673
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
641 674
 		{
642 675
 			$smcFunc['db_free_result']($request);
643
-			if (empty($_REQUEST['boards']) && empty($board))
644
-				unset($context['optimize_msg']['lowest']);
645
-			else
646
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
676
+			if (empty($_REQUEST['boards']) && empty($board)) {
677
+							unset($context['optimize_msg']['lowest']);
678
+			} else {
679
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
680
+			}
647 681
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
648 682
 			$loops++;
683
+		} else {
684
+					$done = true;
649 685
 		}
650
-		else
651
-			$done = true;
652 686
 	}
653 687
 	$data = array();
654 688
 	while ($row = $smcFunc['db_fetch_assoc']($request))
655 689
 	{
656 690
 		// Limit the length of the message, if the option is set.
657
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
658
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
691
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
692
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
693
+		}
659 694
 
660 695
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
661 696
 
@@ -663,8 +698,8 @@  discard block
 block discarded – undo
663 698
 		censorText($row['subject']);
664 699
 
665 700
 		// Being news, this actually makes sense in rss format.
666
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
667
-			$data[] = array(
701
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
702
+					$data[] = array(
668 703
 				'title' => $row['subject'],
669 704
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
670 705
 				'description' => $row['body'],
@@ -674,14 +709,14 @@  discard block
 block discarded – undo
674 709
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
675 710
 				'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
676 711
 			);
677
-		elseif ($xml_format == 'rdf')
678
-			$data[] = array(
712
+		} elseif ($xml_format == 'rdf') {
713
+					$data[] = array(
679 714
 				'title' => $row['subject'],
680 715
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
681 716
 				'description' => $row['body'],
682 717
 			);
683
-		elseif ($xml_format == 'atom')
684
-			$data[] = array(
718
+		} elseif ($xml_format == 'atom') {
719
+					$data[] = array(
685 720
 				'title' => $row['subject'],
686 721
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
687 722
 				'summary' => $row['body'],
@@ -695,9 +730,10 @@  discard block
 block discarded – undo
695 730
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
696 731
 				'id' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
697 732
 			);
733
+		}
698 734
 		// The biggest difference here is more information.
699
-		else
700
-			$data[] = array(
735
+		else {
736
+					$data[] = array(
701 737
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['poster_time']))),
702 738
 				'id' => $row['id_topic'],
703 739
 				'subject' => $row['subject'],
@@ -715,6 +751,7 @@  discard block
 block discarded – undo
715 751
 				),
716 752
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
717 753
 			);
754
+		}
718 755
 	}
719 756
 	$smcFunc['db_free_result']($request);
720 757
 
@@ -761,22 +798,25 @@  discard block
 block discarded – undo
761 798
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
762 799
 		{
763 800
 			$smcFunc['db_free_result']($request);
764
-			if (empty($_REQUEST['boards']) && empty($board))
765
-				unset($context['optimize_msg']['lowest']);
766
-			else
767
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
801
+			if (empty($_REQUEST['boards']) && empty($board)) {
802
+							unset($context['optimize_msg']['lowest']);
803
+			} else {
804
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
805
+			}
768 806
 			$loops++;
807
+		} else {
808
+					$done = true;
769 809
 		}
770
-		else
771
-			$done = true;
772 810
 	}
773 811
 	$messages = array();
774
-	while ($row = $smcFunc['db_fetch_assoc']($request))
775
-		$messages[] = $row['id_msg'];
812
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
813
+			$messages[] = $row['id_msg'];
814
+	}
776 815
 	$smcFunc['db_free_result']($request);
777 816
 
778
-	if (empty($messages))
779
-		return array();
817
+	if (empty($messages)) {
818
+			return array();
819
+	}
780 820
 
781 821
 	// Find the most recent posts this user can see.
782 822
 	$request = $smcFunc['db_query']('', '
@@ -806,8 +846,9 @@  discard block
 block discarded – undo
806 846
 	while ($row = $smcFunc['db_fetch_assoc']($request))
807 847
 	{
808 848
 		// Limit the length of the message, if the option is set.
809
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
810
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
849
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
850
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
851
+		}
811 852
 
812 853
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
813 854
 
@@ -815,8 +856,8 @@  discard block
 block discarded – undo
815 856
 		censorText($row['subject']);
816 857
 
817 858
 		// Doesn't work as well as news, but it kinda does..
818
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
819
-			$data[] = array(
859
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
860
+					$data[] = array(
820 861
 				'title' => $row['subject'],
821 862
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
822 863
 				'description' => $row['body'],
@@ -826,14 +867,14 @@  discard block
 block discarded – undo
826 867
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
827 868
 				'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
828 869
 			);
829
-		elseif ($xml_format == 'rdf')
830
-			$data[] = array(
870
+		} elseif ($xml_format == 'rdf') {
871
+					$data[] = array(
831 872
 				'title' => $row['subject'],
832 873
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
833 874
 				'description' => $row['body'],
834 875
 			);
835
-		elseif ($xml_format == 'atom')
836
-			$data[] = array(
876
+		} elseif ($xml_format == 'atom') {
877
+					$data[] = array(
837 878
 				'title' => $row['subject'],
838 879
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
839 880
 				'summary' => $row['body'],
@@ -847,9 +888,10 @@  discard block
 block discarded – undo
847 888
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
848 889
 				'id' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
849 890
 			);
891
+		}
850 892
 		// A lot of information here.  Should be enough to please the rss-ers.
851
-		else
852
-			$data[] = array(
893
+		else {
894
+					$data[] = array(
853 895
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['poster_time']))),
854 896
 				'id' => $row['id_msg'],
855 897
 				'subject' => $row['subject'],
@@ -876,6 +918,7 @@  discard block
 block discarded – undo
876 918
 				),
877 919
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
878 920
 			);
921
+		}
879 922
 	}
880 923
 	$smcFunc['db_free_result']($request);
881 924
 
@@ -895,20 +938,22 @@  discard block
 block discarded – undo
895 938
 	global $scripturl, $memberContext, $user_profile, $user_info;
896 939
 
897 940
 	// You must input a valid user....
898
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
899
-		return array();
941
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
942
+			return array();
943
+	}
900 944
 
901 945
 	// Make sure the id is a number and not "I like trying to hack the database".
902 946
 	$_GET['u'] = (int) $_GET['u'];
903 947
 	// Load the member's contextual information!
904
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
905
-		return array();
948
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
949
+			return array();
950
+	}
906 951
 
907 952
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
908 953
 	$profile = &$memberContext[$_GET['u']];
909 954
 
910
-	if ($xml_format == 'rss' || $xml_format == 'rss2')
911
-		$data = array(array(
955
+	if ($xml_format == 'rss' || $xml_format == 'rss2') {
956
+			$data = array(array(
912 957
 			'title' => $profile['name'],
913 958
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
914 959
 			'description' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
@@ -916,14 +961,14 @@  discard block
 block discarded – undo
916 961
 			'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered']),
917 962
 			'guid' => $scripturl . '?action=profile;u=' . $profile['id'],
918 963
 		));
919
-	elseif ($xml_format == 'rdf')
920
-		$data = array(array(
964
+	} elseif ($xml_format == 'rdf') {
965
+			$data = array(array(
921 966
 			'title' => $profile['name'],
922 967
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
923 968
 			'description' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
924 969
 		));
925
-	elseif ($xml_format == 'atom')
926
-		$data[] = array(
970
+	} elseif ($xml_format == 'atom') {
971
+			$data[] = array(
927 972
 			'title' => $profile['name'],
928 973
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
929 974
 			'summary' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
@@ -937,7 +982,7 @@  discard block
 block discarded – undo
937 982
 			'id' => $scripturl . '?action=profile;u=' . $profile['id'],
938 983
 			'logo' => !empty($profile['avatar']) ? $profile['avatar']['url'] : '',
939 984
 		);
940
-	else
985
+	} else
941 986
 	{
942 987
 		$data = array(
943 988
 			'username' => $user_info['is_admin'] || $user_info['id'] == $profile['id'] ? $profile['username'] : '',
@@ -951,34 +996,43 @@  discard block
 block discarded – undo
951 996
 		);
952 997
 
953 998
 		// Everything below here might not be set, and thus maybe shouldn't be displayed.
954
-		if ($profile['gender']['name'] != '')
955
-			$data['gender'] = $profile['gender']['name'];
999
+		if ($profile['gender']['name'] != '') {
1000
+					$data['gender'] = $profile['gender']['name'];
1001
+		}
956 1002
 
957
-		if ($profile['avatar']['name'] != '')
958
-			$data['avatar'] = $profile['avatar']['url'];
1003
+		if ($profile['avatar']['name'] != '') {
1004
+					$data['avatar'] = $profile['avatar']['url'];
1005
+		}
959 1006
 
960 1007
 		// If they are online, show an empty tag... no reason to put anything inside it.
961
-		if ($profile['online']['is_online'])
962
-			$data['online'] = '';
963
-
964
-		if ($profile['signature'] != '')
965
-			$data['signature'] = $profile['signature'];
966
-		if ($profile['blurb'] != '')
967
-			$data['blurb'] = $profile['blurb'];
968
-		if ($profile['title'] != '')
969
-			$data['title'] = $profile['title'];
970
-
971
-		if ($profile['website']['title'] != '')
972
-			$data['website'] = array(
1008
+		if ($profile['online']['is_online']) {
1009
+					$data['online'] = '';
1010
+		}
1011
+
1012
+		if ($profile['signature'] != '') {
1013
+					$data['signature'] = $profile['signature'];
1014
+		}
1015
+		if ($profile['blurb'] != '') {
1016
+					$data['blurb'] = $profile['blurb'];
1017
+		}
1018
+		if ($profile['title'] != '') {
1019
+					$data['title'] = $profile['title'];
1020
+		}
1021
+
1022
+		if ($profile['website']['title'] != '') {
1023
+					$data['website'] = array(
973 1024
 				'title' => $profile['website']['title'],
974 1025
 				'link' => $profile['website']['url']
975 1026
 			);
1027
+		}
976 1028
 
977
-		if ($profile['group'] != '')
978
-			$data['position'] = $profile['group'];
1029
+		if ($profile['group'] != '') {
1030
+					$data['position'] = $profile['group'];
1031
+		}
979 1032
 
980
-		if ($profile['show_email'])
981
-			$data['email'] = $profile['email'];
1033
+		if ($profile['show_email']) {
1034
+					$data['email'] = $profile['email'];
1035
+		}
982 1036
 
983 1037
 		if (!empty($profile['birth_date']) && substr($profile['birth_date'], 0, 4) != '0000')
984 1038
 		{
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +282 added lines, -205 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 function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc, $modSettings;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -651,8 +686,9 @@  discard block
 block discarded – undo
651 686
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
652 687
 
653 688
 		// Did they not elect to choose this?
654
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
655
-			continue;
689
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
690
+					continue;
691
+		}
656 692
 
657 693
 		// Right character set!
658 694
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -668,39 +704,43 @@  discard block
 block discarded – undo
668 704
 		if (isset($types['topic']))
669 705
 		{
670 706
 			$titled = false;
671
-			foreach ($types['topic'] as $id => $board)
672
-				foreach ($board['lines'] as $topic)
707
+			foreach ($types['topic'] as $id => $board) {
708
+							foreach ($board['lines'] as $topic)
673 709
 					if (in_array($mid, $topic['members']))
674 710
 					{
675 711
 						if (!$titled)
676 712
 						{
677 713
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
714
+			}
678 715
 							$titled = true;
679 716
 						}
680 717
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
681 718
 					}
682
-			if ($titled)
683
-				$email['body'] .= "\n";
719
+			if ($titled) {
720
+							$email['body'] .= "\n";
721
+			}
684 722
 		}
685 723
 
686 724
 		// What about replies?
687 725
 		if (isset($types['reply']))
688 726
 		{
689 727
 			$titled = false;
690
-			foreach ($types['reply'] as $id => $board)
691
-				foreach ($board['lines'] as $topic)
728
+			foreach ($types['reply'] as $id => $board) {
729
+							foreach ($board['lines'] as $topic)
692 730
 					if (in_array($mid, $topic['members']))
693 731
 					{
694 732
 						if (!$titled)
695 733
 						{
696 734
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
735
+			}
697 736
 							$titled = true;
698 737
 						}
699 738
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
700 739
 					}
701 740
 
702
-			if ($titled)
703
-				$email['body'] .= "\n";
741
+			if ($titled) {
742
+							$email['body'] .= "\n";
743
+			}
704 744
 		}
705 745
 
706 746
 		// Finally, moderation actions!
@@ -709,24 +749,27 @@  discard block
 block discarded – undo
709 749
 			$titled = false;
710 750
 			foreach ($types as $note_type => $type)
711 751
 			{
712
-				if ($note_type == 'topic' || $note_type == 'reply')
713
-					continue;
752
+				if ($note_type == 'topic' || $note_type == 'reply') {
753
+									continue;
754
+				}
714 755
 
715
-				foreach ($type as $id => $board)
716
-					foreach ($board['lines'] as $topic)
756
+				foreach ($type as $id => $board) {
757
+									foreach ($board['lines'] as $topic)
717 758
 						if (in_array($mid, $topic['members']))
718 759
 						{
719 760
 							if (!$titled)
720 761
 							{
721 762
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
763
+				}
722 764
 								$titled = true;
723 765
 							}
724 766
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
725 767
 						}
726 768
 			}
727 769
 		}
728
-		if ($titled)
729
-			$email['body'] .= "\n";
770
+		if ($titled) {
771
+					$email['body'] .= "\n";
772
+		}
730 773
 
731 774
 		// Then just say our goodbyes!
732 775
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -754,8 +797,7 @@  discard block
 block discarded – undo
754 797
 				'not_daily' => 0,
755 798
 			)
756 799
 		);
757
-	}
758
-	else
800
+	} else
759 801
 	{
760 802
 		// Clear any only weekly ones, and stop us from sending daily again.
761 803
 		$smcFunc['db_query']('', '
@@ -817,16 +859,19 @@  discard block
 block discarded – undo
817 859
 	global $modSettings, $smcFunc, $sourcedir;
818 860
 
819 861
 	// Are we intending another script to be sending out the queue?
820
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
821
-		return false;
862
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
863
+			return false;
864
+	}
822 865
 
823 866
 	// By default send 5 at once.
824
-	if (!$number)
825
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
867
+	if (!$number) {
868
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
869
+	}
826 870
 
827 871
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
828
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
829
-		return false;
872
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
873
+			return false;
874
+	}
830 875
 
831 876
 	// By default move the next sending on by 10 seconds, and require an affected row.
832 877
 	if (!$override_limit)
@@ -843,8 +888,9 @@  discard block
 block discarded – undo
843 888
 				'last_send' => $modSettings['mail_next_send'],
844 889
 			)
845 890
 		);
846
-		if ($smcFunc['db_affected_rows']() == 0)
847
-			return false;
891
+		if ($smcFunc['db_affected_rows']() == 0) {
892
+					return false;
893
+		}
848 894
 		$modSettings['mail_next_send'] = time() + $delay;
849 895
 	}
850 896
 
@@ -865,8 +911,9 @@  discard block
 block discarded – undo
865 911
 			$mn += $number;
866 912
 		}
867 913
 		// No more I'm afraid, return!
868
-		else
869
-			return false;
914
+		else {
915
+					return false;
916
+		}
870 917
 
871 918
 		// Reflect that we're about to send some, do it now to be safe.
872 919
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -901,14 +948,15 @@  discard block
 block discarded – undo
901 948
 	$smcFunc['db_free_result']($request);
902 949
 
903 950
 	// Delete, delete, delete!!!
904
-	if (!empty($ids))
905
-		$smcFunc['db_query']('', '
951
+	if (!empty($ids)) {
952
+			$smcFunc['db_query']('', '
906 953
 			DELETE FROM {db_prefix}mail_queue
907 954
 			WHERE id_mail IN ({array_int:mail_list})',
908 955
 			array(
909 956
 				'mail_list' => $ids,
910 957
 			)
911 958
 		);
959
+	}
912 960
 
913 961
 	// Don't believe we have any left?
914 962
 	if (count($ids) < $number)
@@ -926,11 +974,13 @@  discard block
 block discarded – undo
926 974
 		);
927 975
 	}
928 976
 
929
-	if (empty($ids))
930
-		return false;
977
+	if (empty($ids)) {
978
+			return false;
979
+	}
931 980
 
932
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
933
-		require_once($sourcedir . '/Subs-Post.php');
981
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
982
+			require_once($sourcedir . '/Subs-Post.php');
983
+	}
934 984
 
935 985
 	// Send each email, yea!
936 986
 	$failed_emails = array();
@@ -950,15 +1000,17 @@  discard block
 block discarded – undo
950 1000
 
951 1001
 			// Try to stop a timeout, this would be bad...
952 1002
 			@set_time_limit(300);
953
-			if (function_exists('apache_reset_timeout'))
954
-				@apache_reset_timeout();
1003
+			if (function_exists('apache_reset_timeout')) {
1004
+							@apache_reset_timeout();
1005
+			}
1006
+		} else {
1007
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
955 1008
 		}
956
-		else
957
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
958 1009
 
959 1010
 		// Hopefully it sent?
960
-		if (!$result)
961
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1011
+		if (!$result) {
1012
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1013
+		}
962 1014
 	}
963 1015
 
964 1016
 	// Any emails that didn't send?
@@ -973,8 +1025,8 @@  discard block
 block discarded – undo
973 1025
 		);
974 1026
 
975 1027
 		// If we have failed to many times, tell mail to wait a bit and try again.
976
-		if ($modSettings['mail_failed_attempts'] > 5)
977
-			$smcFunc['db_query']('', '
1028
+		if ($modSettings['mail_failed_attempts'] > 5) {
1029
+					$smcFunc['db_query']('', '
978 1030
 				UPDATE {db_prefix}settings
979 1031
 				SET value = {string:next_mail_send}
980 1032
 				WHERE variable = {literal:mail_next_send}
@@ -983,6 +1035,7 @@  discard block
 block discarded – undo
983 1035
 					'next_mail_send' => time() + 60,
984 1036
 					'last_send' => $modSettings['mail_next_send'],
985 1037
 			));
1038
+		}
986 1039
 
987 1040
 		// Add our email back to the queue, manually.
988 1041
 		$smcFunc['db_insert']('insert',
@@ -995,8 +1048,8 @@  discard block
 block discarded – undo
995 1048
 		return false;
996 1049
 	}
997 1050
 	// We where unable to send the email, clear our failed attempts.
998
-	elseif (!empty($modSettings['mail_failed_attempts']))
999
-		$smcFunc['db_query']('', '
1051
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1052
+			$smcFunc['db_query']('', '
1000 1053
 			UPDATE {db_prefix}settings
1001 1054
 			SET value = {string:zero}
1002 1055
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1004,6 +1057,7 @@  discard block
 block discarded – undo
1004 1057
 				'zero' => '0',
1005 1058
 				'mail_failed_attempts' => 'mail_failed_attempts',
1006 1059
 		));
1060
+	}
1007 1061
 
1008 1062
 	// Had something to send...
1009 1063
 	return true;
@@ -1020,16 +1074,18 @@  discard block
 block discarded – undo
1020 1074
 	global $modSettings, $smcFunc;
1021 1075
 
1022 1076
 	$task_query = '';
1023
-	if (!is_array($tasks))
1024
-		$tasks = array($tasks);
1077
+	if (!is_array($tasks)) {
1078
+			$tasks = array($tasks);
1079
+	}
1025 1080
 
1026 1081
 	// Actually have something passed?
1027 1082
 	if (!empty($tasks))
1028 1083
 	{
1029
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1030
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1031
-		else
1032
-			$task_query = ' AND task IN ({array_string:tasks})';
1084
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1085
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1086
+		} else {
1087
+					$task_query = ' AND task IN ({array_string:tasks})';
1088
+		}
1033 1089
 	}
1034 1090
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1035 1091
 
@@ -1050,20 +1106,22 @@  discard block
 block discarded – undo
1050 1106
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1051 1107
 
1052 1108
 		// Only bother moving the task if it's out of place or we're forcing it!
1053
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1054
-			$tasks[$row['id_task']] = $next_time;
1055
-		else
1056
-			$next_time = $row['next_time'];
1109
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1110
+					$tasks[$row['id_task']] = $next_time;
1111
+		} else {
1112
+					$next_time = $row['next_time'];
1113
+		}
1057 1114
 
1058 1115
 		// If this is sooner than the current next task, make this the next task.
1059
-		if ($next_time < $nextTaskTime)
1060
-			$nextTaskTime = $next_time;
1116
+		if ($next_time < $nextTaskTime) {
1117
+					$nextTaskTime = $next_time;
1118
+		}
1061 1119
 	}
1062 1120
 	$smcFunc['db_free_result']($request);
1063 1121
 
1064 1122
 	// Now make the changes!
1065
-	foreach ($tasks as $id => $time)
1066
-		$smcFunc['db_query']('', '
1123
+	foreach ($tasks as $id => $time) {
1124
+			$smcFunc['db_query']('', '
1067 1125
 			UPDATE {db_prefix}scheduled_tasks
1068 1126
 			SET next_time = {int:next_time}
1069 1127
 			WHERE id_task = {int:id_task}',
@@ -1072,11 +1130,13 @@  discard block
 block discarded – undo
1072 1130
 				'id_task' => $id,
1073 1131
 			)
1074 1132
 		);
1133
+	}
1075 1134
 
1076 1135
 	// If the next task is now different update.
1077
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1078
-		updateSettings(array('next_task_time' => $nextTaskTime));
1079
-}
1136
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1137
+			updateSettings(array('next_task_time' => $nextTaskTime));
1138
+	}
1139
+	}
1080 1140
 
1081 1141
 /**
1082 1142
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1089,8 +1149,9 @@  discard block
 block discarded – undo
1089 1149
 function next_time($regularity, $unit, $offset)
1090 1150
 {
1091 1151
 	// Just in case!
1092
-	if ($regularity == 0)
1093
-		$regularity = 2;
1152
+	if ($regularity == 0) {
1153
+			$regularity = 2;
1154
+	}
1094 1155
 
1095 1156
 	$curHour = date('H', time());
1096 1157
 	$curMin = date('i', time());
@@ -1102,15 +1163,16 @@  discard block
 block discarded – undo
1102 1163
 		$off = date('i', $offset);
1103 1164
 
1104 1165
 		// If it's now just pretend it ain't,
1105
-		if ($off == $curMin)
1106
-			$next_time = time() + $regularity;
1107
-		else
1166
+		if ($off == $curMin) {
1167
+					$next_time = time() + $regularity;
1168
+		} else
1108 1169
 		{
1109 1170
 			// Make sure that the offset is always in the past.
1110 1171
 			$off = $off > $curMin ? $off - 60 : $off;
1111 1172
 
1112
-			while ($off <= $curMin)
1113
-				$off += $regularity;
1173
+			while ($off <= $curMin) {
1174
+							$off += $regularity;
1175
+			}
1114 1176
 
1115 1177
 			// Now we know when the time should be!
1116 1178
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1130,11 +1192,13 @@  discard block
 block discarded – undo
1130 1192
 		// Default we'll jump in hours.
1131 1193
 		$applyOffset = 3600;
1132 1194
 		// 24 hours = 1 day.
1133
-		if ($unit == 'd')
1134
-			$applyOffset = 86400;
1195
+		if ($unit == 'd') {
1196
+					$applyOffset = 86400;
1197
+		}
1135 1198
 		// Otherwise a week.
1136
-		if ($unit == 'w')
1137
-			$applyOffset = 604800;
1199
+		if ($unit == 'w') {
1200
+					$applyOffset = 604800;
1201
+		}
1138 1202
 
1139 1203
 		$applyOffset *= $regularity;
1140 1204
 
@@ -1171,8 +1235,9 @@  discard block
 block discarded – undo
1171 1235
 		$settings[$row['variable']] = $row['value'];
1172 1236
 
1173 1237
 		// Is this the default theme?
1174
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1175
-			$settings['default_' . $row['variable']] = $row['value'];
1238
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1239
+					$settings['default_' . $row['variable']] = $row['value'];
1240
+		}
1176 1241
 	}
1177 1242
 	$smcFunc['db_free_result']($result);
1178 1243
 
@@ -1182,12 +1247,14 @@  discard block
 block discarded – undo
1182 1247
 		$settings['template_dirs'] = array($settings['theme_dir']);
1183 1248
 
1184 1249
 		// Based on theme (if there is one).
1185
-		if (!empty($settings['base_theme_dir']))
1186
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1250
+		if (!empty($settings['base_theme_dir'])) {
1251
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1252
+		}
1187 1253
 
1188 1254
 		// Lastly the default theme.
1189
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1190
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1255
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1256
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1257
+		}
1191 1258
 	}
1192 1259
 
1193 1260
 	// Assume we want this.
@@ -1333,8 +1400,9 @@  discard block
 block discarded – undo
1333 1400
 	// Ok should we prune the logs?
1334 1401
 	if (!empty($modSettings['pruningOptions']))
1335 1402
 	{
1336
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1337
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1403
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1404
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1405
+		}
1338 1406
 
1339 1407
 		if (!empty($modSettings['pruneErrorLog']))
1340 1408
 		{
@@ -1400,8 +1468,9 @@  discard block
 block discarded – undo
1400 1468
 				)
1401 1469
 			);
1402 1470
 
1403
-			while ($row = $smcFunc['db_fetch_row']($result))
1404
-				$reports[] = $row[0];
1471
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1472
+							$reports[] = $row[0];
1473
+			}
1405 1474
 
1406 1475
 			$smcFunc['db_free_result']($result);
1407 1476
 
@@ -1563,8 +1632,9 @@  discard block
 block discarded – undo
1563 1632
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1564 1633
 
1565 1634
 		// Send the actual email.
1566
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1567
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1635
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1636
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1637
+		}
1568 1638
 
1569 1639
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1570 1640
 		{
@@ -1587,18 +1657,19 @@  discard block
 block discarded – undo
1587 1657
 	}
1588 1658
 
1589 1659
 	// Insert the alerts if any
1590
-	if (!empty($alert_rows))
1591
-		$smcFunc['db_insert']('',
1660
+	if (!empty($alert_rows)) {
1661
+			$smcFunc['db_insert']('',
1592 1662
 			'{db_prefix}user_alerts',
1593 1663
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1594 1664
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1595 1665
 			$alert_rows,
1596 1666
 			array()
1597 1667
 		);
1668
+	}
1598 1669
 
1599 1670
 	// Mark the reminder as sent.
1600
-	if (!empty($subs_reminded))
1601
-		$smcFunc['db_query']('', '
1671
+	if (!empty($subs_reminded)) {
1672
+			$smcFunc['db_query']('', '
1602 1673
 			UPDATE {db_prefix}log_subscribed
1603 1674
 			SET reminder_sent = {int:reminder_sent}
1604 1675
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1607,6 +1678,7 @@  discard block
 block discarded – undo
1607 1678
 				'reminder_sent' => 1,
1608 1679
 			)
1609 1680
 		);
1681
+	}
1610 1682
 
1611 1683
 	return true;
1612 1684
 }
@@ -1622,13 +1694,13 @@  discard block
 block discarded – undo
1622 1694
 	// We need to know where this thing is going.
1623 1695
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1624 1696
 	{
1625
-		if (!is_array($modSettings['attachmentUploadDir']))
1626
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1697
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1698
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1699
+		}
1627 1700
 
1628 1701
 		// Just use the current path for temp files.
1629 1702
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1630
-	}
1631
-	else
1703
+	} else
1632 1704
 	{
1633 1705
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1634 1706
 	}
@@ -1647,14 +1719,16 @@  discard block
 block discarded – undo
1647 1719
 
1648 1720
 		while ($file = readdir($dir))
1649 1721
 		{
1650
-			if ($file == '.' || $file == '..')
1651
-				continue;
1722
+			if ($file == '.' || $file == '..') {
1723
+							continue;
1724
+			}
1652 1725
 
1653 1726
 			if (strpos($file, 'post_tmp_') !== false)
1654 1727
 			{
1655 1728
 				// Temp file is more than 5 hours old!
1656
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1657
-					@unlink($attach_dir . '/' . $file);
1729
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1730
+									@unlink($attach_dir . '/' . $file);
1731
+				}
1658 1732
 			}
1659 1733
 		}
1660 1734
 		closedir($dir);
@@ -1687,8 +1761,9 @@  discard block
 block discarded – undo
1687 1761
 		)
1688 1762
 	);
1689 1763
 
1690
-	while ($row = $smcFunc['db_fetch_row']($request))
1691
-		$topics[] = $row[0];
1764
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1765
+			$topics[] = $row[0];
1766
+	}
1692 1767
 	$smcFunc['db_free_result']($request);
1693 1768
 
1694 1769
 	// Zap, your gone
@@ -1708,8 +1783,9 @@  discard block
 block discarded – undo
1708 1783
 {
1709 1784
 	global $smcFunc, $sourcedir, $modSettings;
1710 1785
 
1711
-	if (empty($modSettings['drafts_keep_days']))
1712
-		return true;
1786
+	if (empty($modSettings['drafts_keep_days'])) {
1787
+			return true;
1788
+	}
1713 1789
 
1714 1790
 	// init
1715 1791
 	$drafts = array();
@@ -1727,8 +1803,9 @@  discard block
 block discarded – undo
1727 1803
 		)
1728 1804
 	);
1729 1805
 
1730
-	while ($row = $smcFunc['db_fetch_row']($request))
1731
-		$drafts[] = (int) $row[0];
1806
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1807
+			$drafts[] = (int) $row[0];
1808
+	}
1732 1809
 	$smcFunc['db_free_result']($request);
1733 1810
 
1734 1811
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/ManagePosts.php 1 patch
Braces   +39 added lines, -29 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
  * The main entrance point for the 'Posts and topics' screen.
@@ -98,23 +99,23 @@  discard block
 block discarded – undo
98 99
 		{
99 100
 			$_POST['censortext'] = explode("\n", strtr($_POST['censortext'], array("\r" => '')));
100 101
 
101
-			foreach ($_POST['censortext'] as $c)
102
-				list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
103
-		}
104
-		elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
102
+			foreach ($_POST['censortext'] as $c) {
103
+							list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
104
+			}
105
+		} elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
105 106
 		{
106 107
 			if (is_array($_POST['censor_vulgar']))
107 108
 			{
108 109
 				foreach ($_POST['censor_vulgar'] as $i => $value)
109 110
 				{
110
-					if (trim(strtr($value, '*', ' ')) == '')
111
-						unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
111
+					if (trim(strtr($value, '*', ' ')) == '') {
112
+											unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
113
+					}
112 114
 				}
113 115
 
114 116
 				$censored_vulgar = $_POST['censor_vulgar'];
115 117
 				$censored_proper = $_POST['censor_proper'];
116
-			}
117
-			else
118
+			} else
118 119
 			{
119 120
 				$censored_vulgar = explode("\n", strtr($_POST['censor_vulgar'], array("\r" => '')));
120 121
 				$censored_proper = explode("\n", strtr($_POST['censor_proper'], array("\r" => '')));
@@ -151,12 +152,14 @@  discard block
 block discarded – undo
151 152
 	$context['censored_words'] = array();
152 153
 	for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++)
153 154
 	{
154
-		if (empty($censor_vulgar[$i]))
155
-			continue;
155
+		if (empty($censor_vulgar[$i])) {
156
+					continue;
157
+		}
156 158
 
157 159
 		// Skip it, it's either spaces or stars only.
158
-		if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '')
159
-			continue;
160
+		if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '') {
161
+					continue;
162
+		}
160 163
 
161 164
 		$context['censored_words'][$smcFunc['htmlspecialchars'](trim($censor_vulgar[$i]))] = isset($censor_proper[$i]) ? $smcFunc['htmlspecialchars']($censor_proper[$i]) : '';
162 165
 	}
@@ -187,10 +190,11 @@  discard block
 block discarded – undo
187 190
 
188 191
 	// Make an inline conditional a little shorter...
189 192
 	$can_spell_check = false;
190
-	if (function_exists('pspell_new'))
191
-		$can_spell_check = true;
192
-	elseif (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))
193
-		$can_spell_check = true;
193
+	if (function_exists('pspell_new')) {
194
+			$can_spell_check = true;
195
+	} elseif (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))) {
196
+			$can_spell_check = true;
197
+	}
194 198
 
195 199
 	// All the settings...
196 200
 	$config_vars = array(
@@ -221,8 +225,9 @@  discard block
 block discarded – undo
221 225
 
222 226
 	call_integration_hook('integrate_modify_post_settings', array(&$config_vars));
223 227
 
224
-	if ($return_config)
225
-		return $config_vars;
228
+	if ($return_config) {
229
+			return $config_vars;
230
+	}
226 231
 
227 232
 	// We'll want this for our easy save.
228 233
 	require_once($sourcedir . '/ManageServer.php');
@@ -242,17 +247,20 @@  discard block
 block discarded – undo
242 247
 			db_extend('packages');
243 248
 
244 249
 			$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
245
-			foreach ($colData as $column)
246
-				if ($column['name'] == 'body')
250
+			foreach ($colData as $column) {
251
+							if ($column['name'] == 'body')
247 252
 					$body_type = $column['type'];
253
+			}
248 254
 
249
-			if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text')
250
-				fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
255
+			if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text') {
256
+							fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
257
+			}
251 258
 		}
252 259
 
253 260
 		// If we're changing the post preview length let's check its valid
254
-		if (!empty($_POST['preview_characters']))
255
-			$_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
261
+		if (!empty($_POST['preview_characters'])) {
262
+					$_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
263
+		}
256 264
 
257 265
 		call_integration_hook('integrate_save_post_settings');
258 266
 
@@ -313,8 +321,9 @@  discard block
 block discarded – undo
313 321
 
314 322
 	call_integration_hook('integrate_modify_topic_settings', array(&$config_vars));
315 323
 
316
-	if ($return_config)
317
-		return $config_vars;
324
+	if ($return_config) {
325
+			return $config_vars;
326
+	}
318 327
 
319 328
 	// Get the settings template ready.
320 329
 	require_once($sourcedir . '/ManageServer.php');
@@ -367,8 +376,9 @@  discard block
 block discarded – undo
367 376
 		array('int', 'drafts_autosave_frequency', 'postinput' => $txt['manageposts_seconds'], 'subtext' => $txt['drafts_autosave_frequency_subnote']),
368 377
 	);
369 378
 
370
-	if ($return_config)
371
-		return $config_vars;
379
+	if ($return_config) {
380
+			return $config_vars;
381
+	}
372 382
 
373 383
 	// Get the settings template ready.
374 384
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 1 patch
Braces   +633 added lines, -471 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
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -356,8 +361,9 @@  discard block
 block discarded – undo
356 361
 	unset($pm_areas);
357 362
 
358 363
 	// No menu means no access.
359
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
360
-		fatal_lang_error('no_access', false);
364
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
365
+			fatal_lang_error('no_access', false);
366
+	}
361 367
 
362 368
 	// Make a note of the Unique ID for this menu.
363 369
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -368,9 +374,10 @@  discard block
 block discarded – undo
368 374
 	$context['menu_item_selected'] = $current_area;
369 375
 
370 376
 	// Set the template for this area and add the profile layer.
371
-	if (!isset($_REQUEST['xml']))
372
-		$context['template_layers'][] = 'pm';
373
-}
377
+	if (!isset($_REQUEST['xml'])) {
378
+			$context['template_layers'][] = 'pm';
379
+	}
380
+	}
374 381
 
375 382
 /**
376 383
  * The popup for when we ask for the popup from the user.
@@ -402,8 +409,9 @@  discard block
 block discarded – undo
402 409
 		)
403 410
 	);
404 411
 	$pms = array();
405
-	while ($row = $smcFunc['db_fetch_row']($request))
406
-		$pms[] = $row[0];
412
+	while ($row = $smcFunc['db_fetch_row']($request)) {
413
+			$pms[] = $row[0];
414
+	}
407 415
 	$smcFunc['db_free_result']($request);
408 416
 
409 417
 	if (!empty($pms))
@@ -431,8 +439,9 @@  discard block
 block discarded – undo
431 439
 		);
432 440
 		while ($row = $smcFunc['db_fetch_assoc']($request))
433 441
 		{
434
-			if (!empty($row['id_member_from']))
435
-				$senders[] = $row['id_member_from'];
442
+			if (!empty($row['id_member_from'])) {
443
+							$senders[] = $row['id_member_from'];
444
+			}
436 445
 
437 446
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
438 447
 			$row['time'] = timeformat($row['timestamp']);
@@ -442,13 +451,15 @@  discard block
 block discarded – undo
442 451
 		$smcFunc['db_free_result']($request);
443 452
 
444 453
 		$senders = loadMemberData($senders);
445
-		foreach ($senders as $member)
446
-			loadMemberContext($member);
454
+		foreach ($senders as $member) {
455
+					loadMemberContext($member);
456
+		}
447 457
 
448 458
 		// Having loaded everyone, attach them to the PMs.
449
-		foreach ($context['unread_pms'] as $id_pm => $details)
450
-			if (!empty($memberContext[$details['id_member_from']]))
459
+		foreach ($context['unread_pms'] as $id_pm => $details) {
460
+					if (!empty($memberContext[$details['id_member_from']]))
451 461
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
462
+		}
452 463
 	}
453 464
 }
454 465
 
@@ -468,12 +479,13 @@  discard block
 block discarded – undo
468 479
 	}
469 480
 
470 481
 	// Make sure the starting location is valid.
471
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
472
-		$_GET['start'] = (int) $_GET['start'];
473
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
474
-		$_GET['start'] = 0;
475
-	else
476
-		$_GET['start'] = 'new';
482
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
483
+			$_GET['start'] = (int) $_GET['start'];
484
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
485
+			$_GET['start'] = 0;
486
+	} else {
487
+			$_GET['start'] = 'new';
488
+	}
477 489
 
478 490
 	// Set up some basic theme stuff.
479 491
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -490,8 +502,7 @@  discard block
 block discarded – undo
490 502
 	{
491 503
 		$labelQuery = '
492 504
 			AND pmr.in_inbox = 1';
493
-	}
494
-	elseif ($context['folder'] != 'sent')
505
+	} elseif ($context['folder'] != 'sent')
495 506
 	{
496 507
 		$labelJoin = '
497 508
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -533,22 +544,24 @@  discard block
 block discarded – undo
533 544
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
534 545
 
535 546
 	// Now, build the link tree!
536
-	if ($context['current_label_id'] == -1)
537
-		$context['linktree'][] = array(
547
+	if ($context['current_label_id'] == -1) {
548
+			$context['linktree'][] = array(
538 549
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
539 550
 			'name' => $pmbox
540 551
 		);
552
+	}
541 553
 
542 554
 	// Build it further for a label.
543
-	if ($context['current_label_id'] != -1)
544
-		$context['linktree'][] = array(
555
+	if ($context['current_label_id'] != -1) {
556
+			$context['linktree'][] = array(
545 557
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
546 558
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
547 559
 		);
560
+	}
548 561
 
549 562
 	// Figure out how many messages there are.
550
-	if ($context['folder'] == 'sent')
551
-		$request = $smcFunc['db_query']('', '
563
+	if ($context['folder'] == 'sent') {
564
+			$request = $smcFunc['db_query']('', '
552 565
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
553 566
 			FROM {db_prefix}personal_messages AS pm
554 567
 			WHERE pm.id_member_from = {int:current_member}
@@ -558,8 +571,8 @@  discard block
 block discarded – undo
558 571
 				'not_deleted' => 0,
559 572
 			)
560 573
 		);
561
-	else
562
-		$request = $smcFunc['db_query']('', '
574
+	} else {
575
+			$request = $smcFunc['db_query']('', '
563 576
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
564 577
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
565 578
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -570,6 +583,7 @@  discard block
 block discarded – undo
570 583
 				'not_deleted' => 0,
571 584
 			)
572 585
 		);
586
+	}
573 587
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
574 588
 	$smcFunc['db_free_result']($request);
575 589
 
@@ -578,10 +592,11 @@  discard block
 block discarded – undo
578 592
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
579 593
 
580 594
 	// Start on the last page.
581
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
582
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
583
-	elseif ($_GET['start'] < 0)
584
-		$_GET['start'] = 0;
595
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
596
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
597
+	} elseif ($_GET['start'] < 0) {
598
+			$_GET['start'] = 0;
599
+	}
585 600
 
586 601
 	// ... but wait - what if we want to start from a specific message?
587 602
 	if (isset($_GET['pmid']))
@@ -589,19 +604,21 @@  discard block
 block discarded – undo
589 604
 		$pmID = (int) $_GET['pmid'];
590 605
 
591 606
 		// Make sure you have access to this PM.
592
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
593
-			fatal_lang_error('no_access', false);
607
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
608
+					fatal_lang_error('no_access', false);
609
+		}
594 610
 
595 611
 		$context['current_pm'] = $pmID;
596 612
 
597 613
 		// With only one page of PM's we're gonna want page 1.
598
-		if ($max_messages <= $maxPerPage)
599
-			$_GET['start'] = 0;
614
+		if ($max_messages <= $maxPerPage) {
615
+					$_GET['start'] = 0;
616
+		}
600 617
 		// If we pass kstart we assume we're in the right place.
601 618
 		elseif (!isset($_GET['kstart']))
602 619
 		{
603
-			if ($context['folder'] == 'sent')
604
-				$request = $smcFunc['db_query']('', '
620
+			if ($context['folder'] == 'sent') {
621
+							$request = $smcFunc['db_query']('', '
605 622
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
606 623
 					FROM {db_prefix}personal_messages
607 624
 					WHERE id_member_from = {int:current_member}
@@ -613,8 +630,8 @@  discard block
 block discarded – undo
613 630
 						'id_pm' => $pmID,
614 631
 					)
615 632
 				);
616
-			else
617
-				$request = $smcFunc['db_query']('', '
633
+			} else {
634
+							$request = $smcFunc['db_query']('', '
618 635
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
619 636
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
620 637
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -627,6 +644,7 @@  discard block
 block discarded – undo
627 644
 						'id_pm' => $pmID,
628 645
 					)
629 646
 				);
647
+			}
630 648
 
631 649
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
632 650
 			$smcFunc['db_free_result']($request);
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 	{
642 660
 		$pmsg = (int) $_GET['pmsg'];
643 661
 
644
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
645
-			fatal_lang_error('no_access', false);
662
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
663
+					fatal_lang_error('no_access', false);
664
+		}
646 665
 	}
647 666
 
648 667
 	// Set up the page index.
@@ -737,8 +756,9 @@  discard block
 block discarded – undo
737 756
 	{
738 757
 		if (!isset($recipients[$row['id_pm']]))
739 758
 		{
740
-			if (isset($row['id_member_from']))
741
-				$posters[$row['id_pm']] = $row['id_member_from'];
759
+			if (isset($row['id_member_from'])) {
760
+							$posters[$row['id_pm']] = $row['id_member_from'];
761
+			}
742 762
 			$pms[$row['id_pm']] = $row['id_pm'];
743 763
 			$recipients[$row['id_pm']] = array(
744 764
 				'to' => array(),
@@ -747,29 +767,33 @@  discard block
 block discarded – undo
747 767
 		}
748 768
 
749 769
 		// Keep track of the last message so we know what the head is without another query!
750
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
751
-			$lastData = array(
770
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
771
+					$lastData = array(
752 772
 				'id' => $row['id_pm'],
753 773
 				'head' => $row['id_pm_head'],
754 774
 			);
775
+		}
755 776
 	}
756 777
 	$smcFunc['db_free_result']($request);
757 778
 
758 779
 	// Make sure that we have been given a correct head pm id!
759
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
760
-		fatal_lang_error('no_access', false);
780
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
781
+			fatal_lang_error('no_access', false);
782
+	}
761 783
 
762 784
 	if (!empty($pms))
763 785
 	{
764 786
 		// Select the correct current message.
765
-		if (empty($pmID))
766
-			$context['current_pm'] = $lastData['id'];
787
+		if (empty($pmID)) {
788
+					$context['current_pm'] = $lastData['id'];
789
+		}
767 790
 
768 791
 		// This is a list of the pm's that are used for "full" display.
769
-		if ($context['display_mode'] == 0)
770
-			$display_pms = $pms;
771
-		else
772
-			$display_pms = array($context['current_pm']);
792
+		if ($context['display_mode'] == 0) {
793
+					$display_pms = $pms;
794
+		} else {
795
+					$display_pms = array($context['current_pm']);
796
+		}
773 797
 
774 798
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
775 799
 		if ($context['display_mode'] == 2)
@@ -791,16 +815,18 @@  discard block
 block discarded – undo
791 815
 			while ($row = $smcFunc['db_fetch_assoc']($request))
792 816
 			{
793 817
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
794
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
795
-					continue;
796
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
797
-					continue;
818
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
819
+									continue;
820
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
821
+									continue;
822
+				}
798 823
 
799
-				if (!isset($recipients[$row['id_pm']]))
800
-					$recipients[$row['id_pm']] = array(
824
+				if (!isset($recipients[$row['id_pm']])) {
825
+									$recipients[$row['id_pm']] = array(
801 826
 						'to' => array(),
802 827
 						'bcc' => array()
803 828
 					);
829
+				}
804 830
 				$display_pms[] = $row['id_pm'];
805 831
 				$posters[$row['id_pm']] = $row['id_member_from'];
806 832
 			}
@@ -851,8 +877,9 @@  discard block
 block discarded – undo
851 877
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
852 878
 				{
853 879
 					$l_id = $row2['id_label'];
854
-					if (isset($context['labels'][$l_id]))
855
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
880
+					if (isset($context['labels'][$l_id])) {
881
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
882
+					}
856 883
 				}
857 884
 
858 885
 				$smcFunc['db_free_result']($request2);
@@ -869,9 +896,10 @@  discard block
 block discarded – undo
869 896
 		// Make sure we don't load unnecessary data.
870 897
 		if ($context['display_mode'] == 1)
871 898
 		{
872
-			foreach ($posters as $k => $v)
873
-				if (!in_array($k, $display_pms))
899
+			foreach ($posters as $k => $v) {
900
+							if (!in_array($k, $display_pms))
874 901
 					unset($posters[$k]);
902
+			}
875 903
 		}
876 904
 
877 905
 		// Load any users....
@@ -882,8 +910,9 @@  discard block
 block discarded – undo
882 910
 		{
883 911
 			// Get the order right.
884 912
 			$orderBy = array();
885
-			foreach (array_reverse($pms) as $pm)
886
-				$orderBy[] = 'pm.id_pm = ' . $pm;
913
+			foreach (array_reverse($pms) as $pm) {
914
+							$orderBy[] = 'pm.id_pm = ' . $pm;
915
+			}
887 916
 
888 917
 			// Seperate query for these bits!
889 918
 			$subjects_request = $smcFunc['db_query']('', '
@@ -929,9 +958,9 @@  discard block
 block discarded – undo
929 958
 			// Allow mods to add additional buttons here
930 959
 			call_integration_hook('integrate_conversation_buttons');
931 960
 		}
961
+	} else {
962
+			$messages_request = false;
932 963
 	}
933
-	else
934
-		$messages_request = false;
935 964
 
936 965
 	$context['can_send_pm'] = allowedTo('pm_send');
937 966
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -942,11 +971,13 @@  discard block
 block discarded – undo
942 971
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
943 972
 	{
944 973
 		// If the display mode is "old sk00l" do them all...
945
-		if ($context['display_mode'] == 0)
946
-			markMessages(null, $context['current_label_id']);
974
+		if ($context['display_mode'] == 0) {
975
+					markMessages(null, $context['current_label_id']);
976
+		}
947 977
 		// Otherwise do just the current one!
948
-		elseif (!empty($context['current_pm']))
949
-			markMessages($display_pms, $context['current_label_id']);
978
+		elseif (!empty($context['current_pm'])) {
979
+					markMessages($display_pms, $context['current_label_id']);
980
+		}
950 981
 	}
951 982
 }
952 983
 
@@ -964,8 +995,9 @@  discard block
 block discarded – undo
964 995
 
965 996
 	// Count the current message number....
966 997
 	static $counter = null;
967
-	if ($counter === null || $reset)
968
-		$counter = $context['start'];
998
+	if ($counter === null || $reset) {
999
+			$counter = $context['start'];
1000
+	}
969 1001
 
970 1002
 	static $temp_pm_selected = null;
971 1003
 	if ($temp_pm_selected === null)
@@ -1010,19 +1042,22 @@  discard block
 block discarded – undo
1010 1042
 	}
1011 1043
 
1012 1044
 	// Bail if it's false, ie. no messages.
1013
-	if ($messages_request == false)
1014
-		return false;
1045
+	if ($messages_request == false) {
1046
+			return false;
1047
+	}
1015 1048
 
1016 1049
 	// Reset the data?
1017
-	if ($reset == true)
1018
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1050
+	if ($reset == true) {
1051
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1052
+	}
1019 1053
 
1020 1054
 	// Get the next one... bail if anything goes wrong.
1021 1055
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1022 1056
 	if (!$message)
1023 1057
 	{
1024
-		if ($type != 'subject')
1025
-			$smcFunc['db_free_result']($messages_request);
1058
+		if ($type != 'subject') {
1059
+					$smcFunc['db_free_result']($messages_request);
1060
+		}
1026 1061
 
1027 1062
 		return false;
1028 1063
 	}
@@ -1042,8 +1077,7 @@  discard block
 block discarded – undo
1042 1077
 		$memberContext[$message['id_member_from']]['email'] = '';
1043 1078
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1044 1079
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1045
-	}
1046
-	else
1080
+	} else
1047 1081
 	{
1048 1082
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1049 1083
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1084,12 +1118,13 @@  discard block
 block discarded – undo
1084 1118
 	$counter++;
1085 1119
 
1086 1120
 	// Any custom profile fields?
1087
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1088
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1121
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1122
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1089 1123
 			switch ($custom['placement'])
1090 1124
 			{
1091 1125
 				case 1:
1092 1126
 					$output['custom_fields']['icons'][] = $custom;
1127
+	}
1093 1128
 					break;
1094 1129
 				case 2:
1095 1130
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1132,22 +1167,28 @@  discard block
 block discarded – undo
1132 1167
 			$context['search_params'][$k] = $v;
1133 1168
 		}
1134 1169
 	}
1135
-	if (isset($_REQUEST['search']))
1136
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1170
+	if (isset($_REQUEST['search'])) {
1171
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1172
+	}
1137 1173
 
1138
-	if (isset($context['search_params']['search']))
1139
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1140
-	if (isset($context['search_params']['userspec']))
1141
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1174
+	if (isset($context['search_params']['search'])) {
1175
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1176
+	}
1177
+	if (isset($context['search_params']['userspec'])) {
1178
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1179
+	}
1142 1180
 
1143
-	if (!empty($context['search_params']['searchtype']))
1144
-		$context['search_params']['searchtype'] = 2;
1181
+	if (!empty($context['search_params']['searchtype'])) {
1182
+			$context['search_params']['searchtype'] = 2;
1183
+	}
1145 1184
 
1146
-	if (!empty($context['search_params']['minage']))
1147
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1185
+	if (!empty($context['search_params']['minage'])) {
1186
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1187
+	}
1148 1188
 
1149
-	if (!empty($context['search_params']['maxage']))
1150
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1189
+	if (!empty($context['search_params']['maxage'])) {
1190
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1191
+	}
1151 1192
 
1152 1193
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1153 1194
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1174,8 +1215,9 @@  discard block
 block discarded – undo
1174 1215
 		$context['search_errors']['messages'] = array();
1175 1216
 		foreach ($context['search_errors'] as $search_error => $dummy)
1176 1217
 		{
1177
-			if ($search_error == 'messages')
1178
-				continue;
1218
+			if ($search_error == 'messages') {
1219
+							continue;
1220
+			}
1179 1221
 
1180 1222
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1181 1223
 		}
@@ -1197,8 +1239,9 @@  discard block
 block discarded – undo
1197 1239
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1198 1240
 	global $memberContext, $smcFunc;
1199 1241
 
1200
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1201
-		fatal_lang_error('loadavg_search_disabled', false);
1242
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1243
+			fatal_lang_error('loadavg_search_disabled', false);
1244
+	}
1202 1245
 
1203 1246
 	/**
1204 1247
 	 * @todo For the moment force the folder to the inbox.
@@ -1227,35 +1270,40 @@  discard block
 block discarded – undo
1227 1270
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1228 1271
 
1229 1272
 	// Store whether simple search was used (needed if the user wants to do another query).
1230
-	if (!isset($search_params['advanced']))
1231
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1273
+	if (!isset($search_params['advanced'])) {
1274
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1275
+	}
1232 1276
 
1233 1277
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1234
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1235
-		$search_params['searchtype'] = 2;
1278
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1279
+			$search_params['searchtype'] = 2;
1280
+	}
1236 1281
 
1237 1282
 	// Minimum age of messages. Default to zero (don't set param in that case).
1238
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1239
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1283
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1284
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1285
+	}
1240 1286
 
1241 1287
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1242
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1243
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1288
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1289
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1290
+	}
1244 1291
 
1245 1292
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1246 1293
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1247 1294
 
1248 1295
 	// Default the user name to a wildcard matching every user (*).
1249
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1250
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1296
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1297
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1298
+	}
1251 1299
 
1252 1300
 	// This will be full of all kinds of parameters!
1253 1301
 	$searchq_parameters = array();
1254 1302
 
1255 1303
 	// If there's no specific user, then don't mention it in the main query.
1256
-	if (empty($search_params['userspec']))
1257
-		$userQuery = '';
1258
-	else
1304
+	if (empty($search_params['userspec'])) {
1305
+			$userQuery = '';
1306
+	} else
1259 1307
 	{
1260 1308
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1261 1309
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1267,8 +1315,9 @@  discard block
 block discarded – undo
1267 1315
 		{
1268 1316
 			$possible_users[$k] = trim($possible_users[$k]);
1269 1317
 
1270
-			if (strlen($possible_users[$k]) == 0)
1271
-				unset($possible_users[$k]);
1318
+			if (strlen($possible_users[$k]) == 0) {
1319
+							unset($possible_users[$k]);
1320
+			}
1272 1321
 		}
1273 1322
 
1274 1323
 		if (!empty($possible_users))
@@ -1280,8 +1329,9 @@  discard block
 block discarded – undo
1280 1329
 			{
1281 1330
 				$where_params['name_' . $k] = $v;
1282 1331
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1283
-				if (!isset($where_params['real_name']))
1284
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1332
+				if (!isset($where_params['real_name'])) {
1333
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1334
+				}
1285 1335
 			}
1286 1336
 
1287 1337
 			// Who matches those criteria?
@@ -1294,28 +1344,28 @@  discard block
 block discarded – undo
1294 1344
 			);
1295 1345
 
1296 1346
 			// Simply do nothing if there're too many members matching the criteria.
1297
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1298
-				$userQuery = '';
1299
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1347
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1348
+							$userQuery = '';
1349
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1300 1350
 			{
1301 1351
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1302 1352
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1303 1353
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1304
-			}
1305
-			else
1354
+			} else
1306 1355
 			{
1307 1356
 				$memberlist = array();
1308
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-					$memberlist[] = $row['id_member'];
1357
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+									$memberlist[] = $row['id_member'];
1359
+				}
1310 1360
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1311 1361
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1312 1362
 				$searchq_parameters['member_list'] = $memberlist;
1313 1363
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1314 1364
 			}
1315 1365
 			$smcFunc['db_free_result']($request);
1366
+		} else {
1367
+					$userQuery = '';
1316 1368
 		}
1317
-		else
1318
-			$userQuery = '';
1319 1369
 	}
1320 1370
 
1321 1371
 	// Setup the sorting variables...
@@ -1323,8 +1373,9 @@  discard block
 block discarded – undo
1323 1373
 	$sort_columns = array(
1324 1374
 		'pm.id_pm',
1325 1375
 	);
1326
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1327
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1376
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1377
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1378
+	}
1328 1379
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1329 1380
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1330 1381
 
@@ -1334,24 +1385,27 @@  discard block
 block discarded – undo
1334 1385
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1335 1386
 	{
1336 1387
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1337
-		if (isset($search_params['labels']))
1338
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1388
+		if (isset($search_params['labels'])) {
1389
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1390
+		}
1339 1391
 
1340 1392
 		// Assuming we have some labels - make them all integers.
1341 1393
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1342 1394
 		{
1343
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1344
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1395
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1396
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1397
+			}
1398
+		} else {
1399
+					$_REQUEST['searchlabel'] = array();
1345 1400
 		}
1346
-		else
1347
-			$_REQUEST['searchlabel'] = array();
1348 1401
 
1349 1402
 		// Now that everything is cleaned up a bit, make the labels a param.
1350 1403
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1351 1404
 
1352 1405
 		// No labels selected? That must be an error!
1353
-		if (empty($_REQUEST['searchlabel']))
1354
-			$context['search_errors']['no_labels_selected'] = true;
1406
+		if (empty($_REQUEST['searchlabel'])) {
1407
+					$context['search_errors']['no_labels_selected'] = true;
1408
+		}
1355 1409
 		// Otherwise prepare the query!
1356 1410
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1357 1411
 		{
@@ -1374,8 +1428,7 @@  discard block
 block discarded – undo
1374 1428
 					// Not searching the inbox - PM must be labeled
1375 1429
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1376 1430
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1377
-				}
1378
-				else
1431
+				} else
1379 1432
 				{
1380 1433
 					// Searching the inbox - PM doesn't have to be labeled
1381 1434
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1390,8 +1443,9 @@  discard block
 block discarded – undo
1390 1443
 	// What are we actually searching for?
1391 1444
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1392 1445
 	// If we ain't got nothing - we should error!
1393
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1394
-		$context['search_errors']['invalid_search_string'] = true;
1446
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1447
+			$context['search_errors']['invalid_search_string'] = true;
1448
+	}
1395 1449
 
1396 1450
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1397 1451
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1404,12 +1458,14 @@  discard block
 block discarded – undo
1404 1458
 	$excludedWords = array();
1405 1459
 
1406 1460
 	// .. first, we check for things like -"some words", but not "-some words".
1407
-	foreach ($matches[1] as $index => $word)
1408
-		if ($word == '-')
1461
+	foreach ($matches[1] as $index => $word) {
1462
+			if ($word == '-')
1409 1463
 		{
1410 1464
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1411
-			if (strlen($word) > 0)
1412
-				$excludedWords[] = $word;
1465
+	}
1466
+			if (strlen($word) > 0) {
1467
+							$excludedWords[] = $word;
1468
+			}
1413 1469
 			unset($searchArray[$index]);
1414 1470
 		}
1415 1471
 
@@ -1419,8 +1475,9 @@  discard block
 block discarded – undo
1419 1475
 		if (strpos(trim($word), '-') === 0)
1420 1476
 		{
1421 1477
 			$word = substr($smcFunc['strtolower']($word), 1);
1422
-			if (strlen($word) > 0)
1423
-				$excludedWords[] = $word;
1478
+			if (strlen($word) > 0) {
1479
+							$excludedWords[] = $word;
1480
+			}
1424 1481
 			unset($tempSearch[$index]);
1425 1482
 		}
1426 1483
 	}
@@ -1431,9 +1488,9 @@  discard block
 block discarded – undo
1431 1488
 	foreach ($searchArray as $index => $value)
1432 1489
 	{
1433 1490
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1434
-		if ($searchArray[$index] == '')
1435
-			unset($searchArray[$index]);
1436
-		else
1491
+		if ($searchArray[$index] == '') {
1492
+					unset($searchArray[$index]);
1493
+		} else
1437 1494
 		{
1438 1495
 			// Sort out entities first.
1439 1496
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1443,27 +1500,32 @@  discard block
 block discarded – undo
1443 1500
 
1444 1501
 	// Create an array of replacements for highlighting.
1445 1502
 	$context['mark'] = array();
1446
-	foreach ($searchArray as $word)
1447
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1503
+	foreach ($searchArray as $word) {
1504
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1505
+	}
1448 1506
 
1449 1507
 	// This contains *everything*
1450 1508
 	$searchWords = array_merge($searchArray, $excludedWords);
1451 1509
 
1452 1510
 	// Make sure at least one word is being searched for.
1453
-	if (empty($searchArray))
1454
-		$context['search_errors']['invalid_search_string'] = true;
1511
+	if (empty($searchArray)) {
1512
+			$context['search_errors']['invalid_search_string'] = true;
1513
+	}
1455 1514
 
1456 1515
 	// Sort out the search query so the user can edit it - if they want.
1457 1516
 	$context['search_params'] = $search_params;
1458
-	if (isset($context['search_params']['search']))
1459
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1460
-	if (isset($context['search_params']['userspec']))
1461
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1517
+	if (isset($context['search_params']['search'])) {
1518
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1519
+	}
1520
+	if (isset($context['search_params']['userspec'])) {
1521
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1522
+	}
1462 1523
 
1463 1524
 	// Now we have all the parameters, combine them together for pagination and the like...
1464 1525
 	$context['params'] = array();
1465
-	foreach ($search_params as $k => $v)
1466
-		$context['params'][] = $k . '|\'|' . $v;
1526
+	foreach ($search_params as $k => $v) {
1527
+			$context['params'][] = $k . '|\'|' . $v;
1528
+	}
1467 1529
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1468 1530
 
1469 1531
 	// Compile the subject query part.
@@ -1471,26 +1533,31 @@  discard block
 block discarded – undo
1471 1533
 
1472 1534
 	foreach ($searchWords as $index => $word)
1473 1535
 	{
1474
-		if ($word == '')
1475
-			continue;
1536
+		if ($word == '') {
1537
+					continue;
1538
+		}
1476 1539
 
1477
-		if ($search_params['subject_only'])
1478
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1479
-		else
1480
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1540
+		if ($search_params['subject_only']) {
1541
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1542
+		} else {
1543
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1544
+		}
1481 1545
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1482 1546
 	}
1483 1547
 
1484 1548
 	$searchQuery = ' 1=1';
1485
-	if (!empty($andQueryParts))
1486
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1549
+	if (!empty($andQueryParts)) {
1550
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1551
+	}
1487 1552
 
1488 1553
 	// Age limits?
1489 1554
 	$timeQuery = '';
1490
-	if (!empty($search_params['minage']))
1491
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1492
-	if (!empty($search_params['maxage']))
1493
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1555
+	if (!empty($search_params['minage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1557
+	}
1558
+	if (!empty($search_params['maxage'])) {
1559
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1560
+	}
1494 1561
 
1495 1562
 	// If we have errors - return back to the first screen...
1496 1563
 	if (!empty($context['search_errors']))
@@ -1576,8 +1643,9 @@  discard block
 block discarded – undo
1576 1643
 			)
1577 1644
 		);
1578 1645
 		$real_pm_ids = array();
1579
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1580
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1646
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1647
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1648
+		}
1581 1649
 		$smcFunc['db_free_result']($request);
1582 1650
 	}
1583 1651
 
@@ -1607,8 +1675,9 @@  discard block
 block discarded – undo
1607 1675
 		);
1608 1676
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1609 1677
 		{
1610
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1611
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1678
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1679
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1680
+			}
1612 1681
 
1613 1682
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1614 1683
 			{
@@ -1629,12 +1698,14 @@  discard block
 block discarded – undo
1629 1698
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1630 1699
 				{
1631 1700
 					$l_id = $row2['id_label'];
1632
-					if (isset($context['labels'][$l_id]))
1633
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1701
+					if (isset($context['labels'][$l_id])) {
1702
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1703
+					}
1634 1704
 
1635 1705
 					// Here we find the first label on a message - for linking to posts in results
1636
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1637
-						$context['first_label'][$row['id_pm']] = $l_id;
1706
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1707
+											$context['first_label'][$row['id_pm']] = $l_id;
1708
+					}
1638 1709
 				}
1639 1710
 
1640 1711
 				$smcFunc['db_free_result']($request2);
@@ -1761,8 +1832,9 @@  discard block
 block discarded – undo
1761 1832
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1762 1833
 		$smcFunc['db_free_result']($request);
1763 1834
 
1764
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1765
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1835
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1836
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1837
+		}
1766 1838
 	}
1767 1839
 
1768 1840
 	// Quoting/Replying to a message?
@@ -1771,8 +1843,9 @@  discard block
 block discarded – undo
1771 1843
 		$pmsg = (int) $_REQUEST['pmsg'];
1772 1844
 
1773 1845
 		// Make sure this is yours.
1774
-		if (!isAccessiblePM($pmsg))
1775
-			fatal_lang_error('no_access', false);
1846
+		if (!isAccessiblePM($pmsg)) {
1847
+					fatal_lang_error('no_access', false);
1848
+		}
1776 1849
 
1777 1850
 		// Work out whether this is one you've received?
1778 1851
 		$request = $smcFunc['db_query']('', '
@@ -1809,8 +1882,9 @@  discard block
 block discarded – undo
1809 1882
 				'id_pm' => $pmsg,
1810 1883
 			)
1811 1884
 		);
1812
-		if ($smcFunc['db_num_rows']($request) == 0)
1813
-			fatal_lang_error('pm_not_yours', false);
1885
+		if ($smcFunc['db_num_rows']($request) == 0) {
1886
+					fatal_lang_error('pm_not_yours', false);
1887
+		}
1814 1888
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1815 1889
 		$smcFunc['db_free_result']($request);
1816 1890
 
@@ -1821,9 +1895,9 @@  discard block
 block discarded – undo
1821 1895
 		// Add 'Re: ' to it....
1822 1896
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1823 1897
 		{
1824
-			if ($language === $user_info['language'])
1825
-				$context['response_prefix'] = $txt['response_prefix'];
1826
-			else
1898
+			if ($language === $user_info['language']) {
1899
+							$context['response_prefix'] = $txt['response_prefix'];
1900
+			} else
1827 1901
 			{
1828 1902
 				loadLanguage('index', $language, false);
1829 1903
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1832,22 +1906,25 @@  discard block
 block discarded – undo
1832 1906
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1833 1907
 		}
1834 1908
 		$form_subject = $row_quoted['subject'];
1835
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1836
-			$form_subject = $context['response_prefix'] . $form_subject;
1909
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1910
+					$form_subject = $context['response_prefix'] . $form_subject;
1911
+		}
1837 1912
 
1838 1913
 		if (isset($_REQUEST['quote']))
1839 1914
 		{
1840 1915
 			// Remove any nested quotes and <br>...
1841 1916
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1842
-			if (!empty($modSettings['removeNestedQuotes']))
1843
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1844
-			if (empty($row_quoted['id_member']))
1845
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1846
-			else
1847
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1917
+			if (!empty($modSettings['removeNestedQuotes'])) {
1918
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1919
+			}
1920
+			if (empty($row_quoted['id_member'])) {
1921
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1922
+			} else {
1923
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1924
+			}
1925
+		} else {
1926
+					$form_message = '';
1848 1927
 		}
1849
-		else
1850
-			$form_message = '';
1851 1928
 
1852 1929
 		// Do the BBC thang on the message.
1853 1930
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1868,8 +1945,7 @@  discard block
 block discarded – undo
1868 1945
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1869 1946
 			'body' => $row_quoted['body']
1870 1947
 		);
1871
-	}
1872
-	else
1948
+	} else
1873 1949
 	{
1874 1950
 		$context['quoted_message'] = false;
1875 1951
 		$form_subject = '';
@@ -1888,11 +1964,12 @@  discard block
 block discarded – undo
1888 1964
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1889 1965
 		{
1890 1966
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1891
-			if ($row_quoted['id_member'] != $user_info['id'])
1892
-				$context['recipients']['to'][] = array(
1967
+			if ($row_quoted['id_member'] != $user_info['id']) {
1968
+							$context['recipients']['to'][] = array(
1893 1969
 					'id' => $row_quoted['id_member'],
1894 1970
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1895 1971
 				);
1972
+			}
1896 1973
 
1897 1974
 			// Now to get the others.
1898 1975
 			$request = $smcFunc['db_query']('', '
@@ -1908,18 +1985,19 @@  discard block
 block discarded – undo
1908 1985
 					'not_bcc' => 0,
1909 1986
 				)
1910 1987
 			);
1911
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1912
-				$context['recipients']['to'][] = array(
1988
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1989
+							$context['recipients']['to'][] = array(
1913 1990
 					'id' => $row['id_member'],
1914 1991
 					'name' => $row['real_name'],
1915 1992
 				);
1993
+			}
1916 1994
 			$smcFunc['db_free_result']($request);
1917
-		}
1918
-		else
1995
+		} else
1919 1996
 		{
1920 1997
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1921
-			foreach ($_REQUEST['u'] as $key => $uID)
1922
-				$_REQUEST['u'][$key] = (int) $uID;
1998
+			foreach ($_REQUEST['u'] as $key => $uID) {
1999
+							$_REQUEST['u'][$key] = (int) $uID;
2000
+			}
1923 2001
 
1924 2002
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1925 2003
 
@@ -1933,22 +2011,24 @@  discard block
 block discarded – undo
1933 2011
 					'limit' => count($_REQUEST['u']),
1934 2012
 				)
1935 2013
 			);
1936
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1937
-				$context['recipients']['to'][] = array(
2014
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2015
+							$context['recipients']['to'][] = array(
1938 2016
 					'id' => $row['id_member'],
1939 2017
 					'name' => $row['real_name'],
1940 2018
 				);
2019
+			}
1941 2020
 			$smcFunc['db_free_result']($request);
1942 2021
 		}
1943 2022
 
1944 2023
 		// Get a literal name list in case the user has JavaScript disabled.
1945 2024
 		$names = array();
1946
-		foreach ($context['recipients']['to'] as $to)
1947
-			$names[] = $to['name'];
2025
+		foreach ($context['recipients']['to'] as $to) {
2026
+					$names[] = $to['name'];
2027
+		}
1948 2028
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2029
+	} else {
2030
+			$context['to_value'] = '';
1949 2031
 	}
1950
-	else
1951
-		$context['to_value'] = '';
1952 2032
 
1953 2033
 	// Set the defaults...
1954 2034
 	$context['subject'] = $form_subject;
@@ -2018,8 +2098,9 @@  discard block
 block discarded – undo
2018 2098
 
2019 2099
 	// validate with loadMemberData()
2020 2100
 	$memberResult = loadMemberData($user_info['id'], false);
2021
-	if (!$memberResult)
2022
-		fatal_lang_error('not_a_user', false);
2101
+	if (!$memberResult) {
2102
+			fatal_lang_error('not_a_user', false);
2103
+	}
2023 2104
 	list ($memID) = $memberResult;
2024 2105
 
2025 2106
 	// drafts is where the functions reside
@@ -2045,9 +2126,9 @@  discard block
 block discarded – undo
2045 2126
 		$context['sub_template'] = 'send';
2046 2127
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2047 2128
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2129
+	} else {
2130
+			$context['sub_template'] = 'pm';
2048 2131
 	}
2049
-	else
2050
-		$context['sub_template'] = 'pm';
2051 2132
 
2052 2133
 	$context['page_title'] = $txt['send_message'];
2053 2134
 
@@ -2108,10 +2189,11 @@  discard block
 block discarded – undo
2108 2189
 		);
2109 2190
 		if ($smcFunc['db_num_rows']($request) == 0)
2110 2191
 		{
2111
-			if (!isset($_REQUEST['xml']))
2112
-				fatal_lang_error('pm_not_yours', false);
2113
-			else
2114
-				$error_types[] = 'pm_not_yours';
2192
+			if (!isset($_REQUEST['xml'])) {
2193
+							fatal_lang_error('pm_not_yours', false);
2194
+			} else {
2195
+							$error_types[] = 'pm_not_yours';
2196
+			}
2115 2197
 		}
2116 2198
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2117 2199
 		$smcFunc['db_free_result']($request);
@@ -2158,14 +2240,16 @@  discard block
 block discarded – undo
2158 2240
 		$context['post_error'][$error_type] = true;
2159 2241
 		if (isset($txt['error_' . $error_type]))
2160 2242
 		{
2161
-			if ($error_type == 'long_message')
2162
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2243
+			if ($error_type == 'long_message') {
2244
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2245
+			}
2163 2246
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2164 2247
 		}
2165 2248
 
2166 2249
 		// If it's not a minor error flag it as such.
2167
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2168
-			$context['error_type'] = 'serious';
2250
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2251
+					$context['error_type'] = 'serious';
2252
+		}
2169 2253
 	}
2170 2254
 
2171 2255
 	// We need to load the editor once more.
@@ -2223,8 +2307,9 @@  discard block
 block discarded – undo
2223 2307
 	require_once($sourcedir . '/Subs-Auth.php');
2224 2308
 
2225 2309
 	// PM Drafts enabled and needed?
2226
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2227
-		require_once($sourcedir . '/Drafts.php');
2310
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2311
+			require_once($sourcedir . '/Drafts.php');
2312
+	}
2228 2313
 
2229 2314
 	loadLanguage('PersonalMessage', '', false);
2230 2315
 
@@ -2254,24 +2339,27 @@  discard block
 block discarded – undo
2254 2339
 
2255 2340
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2256 2341
 		{
2257
-			if (!isset($_REQUEST['xml']))
2258
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2259
-			else
2260
-				$post_errors[] = 'pm_too_many_per_hour';
2342
+			if (!isset($_REQUEST['xml'])) {
2343
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2344
+			} else {
2345
+							$post_errors[] = 'pm_too_many_per_hour';
2346
+			}
2261 2347
 		}
2262 2348
 	}
2263 2349
 
2264 2350
 	// If your session timed out, show an error, but do allow to re-submit.
2265
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2266
-		$post_errors[] = 'session_timeout';
2351
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2352
+			$post_errors[] = 'session_timeout';
2353
+	}
2267 2354
 
2268 2355
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2269 2356
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2270 2357
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2271 2358
 
2272 2359
 	// Route the input from the 'u' parameter to the 'to'-list.
2273
-	if (!empty($_POST['u']))
2274
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2360
+	if (!empty($_POST['u'])) {
2361
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2362
+	}
2275 2363
 
2276 2364
 	// Construct the list of recipients.
2277 2365
 	$recipientList = array();
@@ -2283,8 +2371,9 @@  discard block
 block discarded – undo
2283 2371
 		$recipientList[$recipientType] = array();
2284 2372
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2285 2373
 		{
2286
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2287
-				$recipientList[$recipientType][] = (int) $recipient;
2374
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2375
+							$recipientList[$recipientType][] = (int) $recipient;
2376
+			}
2288 2377
 		}
2289 2378
 
2290 2379
 		// Are there also literal names set?
@@ -2298,10 +2387,11 @@  discard block
 block discarded – undo
2298 2387
 
2299 2388
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2300 2389
 			{
2301
-				if (strlen(trim($recipient)) > 0)
2302
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2303
-				else
2304
-					unset($namedRecipientList[$recipientType][$index]);
2390
+				if (strlen(trim($recipient)) > 0) {
2391
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2392
+				} else {
2393
+									unset($namedRecipientList[$recipientType][$index]);
2394
+				}
2305 2395
 			}
2306 2396
 
2307 2397
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2331,8 +2421,9 @@  discard block
 block discarded – undo
2331 2421
 		}
2332 2422
 
2333 2423
 		// Selected a recipient to be deleted? Remove them now.
2334
-		if (!empty($_POST['delete_recipient']))
2335
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2424
+		if (!empty($_POST['delete_recipient'])) {
2425
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2426
+		}
2336 2427
 
2337 2428
 		// Make sure we don't include the same name twice
2338 2429
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2342,8 +2433,9 @@  discard block
 block discarded – undo
2342 2433
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2343 2434
 
2344 2435
 	// Check if there's at least one recipient.
2345
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2346
-		$post_errors[] = 'no_to';
2436
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2437
+			$post_errors[] = 'no_to';
2438
+	}
2347 2439
 
2348 2440
 	// Make sure that we remove the members who did get it from the screen.
2349 2441
 	if (!$is_recipient_change)
@@ -2357,28 +2449,31 @@  discard block
 block discarded – undo
2357 2449
 				// Since we already have a post error, remove the previous one.
2358 2450
 				$post_errors = array_diff($post_errors, array('no_to'));
2359 2451
 
2360
-				foreach ($namesNotFound[$recipientType] as $name)
2361
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2452
+				foreach ($namesNotFound[$recipientType] as $name) {
2453
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2454
+				}
2362 2455
 			}
2363 2456
 		}
2364 2457
 	}
2365 2458
 
2366 2459
 	// Did they make any mistakes?
2367
-	if ($_REQUEST['subject'] == '')
2368
-		$post_errors[] = 'no_subject';
2369
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2370
-		$post_errors[] = 'no_message';
2371
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2372
-		$post_errors[] = 'long_message';
2373
-	else
2460
+	if ($_REQUEST['subject'] == '') {
2461
+			$post_errors[] = 'no_subject';
2462
+	}
2463
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2464
+			$post_errors[] = 'no_message';
2465
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2466
+			$post_errors[] = 'long_message';
2467
+	} else
2374 2468
 	{
2375 2469
 		// Preparse the message.
2376 2470
 		$message = $_REQUEST['message'];
2377 2471
 		preparsecode($message);
2378 2472
 
2379 2473
 		// Make sure there's still some content left without the tags.
2380
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2381
-			$post_errors[] = 'no_message';
2474
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2475
+					$post_errors[] = 'no_message';
2476
+		}
2382 2477
 	}
2383 2478
 
2384 2479
 	// Wrong verification code?
@@ -2390,13 +2485,15 @@  discard block
 block discarded – undo
2390 2485
 		);
2391 2486
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2392 2487
 
2393
-		if (is_array($context['require_verification']))
2394
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2488
+		if (is_array($context['require_verification'])) {
2489
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2490
+		}
2395 2491
 	}
2396 2492
 
2397 2493
 	// If they did, give a chance to make ammends.
2398
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2399
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2494
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2495
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2496
+	}
2400 2497
 
2401 2498
 	// Want to take a second glance before you send?
2402 2499
 	if (isset($_REQUEST['preview']))
@@ -2427,8 +2524,9 @@  discard block
 block discarded – undo
2427 2524
 		foreach ($namesNotFound as $recipientType => $names)
2428 2525
 		{
2429 2526
 			$post_errors[] = 'bad_' . $recipientType;
2430
-			foreach ($names as $name)
2431
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2527
+			foreach ($names as $name) {
2528
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2529
+			}
2432 2530
 		}
2433 2531
 
2434 2532
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2458,13 +2556,14 @@  discard block
 block discarded – undo
2458 2556
 	checkSubmitOnce('check');
2459 2557
 
2460 2558
 	// Do the actual sending of the PM.
2461
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2462
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2463
-	else
2464
-		$context['send_log'] = array(
2559
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2560
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2561
+	} else {
2562
+			$context['send_log'] = array(
2465 2563
 			'sent' => array(),
2466 2564
 			'failed' => array()
2467 2565
 		);
2566
+	}
2468 2567
 
2469 2568
 	// Mark the message as "replied to".
2470 2569
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2482,11 +2581,12 @@  discard block
 block discarded – undo
2482 2581
 	}
2483 2582
 
2484 2583
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2485
-	if (!empty($context['send_log']['failed']))
2486
-		return messagePostError($post_errors, $namesNotFound, array(
2584
+	if (!empty($context['send_log']['failed'])) {
2585
+			return messagePostError($post_errors, $namesNotFound, array(
2487 2586
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2488 2587
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2489 2588
 		));
2589
+	}
2490 2590
 
2491 2591
 	// Message sent successfully?
2492 2592
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2494,8 +2594,9 @@  discard block
 block discarded – undo
2494 2594
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2495 2595
 
2496 2596
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2497
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2498
-			DeleteDraft($_POST['id_pm_draft']);
2597
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2598
+					DeleteDraft($_POST['id_pm_draft']);
2599
+		}
2499 2600
 	}
2500 2601
 
2501 2602
 	// Go back to the where they sent from, if possible...
@@ -2510,24 +2611,28 @@  discard block
 block discarded – undo
2510 2611
 
2511 2612
 	checkSession('request');
2512 2613
 
2513
-	if (isset($_REQUEST['del_selected']))
2514
-		$_REQUEST['pm_action'] = 'delete';
2614
+	if (isset($_REQUEST['del_selected'])) {
2615
+			$_REQUEST['pm_action'] = 'delete';
2616
+	}
2515 2617
 
2516 2618
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2517 2619
 	{
2518
-		foreach ($_REQUEST['pms'] as $pm)
2519
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2620
+		foreach ($_REQUEST['pms'] as $pm) {
2621
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2622
+		}
2520 2623
 	}
2521 2624
 
2522
-	if (empty($_REQUEST['pm_actions']))
2523
-		redirectexit($context['current_label_redirect']);
2625
+	if (empty($_REQUEST['pm_actions'])) {
2626
+			redirectexit($context['current_label_redirect']);
2627
+	}
2524 2628
 
2525 2629
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2526 2630
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2527 2631
 	{
2528 2632
 		$id_pms = array();
2529
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2530
-			$id_pms[] = (int) $pm;
2633
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2634
+					$id_pms[] = (int) $pm;
2635
+		}
2531 2636
 
2532 2637
 		$request = $smcFunc['db_query']('', '
2533 2638
 			SELECT id_pm_head, id_pm
@@ -2538,8 +2643,9 @@  discard block
 block discarded – undo
2538 2643
 			)
2539 2644
 		);
2540 2645
 		$pm_heads = array();
2541
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2542
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2646
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2647
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2648
+		}
2543 2649
 		$smcFunc['db_free_result']($request);
2544 2650
 
2545 2651
 		$request = $smcFunc['db_query']('', '
@@ -2553,8 +2659,9 @@  discard block
 block discarded – undo
2553 2659
 		// Copy the action from the single to PM to the others.
2554 2660
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2555 2661
 		{
2556
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2557
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2662
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2663
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2664
+			}
2558 2665
 		}
2559 2666
 		$smcFunc['db_free_result']($request);
2560 2667
 	}
@@ -2566,22 +2673,21 @@  discard block
 block discarded – undo
2566 2673
 	$labels = array();
2567 2674
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2568 2675
 	{
2569
-		if ($action === 'delete')
2570
-			$to_delete[] = (int) $pm;
2571
-		else
2676
+		if ($action === 'delete') {
2677
+					$to_delete[] = (int) $pm;
2678
+		} else
2572 2679
 		{
2573 2680
 			if (substr($action, 0, 4) == 'add_')
2574 2681
 			{
2575 2682
 				$type = 'add';
2576 2683
 				$action = substr($action, 4);
2577
-			}
2578
-			elseif (substr($action, 0, 4) == 'rem_')
2684
+			} elseif (substr($action, 0, 4) == 'rem_')
2579 2685
 			{
2580 2686
 				$type = 'rem';
2581 2687
 				$action = substr($action, 4);
2688
+			} else {
2689
+							$type = 'unk';
2582 2690
 			}
2583
-			else
2584
-				$type = 'unk';
2585 2691
 
2586 2692
 			if ($action == '-1' || (int) $action > 0)
2587 2693
 			{
@@ -2592,8 +2698,9 @@  discard block
 block discarded – undo
2592 2698
 	}
2593 2699
 
2594 2700
 	// Deleting, it looks like?
2595
-	if (!empty($to_delete))
2596
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2701
+	if (!empty($to_delete)) {
2702
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2703
+	}
2597 2704
 
2598 2705
 	// Are we labeling anything?
2599 2706
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2661,8 +2768,7 @@  discard block
 block discarded – undo
2661 2768
 				}
2662 2769
 
2663 2770
 				$smcFunc['db_free_result']($request2);
2664
-			}
2665
-			elseif ($type == 'rem')
2771
+			} elseif ($type == 'rem')
2666 2772
 			{
2667 2773
 				// If we're removing from the inbox, see if we have at least one other label.
2668 2774
 				// This query is faster than the one above
@@ -2694,21 +2800,25 @@  discard block
 block discarded – undo
2694 2800
 			if ($to_label[$row['id_pm']] != '-1')
2695 2801
 			{
2696 2802
 				// If this label is in the list and we're not adding it, remove it
2697
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2698
-					unset($labels[$to_label[$row['id_pm']]]);
2699
-				else if ($type !== 'rem')
2700
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2803
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2804
+									unset($labels[$to_label[$row['id_pm']]]);
2805
+				} else if ($type !== 'rem') {
2806
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2807
+				}
2701 2808
 			}
2702 2809
 
2703 2810
 			// Removing all labels or just removing the inbox label
2704
-			if ($type == 'rem' && empty($labels))
2705
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2811
+			if ($type == 'rem' && empty($labels)) {
2812
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2813
+			}
2706 2814
 			// Adding new labels, but removing inbox and applying new ones
2707
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2708
-				$in_inbox = 0;
2815
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2816
+							$in_inbox = 0;
2817
+			}
2709 2818
 			// Just adding it to the inbox
2710
-			else
2711
-				$in_inbox = 1;
2819
+			else {
2820
+							$in_inbox = 1;
2821
+			}
2712 2822
 
2713 2823
 			// Are we adding it to or removing it from the inbox?
2714 2824
 			if ($in_inbox != $row['in_inbox'])
@@ -2750,8 +2860,9 @@  discard block
 block discarded – undo
2750 2860
 			if (!empty($labels_to_apply))
2751 2861
 			{
2752 2862
 				$inserts = array();
2753
-				foreach ($labels_to_apply as $label)
2754
-					$inserts[] = array($row['id_pm'], $label);
2863
+				foreach ($labels_to_apply as $label) {
2864
+									$inserts[] = array($row['id_pm'], $label);
2865
+				}
2755 2866
 
2756 2867
 				$smcFunc['db_insert']('',
2757 2868
 					'{db_prefix}pm_labeled_messages',
@@ -2795,11 +2906,13 @@  discard block
 block discarded – undo
2795 2906
 	checkSession('get');
2796 2907
 
2797 2908
 	// If all then delete all messages the user has.
2798
-	if ($_REQUEST['f'] == 'all')
2799
-		deleteMessages(null, null);
2909
+	if ($_REQUEST['f'] == 'all') {
2910
+			deleteMessages(null, null);
2911
+	}
2800 2912
 	// Otherwise just the selected folder.
2801
-	else
2802
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2913
+	else {
2914
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2915
+	}
2803 2916
 
2804 2917
 	// Done... all gone.
2805 2918
 	redirectexit($context['current_label_redirect']);
@@ -2836,8 +2949,9 @@  discard block
 block discarded – undo
2836 2949
 				'msgtime' => $deleteTime,
2837 2950
 			)
2838 2951
 		);
2839
-		while ($row = $smcFunc['db_fetch_row']($request))
2840
-			$toDelete[] = $row[0];
2952
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2953
+					$toDelete[] = $row[0];
2954
+		}
2841 2955
 		$smcFunc['db_free_result']($request);
2842 2956
 
2843 2957
 		// Select all messages in their inbox older than $deleteTime.
@@ -2854,8 +2968,9 @@  discard block
 block discarded – undo
2854 2968
 				'msgtime' => $deleteTime,
2855 2969
 			)
2856 2970
 		);
2857
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2858
-			$toDelete[] = $row['id_pm'];
2971
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2972
+					$toDelete[] = $row['id_pm'];
2973
+		}
2859 2974
 		$smcFunc['db_free_result']($request);
2860 2975
 
2861 2976
 		// Delete the actual messages.
@@ -2886,26 +3001,29 @@  discard block
 block discarded – undo
2886 3001
 {
2887 3002
 	global $user_info, $smcFunc;
2888 3003
 
2889
-	if ($owner === null)
2890
-		$owner = array($user_info['id']);
2891
-	elseif (empty($owner))
2892
-		return;
2893
-	elseif (!is_array($owner))
2894
-		$owner = array($owner);
3004
+	if ($owner === null) {
3005
+			$owner = array($user_info['id']);
3006
+	} elseif (empty($owner)) {
3007
+			return;
3008
+	} elseif (!is_array($owner)) {
3009
+			$owner = array($owner);
3010
+	}
2895 3011
 
2896 3012
 	if ($personal_messages !== null)
2897 3013
 	{
2898
-		if (empty($personal_messages) || !is_array($personal_messages))
2899
-			return;
3014
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3015
+					return;
3016
+		}
2900 3017
 
2901
-		foreach ($personal_messages as $index => $delete_id)
2902
-			$personal_messages[$index] = (int) $delete_id;
3018
+		foreach ($personal_messages as $index => $delete_id) {
3019
+					$personal_messages[$index] = (int) $delete_id;
3020
+		}
2903 3021
 
2904 3022
 		$where = '
2905 3023
 				AND id_pm IN ({array_int:pm_list})';
3024
+	} else {
3025
+			$where = '';
2906 3026
 	}
2907
-	else
2908
-		$where = '';
2909 3027
 
2910 3028
 	if ($folder == 'sent' || $folder === null)
2911 3029
 	{
@@ -2940,17 +3058,19 @@  discard block
 block discarded – undo
2940 3058
 		// ...And update the statistics accordingly - now including unread messages!.
2941 3059
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2942 3060
 		{
2943
-			if ($row['is_read'])
2944
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2945
-			else
2946
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3061
+			if ($row['is_read']) {
3062
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3063
+			} else {
3064
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3065
+			}
2947 3066
 
2948 3067
 			// If this is the current member we need to make their message count correct.
2949 3068
 			if ($user_info['id'] == $row['id_member'])
2950 3069
 			{
2951 3070
 				$user_info['messages'] -= $row['num_deleted_messages'];
2952
-				if (!($row['is_read']))
2953
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3071
+				if (!($row['is_read'])) {
3072
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3073
+				}
2954 3074
 			}
2955 3075
 		}
2956 3076
 		$smcFunc['db_free_result']($request);
@@ -3018,8 +3138,9 @@  discard block
 block discarded – undo
3018 3138
 		)
3019 3139
 	);
3020 3140
 	$remove_pms = array();
3021
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3022
-		$remove_pms[] = $row['sender'];
3141
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3142
+			$remove_pms[] = $row['sender'];
3143
+	}
3023 3144
 	$smcFunc['db_free_result']($request);
3024 3145
 
3025 3146
 	if (!empty($remove_pms))
@@ -3064,8 +3185,9 @@  discard block
 block discarded – undo
3064 3185
 {
3065 3186
 	global $user_info, $context, $smcFunc;
3066 3187
 
3067
-	if ($owner === null)
3068
-		$owner = $user_info['id'];
3188
+	if ($owner === null) {
3189
+			$owner = $user_info['id'];
3190
+	}
3069 3191
 
3070 3192
 	$in_inbox = '';
3071 3193
 
@@ -3089,8 +3211,7 @@  discard block
 block discarded – undo
3089 3211
 		}
3090 3212
 
3091 3213
 		$smcFunc['db_free_result']($get_messages);
3092
-	}
3093
-	elseif ($label = '-1')
3214
+	} elseif ($label = '-1')
3094 3215
 	{
3095 3216
 		// Marking all PMs in your inbox read
3096 3217
 		$in_inbox = '
@@ -3115,8 +3236,9 @@  discard block
 block discarded – undo
3115 3236
 	{
3116 3237
 		if ($owner == $user_info['id'])
3117 3238
 		{
3118
-			foreach ($context['labels'] as $label)
3119
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3239
+			foreach ($context['labels'] as $label) {
3240
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3241
+			}
3120 3242
 		}
3121 3243
 
3122 3244
 		$result = $smcFunc['db_query']('', '
@@ -3136,8 +3258,9 @@  discard block
 block discarded – undo
3136 3258
 		{
3137 3259
 			$total_unread += $row['num'];
3138 3260
 
3139
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3140
-				continue;
3261
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3262
+							continue;
3263
+			}
3141 3264
 
3142 3265
 			$this_labels = array();
3143 3266
 
@@ -3161,11 +3284,13 @@  discard block
 block discarded – undo
3161 3284
 
3162 3285
 			$smcFunc['db_free_result']($result2);
3163 3286
 
3164
-			foreach ($this_labels as $this_label)
3165
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3287
+			foreach ($this_labels as $this_label) {
3288
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3289
+			}
3166 3290
 
3167
-			if ($row['in_inbox'] == 1)
3168
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3291
+			if ($row['in_inbox'] == 1) {
3292
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3293
+			}
3169 3294
 		}
3170 3295
 		$smcFunc['db_free_result']($result);
3171 3296
 
@@ -3174,8 +3299,9 @@  discard block
 block discarded – undo
3174 3299
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3175 3300
 
3176 3301
 		// If it was for the current member, reflect this in the $user_info array too.
3177
-		if ($owner == $user_info['id'])
3178
-			$user_info['unread_messages'] = $total_unread;
3302
+		if ($owner == $user_info['id']) {
3303
+					$user_info['unread_messages'] = $total_unread;
3304
+		}
3179 3305
 	}
3180 3306
 }
3181 3307
 
@@ -3203,8 +3329,9 @@  discard block
 block discarded – undo
3203 3329
 	// Add all existing labels to the array to save, slashing them as necessary...
3204 3330
 	foreach ($context['labels'] as $label)
3205 3331
 	{
3206
-		if ($label['id'] != -1)
3207
-			$the_labels[$label['id']] = $label['name'];
3332
+		if ($label['id'] != -1) {
3333
+					$the_labels[$label['id']] = $label['name'];
3334
+		}
3208 3335
 	}
3209 3336
 
3210 3337
 	if (isset($_POST[$context['session_var']]))
@@ -3223,8 +3350,9 @@  discard block
 block discarded – undo
3223 3350
 		{
3224 3351
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3225 3352
 
3226
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3227
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3353
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3354
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3355
+			}
3228 3356
 			if ($_POST['label'] != '')
3229 3357
 			{
3230 3358
 				$the_labels[] = $_POST['label'];
@@ -3245,24 +3373,25 @@  discard block
 block discarded – undo
3245 3373
 		{
3246 3374
 			foreach ($the_labels as $id => $name)
3247 3375
 			{
3248
-				if ($id == -1)
3249
-					continue;
3250
-				elseif (isset($_POST['label_name'][$id]))
3376
+				if ($id == -1) {
3377
+									continue;
3378
+				} elseif (isset($_POST['label_name'][$id]))
3251 3379
 				{
3252 3380
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3253 3381
 
3254
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3255
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3382
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3383
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3384
+					}
3256 3385
 					if ($_POST['label_name'][$id] != '')
3257 3386
 					{
3258 3387
 						// Changing the name of this label?
3259
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3260
-							$label_updates[$id] = $_POST['label_name'][$id];
3388
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3389
+													$label_updates[$id] = $_POST['label_name'][$id];
3390
+						}
3261 3391
 
3262 3392
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3263 3393
 
3264
-					}
3265
-					else
3394
+					} else
3266 3395
 					{
3267 3396
 						unset($the_labels[(int) $id]);
3268 3397
 						$labels_to_remove[] = $id;
@@ -3276,8 +3405,9 @@  discard block
 block discarded – undo
3276 3405
 		if (!empty($labels_to_add))
3277 3406
 		{
3278 3407
 			$inserts = array();
3279
-			foreach ($labels_to_add AS $label)
3280
-				$inserts[] = array($user_info['id'], $label);
3408
+			foreach ($labels_to_add AS $label) {
3409
+							$inserts[] = array($user_info['id'], $label);
3410
+			}
3281 3411
 
3282 3412
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3283 3413
 		}
@@ -3367,8 +3497,9 @@  discard block
 block discarded – undo
3367 3497
 				// Each action...
3368 3498
 				foreach ($rule['actions'] as $k2 => $action)
3369 3499
 				{
3370
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3371
-						continue;
3500
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3501
+											continue;
3502
+					}
3372 3503
 
3373 3504
 					$rule_changes[] = $rule['id'];
3374 3505
 
@@ -3383,8 +3514,8 @@  discard block
 block discarded – undo
3383 3514
 		{
3384 3515
 			$rule_changes = array_unique($rule_changes);
3385 3516
 			// Update/delete as appropriate.
3386
-			foreach ($rule_changes as $k => $id)
3387
-				if (!empty($context['rules'][$id]['actions']))
3517
+			foreach ($rule_changes as $k => $id) {
3518
+							if (!empty($context['rules'][$id]['actions']))
3388 3519
 				{
3389 3520
 					$smcFunc['db_query']('', '
3390 3521
 						UPDATE {db_prefix}pm_rules
@@ -3397,12 +3528,13 @@  discard block
 block discarded – undo
3397 3528
 							'actions' => json_encode($context['rules'][$id]['actions']),
3398 3529
 						)
3399 3530
 					);
3531
+			}
3400 3532
 					unset($rule_changes[$k]);
3401 3533
 				}
3402 3534
 
3403 3535
 			// Anything left here means it's lost all actions...
3404
-			if (!empty($rule_changes))
3405
-				$smcFunc['db_query']('', '
3536
+			if (!empty($rule_changes)) {
3537
+							$smcFunc['db_query']('', '
3406 3538
 					DELETE FROM {db_prefix}pm_rules
3407 3539
 					WHERE id_rule IN ({array_int:rule_list})
3408 3540
 							AND id_member = {int:current_member}',
@@ -3411,6 +3543,7 @@  discard block
 block discarded – undo
3411 3543
 						'rule_list' => $rule_changes,
3412 3544
 					)
3413 3545
 				);
3546
+			}
3414 3547
 		}
3415 3548
 
3416 3549
 		// Make sure we're not caching this!
@@ -3480,8 +3613,9 @@  discard block
 block discarded – undo
3480 3613
 		// Save the fields.
3481 3614
 		saveProfileFields();
3482 3615
 
3483
-		if (!empty($profile_vars))
3484
-			updateMemberData($user_info['id'], $profile_vars);
3616
+		if (!empty($profile_vars)) {
3617
+					updateMemberData($user_info['id'], $profile_vars);
3618
+		}
3485 3619
 	}
3486 3620
 
3487 3621
 	setupProfileContext(
@@ -3506,13 +3640,15 @@  discard block
 block discarded – undo
3506 3640
 	global $user_info, $language, $modSettings, $smcFunc;
3507 3641
 
3508 3642
 	// Check that this feature is even enabled!
3509
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3510
-		fatal_lang_error('no_access', false);
3643
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3644
+			fatal_lang_error('no_access', false);
3645
+	}
3511 3646
 
3512 3647
 	$pmsg = (int) $_REQUEST['pmsg'];
3513 3648
 
3514
-	if (!isAccessiblePM($pmsg, 'inbox'))
3515
-		fatal_lang_error('no_access', false);
3649
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3650
+			fatal_lang_error('no_access', false);
3651
+	}
3516 3652
 
3517 3653
 	$context['pm_id'] = $pmsg;
3518 3654
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3534,8 +3670,9 @@  discard block
 block discarded – undo
3534 3670
 			)
3535 3671
 		);
3536 3672
 		$context['admins'] = array();
3537
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3538
-			$context['admins'][$row['id_member']] = $row['real_name'];
3673
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3674
+					$context['admins'][$row['id_member']] = $row['real_name'];
3675
+		}
3539 3676
 		$smcFunc['db_free_result']($request);
3540 3677
 
3541 3678
 		// How many admins in total?
@@ -3564,8 +3701,9 @@  discard block
 block discarded – undo
3564 3701
 			)
3565 3702
 		);
3566 3703
 		// Can only be a hacker here!
3567
-		if ($smcFunc['db_num_rows']($request) == 0)
3568
-			fatal_lang_error('no_access', false);
3704
+		if ($smcFunc['db_num_rows']($request) == 0) {
3705
+					fatal_lang_error('no_access', false);
3706
+		}
3569 3707
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3570 3708
 		$smcFunc['db_free_result']($request);
3571 3709
 
@@ -3589,15 +3727,17 @@  discard block
 block discarded – undo
3589 3727
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3590 3728
 		{
3591 3729
 			// If it's hidden still don't reveal their names - privacy after all ;)
3592
-			if ($row['bcc'])
3593
-				$hidden_recipients++;
3594
-			else
3595
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3730
+			if ($row['bcc']) {
3731
+							$hidden_recipients++;
3732
+			} else {
3733
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3734
+			}
3596 3735
 		}
3597 3736
 		$smcFunc['db_free_result']($request);
3598 3737
 
3599
-		if ($hidden_recipients)
3600
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3738
+		if ($hidden_recipients) {
3739
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3740
+		}
3601 3741
 
3602 3742
 		// Now let's get out and loop through the admins.
3603 3743
 		$request = $smcFunc['db_query']('', '
@@ -3613,8 +3753,9 @@  discard block
 block discarded – undo
3613 3753
 		);
3614 3754
 
3615 3755
 		// Maybe we shouldn't advertise this?
3616
-		if ($smcFunc['db_num_rows']($request) == 0)
3617
-			fatal_lang_error('no_access', false);
3756
+		if ($smcFunc['db_num_rows']($request) == 0) {
3757
+					fatal_lang_error('no_access', false);
3758
+		}
3618 3759
 
3619 3760
 		$memberFromName = un_htmlspecialchars($memberFromName);
3620 3761
 
@@ -3633,8 +3774,9 @@  discard block
 block discarded – undo
3633 3774
 				// Make the body.
3634 3775
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3635 3776
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3636
-				if (!empty($recipients))
3637
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3777
+				if (!empty($recipients)) {
3778
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3779
+				}
3638 3780
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3639 3781
 
3640 3782
 				// Plonk it in the array ;)
@@ -3654,12 +3796,14 @@  discard block
 block discarded – undo
3654 3796
 		$smcFunc['db_free_result']($request);
3655 3797
 
3656 3798
 		// Send a different email for each language.
3657
-		foreach ($messagesToSend as $lang => $message)
3658
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3799
+		foreach ($messagesToSend as $lang => $message) {
3800
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3801
+		}
3659 3802
 
3660 3803
 		// Give the user their own language back!
3661
-		if (!empty($modSettings['userLanguage']))
3662
-			loadLanguage('PersonalMessage', '', false);
3804
+		if (!empty($modSettings['userLanguage'])) {
3805
+					loadLanguage('PersonalMessage', '', false);
3806
+		}
3663 3807
 
3664 3808
 		// Leave them with a template.
3665 3809
 		$context['sub_template'] = 'report_message_complete';
@@ -3705,8 +3849,9 @@  discard block
 block discarded – undo
3705 3849
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3706 3850
 	{
3707 3851
 		// Hide hidden groups!
3708
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3709
-			continue;
3852
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3853
+					continue;
3854
+		}
3710 3855
 
3711 3856
 		$context['groups'][$row['id_group']] = $row['group_name'];
3712 3857
 	}
@@ -3732,9 +3877,10 @@  discard block
 block discarded – undo
3732 3877
 			$context['rule'] = $context['rules'][$context['rid']];
3733 3878
 			$members = array();
3734 3879
 			// Need to get member names!
3735
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3736
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3880
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3881
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3737 3882
 					$members[(int) $criteria['v']] = $k;
3883
+			}
3738 3884
 
3739 3885
 			if (!empty($members))
3740 3886
 			{
@@ -3746,19 +3892,20 @@  discard block
 block discarded – undo
3746 3892
 						'member_list' => array_keys($members),
3747 3893
 					)
3748 3894
 				);
3749
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3750
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3895
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3896
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3897
+				}
3751 3898
 				$smcFunc['db_free_result']($request);
3752 3899
 			}
3753
-		}
3754
-		else
3755
-			$context['rule'] = array(
3900
+		} else {
3901
+					$context['rule'] = array(
3756 3902
 				'id' => '',
3757 3903
 				'name' => '',
3758 3904
 				'criteria' => array(),
3759 3905
 				'actions' => array(),
3760 3906
 				'logic' => 'and',
3761 3907
 			);
3908
+		}
3762 3909
 	}
3763 3910
 	// Saving?
3764 3911
 	elseif (isset($_GET['save']))
@@ -3768,22 +3915,25 @@  discard block
 block discarded – undo
3768 3915
 
3769 3916
 		// Name is easy!
3770 3917
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3771
-		if (empty($ruleName))
3772
-			fatal_lang_error('pm_rule_no_name', false);
3918
+		if (empty($ruleName)) {
3919
+					fatal_lang_error('pm_rule_no_name', false);
3920
+		}
3773 3921
 
3774 3922
 		// Sanity check...
3775
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3776
-			fatal_lang_error('pm_rule_no_criteria', false);
3923
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3924
+					fatal_lang_error('pm_rule_no_criteria', false);
3925
+		}
3777 3926
 
3778 3927
 		// Let's do the criteria first - it's also hardest!
3779 3928
 		$criteria = array();
3780 3929
 		foreach ($_POST['ruletype'] as $ind => $type)
3781 3930
 		{
3782 3931
 			// Check everything is here...
3783
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3784
-				continue;
3785
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3786
-				continue;
3932
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3933
+							continue;
3934
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3935
+							continue;
3936
+			}
3787 3937
 
3788 3938
 			// Members need to be found.
3789 3939
 			if ($type == 'mid')
@@ -3807,13 +3957,13 @@  discard block
 block discarded – undo
3807 3957
 				$smcFunc['db_free_result']($request);
3808 3958
 
3809 3959
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3960
+			} elseif ($type == 'bud') {
3961
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3962
+			} elseif ($type == 'gid') {
3963
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3964
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3965
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3810 3966
 			}
3811
-			elseif ($type == 'bud')
3812
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3813
-			elseif ($type == 'gid')
3814
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3815
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3816
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3817 3967
 		}
3818 3968
 
3819 3969
 		// Also do the actions!
@@ -3823,26 +3973,29 @@  discard block
 block discarded – undo
3823 3973
 		foreach ($_POST['acttype'] as $ind => $type)
3824 3974
 		{
3825 3975
 			// Picking a valid label?
3826
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3827
-				continue;
3976
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3977
+							continue;
3978
+			}
3828 3979
 
3829 3980
 			// Record what we're doing.
3830
-			if ($type == 'del')
3831
-				$doDelete = 1;
3832
-			elseif ($type == 'lab')
3833
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3981
+			if ($type == 'del') {
3982
+							$doDelete = 1;
3983
+			} elseif ($type == 'lab') {
3984
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3985
+			}
3834 3986
 		}
3835 3987
 
3836
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3837
-			fatal_lang_error('pm_rule_no_criteria', false);
3988
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3989
+					fatal_lang_error('pm_rule_no_criteria', false);
3990
+		}
3838 3991
 
3839 3992
 		// What are we storing?
3840 3993
 		$criteria = json_encode($criteria);
3841 3994
 		$actions = json_encode($actions);
3842 3995
 
3843 3996
 		// Create the rule?
3844
-		if (empty($context['rid']))
3845
-			$smcFunc['db_insert']('',
3997
+		if (empty($context['rid'])) {
3998
+					$smcFunc['db_insert']('',
3846 3999
 				'{db_prefix}pm_rules',
3847 4000
 				array(
3848 4001
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3853,8 +4006,8 @@  discard block
 block discarded – undo
3853 4006
 				),
3854 4007
 				array('id_rule')
3855 4008
 			);
3856
-		else
3857
-			$smcFunc['db_query']('', '
4009
+		} else {
4010
+					$smcFunc['db_query']('', '
3858 4011
 				UPDATE {db_prefix}pm_rules
3859 4012
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3860 4013
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3870,6 +4023,7 @@  discard block
 block discarded – undo
3870 4023
 					'actions' => $actions,
3871 4024
 				)
3872 4025
 			);
4026
+		}
3873 4027
 
3874 4028
 		redirectexit('action=pm;sa=manrules');
3875 4029
 	}
@@ -3878,11 +4032,12 @@  discard block
 block discarded – undo
3878 4032
 	{
3879 4033
 		checkSession();
3880 4034
 		$toDelete = array();
3881
-		foreach ($_POST['delrule'] as $k => $v)
3882
-			$toDelete[] = (int) $k;
4035
+		foreach ($_POST['delrule'] as $k => $v) {
4036
+					$toDelete[] = (int) $k;
4037
+		}
3883 4038
 
3884
-		if (!empty($toDelete))
3885
-			$smcFunc['db_query']('', '
4039
+		if (!empty($toDelete)) {
4040
+					$smcFunc['db_query']('', '
3886 4041
 				DELETE FROM {db_prefix}pm_rules
3887 4042
 				WHERE id_rule IN ({array_int:delete_list})
3888 4043
 					AND id_member = {int:current_member}',
@@ -3891,6 +4046,7 @@  discard block
 block discarded – undo
3891 4046
 					'delete_list' => $toDelete,
3892 4047
 				)
3893 4048
 			);
4049
+		}
3894 4050
 
3895 4051
 		redirectexit('action=pm;sa=manrules');
3896 4052
 	}
@@ -3909,8 +4065,9 @@  discard block
 block discarded – undo
3909 4065
 	loadRules();
3910 4066
 
3911 4067
 	// No rules?
3912
-	if (empty($context['rules']))
3913
-		return;
4068
+	if (empty($context['rules'])) {
4069
+			return;
4070
+	}
3914 4071
 
3915 4072
 	// Just unread ones?
3916 4073
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3940,8 +4097,9 @@  discard block
 block discarded – undo
3940 4097
 			// Loop through all the criteria hoping to make a match.
3941 4098
 			foreach ($rule['criteria'] as $criterium)
3942 4099
 			{
3943
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3944
-					$match = true;
4100
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4101
+									$match = true;
4102
+				}
3945 4103
 				// If we're adding and one criteria don't match then we stop!
3946 4104
 				elseif ($rule['logic'] == 'and')
3947 4105
 				{
@@ -3953,17 +4111,18 @@  discard block
 block discarded – undo
3953 4111
 			// If we have a match the rule must be true - act!
3954 4112
 			if ($match)
3955 4113
 			{
3956
-				if ($rule['delete'])
3957
-					$actions['deletes'][] = $row['id_pm'];
3958
-				else
4114
+				if ($rule['delete']) {
4115
+									$actions['deletes'][] = $row['id_pm'];
4116
+				} else
3959 4117
 				{
3960 4118
 					foreach ($rule['actions'] as $ruleAction)
3961 4119
 					{
3962 4120
 						if ($ruleAction['t'] == 'lab')
3963 4121
 						{
3964 4122
 							// Get a basic pot started!
3965
-							if (!isset($actions['labels'][$row['id_pm']]))
3966
-								$actions['labels'][$row['id_pm']] = array();
4123
+							if (!isset($actions['labels'][$row['id_pm']])) {
4124
+															$actions['labels'][$row['id_pm']] = array();
4125
+							}
3967 4126
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3968 4127
 						}
3969 4128
 					}
@@ -3974,8 +4133,9 @@  discard block
 block discarded – undo
3974 4133
 	$smcFunc['db_free_result']($request);
3975 4134
 
3976 4135
 	// Deletes are easy!
3977
-	if (!empty($actions['deletes']))
3978
-		deleteMessages($actions['deletes']);
4136
+	if (!empty($actions['deletes'])) {
4137
+			deleteMessages($actions['deletes']);
4138
+	}
3979 4139
 
3980 4140
 	// Relabel?
3981 4141
 	if (!empty($actions['labels']))
@@ -4002,8 +4162,7 @@  discard block
 block discarded – undo
4002 4162
 								'current_member' => $user_info['id'],
4003 4163
 							)
4004 4164
 						);
4005
-					}
4006
-					else
4165
+					} else
4007 4166
 					{
4008 4167
 						$realLabels[] = $label['id'];
4009 4168
 					}
@@ -4012,8 +4171,9 @@  discard block
 block discarded – undo
4012 4171
 
4013 4172
 			$inserts = array();
4014 4173
 			// Now we insert the label info
4015
-			foreach ($realLabels as $a_label)
4016
-				$inserts[] = array($pm, $a_label);
4174
+			foreach ($realLabels as $a_label) {
4175
+							$inserts[] = array($pm, $a_label);
4176
+			}
4017 4177
 
4018 4178
 			$smcFunc['db_insert']('ignore',
4019 4179
 				'{db_prefix}pm_labeled_messages',
@@ -4034,8 +4194,9 @@  discard block
 block discarded – undo
4034 4194
 {
4035 4195
 	global $user_info, $context, $smcFunc;
4036 4196
 
4037
-	if (isset($context['rules']) && !$reload)
4038
-		return;
4197
+	if (isset($context['rules']) && !$reload) {
4198
+			return;
4199
+	}
4039 4200
 
4040 4201
 	$request = $smcFunc['db_query']('', '
4041 4202
 		SELECT
@@ -4059,8 +4220,9 @@  discard block
 block discarded – undo
4059 4220
 			'logic' => $row['is_or'] ? 'or' : 'and',
4060 4221
 		);
4061 4222
 
4062
-		if ($row['delete_pm'])
4063
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4223
+		if ($row['delete_pm']) {
4224
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4225
+		}
4064 4226
 	}
4065 4227
 	$smcFunc['db_free_result']($request);
4066 4228
 }
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +117 added lines, -83 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
  * Log an error, if the error logging is enabled.
@@ -36,8 +37,9 @@  discard block
 block discarded – undo
36 37
 	static $tried_hook = false;
37 38
 
38 39
 	// Check if error logging is actually on.
39
-	if (empty($modSettings['enableErrorLogging']))
40
-		return $error_message;
40
+	if (empty($modSettings['enableErrorLogging'])) {
41
+			return $error_message;
42
+	}
41 43
 
42 44
 	// Basically, htmlspecialchars it minus &. (for entities!)
43 45
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -45,22 +47,26 @@  discard block
 block discarded – undo
45 47
 
46 48
 	// Add a file and line to the error message?
47 49
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
48
-	if ($file == null)
49
-		$file = '';
50
-	else
51
-		// Window style slashes don't play well, lets convert them to the unix style.
50
+	if ($file == null) {
51
+			$file = '';
52
+	} else {
53
+			// Window style slashes don't play well, lets convert them to the unix style.
52 54
 		$file = str_replace('\\', '/', $file);
55
+	}
53 56
 
54
-	if ($line == null)
55
-		$line = 0;
56
-	else
57
-		$line = (int) $line;
57
+	if ($line == null) {
58
+			$line = 0;
59
+	} else {
60
+			$line = (int) $line;
61
+	}
58 62
 
59 63
 	// Just in case there's no id_member or IP set yet.
60
-	if (empty($user_info['id']))
61
-		$user_info['id'] = 0;
62
-	if (empty($user_info['ip']))
63
-		$user_info['ip'] = '';
64
+	if (empty($user_info['id'])) {
65
+			$user_info['id'] = 0;
66
+	}
67
+	if (empty($user_info['ip'])) {
68
+			$user_info['ip'] = '';
69
+	}
64 70
 
65 71
 	// Find the best query string we can...
66 72
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
@@ -69,8 +75,9 @@  discard block
 block discarded – undo
69 75
 	$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
70 76
 
71 77
 	// Just so we know what board error messages are from.
72
-	if (isset($_POST['board']) && !isset($_GET['board']))
73
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
78
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
79
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
80
+	}
74 81
 
75 82
 	// What types of categories do we have?
76 83
 	$known_error_types = array(
@@ -132,12 +139,14 @@  discard block
 block discarded – undo
132 139
 	global $txt;
133 140
 
134 141
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
135
-	if (!empty($status))
136
-		send_http_status($status);
142
+	if (!empty($status)) {
143
+			send_http_status($status);
144
+	}
137 145
 
138 146
 	// We don't have $txt yet, but that's okay...
139
-	if (empty($txt))
140
-		die($error);
147
+	if (empty($txt)) {
148
+			die($error);
149
+	}
141 150
 
142 151
 	log_error_online($error, false);
143 152
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -164,8 +173,9 @@  discard block
 block discarded – undo
164 173
 	static $fatal_error_called = false;
165 174
 
166 175
 	// Send the status header - set this to 0 or false if you don't want to send one at all
167
-	if (!empty($status))
168
-		send_http_status($status);
176
+	if (!empty($status)) {
177
+			send_http_status($status);
178
+	}
169 179
 
170 180
 	// Try to load a theme if we don't have one.
171 181
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -175,8 +185,9 @@  discard block
 block discarded – undo
175 185
 	}
176 186
 
177 187
 	// If we have no theme stuff we can't have the language file...
178
-	if (empty($context['theme_loaded']))
179
-		die($error);
188
+	if (empty($context['theme_loaded'])) {
189
+			die($error);
190
+	}
180 191
 
181 192
 	$reload_lang_file = true;
182 193
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -212,8 +223,9 @@  discard block
 block discarded – undo
212 223
 	global $settings, $modSettings, $db_show_debug;
213 224
 
214 225
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
215
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
216
-		return;
226
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
227
+			return;
228
+	}
217 229
 
218 230
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
219 231
 	{
@@ -221,19 +233,22 @@  discard block
 block discarded – undo
221 233
 		$count = count($array);
222 234
 		for ($i = 0; $i < $count; $i++)
223 235
 		{
224
-			if ($array[$i]['function'] != 'loadSubTemplate')
225
-				continue;
236
+			if ($array[$i]['function'] != 'loadSubTemplate') {
237
+							continue;
238
+			}
226 239
 
227 240
 			// This is a bug in PHP, with eval, it seems!
228
-			if (empty($array[$i]['args']))
229
-				$i++;
241
+			if (empty($array[$i]['args'])) {
242
+							$i++;
243
+			}
230 244
 			break;
231 245
 		}
232 246
 
233
-		if (isset($array[$i]) && !empty($array[$i]['args']))
234
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
235
-		else
236
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
247
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
248
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
249
+		} else {
250
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
251
+		}
237 252
 	}
238 253
 
239 254
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -242,8 +257,9 @@  discard block
 block discarded – undo
242 257
 		if ($error_level % 255 != E_ERROR)
243 258
 		{
244 259
 			$temporary = ob_get_contents();
245
-			if (substr($temporary, -2) == '="')
246
-				echo '"';
260
+			if (substr($temporary, -2) == '="') {
261
+							echo '"';
262
+			}
247 263
 		}
248 264
 
249 265
 		// Debugging!  This should look like a PHP error message.
@@ -259,23 +275,27 @@  discard block
 block discarded – undo
259 275
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
260 276
 
261 277
 	// Dying on these errors only causes MORE problems (blank pages!)
262
-	if ($file == 'Unknown')
263
-		return;
278
+	if ($file == 'Unknown') {
279
+			return;
280
+	}
264 281
 
265 282
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
266
-	if ($error_level % 255 == E_ERROR)
267
-		obExit(false);
268
-	else
269
-		return;
283
+	if ($error_level % 255 == E_ERROR) {
284
+			obExit(false);
285
+	} else {
286
+			return;
287
+	}
270 288
 
271 289
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
272
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
273
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
290
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
291
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
292
+	}
274 293
 
275 294
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
276
-	if ($error_level % 255 == E_ERROR)
277
-		die('No direct access...');
278
-}
295
+	if ($error_level % 255 == E_ERROR) {
296
+			die('No direct access...');
297
+	}
298
+	}
279 299
 
280 300
 /**
281 301
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -291,24 +311,28 @@  discard block
 block discarded – undo
291 311
 
292 312
 	// Attempt to prevent a recursive loop.
293 313
 	++$level;
294
-	if ($level > 1)
295
-		return false;
314
+	if ($level > 1) {
315
+			return false;
316
+	}
296 317
 
297 318
 	// Maybe they came from dlattach or similar?
298
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
299
-		loadTheme();
319
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
320
+			loadTheme();
321
+	}
300 322
 
301 323
 	// Don't bother indexing errors mate...
302 324
 	$context['robot_no_index'] = true;
303 325
 
304
-	if (!isset($context['error_title']))
305
-		$context['error_title'] = $txt['error_occured'];
326
+	if (!isset($context['error_title'])) {
327
+			$context['error_title'] = $txt['error_occured'];
328
+	}
306 329
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
307 330
 
308 331
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
309 332
 
310
-	if (empty($context['page_title']))
311
-		$context['page_title'] = $context['error_title'];
333
+	if (empty($context['page_title'])) {
334
+			$context['page_title'] = $context['error_title'];
335
+	}
312 336
 
313 337
 	loadTemplate('Errors');
314 338
 	$context['sub_template'] = 'fatal_error';
@@ -316,23 +340,26 @@  discard block
 block discarded – undo
316 340
 	// If this is SSI, what do they want us to do?
317 341
 	if (SMF == 'SSI')
318 342
 	{
319
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
320
-			$ssi_on_error_method();
321
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
322
-			loadSubTemplate('fatal_error');
343
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
344
+					$ssi_on_error_method();
345
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
346
+					loadSubTemplate('fatal_error');
347
+		}
323 348
 
324 349
 		// No layers?
325
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
326
-			exit;
350
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
351
+					exit;
352
+		}
327 353
 	}
328 354
 	// Alternatively from the cron call?
329 355
 	elseif (SMF == 'BACKGROUND')
330 356
 	{
331 357
 		// We can't rely on even having language files available.
332
-		if (defined('FROM_CLI') && FROM_CLI)
333
-			echo 'cron error: ', $context['error_message'];
334
-		else
335
-			echo 'An error occurred. More information may be available in your logs.';
358
+		if (defined('FROM_CLI') && FROM_CLI) {
359
+					echo 'cron error: ', $context['error_message'];
360
+		} else {
361
+					echo 'An error occurred. More information may be available in your logs.';
362
+		}
336 363
 		exit;
337 364
 	}
338 365
 
@@ -360,8 +387,8 @@  discard block
 block discarded – undo
360 387
 
361 388
 	set_fatal_error_headers();
362 389
 
363
-	if (!empty($maintenance))
364
-		echo '<!DOCTYPE html>
390
+	if (!empty($maintenance)) {
391
+			echo '<!DOCTYPE html>
365 392
 <html>
366 393
 	<head>
367 394
 		<meta name="robots" content="noindex">
@@ -372,6 +399,7 @@  discard block
 block discarded – undo
372 399
 		', $mmessage, '
373 400
 	</body>
374 401
 </html>';
402
+	}
375 403
 
376 404
 	die();
377 405
 }
@@ -393,15 +421,17 @@  discard block
 block discarded – undo
393 421
 	// For our purposes, we're gonna want this on if at all possible.
394 422
 	$modSettings['cache_enable'] = '1';
395 423
 
396
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
397
-		$db_last_error = max($db_last_error, $temp);
424
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
425
+			$db_last_error = max($db_last_error, $temp);
426
+	}
398 427
 
399 428
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
400 429
 	{
401 430
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
402 431
 		cache_put_data('db_last_error', time(), 600);
403
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
404
-			logLastDatabaseError();
432
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
433
+					logLastDatabaseError();
434
+		}
405 435
 
406 436
 		// Language files aren't loaded yet :(.
407 437
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -482,12 +512,14 @@  discard block
 block discarded – undo
482 512
 	global $smcFunc, $user_info, $modSettings;
483 513
 
484 514
 	// Don't bother if Who's Online is disabled.
485
-	if (empty($modSettings['who_enabled']))
486
-		return;
515
+	if (empty($modSettings['who_enabled'])) {
516
+			return;
517
+	}
487 518
 
488 519
 	// Maybe they came from SSI or similar where sessions are not recorded?
489
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
490
-		return;
520
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
521
+			return;
522
+	}
491 523
 
492 524
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
493 525
 
@@ -506,8 +538,9 @@  discard block
 block discarded – undo
506 538
 		$url = smf_json_decode($url, true);
507 539
 		$url['error'] = $error;
508 540
 
509
-		if (!empty($sprintf))
510
-			$url['error_params'] = $sprintf;
541
+		if (!empty($sprintf)) {
542
+					$url['error_params'] = $sprintf;
543
+		}
511 544
 
512 545
 		$smcFunc['db_query']('', '
513 546
 			UPDATE {db_prefix}log_online
@@ -538,10 +571,11 @@  discard block
 block discarded – undo
538 571
 
539 572
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
540 573
 
541
-	if (!isset($statuses[$code]))
542
-		header($protocol . ' 500 Internal Server Error');
543
-	else
544
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
545
-}
574
+	if (!isset($statuses[$code])) {
575
+			header($protocol . ' 500 Internal Server Error');
576
+	} else {
577
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
578
+	}
579
+	}
546 580
 
547 581
 ?>
548 582
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/DbSearch-mysql.php 1 patch
Braces   +13 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  *  Add the file functions to the $smcFunc array.
@@ -23,14 +24,15 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') {
28
+			$smcFunc += array(
28 29
 			'db_search_query' => 'smf_db_query',
29 30
 			'db_search_support' => 'smf_db_search_support',
30 31
 			'db_create_word_search' => 'smf_db_create_word_search',
31 32
 			'db_support_ignore' => true,
32 33
 		);
33
-}
34
+	}
35
+	}
34 36
 
35 37
 /**
36 38
  * This function will tell you whether this database type supports this search type.
@@ -54,12 +56,13 @@  discard block
 block discarded – undo
54 56
 {
55 57
 	global $smcFunc;
56 58
 
57
-	if ($size == 'small')
58
-		$size = 'smallint(5)';
59
-	elseif ($size == 'medium')
60
-		$size = 'mediumint(8)';
61
-	else
62
-		$size = 'int(10)';
59
+	if ($size == 'small') {
60
+			$size = 'smallint(5)';
61
+	} elseif ($size == 'medium') {
62
+			$size = 'mediumint(8)';
63
+	} else {
64
+			$size = 'int(10)';
65
+	}
63 66
 
64 67
 	$smcFunc['db_query']('', '
65 68
 		CREATE TABLE {db_prefix}log_search_words (
Please login to merge, or discard this patch.
Sources/Notify.php 1 patch
Braces   +23 added lines, -20 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
  * Turn off/on notification for a particular board.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	is_not_guest();
35 36
 
36 37
 	// You have to specify a board to turn notifications on!
37
-	if (empty($board))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($board)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// No subaction: find out what to do.
41 43
 	if (isset($_GET['mode']))
@@ -48,16 +50,16 @@  discard block
 block discarded – undo
48 50
 		require_once($sourcedir . '/Subs-Notify.php');
49 51
 		setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref));
50 52
 
51
-		if ($mode > 1)
52
-			// Turn notification on.  (note this just blows smoke if it's already on.)
53
+		if ($mode > 1) {
54
+					// Turn notification on.  (note this just blows smoke if it's already on.)
53 55
 			$smcFunc['db_insert']('ignore',
54 56
 				'{db_prefix}log_notify',
55 57
 				array('id_member' => 'int', 'id_board' => 'int'),
56 58
 				array($user_info['id'], $board),
57 59
 				array('id_member', 'id_board')
58 60
 			);
59
-		else
60
-			$smcFunc['db_query']('', '
61
+		} else {
62
+					$smcFunc['db_query']('', '
61 63
 				DELETE FROM {db_prefix}log_notify
62 64
 				WHERE id_member = {int:current_member}
63 65
 				AND id_board = {int:current_board}',
@@ -66,6 +68,7 @@  discard block
 block discarded – undo
66 68
 					'current_member' => $user_info['id'],
67 69
 				)
68 70
 			);
71
+		}
69 72
 
70 73
 	}
71 74
 
@@ -81,10 +84,10 @@  discard block
 block discarded – undo
81 84
 			),
82 85
 		);
83 86
 		$context['sub_template'] = 'generic_xml';
87
+	} else {
88
+			redirectexit('board=' . $board . '.' . $_REQUEST['start']);
89
+	}
84 90
 	}
85
-	else
86
-		redirectexit('board=' . $board . '.' . $_REQUEST['start']);
87
-}
88 91
 
89 92
 /**
90 93
  * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences
@@ -108,8 +111,9 @@  discard block
 block discarded – undo
108 111
 			$mode = (int) $_GET['mode'];
109 112
 			$alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3);
110 113
 
111
-			if (empty($mode))
112
-				$mode = 1;
114
+			if (empty($mode)) {
115
+							$mode = 1;
116
+			}
113 117
 
114 118
 			$request = $smcFunc['db_query']('', '
115 119
 				SELECT id_member, id_topic, id_msg, unwatched
@@ -132,8 +136,7 @@  discard block
 block discarded – undo
132 136
 					'id_msg' => 0,
133 137
 					'unwatched' => empty($mode) ? 1 : 0,
134 138
 				);
135
-			}
136
-			else
139
+			} else
137 140
 			{
138 141
 				$insert = false;
139 142
 				$log['unwatched'] = empty($mode) ? 1 : 0;
@@ -160,9 +163,8 @@  discard block
 block discarded – undo
160 163
 					array($user_info['id'], $log['id_topic']),
161 164
 					array('id_member', 'id_board')
162 165
 				);
163
-			}
164
-			else
165
-				$smcFunc['db_query']('', '
166
+			} else {
167
+							$smcFunc['db_query']('', '
166 168
 					DELETE FROM {db_prefix}log_notify
167 169
 					WHERE id_topic = {int:topic}
168 170
 						AND id_member = {int:member}',
@@ -170,6 +172,7 @@  discard block
 block discarded – undo
170 172
 						'topic' => $log['id_topic'],
171 173
 						'member' => $user_info['id'],
172 174
 					));
175
+			}
173 176
 
174 177
 		}
175 178
 	}
@@ -186,9 +189,9 @@  discard block
 block discarded – undo
186 189
 			),
187 190
 		);
188 191
 		$context['sub_template'] = 'generic_xml';
192
+	} else {
193
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
194
+	}
189 195
 	}
190
-	else
191
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
192
-}
193 196
 
194 197
 ?>
195 198
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Attachments.php 1 patch
Braces   +102 added lines, -76 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
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -121,19 +125,21 @@  discard block
 block discarded – undo
121 125
 		$result = array();
122 126
 
123 127
 		// You gotta be able to post attachments.
124
-		if (!$this->_canPostAttachment)
125
-			return $this->setResponse(array(
128
+		if (!$this->_canPostAttachment) {
129
+					return $this->setResponse(array(
126 130
 				'text' => 'attached_file_cannot',
127 131
 				'type' => 'error',
128 132
 				'data' => false,
129 133
 			));
134
+		}
130 135
 
131 136
 		// Process them at once!
132 137
 		$this->processAttachments();
133 138
 
134 139
 		// The attachments was created and moved the the right folder, time to update the DB.
135
-		if (!empty($_SESSION['temp_attachments']))
136
-			$this->createAtttach();
140
+		if (!empty($_SESSION['temp_attachments'])) {
141
+					$this->createAtttach();
142
+		}
137 143
 
138 144
 		// Set the response.
139 145
 		$this->setResponse();
@@ -146,8 +152,9 @@  discard block
 block discarded – undo
146 152
 	{
147 153
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
148 154
 
149
-		if (!isset($_FILES['attachment']['name']))
150
-			$_FILES['attachment']['tmp_name'] = array();
155
+		if (!isset($_FILES['attachment']['name'])) {
156
+					$_FILES['attachment']['tmp_name'] = array();
157
+		}
151 158
 
152 159
 		// If there are attachments, calculate the total size and how many.
153 160
 		$context['attachments']['total_size'] = 0;
@@ -157,25 +164,30 @@  discard block
 block discarded – undo
157 164
 		if (isset($_REQUEST['msg']))
158 165
 		{
159 166
 			$context['attachments']['quantity'] = count($context['current_attachments']);
160
-			foreach ($context['current_attachments'] as $attachment)
161
-				$context['attachments']['total_size'] += $attachment['size'];
167
+			foreach ($context['current_attachments'] as $attachment) {
168
+							$context['attachments']['total_size'] += $attachment['size'];
169
+			}
162 170
 		}
163 171
 
164 172
 		// A bit of house keeping first.
165
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
166
-			unset($_SESSION['temp_attachments']);
173
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
174
+					unset($_SESSION['temp_attachments']);
175
+		}
167 176
 
168 177
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
169
-		if (!isset($_SESSION['temp_attachments']))
170
-			$_SESSION['temp_attachments'] = array();
178
+		if (!isset($_SESSION['temp_attachments'])) {
179
+					$_SESSION['temp_attachments'] = array();
180
+		}
171 181
 
172 182
 		// Make sure we're uploading to the right place.
173
-		if (!empty($modSettings['automanage_attachments']))
174
-			automanage_attachments_check_directory();
183
+		if (!empty($modSettings['automanage_attachments'])) {
184
+					automanage_attachments_check_directory();
185
+		}
175 186
 
176 187
 		// Is the attachments folder actually there?
177
-		if (!empty($context['dir_creation_error']))
178
-			$this->_generalErrors[] = $context['dir_creation_error'];
188
+		if (!empty($context['dir_creation_error'])) {
189
+					$this->_generalErrors[] = $context['dir_creation_error'];
190
+		}
179 191
 
180 192
 		// The current attach folder ha some issues...
181 193
 		elseif (!is_dir($this->_attchDir))
@@ -200,13 +212,12 @@  discard block
 block discarded – undo
200 212
 			);
201 213
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
202 214
 			$smcFunc['db_free_result']($request);
203
-		}
204
-
205
-		else
206
-			$context['attachments'] = array(
215
+		} else {
216
+					$context['attachments'] = array(
207 217
 				'quantity' => 0,
208 218
 				'total_size' => 0,
209 219
 			);
220
+		}
210 221
 
211 222
 		// Check for other general errors here.
212 223
 
@@ -214,9 +225,10 @@  discard block
 block discarded – undo
214 225
 		if (!empty($this->_generalErrors))
215 226
 		{
216 227
 			// And delete the files 'cos they ain't going nowhere.
217
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
218
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
228
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
229
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
219 230
 					unlink($_FILES['attachment']['tmp_name'][$n]);
231
+			}
220 232
 
221 233
 			$_FILES['attachment']['tmp_name'] = array();
222 234
 
@@ -227,26 +239,29 @@  discard block
 block discarded – undo
227 239
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
228 240
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
229 241
 		{
230
-			if ($_FILES['attachment']['name'][$n] == '')
231
-				continue;
242
+			if ($_FILES['attachment']['name'][$n] == '') {
243
+							continue;
244
+			}
232 245
 
233 246
 			// First, let's first check for PHP upload errors.
234 247
 			$errors = array();
235 248
 			if (!empty($_FILES['attachment']['error'][$n]))
236 249
 			{
237
-				if ($_FILES['attachment']['error'][$n] == 2)
238
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
239
-
240
-				else
241
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
250
+				if ($_FILES['attachment']['error'][$n] == 2) {
251
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
252
+				} else {
253
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
254
+				}
242 255
 
243 256
 				// Log this one, because...
244
-				if ($_FILES['attachment']['error'][$n] == 6)
245
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				if ($_FILES['attachment']['error'][$n] == 6) {
258
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
259
+				}
246 260
 
247 261
 				// Weird, no errors were cached, still fill out a generic one.
248
-				if (empty($errors))
249
-					$errors[] = 'attach_php_error';
262
+				if (empty($errors)) {
263
+									$errors[] = 'attach_php_error';
264
+				}
250 265
 			}
251 266
 
252 267
 			// Try to move and rename the file before doing any more checks on it.
@@ -266,16 +281,18 @@  discard block
 block discarded – undo
266 281
 				);
267 282
 
268 283
 				// Move the file to the attachments folder with a temp name for now.
269
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
270
-					smf_chmod($destName, 0644);
284
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
285
+									smf_chmod($destName, 0644);
286
+				}
271 287
 
272 288
 				// This is madness!!
273 289
 				else
274 290
 				{
275 291
 					// File couldn't be moved.
276 292
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
277
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
278
-						unlink($_FILES['attachment']['tmp_name'][$n]);
293
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
294
+											unlink($_FILES['attachment']['tmp_name'][$n]);
295
+					}
279 296
 				}
280 297
 			}
281 298
 
@@ -288,13 +305,15 @@  discard block
 block discarded – undo
288 305
 					'errors' => $errors,
289 306
 				);
290 307
 
291
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
292
-					unlink($_FILES['attachment']['tmp_name'][$n]);
308
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
309
+									unlink($_FILES['attachment']['tmp_name'][$n]);
310
+				}
293 311
 			}
294 312
 
295 313
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
296
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
297
-				attachmentChecks($attachID);
314
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
315
+							attachmentChecks($attachID);
316
+			}
298 317
 		}
299 318
 
300 319
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -333,23 +352,24 @@  discard block
 block discarded – undo
333 352
 				'errors' => $attachment['errors'],
334 353
 			);
335 354
 
336
-			if (empty($attachment['errors']))
337
-				if (createAttachment($attachmentOptions))
355
+			if (empty($attachment['errors'])) {
356
+							if (createAttachment($attachmentOptions))
338 357
 				{
339 358
 					// Avoid JS getting confused.
340 359
 					$attachmentOptions['attachID'] = $attachmentOptions['id'];
360
+			}
341 361
 					unset($attachmentOptions['id']);
342 362
 
343 363
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
344 364
 
345
-					if (!empty($attachmentOptions['thumb']))
346
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
347
-
348
-					if ($this->_msg)
349
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
350
-				}
365
+					if (!empty($attachmentOptions['thumb'])) {
366
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					}
351 368
 
352
-			elseif (!empty($attachmentOptions['errors']))
369
+					if ($this->_msg) {
370
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					}
372
+				} elseif (!empty($attachmentOptions['errors']))
353 373
 			{
354 374
 				// Sort out the errors for display and delete any associated files.
355 375
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -361,14 +381,16 @@  discard block
 block discarded – undo
361 381
 					if (!is_array($error))
362 382
 					{
363 383
 						$attachmentOptions['errors'][] = $txt[$error];
364
-						if (in_array($error, $log_these))
365
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
384
+						if (in_array($error, $log_these)) {
385
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
386
+						}
387
+					} else {
388
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
366 389
 					}
367
-					else
368
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
369 390
 				}
370
-				if (file_exists($attachment['tmp_name']))
371
-					unlink($attachment['tmp_name']);
391
+				if (file_exists($attachment['tmp_name'])) {
392
+									unlink($attachment['tmp_name']);
393
+				}
372 394
 			}
373 395
 
374 396
 			// Regardless of errors, pass the results.
@@ -376,8 +398,9 @@  discard block
 block discarded – undo
376 398
 		}
377 399
 
378 400
 		// Temp save this on the db.
379
-		if (!empty($_SESSION['already_attached']))
380
-			$this->_attachSuccess = $_SESSION['already_attached'];
401
+		if (!empty($_SESSION['already_attached'])) {
402
+					$this->_attachSuccess = $_SESSION['already_attached'];
403
+		}
381 404
 
382 405
 		unset($_SESSION['temp_attachments']);
383 406
 	}
@@ -397,14 +420,16 @@  discard block
 block discarded – undo
397 420
 		if ($this->_sa == 'add')
398 421
 		{
399 422
 			// Is there any generic errors? made some sense out of them!
400
-			if ($this->_generalErrors)
401
-				foreach ($this->_generalErrors as $k => $v)
423
+			if ($this->_generalErrors) {
424
+							foreach ($this->_generalErrors as $k => $v)
402 425
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
426
+			}
403 427
 
404 428
 			// Gotta urlencode the filename.
405
-			if ($this->_attachResults)
406
-				foreach ($this->_attachResults as $k => $v)
429
+			if ($this->_attachResults) {
430
+							foreach ($this->_attachResults as $k => $v)
407 431
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
432
+			}
408 433
 
409 434
 			$this->_response = array(
410 435
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -413,9 +438,10 @@  discard block
 block discarded – undo
413 438
 		}
414 439
 
415 440
 		// Rest of us mere mortals gets no special treatment...
416
-		elseif (!empty($data))
417
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
441
+		elseif (!empty($data)) {
442
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
418 443
 				$this->_response['text'] = $txt[$data['text']];
444
+		}
419 445
 	}
420 446
 
421 447
 	protected function sendResponse()
@@ -424,11 +450,11 @@  discard block
 block discarded – undo
424 450
 
425 451
 		ob_end_clean();
426 452
 
427
-		if (!empty($modSettings['CompressedOutput']))
428
-			@ob_start('ob_gzhandler');
429
-
430
-		else
431
-			ob_start();
453
+		if (!empty($modSettings['CompressedOutput'])) {
454
+					@ob_start('ob_gzhandler');
455
+		} else {
456
+					ob_start();
457
+		}
432 458
 
433 459
 		// Set the header.
434 460
 		header('Content-Type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.