Completed
Pull Request — release-2.1 (#4574)
by Matthew
07:51
created
Sources/DbExtra-mysql.php 1 patch
Braces   +72 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 			'db_allow_persistent' => 'smf_db_allow_persistent',
35 36
 		);
36
-}
37
+	}
38
+	}
37 39
 
38 40
 /**
39 41
  * Backup $table to $backup_table.
@@ -75,8 +77,9 @@  discard block
 block discarded – undo
75 77
 			));
76 78
 
77 79
 		// Old school or no school?
78
-		if ($request)
79
-			return $request;
80
+		if ($request) {
81
+					return $request;
82
+		}
80 83
 	}
81 84
 
82 85
 	// At this point, the quick method failed.
@@ -100,8 +103,9 @@  discard block
 block discarded – undo
100 103
 	foreach ($create as $k => $l)
101 104
 	{
102 105
 		// Get the name of the auto_increment column.
103
-		if (strpos($l, 'auto_increment'))
104
-			$auto_inc = trim($l);
106
+		if (strpos($l, 'auto_increment')) {
107
+					$auto_inc = trim($l);
108
+		}
105 109
 
106 110
 		// For the engine type, see if we can work out what it is.
107 111
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -109,30 +113,36 @@  discard block
 block discarded – undo
109 113
 			// Extract the engine type.
110 114
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
111 115
 
112
-			if (!empty($match[1]))
113
-				$engine = $match[1];
116
+			if (!empty($match[1])) {
117
+							$engine = $match[1];
118
+			}
114 119
 
115
-			if (!empty($match[2]))
116
-				$engine = $match[2];
120
+			if (!empty($match[2])) {
121
+							$engine = $match[2];
122
+			}
117 123
 
118
-			if (!empty($match[5]))
119
-				$charset = $match[5];
124
+			if (!empty($match[5])) {
125
+							$charset = $match[5];
126
+			}
120 127
 
121
-			if (!empty($match[7]))
122
-				$collate = $match[7];
128
+			if (!empty($match[7])) {
129
+							$collate = $match[7];
130
+			}
123 131
 		}
124 132
 
125 133
 		// Skip everything but keys...
126
-		if (strpos($l, 'KEY') === false)
127
-			unset($create[$k]);
134
+		if (strpos($l, 'KEY') === false) {
135
+					unset($create[$k]);
136
+		}
128 137
 	}
129 138
 
130
-	if (!empty($create))
131
-		$create = '(
139
+	if (!empty($create)) {
140
+			$create = '(
132 141
 			' . implode('
133 142
 			', $create) . ')';
134
-	else
135
-		$create = '';
143
+	} else {
144
+			$create = '';
145
+	}
136 146
 
137 147
 	$request = $smcFunc['db_query']('', '
138 148
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -151,8 +161,9 @@  discard block
 block discarded – undo
151 161
 
152 162
 	if ($auto_inc != '')
153 163
 	{
154
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
155
-			$auto_inc = substr($auto_inc, 0, -1);
164
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
165
+					$auto_inc = substr($auto_inc, 0, -1);
166
+		}
156 167
 
157 168
 		$smcFunc['db_query']('', '
158 169
 			ALTER TABLE {raw:backup_table}
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 				'table' => $table,
197 208
 			)
198 209
 		);
199
-	if (!$request)
200
-		return -1;
210
+	if (!$request) {
211
+			return -1;
212
+	}
201 213
 
202 214
 	// How much left?
203 215
 	$request = $smcFunc['db_query']('', '
@@ -240,8 +252,9 @@  discard block
 block discarded – undo
240 252
 		)
241 253
 	);
242 254
 	$tables = array();
243
-	while ($row = $smcFunc['db_fetch_row']($request))
244
-		$tables[] = $row[0];
255
+	while ($row = $smcFunc['db_fetch_row']($request)) {
256
+			$tables[] = $row[0];
257
+	}
245 258
 	$smcFunc['db_free_result']($request);
246 259
 
247 260
 	return $tables;
@@ -285,8 +298,9 @@  discard block
 block discarded – undo
285 298
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
286 299
 		{
287 300
 			// Make a special case of auto-timestamp.
288
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
289
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
301
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
302
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
303
+			}
290 304
 			// Text shouldn't have a default.
291 305
 			elseif ($row['Default'] !== null)
292 306
 			{
@@ -321,14 +335,16 @@  discard block
 block discarded – undo
321 335
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
322 336
 
323 337
 		// Is this the first column in the index?
324
-		if (empty($indexes[$row['Key_name']]))
325
-			$indexes[$row['Key_name']] = array();
338
+		if (empty($indexes[$row['Key_name']])) {
339
+					$indexes[$row['Key_name']] = array();
340
+		}
326 341
 
327 342
 		// A sub part, like only indexing 15 characters of a varchar.
328
-		if (!empty($row['Sub_part']))
329
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
330
-		else
331
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
343
+		if (!empty($row['Sub_part'])) {
344
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
345
+		} else {
346
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
347
+		}
332 348
 	}
333 349
 	$smcFunc['db_free_result']($result);
334 350
 
@@ -366,8 +382,9 @@  discard block
 block discarded – undo
366 382
 {
367 383
 	static $ver;
368 384
 
369
-	if (!empty($ver))
370
-		return $ver;
385
+	if (!empty($ver)) {
386
+			return $ver;
387
+	}
371 388
 
372 389
 	global $smcFunc;
373 390
 
@@ -392,8 +409,9 @@  discard block
 block discarded – undo
392 409
 	global $smcFunc;
393 410
 	static $db_type;
394 411
 
395
-	if (!empty($db_type))
396
-		return $db_type;
412
+	if (!empty($db_type)) {
413
+			return $db_type;
414
+	}
397 415
 
398 416
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
399 417
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -402,13 +420,15 @@  discard block
 block discarded – undo
402 420
 	// Skip these if we don't have a comment.
403 421
 	if (!empty($comment))
404 422
 	{
405
-		if (stripos($comment, 'percona') !== false)
406
-			return 'Percona';
407
-		if (stripos($comment, 'mariadb') !== false)
408
-			return 'MariaDB';
423
+		if (stripos($comment, 'percona') !== false) {
424
+					return 'Percona';
425
+		}
426
+		if (stripos($comment, 'mariadb') !== false) {
427
+					return 'MariaDB';
428
+		}
429
+	} else {
430
+			return 'fail';
409 431
 	}
410
-	else
411
-		return 'fail';
412 432
 
413 433
 	return 'MySQL';
414 434
 }
@@ -421,10 +441,11 @@  discard block
 block discarded – undo
421 441
 function smf_db_allow_persistent()
422 442
 {
423 443
 	$value = ini_get('mysqli.allow_persistent');
424
-	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1')
425
-		return true;
426
-	else
427
-		return false;
428
-}
444
+	if (strtolower($value) == 'on' || strtolower($value) == 'true' || $value == '1') {
445
+			return true;
446
+	} else {
447
+			return false;
448
+	}
449
+	}
429 450
 
430 451
 ?>
431 452
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +412 added lines, -309 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -381,8 +395,7 @@  discard block
 block discarded – undo
381 395
 
382 396
 			// Put the tags back into the body.
383 397
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
384
-		}
385
-		else
398
+		} else
386 399
 		{
387 400
 			// Just get rid of this evil tag.
388 401
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -395,8 +408,9 @@  discard block
 block discarded – undo
395 408
 		// Find the position of this again.
396 409
 		$start_pos = strpos($text, $matches[0]);
397 410
 		$end_pos = false;
398
-		if ($start_pos === false)
399
-			break;
411
+		if ($start_pos === false) {
412
+					break;
413
+		}
400 414
 
401 415
 		// This must have an end tag - and we must find the right one.
402 416
 		$lower_text = strtolower($text);
@@ -429,8 +443,9 @@  discard block
 block discarded – undo
429 443
 				break;
430 444
 			}
431 445
 		}
432
-		if ($end_pos === false)
433
-			break;
446
+		if ($end_pos === false) {
447
+					break;
448
+		}
434 449
 
435 450
 		// Now work out what the attributes are.
436 451
 		$attribs = fetchTagAttributes($matches[1]);
@@ -444,11 +459,11 @@  discard block
 block discarded – undo
444 459
 				$v = (int) trim($v);
445 460
 				$v = empty($v) ? 1 : $v;
446 461
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
462
+			} elseif ($s == 'face') {
463
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
464
+			} elseif ($s == 'color') {
465
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
447 466
 			}
448
-			elseif ($s == 'face')
449
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
450
-			elseif ($s == 'color')
451
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
452 467
 		}
453 468
 
454 469
 		// As before add in our tags.
@@ -456,8 +471,9 @@  discard block
 block discarded – undo
456 471
 		foreach ($tags as $tag)
457 472
 		{
458 473
 			$before .= $tag[0];
459
-			if (isset($tag[1]))
460
-				$after = $tag[1] . $after;
474
+			if (isset($tag[1])) {
475
+							$after = $tag[1] . $after;
476
+			}
461 477
 		}
462 478
 
463 479
 		// Remove the tag so it's never checked again.
@@ -468,8 +484,9 @@  discard block
 block discarded – undo
468 484
 	}
469 485
 
470 486
 	// Almost there, just a little more time.
471
-	if (connection_aborted() && $context['server']['is_apache'])
472
-		@apache_reset_timeout();
487
+	if (connection_aborted() && $context['server']['is_apache']) {
488
+			@apache_reset_timeout();
489
+	}
473 490
 
474 491
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
475 492
 	{
@@ -525,12 +542,13 @@  discard block
 block discarded – undo
525 542
 						{
526 543
 							$inList = true;
527 544
 
528
-							if ($tag === 'ol')
529
-								$listType = 'decimal';
530
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
531
-								$listType = $listTypeMapping[$match[1]];
532
-							else
533
-								$listType = null;
545
+							if ($tag === 'ol') {
546
+															$listType = 'decimal';
547
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
548
+															$listType = $listTypeMapping[$match[1]];
549
+							} else {
550
+															$listType = null;
551
+							}
534 552
 
535 553
 							$listDepth++;
536 554
 
@@ -594,9 +612,7 @@  discard block
 block discarded – undo
594 612
 							$parts[$i + 1] = '';
595 613
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
596 614
 							$parts[$i + 3] = '';
597
-						}
598
-
599
-						else
615
+						} else
600 616
 						{
601 617
 							// We're in a list item.
602 618
 							if ($listDepth > 0)
@@ -633,9 +649,7 @@  discard block
 block discarded – undo
633 649
 							$parts[$i + 1] = '';
634 650
 							$parts[$i + 2] = '';
635 651
 							$parts[$i + 3] = '';
636
-						}
637
-
638
-						else
652
+						} else
639 653
 						{
640 654
 							// Remove the trailing breaks from the list item.
641 655
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -673,8 +687,9 @@  discard block
 block discarded – undo
673 687
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
674 688
 		}
675 689
 
676
-		for ($i = $listDepth; $i > 0; $i--)
677
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
690
+		for ($i = $listDepth; $i > 0; $i--) {
691
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		}
678 693
 
679 694
 	}
680 695
 
@@ -683,8 +698,9 @@  discard block
 block discarded – undo
683 698
 	{
684 699
 		// Find the position of the image.
685 700
 		$start_pos = strpos($text, $matches[0]);
686
-		if ($start_pos === false)
687
-			break;
701
+		if ($start_pos === false) {
702
+					break;
703
+		}
688 704
 		$end_pos = $start_pos + strlen($matches[0]);
689 705
 
690 706
 		$params = '';
@@ -693,12 +709,13 @@  discard block
 block discarded – undo
693 709
 		$attrs = fetchTagAttributes($matches[1]);
694 710
 		foreach ($attrs as $attrib => $value)
695 711
 		{
696
-			if (in_array($attrib, array('width', 'height')))
697
-				$params .= ' ' . $attrib . '=' . (int) $value;
698
-			elseif ($attrib == 'alt' && trim($value) != '')
699
-				$params .= ' alt=' . trim($value);
700
-			elseif ($attrib == 'src')
701
-				$src = trim($value);
712
+			if (in_array($attrib, array('width', 'height'))) {
713
+							$params .= ' ' . $attrib . '=' . (int) $value;
714
+			} elseif ($attrib == 'alt' && trim($value) != '') {
715
+							$params .= ' alt=' . trim($value);
716
+			} elseif ($attrib == 'src') {
717
+							$src = trim($value);
718
+			}
702 719
 		}
703 720
 
704 721
 		$tag = '';
@@ -709,10 +726,11 @@  discard block
 block discarded – undo
709 726
 			{
710 727
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
711 728
 
712
-				if (substr($src, 0, 1) === '/')
713
-					$src = $baseURL . $src;
714
-				else
715
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				if (substr($src, 0, 1) === '/') {
730
+									$src = $baseURL . $src;
731
+				} else {
732
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
733
+				}
716 734
 			}
717 735
 
718 736
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -890,20 +908,23 @@  discard block
 block discarded – undo
890 908
 		},
891 909
 	);
892 910
 
893
-	foreach ($tags as $tag => $replace)
894
-		$text = preg_replace_callback($tag, $replace, $text);
911
+	foreach ($tags as $tag => $replace) {
912
+			$text = preg_replace_callback($tag, $replace, $text);
913
+	}
895 914
 
896 915
 	// Please give us just a little more time.
897
-	if (connection_aborted() && $context['server']['is_apache'])
898
-		@apache_reset_timeout();
916
+	if (connection_aborted() && $context['server']['is_apache']) {
917
+			@apache_reset_timeout();
918
+	}
899 919
 
900 920
 	// What about URL's - the pain in the ass of the tag world.
901 921
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
902 922
 	{
903 923
 		// Find the position of the URL.
904 924
 		$start_pos = strpos($text, $matches[0]);
905
-		if ($start_pos === false)
906
-			break;
925
+		if ($start_pos === false) {
926
+					break;
927
+		}
907 928
 		$end_pos = $start_pos + strlen($matches[0]);
908 929
 
909 930
 		$tag_type = 'url';
@@ -917,8 +938,9 @@  discard block
 block discarded – undo
917 938
 				$href = trim($value);
918 939
 
919 940
 				// Are we dealing with an FTP link?
920
-				if (preg_match('~^ftps?://~', $href) === 1)
921
-					$tag_type = 'ftp';
941
+				if (preg_match('~^ftps?://~', $href) === 1) {
942
+									$tag_type = 'ftp';
943
+				}
922 944
 
923 945
 				// Or is this a link to an email address?
924 946
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -932,28 +954,31 @@  discard block
 block discarded – undo
932 954
 				{
933 955
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
934 956
 
935
-					if (substr($href, 0, 1) === '/')
936
-						$href = $baseURL . $href;
937
-					else
938
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					if (substr($href, 0, 1) === '/') {
958
+											$href = $baseURL . $href;
959
+					} else {
960
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
961
+					}
939 962
 				}
940 963
 			}
941 964
 
942 965
 			// External URL?
943 966
 			if ($attrib == 'target' && $tag_type == 'url')
944 967
 			{
945
-				if (trim($value) == '_blank')
946
-					$tag_type == 'iurl';
968
+				if (trim($value) == '_blank') {
969
+									$tag_type == 'iurl';
970
+				}
947 971
 			}
948 972
 		}
949 973
 
950 974
 		$tag = '';
951 975
 		if ($href != '')
952 976
 		{
953
-			if ($matches[2] == $href)
954
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
955
-			else
956
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			if ($matches[2] == $href) {
978
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
979
+			} else {
980
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
981
+			}
957 982
 		}
958 983
 
959 984
 		// Replace the tag
@@ -992,17 +1017,18 @@  discard block
 block discarded – undo
992 1017
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
993 1018
 		if ($text[$i] == '=')
994 1019
 		{
995
-			if ($tag_state == 0)
996
-				$tag_state = 1;
997
-			elseif ($tag_state == 2)
998
-				$value .= '=';
1020
+			if ($tag_state == 0) {
1021
+							$tag_state = 1;
1022
+			} elseif ($tag_state == 2) {
1023
+							$value .= '=';
1024
+			}
999 1025
 		}
1000 1026
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1001 1027
 		elseif ($text[$i] == ' ')
1002 1028
 		{
1003
-			if ($tag_state == 2)
1004
-				$value .= ' ';
1005
-			elseif ($tag_state == 1)
1029
+			if ($tag_state == 2) {
1030
+							$value .= ' ';
1031
+			} elseif ($tag_state == 1)
1006 1032
 			{
1007 1033
 				$attribs[$key] = $value;
1008 1034
 				$key = $value = '';
@@ -1013,24 +1039,27 @@  discard block
 block discarded – undo
1013 1039
 		elseif ($text[$i] == '"')
1014 1040
 		{
1015 1041
 			// Must be either going into or out of a string.
1016
-			if ($tag_state == 1)
1017
-				$tag_state = 2;
1018
-			else
1019
-				$tag_state = 1;
1042
+			if ($tag_state == 1) {
1043
+							$tag_state = 2;
1044
+			} else {
1045
+							$tag_state = 1;
1046
+			}
1020 1047
 		}
1021 1048
 		// Otherwise it's fine.
1022 1049
 		else
1023 1050
 		{
1024
-			if ($tag_state == 0)
1025
-				$key .= $text[$i];
1026
-			else
1027
-				$value .= $text[$i];
1051
+			if ($tag_state == 0) {
1052
+							$key .= $text[$i];
1053
+			} else {
1054
+							$value .= $text[$i];
1055
+			}
1028 1056
 		}
1029 1057
 	}
1030 1058
 
1031 1059
 	// Anything left?
1032
-	if ($key != '' && $value != '')
1033
-		$attribs[$key] = $value;
1060
+	if ($key != '' && $value != '') {
1061
+			$attribs[$key] = $value;
1062
+	}
1034 1063
 
1035 1064
 	return $attribs;
1036 1065
 }
@@ -1046,15 +1075,17 @@  discard block
 block discarded – undo
1046 1075
 	global $modSettings;
1047 1076
 
1048 1077
 	// Don't care about the texts that are too short.
1049
-	if (strlen($text) < 3)
1050
-		return $text;
1078
+	if (strlen($text) < 3) {
1079
+			return $text;
1080
+	}
1051 1081
 
1052 1082
 	// A list of tags that's disabled by the admin.
1053 1083
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1054 1084
 
1055 1085
 	// Add flash if it's disabled as embedded tag.
1056
-	if (empty($modSettings['enableEmbeddedFlash']))
1057
-		$disabled['flash'] = true;
1086
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1087
+			$disabled['flash'] = true;
1088
+	}
1058 1089
 
1059 1090
 	// Get a list of all the tags that are not disabled.
1060 1091
 	$all_tags = parse_bbc(false);
@@ -1062,10 +1093,12 @@  discard block
 block discarded – undo
1062 1093
 	$self_closing_tags = array();
1063 1094
 	foreach ($all_tags as $tag)
1064 1095
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1096
+		if (!isset($disabled[$tag['tag']])) {
1097
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1098
+		}
1099
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1100
+					$self_closing_tags[] = $tag['tag'];
1101
+		}
1069 1102
 	}
1070 1103
 
1071 1104
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1125,19 @@  discard block
 block discarded – undo
1092 1125
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1126
 
1094 1127
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1128
+				if ($isClosingTag && $insideTag === $tagName) {
1129
+									$insideTag = null;
1130
+				}
1097 1131
 
1098 1132
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1133
+				elseif (!$isClosingTag && $insideTag === null) {
1134
+									$insideTag = $tagName;
1135
+				}
1101 1136
 
1102 1137
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1138
+				else {
1139
+									unset($matches[$i]);
1140
+				}
1105 1141
 			}
1106 1142
 
1107 1143
 			// The next one is gonna be the other one.
@@ -1109,8 +1145,9 @@  discard block
 block discarded – undo
1109 1145
 		}
1110 1146
 
1111 1147
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1148
+		if ($insideTag !== null) {
1149
+					$matches[] = '[/' . $insideTag . ']';
1150
+		}
1114 1151
 
1115 1152
 		// And a complete text string again.
1116 1153
 		$text = implode('', $matches);
@@ -1119,8 +1156,9 @@  discard block
 block discarded – undo
1119 1156
 	// Quickly remove any tags which are back to back.
1120 1157
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1158
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1159
+	while (strlen($text) !== $lastlen) {
1160
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1161
+	}
1124 1162
 
1125 1163
 	// Need to sort the tags my name length.
1126 1164
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1195,9 @@  discard block
 block discarded – undo
1157 1195
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1196
 
1159 1197
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1198
+			if ($tag === '') {
1199
+							continue;
1200
+			}
1162 1201
 
1163 1202
 			// Special case: inside [code] blocks any code is left untouched.
1164 1203
 			elseif ($tag === 'code')
@@ -1169,8 +1208,9 @@  discard block
 block discarded – undo
1169 1208
 					$inCode = false;
1170 1209
 
1171 1210
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1211
+					if (!empty($inlineElements)) {
1212
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1213
+					}
1174 1214
 				}
1175 1215
 
1176 1216
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1239,9 @@  discard block
 block discarded – undo
1199 1239
 					$inNoBbc = false;
1200 1240
 
1201 1241
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1242
+					if (!empty($inlineElements)) {
1243
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1244
+					}
1204 1245
 				}
1205 1246
 
1206 1247
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1261,9 @@  discard block
 block discarded – undo
1220 1261
 			}
1221 1262
 
1222 1263
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1264
+			elseif ($inCode || $inNoBbc) {
1265
+							continue;
1266
+			}
1225 1267
 
1226 1268
 			// We're dealing with an opening tag.
1227 1269
 			if ($isOpeningTag)
@@ -1262,8 +1304,9 @@  discard block
 block discarded – undo
1262 1304
 							if ($parts[$j + 3] === $tag)
1263 1305
 							{
1264 1306
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1307
+								if ($parts[$j + 2] === '') {
1308
+																	$curLevel++;
1309
+								}
1267 1310
 
1268 1311
 								// A closing tag, decrease the level.
1269 1312
 								else
@@ -1286,13 +1329,15 @@  discard block
 block discarded – undo
1286 1329
 					{
1287 1330
 						if ($isCompetingTag)
1288 1331
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1332
+							if (!isset($competingElements[$tag])) {
1333
+															$competingElements[$tag] = array();
1334
+							}
1291 1335
 
1292 1336
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1337
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1338
+							if (count($competingElements[$tag]) > 1) {
1339
+															$parts[$i] .= '[/' . $tag . ']';
1340
+							}
1296 1341
 						}
1297 1342
 
1298 1343
 						$inlineElements[$elementContent] = $tag;
@@ -1313,15 +1358,17 @@  discard block
 block discarded – undo
1313 1358
 						$addClosingTags = array();
1314 1359
 						while ($element = array_pop($blockElements))
1315 1360
 						{
1316
-							if ($element === $tag)
1317
-								break;
1361
+							if ($element === $tag) {
1362
+															break;
1363
+							}
1318 1364
 
1319 1365
 							// Still a block tag was open not equal to this tag.
1320 1366
 							$addClosingTags[] = $element['type'];
1321 1367
 						}
1322 1368
 
1323
-						if (!empty($addClosingTags))
1324
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						if (!empty($addClosingTags)) {
1370
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1371
+						}
1325 1372
 
1326 1373
 						// Apparently the closing tag was not found on the stack.
1327 1374
 						if (!is_string($element) || $element !== $tag)
@@ -1331,8 +1378,7 @@  discard block
 block discarded – undo
1331 1378
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1332 1379
 							continue;
1333 1380
 						}
1334
-					}
1335
-					else
1381
+					} else
1336 1382
 					{
1337 1383
 						// Get rid of this closing tag!
1338 1384
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1361,53 +1407,62 @@  discard block
 block discarded – undo
1361 1407
 							unset($inlineElements[$tagContentToBeClosed]);
1362 1408
 
1363 1409
 							// Was this the tag we were looking for?
1364
-							if ($tagToBeClosed === $tag)
1365
-								break;
1410
+							if ($tagToBeClosed === $tag) {
1411
+															break;
1412
+							}
1366 1413
 
1367 1414
 							// Nope, close it and look further!
1368
-							else
1369
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							else {
1416
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1417
+							}
1370 1418
 						}
1371 1419
 
1372 1420
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1373 1421
 						{
1374 1422
 							array_pop($competingElements[$tag]);
1375 1423
 
1376
-							if (count($competingElements[$tag]) > 0)
1377
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							if (count($competingElements[$tag]) > 0) {
1425
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1426
+							}
1378 1427
 						}
1379 1428
 					}
1380 1429
 
1381 1430
 					// Unexpected closing tag, ex-ter-mi-nate.
1382
-					else
1383
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					else {
1432
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1433
+					}
1384 1434
 				}
1385 1435
 			}
1386 1436
 		}
1387 1437
 
1388 1438
 		// Close the code tags.
1389
-		if ($inCode)
1390
-			$parts[$i] .= '[/code]';
1439
+		if ($inCode) {
1440
+					$parts[$i] .= '[/code]';
1441
+		}
1391 1442
 
1392 1443
 		// The same for nobbc tags.
1393
-		elseif ($inNoBbc)
1394
-			$parts[$i] .= '[/nobbc]';
1444
+		elseif ($inNoBbc) {
1445
+					$parts[$i] .= '[/nobbc]';
1446
+		}
1395 1447
 
1396 1448
 		// Still inline tags left unclosed? Close them now, better late than never.
1397
-		elseif (!empty($inlineElements))
1398
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		elseif (!empty($inlineElements)) {
1450
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1451
+		}
1399 1452
 
1400 1453
 		// Now close the block elements.
1401
-		if (!empty($blockElements))
1402
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		if (!empty($blockElements)) {
1455
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1456
+		}
1403 1457
 
1404 1458
 		$text = implode('', $parts);
1405 1459
 	}
1406 1460
 
1407 1461
 	// Final clean up of back to back tags.
1408 1462
 	$lastlen = 0;
1409
-	while (strlen($text) !== $lastlen)
1410
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	while (strlen($text) !== $lastlen) {
1464
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1465
+	}
1411 1466
 
1412 1467
 	return $text;
1413 1468
 }
@@ -1436,22 +1491,25 @@  discard block
 block discarded – undo
1436 1491
 	$context['template_layers'] = array();
1437 1492
 	// Lets make sure we aren't going to output anything nasty.
1438 1493
 	@ob_end_clean();
1439
-	if (!empty($modSettings['enableCompressedOutput']))
1440
-		@ob_start('ob_gzhandler');
1441
-	else
1442
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1443 1499
 
1444 1500
 	// If we don't have any locale better avoid broken js
1445
-	if (empty($txt['lang_locale']))
1446
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1447 1504
 
1448 1505
 	$file_data = '(function ($) {
1449 1506
 	\'use strict\';
1450 1507
 
1451 1508
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1452
-	foreach ($editortxt as $key => $val)
1453
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1454 1511
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1512
+	}
1455 1513
 
1456 1514
 	$file_data .= '
1457 1515
 		dateFormat: "day.month.year"
@@ -1519,8 +1577,9 @@  discard block
 block discarded – undo
1519 1577
 				)
1520 1578
 			);
1521 1579
 			$icon_data = array();
1522
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1523
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1524 1583
 			$smcFunc['db_free_result']($request);
1525 1584
 
1526 1585
 			$icons = array();
@@ -1535,9 +1594,9 @@  discard block
 block discarded – undo
1535 1594
 			}
1536 1595
 
1537 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1538 1599
 		}
1539
-		else
1540
-			$icons = $temp;
1541 1600
 	}
1542 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1543 1602
 
@@ -1579,8 +1638,9 @@  discard block
 block discarded – undo
1579 1638
 	{
1580 1639
 		// Some general stuff.
1581 1640
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1582
-		if (!empty($context['drafts_autosave']))
1583
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1641
+		if (!empty($context['drafts_autosave'])) {
1642
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1643
+		}
1584 1644
 
1585 1645
 		// This really has some WYSIWYG stuff.
1586 1646
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1598,8 +1658,9 @@  discard block
 block discarded – undo
1598 1658
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1599 1659
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1600 1660
 		// editor language file
1601
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1602
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1661
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1662
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1663
+		}
1603 1664
 
1604 1665
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1605 1666
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1608,11 +1669,12 @@  discard block
 block discarded – undo
1608 1669
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1609 1670
 
1610 1671
 			// Some hidden information is needed in order to make the spell checking work.
1611
-			if (!isset($_REQUEST['xml']))
1612
-				$context['insert_after_template'] .= '
1672
+			if (!isset($_REQUEST['xml'])) {
1673
+							$context['insert_after_template'] .= '
1613 1674
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1614 1675
 			<input type="hidden" name="spellstring" value="">
1615 1676
 		</form>';
1677
+			}
1616 1678
 		}
1617 1679
 	}
1618 1680
 
@@ -1803,10 +1865,12 @@  discard block
 block discarded – undo
1803 1865
 
1804 1866
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1805 1867
 		$disabled_tags = array();
1806
-		if (!empty($modSettings['disabledBBC']))
1807
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1808
-		if (empty($modSettings['enableEmbeddedFlash']))
1809
-			$disabled_tags[] = 'flash';
1868
+		if (!empty($modSettings['disabledBBC'])) {
1869
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1870
+		}
1871
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1872
+					$disabled_tags[] = 'flash';
1873
+		}
1810 1874
 
1811 1875
 		foreach ($disabled_tags as $tag)
1812 1876
 		{
@@ -1818,9 +1882,10 @@  discard block
 block discarded – undo
1818 1882
 				$context['disabled_tags']['orderedlist'] = true;
1819 1883
 			}
1820 1884
 
1821
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1822
-				if ($tag === $thisTag)
1885
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1886
+							if ($tag === $thisTag)
1823 1887
 					$context['disabled_tags'][$tagNameBBC] = true;
1888
+			}
1824 1889
 
1825 1890
 			$context['disabled_tags'][$tag] = true;
1826 1891
 		}
@@ -1831,8 +1896,9 @@  discard block
 block discarded – undo
1831 1896
 
1832 1897
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1833 1898
 		{
1834
-			if (!isset($context['bbc_toolbar'][$row]))
1835
-				$context['bbc_toolbar'][$row] = array();
1899
+			if (!isset($context['bbc_toolbar'][$row])) {
1900
+							$context['bbc_toolbar'][$row] = array();
1901
+			}
1836 1902
 
1837 1903
 			$tagsRow = array();
1838 1904
 
@@ -1868,20 +1934,21 @@  discard block
 block discarded – undo
1868 1934
 
1869 1935
 					$context['bbcodes_handlers'] .= '
1870 1936
 						});';
1871
-				}
1872
-				else
1937
+				} else
1873 1938
 				{
1874 1939
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1875 1940
 					$tagsRow = array();
1876 1941
 				}
1877 1942
 			}
1878 1943
 
1879
-			if (!empty($tagsRow))
1880
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1944
+			if (!empty($tagsRow)) {
1945
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1946
+			}
1881 1947
 		}
1882 1948
 
1883
-		if (!empty($bbcodes_styles))
1884
-			addInlineCss($bbcodes_styles);
1949
+		if (!empty($bbcodes_styles)) {
1950
+					addInlineCss($bbcodes_styles);
1951
+		}
1885 1952
 	}
1886 1953
 
1887 1954
 	// Initialize smiley array... if not loaded before.
@@ -1893,8 +1960,8 @@  discard block
 block discarded – undo
1893 1960
 		);
1894 1961
 
1895 1962
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1896
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1897
-			$context['smileys']['postform'][] = array(
1963
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1964
+					$context['smileys']['postform'][] = array(
1898 1965
 				'smileys' => array(
1899 1966
 					array(
1900 1967
 						'code' => ':)',
@@ -1980,7 +2047,7 @@  discard block
 block discarded – undo
1980 2047
 				),
1981 2048
 				'isLast' => true,
1982 2049
 			);
1983
-		elseif ($user_info['smiley_set'] != 'none')
2050
+		} elseif ($user_info['smiley_set'] != 'none')
1984 2051
 		{
1985 2052
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1986 2053
 			{
@@ -2003,17 +2070,19 @@  discard block
 block discarded – undo
2003 2070
 
2004 2071
 				foreach ($context['smileys'] as $section => $smileyRows)
2005 2072
 				{
2006
-					foreach ($smileyRows as $rowIndex => $smileys)
2007
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2073
+					foreach ($smileyRows as $rowIndex => $smileys) {
2074
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2075
+					}
2008 2076
 
2009
-					if (!empty($smileyRows))
2010
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2077
+					if (!empty($smileyRows)) {
2078
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2079
+					}
2011 2080
 				}
2012 2081
 
2013 2082
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2083
+			} else {
2084
+							$context['smileys'] = $temp;
2014 2085
 			}
2015
-			else
2016
-				$context['smileys'] = $temp;
2017 2086
 		}
2018 2087
 	}
2019 2088
 
@@ -2029,12 +2098,15 @@  discard block
 block discarded – undo
2029 2098
 		'plugins' => 'undo' . (empty($modSettings['disabledBBC']) || strpos($modSettings['disabledBBC'], 'youtube') === false ? ',autoyoutube' : ''),
2030 2099
 		'bbcodeTrim' => true,
2031 2100
 	);
2032
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2033
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2034
-	if (!empty($context['right_to_left']))
2035
-		$sce_options['rtl'] = true;
2036
-	if ($editorOptions['id'] != 'quickReply')
2037
-		$sce_options['autofocus'] = true;
2101
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2102
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2103
+	}
2104
+	if (!empty($context['right_to_left'])) {
2105
+			$sce_options['rtl'] = true;
2106
+	}
2107
+	if ($editorOptions['id'] != 'quickReply') {
2108
+			$sce_options['autofocus'] = true;
2109
+	}
2038 2110
 
2039 2111
 	$sce_options['emoticons'] = array();
2040 2112
 	$sce_options['emoticonsEnabled'] = false;
@@ -2050,10 +2122,11 @@  discard block
 block discarded – undo
2050 2122
 			$countLocations--;
2051 2123
 
2052 2124
 			unset($smiley_location);
2053
-			if ($location == 'postform')
2054
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2055
-			elseif ($location == 'popup')
2056
-				$smiley_location = &$sce_options['emoticons']['popup'];
2125
+			if ($location == 'postform') {
2126
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2127
+			} elseif ($location == 'popup') {
2128
+							$smiley_location = &$sce_options['emoticons']['popup'];
2129
+			}
2057 2130
 
2058 2131
 			$numRows = count($smileyRows);
2059 2132
 
@@ -2061,11 +2134,13 @@  discard block
 block discarded – undo
2061 2134
 			$emptyPlaceholder = 0;
2062 2135
 			foreach ($smileyRows as $smileyRow)
2063 2136
 			{
2064
-				foreach ($smileyRow['smileys'] as $smiley)
2065
-					$smiley_location[$smiley['code']] = $settings['smileys_url'] . '/' . $smiley['filename'];
2137
+				foreach ($smileyRow['smileys'] as $smiley) {
2138
+									$smiley_location[$smiley['code']] = $settings['smileys_url'] . '/' . $smiley['filename'];
2139
+				}
2066 2140
 
2067
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2068
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2141
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2142
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2143
+				}
2069 2144
 			}
2070 2145
 		}
2071 2146
 	}
@@ -2080,8 +2155,9 @@  discard block
 block discarded – undo
2080 2155
 
2081 2156
 			$count_tags--;
2082 2157
 
2083
-			if (!empty($count_tags))
2084
-				$sce_options['toolbar'] .= '||';
2158
+			if (!empty($count_tags)) {
2159
+							$sce_options['toolbar'] .= '||';
2160
+			}
2085 2161
 		}
2086 2162
 	}
2087 2163
 
@@ -2109,8 +2185,9 @@  discard block
 block discarded – undo
2109 2185
 		loadTemplate('GenericControls');
2110 2186
 
2111 2187
 		// Some javascript ma'am?
2112
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2113
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2188
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2189
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2190
+		}
2114 2191
 
2115 2192
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2116 2193
 
@@ -2123,8 +2200,8 @@  discard block
 block discarded – undo
2123 2200
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2124 2201
 
2125 2202
 	// Log this into our collection.
2126
-	if ($isNew)
2127
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2203
+	if ($isNew) {
2204
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2128 2205
 			'id' => $verificationOptions['id'],
2129 2206
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2130 2207
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2135,13 +2212,15 @@  discard block
 block discarded – undo
2135 2212
 			'questions' => array(),
2136 2213
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2137 2214
 		);
2215
+	}
2138 2216
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2139 2217
 
2140 2218
 	// Is there actually going to be anything?
2141
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2142
-		return false;
2143
-	elseif (!$isNew && !$do_test)
2144
-		return true;
2219
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2220
+			return false;
2221
+	} elseif (!$isNew && !$do_test) {
2222
+			return true;
2223
+	}
2145 2224
 
2146 2225
 	// Sanitize reCAPTCHA fields?
2147 2226
 	if ($thisVerification['can_recaptcha'])
@@ -2154,11 +2233,12 @@  discard block
 block discarded – undo
2154 2233
 	}
2155 2234
 
2156 2235
 	// Add javascript for the object.
2157
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2158
-		$context['insert_after_template'] .= '
2236
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2237
+			$context['insert_after_template'] .= '
2159 2238
 			<script>
2160 2239
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2161 2240
 			</script>';
2241
+	}
2162 2242
 
2163 2243
 	// If we want questions do we have a cache of all the IDs?
2164 2244
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2181,8 +2261,9 @@  discard block
 block discarded – undo
2181 2261
 				unset ($row['id_question']);
2182 2262
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2183 2263
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2184
-				foreach ($row['answers'] as $k => $v)
2185
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2264
+				foreach ($row['answers'] as $k => $v) {
2265
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2266
+				}
2186 2267
 
2187 2268
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2188 2269
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2193,35 +2274,42 @@  discard block
 block discarded – undo
2193 2274
 		}
2194 2275
 	}
2195 2276
 
2196
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2197
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2277
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2278
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2279
+	}
2198 2280
 
2199 2281
 	// Do we need to refresh the verification?
2200
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2201
-		$force_refresh = true;
2202
-	else
2203
-		$force_refresh = false;
2282
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2283
+			$force_refresh = true;
2284
+	} else {
2285
+			$force_refresh = false;
2286
+	}
2204 2287
 
2205 2288
 	// This can also force a fresh, although unlikely.
2206
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2207
-		$force_refresh = true;
2289
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2290
+			$force_refresh = true;
2291
+	}
2208 2292
 
2209 2293
 	$verification_errors = array();
2210 2294
 	// Start with any testing.
2211 2295
 	if ($do_test)
2212 2296
 	{
2213 2297
 		// This cannot happen!
2214
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2215
-			fatal_lang_error('no_access', false);
2298
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2299
+					fatal_lang_error('no_access', false);
2300
+		}
2216 2301
 		// ... nor this!
2217
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2218
-			fatal_lang_error('no_access', false);
2302
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2303
+					fatal_lang_error('no_access', false);
2304
+		}
2219 2305
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2220
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2221
-			fatal_lang_error('no_access', false);
2306
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2307
+					fatal_lang_error('no_access', false);
2308
+		}
2222 2309
 		// While we're here, did the user do something bad?
2223
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2224
-			$verification_errors[] = 'wrong_verification_answer';
2310
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2311
+					$verification_errors[] = 'wrong_verification_answer';
2312
+		}
2225 2313
 
2226 2314
 		if ($thisVerification['can_recaptcha'])
2227 2315
 		{
@@ -2232,22 +2320,25 @@  discard block
 block discarded – undo
2232 2320
 			{
2233 2321
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2234 2322
 
2235
-				if (!$resp->isSuccess())
2236
-					$verification_errors[] = 'wrong_verification_code';
2323
+				if (!$resp->isSuccess()) {
2324
+									$verification_errors[] = 'wrong_verification_code';
2325
+				}
2326
+			} else {
2327
+							$verification_errors[] = 'wrong_verification_code';
2237 2328
 			}
2238
-			else
2239
-				$verification_errors[] = 'wrong_verification_code';
2240 2329
 		}
2241
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2242
-			$verification_errors[] = 'wrong_verification_code';
2330
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2331
+					$verification_errors[] = 'wrong_verification_code';
2332
+		}
2243 2333
 		if ($thisVerification['number_questions'])
2244 2334
 		{
2245 2335
 			$incorrectQuestions = array();
2246 2336
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2247 2337
 			{
2248 2338
 				// We don't have this question any more, thus no answers.
2249
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2250
-					continue;
2339
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2340
+									continue;
2341
+				}
2251 2342
 				// This is quite complex. We have our question but it might have multiple answers.
2252 2343
 				// First, did they actually answer this question?
2253 2344
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2259,24 +2350,28 @@  discard block
 block discarded – undo
2259 2350
 				else
2260 2351
 				{
2261 2352
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2262
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2263
-						$incorrectQuestions[] = $q;
2353
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2354
+											$incorrectQuestions[] = $q;
2355
+					}
2264 2356
 				}
2265 2357
 			}
2266 2358
 
2267
-			if (!empty($incorrectQuestions))
2268
-				$verification_errors[] = 'wrong_verification_answer';
2359
+			if (!empty($incorrectQuestions)) {
2360
+							$verification_errors[] = 'wrong_verification_answer';
2361
+			}
2269 2362
 		}
2270 2363
 	}
2271 2364
 
2272 2365
 	// Any errors means we refresh potentially.
2273 2366
 	if (!empty($verification_errors))
2274 2367
 	{
2275
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2276
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2368
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2369
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2370
+		}
2277 2371
 		// Too many errors?
2278
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2279
-			$force_refresh = true;
2372
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2373
+					$force_refresh = true;
2374
+		}
2280 2375
 
2281 2376
 		// Keep a track of these.
2282 2377
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2309,8 +2404,9 @@  discard block
 block discarded – undo
2309 2404
 			// Are we overriding the range?
2310 2405
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2311 2406
 
2312
-			for ($i = 0; $i < 6; $i++)
2313
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2407
+			for ($i = 0; $i < 6; $i++) {
2408
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2409
+			}
2314 2410
 		}
2315 2411
 
2316 2412
 		// Getting some new questions?
@@ -2318,8 +2414,9 @@  discard block
 block discarded – undo
2318 2414
 		{
2319 2415
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2320 2416
 			$possible_langs = array();
2321
-			if (isset($_SESSION['language']))
2322
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2417
+			if (isset($_SESSION['language'])) {
2418
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2419
+			}
2323 2420
 			if (!empty($user_info['language']));
2324 2421
 			$possible_langs[] = $user_info['language'];
2325 2422
 			$possible_langs[] = $language;
@@ -2338,8 +2435,7 @@  discard block
 block discarded – undo
2338 2435
 				}
2339 2436
 			}
2340 2437
 		}
2341
-	}
2342
-	else
2438
+	} else
2343 2439
 	{
2344 2440
 		// Same questions as before.
2345 2441
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2349,8 +2445,9 @@  discard block
 block discarded – undo
2349 2445
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2350 2446
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2351 2447
 	{
2352
-		if (!isset($context['html_headers']))
2353
-			$context['html_headers'] = '';
2448
+		if (!isset($context['html_headers'])) {
2449
+					$context['html_headers'] = '';
2450
+		}
2354 2451
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2355 2452
 	}
2356 2453
 
@@ -2376,11 +2473,13 @@  discard block
 block discarded – undo
2376 2473
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2377 2474
 
2378 2475
 	// Return errors if we have them.
2379
-	if (!empty($verification_errors))
2380
-		return $verification_errors;
2476
+	if (!empty($verification_errors)) {
2477
+			return $verification_errors;
2478
+	}
2381 2479
 	// If we had a test that one, make a note.
2382
-	elseif ($do_test)
2383
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2480
+	elseif ($do_test) {
2481
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2482
+	}
2384 2483
 
2385 2484
 	// Say that everything went well chaps.
2386 2485
 	return true;
@@ -2405,8 +2504,9 @@  discard block
 block discarded – undo
2405 2504
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2406 2505
 
2407 2506
 	// If we're just checking the callback function is registered return true or false.
2408
-	if ($checkRegistered != null)
2409
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2507
+	if ($checkRegistered != null) {
2508
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2509
+	}
2410 2510
 
2411 2511
 	checkSession('get');
2412 2512
 	loadTemplate('Xml');
@@ -2557,24 +2657,27 @@  discard block
 block discarded – undo
2557 2657
 		foreach ($possible_versions as $ver)
2558 2658
 		{
2559 2659
 			$ver = trim($ver);
2560
-			if (strpos($ver, 'SMF') === 0)
2561
-				$versions[] = $ver;
2660
+			if (strpos($ver, 'SMF') === 0) {
2661
+							$versions[] = $ver;
2662
+			}
2562 2663
 		}
2563 2664
 	}
2564 2665
 	$smcFunc['db_free_result']($request);
2565 2666
 
2566 2667
 	// Just in case we don't have ANYthing.
2567
-	if (empty($versions))
2568
-		$versions = array('SMF 2.0');
2668
+	if (empty($versions)) {
2669
+			$versions = array('SMF 2.0');
2670
+	}
2569 2671
 
2570
-	foreach ($versions as $id => $version)
2571
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2672
+	foreach ($versions as $id => $version) {
2673
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2572 2674
 			$xml_data['items']['children'][] = array(
2573 2675
 				'attributes' => array(
2574 2676
 					'id' => $id,
2575 2677
 				),
2576 2678
 				'value' => $version,
2577 2679
 			);
2680
+	}
2578 2681
 
2579 2682
 	return $xml_data;
2580 2683
 }
Please login to merge, or discard this patch.
Sources/Profile.php 1 patch
Braces   +158 added lines, -120 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -29,18 +30,21 @@  discard block
 block discarded – undo
29 30
 	global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc;
30 31
 
31 32
 	// Don't reload this as we may have processed error strings.
32
-	if (empty($post_errors))
33
-		loadLanguage('Profile+Drafts');
33
+	if (empty($post_errors)) {
34
+			loadLanguage('Profile+Drafts');
35
+	}
34 36
 	loadTemplate('Profile');
35 37
 
36 38
 	require_once($sourcedir . '/Subs-Menu.php');
37 39
 
38 40
 	// Did we get the user by name...
39
-	if (isset($_REQUEST['user']))
40
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
41
+	if (isset($_REQUEST['user'])) {
42
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
43
+	}
41 44
 	// ... or by id_member?
42
-	elseif (!empty($_REQUEST['u']))
43
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
45
+	elseif (!empty($_REQUEST['u'])) {
46
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
47
+	}
44 48
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
45 49
 	else
46 50
 	{
@@ -50,8 +54,9 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 
52 56
 	// Check if loadMemberData() has returned a valid result.
53
-	if (!$memberResult)
54
-		fatal_lang_error('not_a_user', false, 404);
57
+	if (!$memberResult) {
58
+			fatal_lang_error('not_a_user', false, 404);
59
+	}
55 60
 
56 61
 	// If all went well, we have a valid member ID!
57 62
 	list ($memID) = $memberResult;
@@ -67,8 +72,9 @@  discard block
 block discarded – undo
67 72
 
68 73
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
69 74
 	// And we care about what the current user can do, not what the user whose profile it is.
70
-	if ($user_info['mod_cache']['gq'] != '0=1')
71
-		$user_info['permissions'][] = 'approve_group_requests';
75
+	if ($user_info['mod_cache']['gq'] != '0=1') {
76
+			$user_info['permissions'][] = 'approve_group_requests';
77
+	}
72 78
 
73 79
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
74 80
 	$context['subs_available'] = false;
@@ -436,21 +442,25 @@  discard block
 block discarded – undo
436 442
 		foreach ($section['areas'] as $area_id => $area)
437 443
 		{
438 444
 			// If it said no permissions that meant it wasn't valid!
439
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
440
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
445
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
446
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
447
+			}
441 448
 			// Otherwise pick the right set.
442
-			else
443
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
449
+			else {
450
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
451
+			}
444 452
 
445 453
 			// Password required in most cases
446
-			if (!empty($area['password']))
447
-				$context['password_areas'][] = $area_id;
454
+			if (!empty($area['password'])) {
455
+							$context['password_areas'][] = $area_id;
456
+			}
448 457
 		}
449 458
 	}
450 459
 
451 460
 	// Is there an updated message to show?
452
-	if (isset($_GET['updated']))
453
-		$context['profile_updated'] = $txt['profile_updated_own'];
461
+	if (isset($_GET['updated'])) {
462
+			$context['profile_updated'] = $txt['profile_updated_own'];
463
+	}
454 464
 
455 465
 	// Set a few options for the menu.
456 466
 	$menuOptions = array(
@@ -465,8 +475,9 @@  discard block
 block discarded – undo
465 475
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
466 476
 
467 477
 	// No menu means no access.
468
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
469
-		fatal_lang_error('no_access', false);
478
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
479
+			fatal_lang_error('no_access', false);
480
+	}
470 481
 
471 482
 	// Make a note of the Unique ID for this menu.
472 483
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -492,8 +503,9 @@  discard block
 block discarded – undo
492 503
 			if ($current_area == $area_id)
493 504
 			{
494 505
 				// This can't happen - but is a security check.
495
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
496
-					fatal_lang_error('no_access', false);
506
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
507
+									fatal_lang_error('no_access', false);
508
+				}
497 509
 
498 510
 				// Are we saving data in a valid area?
499 511
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -512,12 +524,14 @@  discard block
 block discarded – undo
512 524
 				}
513 525
 
514 526
 				// Does this require session validating?
515
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
516
-					$security_checks['validate'] = true;
527
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
528
+									$security_checks['validate'] = true;
529
+				}
517 530
 
518 531
 				// Permissions for good measure.
519
-				if (!empty($profile_include_data['permission']))
520
-					$security_checks['permission'] = $profile_include_data['permission'];
532
+				if (!empty($profile_include_data['permission'])) {
533
+									$security_checks['permission'] = $profile_include_data['permission'];
534
+				}
521 535
 
522 536
 				// Either way got something.
523 537
 				$found_area = true;
@@ -526,21 +540,26 @@  discard block
 block discarded – undo
526 540
 	}
527 541
 
528 542
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
529
-	if (!$found_area)
530
-		fatal_lang_error('no_access', false);
543
+	if (!$found_area) {
544
+			fatal_lang_error('no_access', false);
545
+	}
531 546
 
532 547
 	// Release this now.
533 548
 	unset($profile_areas);
534 549
 
535 550
 	// Now the context is setup have we got any security checks to carry out additional to that above?
536
-	if (isset($security_checks['session']))
537
-		checkSession($security_checks['session']);
538
-	if (isset($security_checks['validate']))
539
-		validateSession();
540
-	if (isset($security_checks['validateToken']))
541
-		validateToken($token_name, $token_type);
542
-	if (isset($security_checks['permission']))
543
-		isAllowedTo($security_checks['permission']);
551
+	if (isset($security_checks['session'])) {
552
+			checkSession($security_checks['session']);
553
+	}
554
+	if (isset($security_checks['validate'])) {
555
+			validateSession();
556
+	}
557
+	if (isset($security_checks['validateToken'])) {
558
+			validateToken($token_name, $token_type);
559
+	}
560
+	if (isset($security_checks['permission'])) {
561
+			isAllowedTo($security_checks['permission']);
562
+	}
544 563
 
545 564
 	// Create a token if needed.
546 565
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -550,8 +569,9 @@  discard block
 block discarded – undo
550 569
 	}
551 570
 
552 571
 	// File to include?
553
-	if (isset($profile_include_data['file']))
554
-		require_once($sourcedir . '/' . $profile_include_data['file']);
572
+	if (isset($profile_include_data['file'])) {
573
+			require_once($sourcedir . '/' . $profile_include_data['file']);
574
+	}
555 575
 
556 576
 	// Build the link tree.
557 577
 	$context['linktree'][] = array(
@@ -559,17 +579,19 @@  discard block
 block discarded – undo
559 579
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
560 580
 	);
561 581
 
562
-	if (!empty($profile_include_data['label']))
563
-		$context['linktree'][] = array(
582
+	if (!empty($profile_include_data['label'])) {
583
+			$context['linktree'][] = array(
564 584
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
565 585
 			'name' => $profile_include_data['label'],
566 586
 		);
587
+	}
567 588
 
568
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
569
-		$context['linktree'][] = array(
589
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
590
+			$context['linktree'][] = array(
570 591
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
571 592
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
572 593
 		);
594
+	}
573 595
 
574 596
 	// Set the template for this area and add the profile layer.
575 597
 	$context['sub_template'] = $profile_include_data['function'];
@@ -595,12 +617,14 @@  discard block
 block discarded – undo
595 617
 		if ($check_password)
596 618
 		{
597 619
 			// Check to ensure we're forcing SSL for authentication
598
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
621
+							fatal_lang_error('login_ssl_required');
622
+			}
600 623
 
601 624
 			// You didn't even enter a password!
602
-			if (trim($_POST['oldpasswrd']) == '')
603
-				$post_errors[] = 'no_password';
625
+			if (trim($_POST['oldpasswrd']) == '') {
626
+							$post_errors[] = 'no_password';
627
+			}
604 628
 
605 629
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
606 630
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -609,42 +633,43 @@  discard block
 block discarded – undo
609 633
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
610 634
 
611 635
 			// Bad password!!!
612
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
613
-				$post_errors[] = 'bad_password';
636
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
637
+							$post_errors[] = 'bad_password';
638
+			}
614 639
 
615 640
 			// Warn other elements not to jump the gun and do custom changes!
616
-			if (in_array('bad_password', $post_errors))
617
-				$context['password_auth_failed'] = true;
641
+			if (in_array('bad_password', $post_errors)) {
642
+							$context['password_auth_failed'] = true;
643
+			}
618 644
 		}
619 645
 
620 646
 		// Change the IP address in the database.
621
-		if ($context['user']['is_owner'])
622
-			$profile_vars['member_ip'] = $user_info['ip'];
647
+		if ($context['user']['is_owner']) {
648
+					$profile_vars['member_ip'] = $user_info['ip'];
649
+		}
623 650
 
624 651
 		// Now call the sub-action function...
625 652
 		if ($current_area == 'activateaccount')
626 653
 		{
627
-			if (empty($post_errors))
628
-				activateAccount($memID);
629
-		}
630
-		elseif ($current_area == 'deleteaccount')
654
+			if (empty($post_errors)) {
655
+							activateAccount($memID);
656
+			}
657
+		} elseif ($current_area == 'deleteaccount')
631 658
 		{
632 659
 			if (empty($post_errors))
633 660
 			{
634 661
 				deleteAccount2($memID);
635 662
 				redirectexit();
636 663
 			}
637
-		}
638
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
664
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
639 665
 		{
640 666
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
641 667
 
642 668
 			// Whatever we've done, we have nothing else to do here...
643 669
 			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
644
-		}
645
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
646
-			saveProfileFields();
647
-		else
670
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
671
+					saveProfileFields();
672
+		} else
648 673
 		{
649 674
 			$force_redirect = true;
650 675
 			// Ensure we include this.
@@ -660,34 +685,36 @@  discard block
 block discarded – undo
660 685
 			// Load the language file so we can give a nice explanation of the errors.
661 686
 			loadLanguage('Errors');
662 687
 			$context['post_errors'] = $post_errors;
663
-		}
664
-		elseif (!empty($profile_vars))
688
+		} elseif (!empty($profile_vars))
665 689
 		{
666 690
 			// If we've changed the password, notify any integration that may be listening in.
667
-			if (isset($profile_vars['passwd']))
668
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
691
+			if (isset($profile_vars['passwd'])) {
692
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
693
+			}
669 694
 
670 695
 			updateMemberData($memID, $profile_vars);
671 696
 
672 697
 			// What if this is the newest member?
673
-			if ($modSettings['latestMember'] == $memID)
674
-				updateStats('member');
675
-			elseif (isset($profile_vars['real_name']))
676
-				updateSettings(array('memberlist_updated' => time()));
698
+			if ($modSettings['latestMember'] == $memID) {
699
+							updateStats('member');
700
+			} elseif (isset($profile_vars['real_name'])) {
701
+							updateSettings(array('memberlist_updated' => time()));
702
+			}
677 703
 
678 704
 			// If the member changed his/her birthdate, update calendar statistics.
679
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
680
-				updateSettings(array(
705
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
706
+							updateSettings(array(
681 707
 					'calendar_updated' => time(),
682 708
 				));
709
+			}
683 710
 
684 711
 			// Anything worth logging?
685 712
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
686 713
 			{
687 714
 				$log_changes = array();
688 715
 				require_once($sourcedir . '/Logging.php');
689
-				foreach ($context['log_changes'] as $k => $v)
690
-					$log_changes[] = array(
716
+				foreach ($context['log_changes'] as $k => $v) {
717
+									$log_changes[] = array(
691 718
 						'action' => $k,
692 719
 						'log_type' => 'user',
693 720
 						'extra' => array_merge($v, array(
@@ -695,14 +722,16 @@  discard block
 block discarded – undo
695 722
 							'member_affected' => $memID,
696 723
 						)),
697 724
 					);
725
+				}
698 726
 
699 727
 				logActions($log_changes);
700 728
 			}
701 729
 
702 730
 			// Have we got any post save functions to execute?
703
-			if (!empty($context['profile_execute_on_save']))
704
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
731
+			if (!empty($context['profile_execute_on_save'])) {
732
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
705 733
 					$saveFunc();
734
+			}
706 735
 
707 736
 			// Let them know it worked!
708 737
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -716,27 +745,31 @@  discard block
 block discarded – undo
716 745
 	if (!empty($post_errors))
717 746
 	{
718 747
 		// Set all the errors so the template knows what went wrong.
719
-		foreach ($post_errors as $error_type)
720
-			$context['modify_error'][$error_type] = true;
748
+		foreach ($post_errors as $error_type) {
749
+					$context['modify_error'][$error_type] = true;
750
+		}
721 751
 	}
722 752
 	// If it's you then we should redirect upon save.
723
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
724
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
725
-	elseif (!empty($force_redirect))
726
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
753
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
754
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
755
+	} elseif (!empty($force_redirect)) {
756
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
757
+	}
727 758
 
728 759
 
729 760
 	// Get the right callable.
730 761
 	$call = call_helper($profile_include_data['function'], true);
731 762
 
732 763
 	// Is it valid?
733
-	if (!empty($call))
734
-		call_user_func($call, $memID);
764
+	if (!empty($call)) {
765
+			call_user_func($call, $memID);
766
+	}
735 767
 
736 768
 	// Set the page title if it's not already set...
737
-	if (!isset($context['page_title']))
738
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
739
-}
769
+	if (!isset($context['page_title'])) {
770
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
771
+	}
772
+	}
740 773
 
741 774
 /**
742 775
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -859,16 +892,18 @@  discard block
 block discarded – undo
859 892
 	if (!allowedTo('admin_forum') && $area != 'register')
860 893
 	{
861 894
 		// If it's the owner they can see two types of private fields, regardless.
862
-		if ($memID == $user_info['id'])
863
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
864
-		else
865
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
895
+		if ($memID == $user_info['id']) {
896
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
897
+		} else {
898
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
899
+		}
866 900
 	}
867 901
 
868
-	if ($area == 'register')
869
-		$where .= ' AND show_reg != 0';
870
-	elseif ($area != 'summary')
871
-		$where .= ' AND show_profile = {string:area}';
902
+	if ($area == 'register') {
903
+			$where .= ' AND show_reg != 0';
904
+	} elseif ($area != 'summary') {
905
+			$where .= ' AND show_profile = {string:area}';
906
+	}
872 907
 
873 908
 	// Load all the relevant fields - and data.
874 909
 	$request = $smcFunc['db_query']('', '
@@ -893,8 +928,9 @@  discard block
 block discarded – undo
893 928
 			$fieldOptions = explode(',', $row['field_options']);
894 929
 			foreach ($fieldOptions as $k => $v)
895 930
 			{
896
-				if (empty($currentKey))
897
-					$currentKey = $v === $value ? $k : 0;
931
+				if (empty($currentKey)) {
932
+									$currentKey = $v === $value ? $k : 0;
933
+				}
898 934
 			}
899 935
 		}
900 936
 
@@ -906,13 +942,15 @@  discard block
 block discarded – undo
906 942
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
907 943
 		{
908 944
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
909
-			if (in_array($row['field_type'], array('select', 'radio')))
910
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
945
+			if (in_array($row['field_type'], array('select', 'radio'))) {
946
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
947
+			}
911 948
 		}
912 949
 
913 950
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
914
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None')
915
-			continue;
951
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') {
952
+					continue;
953
+		}
916 954
 
917 955
 		// HTML for the input form.
918 956
 		$output_html = $value;
@@ -921,8 +959,7 @@  discard block
 block discarded – undo
921 959
 			$true = (!$exists && $row['default_value']) || $value;
922 960
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>';
923 961
 			$output_html = $true ? $txt['yes'] : $txt['no'];
924
-		}
925
-		elseif ($row['field_type'] == 'select')
962
+		} elseif ($row['field_type'] == 'select')
926 963
 		{
927 964
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
928 965
 			$options = explode(',', $row['field_options']);
@@ -930,13 +967,13 @@  discard block
 block discarded – undo
930 967
 			{
931 968
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
932 969
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
933
-				if ($true)
934
-					$output_html = $v;
970
+				if ($true) {
971
+									$output_html = $v;
972
+				}
935 973
 			}
936 974
 
937 975
 			$input_html .= '</select>';
938
-		}
939
-		elseif ($row['field_type'] == 'radio')
976
+		} elseif ($row['field_type'] == 'radio')
940 977
 		{
941 978
 			$input_html = '<fieldset>';
942 979
 			$options = explode(',', $row['field_options']);
@@ -944,37 +981,38 @@  discard block
 block discarded – undo
944 981
 			{
945 982
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
946 983
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
947
-				if ($true)
948
-					$output_html = $v;
984
+				if ($true) {
985
+									$output_html = $v;
986
+				}
949 987
 			}
950 988
 			$input_html .= '</fieldset>';
951
-		}
952
-		elseif ($row['field_type'] == 'text')
989
+		} elseif ($row['field_type'] == 'text')
953 990
 		{
954 991
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
955
-		}
956
-		else
992
+		} else
957 993
 		{
958 994
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
959 995
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
960 996
 		}
961 997
 
962 998
 		// Parse BBCode
963
-		if ($row['bbc'])
964
-			$output_html = parse_bbc($output_html);
965
-		elseif ($row['field_type'] == 'textarea')
966
-			// Allow for newlines at least
999
+		if ($row['bbc']) {
1000
+					$output_html = parse_bbc($output_html);
1001
+		} elseif ($row['field_type'] == 'textarea') {
1002
+					// Allow for newlines at least
967 1003
 			$output_html = strtr($output_html, array("\n" => '<br>'));
1004
+		}
968 1005
 
969 1006
 		// Enclosing the user input within some other text?
970
-		if (!empty($row['enclose']) && !empty($output_html))
971
-			$output_html = strtr($row['enclose'], array(
1007
+		if (!empty($row['enclose']) && !empty($output_html)) {
1008
+					$output_html = strtr($row['enclose'], array(
972 1009
 				'{SCRIPTURL}' => $scripturl,
973 1010
 				'{IMAGES_URL}' => $settings['images_url'],
974 1011
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
975 1012
 				'{INPUT}' => un_htmlspecialchars($output_html),
976 1013
 				'{KEY}' => $currentKey
977 1014
 			));
1015
+		}
978 1016
 
979 1017
 		$context['custom_fields'][] = array(
980 1018
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.
Sources/Memberlist.php 1 patch
Braces   +84 added lines, -65 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Shows a listing of registered members.
@@ -110,8 +111,9 @@  discard block
 block discarded – undo
110 111
 
111 112
 	$context['custom_profile_fields'] = getCustFieldsMList();
112 113
 
113
-	if (!empty($context['custom_profile_fields']['columns']))
114
-		$context['columns'] += $context['custom_profile_fields']['columns'];
114
+	if (!empty($context['custom_profile_fields']['columns'])) {
115
+			$context['columns'] += $context['custom_profile_fields']['columns'];
116
+	}
115 117
 
116 118
 	$context['colspan'] = 0;
117 119
 	$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
@@ -147,12 +149,12 @@  discard block
 block discarded – undo
147 149
 	call_integration_hook('integrate_memberlist_buttons');
148 150
 
149 151
 	// Jump to the sub action.
150
-	if (isset($subActions[$context['listing_by']]))
151
-		call_helper($subActions[$context['listing_by']][1]);
152
-
153
-	else
154
-		call_helper($subActions['all'][1]);
155
-}
152
+	if (isset($subActions[$context['listing_by']])) {
153
+			call_helper($subActions[$context['listing_by']][1]);
154
+	} else {
155
+			call_helper($subActions['all'][1]);
156
+	}
157
+	}
156 158
 
157 159
 /**
158 160
  * List all members, page by page, with sorting.
@@ -177,8 +179,9 @@  discard block
 block discarded – undo
177 179
 	if ($use_cache)
178 180
 	{
179 181
 		// Maybe there's something cached already.
180
-		if (!empty($modSettings['memberlist_cache']))
181
-			$memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true);
182
+		if (!empty($modSettings['memberlist_cache'])) {
183
+					$memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true);
184
+		}
182 185
 
183 186
 		// The chunk size for the cached index.
184 187
 		$cache_step_size = 500;
@@ -234,13 +237,15 @@  discard block
 block discarded – undo
234 237
 	}
235 238
 
236 239
 	// Set defaults for sort (real_name) and start. (0)
237
-	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
238
-		$_REQUEST['sort'] = 'real_name';
240
+	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
241
+			$_REQUEST['sort'] = 'real_name';
242
+	}
239 243
 
240 244
 	if (!is_numeric($_REQUEST['start']))
241 245
 	{
242
-		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0)
243
-			fatal_error('Hacker?', false);
246
+		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) {
247
+					fatal_error('Hacker?', false);
248
+		}
244 249
 
245 250
 		$_REQUEST['start'] = $match[0];
246 251
 
@@ -259,16 +264,18 @@  discard block
 block discarded – undo
259 264
 	}
260 265
 
261 266
 	$context['letter_links'] = '';
262
-	for ($i = 97; $i < 123; $i++)
263
-		$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
267
+	for ($i = 97; $i < 123; $i++) {
268
+			$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
269
+	}
264 270
 
265 271
 	// Sort out the column information.
266 272
 	foreach ($context['columns'] as $col => $column_details)
267 273
 	{
268 274
 		$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0';
269 275
 
270
-		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
271
-			$context['columns'][$col]['href'] .= ';desc';
276
+		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
277
+					$context['columns'][$col]['href'] .= ';desc';
278
+		}
272 279
 
273 280
 		$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
274 281
 		$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -317,8 +324,9 @@  discard block
 block discarded – undo
317 324
 	elseif ($use_cache && $_REQUEST['sort'] === 'real_name')
318 325
 	{
319 326
 		$first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
320
-		if ($first_offset < 0)
321
-			$first_offset = 0;
327
+		if ($first_offset < 0) {
328
+					$first_offset = 0;
329
+		}
322 330
 		$second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
323 331
 
324 332
 		$where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
@@ -328,8 +336,9 @@  discard block
 block discarded – undo
328 336
 	}
329 337
 
330 338
 	$custom_fields_qry = '';
331
-	if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']]))
332
-		$custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']];
339
+	if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) {
340
+			$custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']];
341
+	}
333 342
 
334 343
 	// Select the members from the database.
335 344
 	$request = $smcFunc['db_query']('', '
@@ -399,12 +408,13 @@  discard block
 block discarded – undo
399 408
 		)
400 409
 	);
401 410
 	$context['custom_search_fields'] = array();
402
-	while ($row = $smcFunc['db_fetch_assoc']($request))
403
-		$context['custom_search_fields'][$row['col_name']] = array(
411
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
412
+			$context['custom_search_fields'][$row['col_name']] = array(
404 413
 			'colname' => $row['col_name'],
405 414
 			'name' => $row['field_name'],
406 415
 			'desc' => $row['field_desc'],
407 416
 		);
417
+	}
408 418
 	$smcFunc['db_free_result']($request);
409 419
 
410 420
 	// They're searching..
@@ -417,23 +427,27 @@  discard block
 block discarded – undo
417 427
 		$context['old_search_value'] = urlencode($_REQUEST['search']);
418 428
 
419 429
 		// No fields?  Use default...
420
-		if (empty($_POST['fields']))
421
-			$_POST['fields'] = array('name');
430
+		if (empty($_POST['fields'])) {
431
+					$_POST['fields'] = array('name');
432
+		}
422 433
 
423 434
 		// Set defaults for how the results are sorted
424
-		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
425
-			$_REQUEST['sort'] = 'real_name';
435
+		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
436
+					$_REQUEST['sort'] = 'real_name';
437
+		}
426 438
 
427 439
 		// Build the column link / sort information.
428 440
 		foreach ($context['columns'] as $col => $column_details)
429 441
 		{
430 442
 			$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col;
431 443
 
432
-			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
433
-				$context['columns'][$col]['href'] .= ';desc';
444
+			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
445
+							$context['columns'][$col]['href'] .= ';desc';
446
+			}
434 447
 
435
-			if (isset($_POST['search']) && isset($_POST['fields']))
436
-				$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
448
+			if (isset($_POST['search']) && isset($_POST['fields'])) {
449
+							$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
450
+			}
437 451
 
438 452
 			$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
439 453
 			$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -456,8 +470,7 @@  discard block
 block discarded – undo
456 470
 		{
457 471
 			$fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name');
458 472
 			$search_fields[] = 'name';
459
-		}
460
-		else
473
+		} else
461 474
 		{
462 475
 			$fields = array();
463 476
 			$search_fields = array();
@@ -482,9 +495,10 @@  discard block
 block discarded – undo
482 495
 			$search_fields[] = 'email';
483 496
 		}
484 497
 
485
-		if ($smcFunc['db_case_sensitive'])
486
-			foreach ($fields as $key => $field)
498
+		if ($smcFunc['db_case_sensitive']) {
499
+					foreach ($fields as $key => $field)
487 500
 				$fields[$key] = 'LOWER(' . $field . ')';
501
+		}
488 502
 
489 503
 		$customJoin = array();
490 504
 		$customCount = 10;
@@ -503,8 +517,9 @@  discard block
 block discarded – undo
503 517
 		}
504 518
 
505 519
 		// No search fields? That means you're trying to hack things
506
-		if (empty($search_fields))
507
-			fatal_lang_error('invalid_search_string', false);
520
+		if (empty($search_fields)) {
521
+					fatal_lang_error('invalid_search_string', false);
522
+		}
508 523
 
509 524
 		$query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}');
510 525
 
@@ -542,8 +557,7 @@  discard block
 block discarded – undo
542 557
 		);
543 558
 		printMemberListRows($request);
544 559
 		$smcFunc['db_free_result']($request);
545
-	}
546
-	else
560
+	} else
547 561
 	{
548 562
 		// These are all the possible fields.
549 563
 		$context['search_fields'] = array(
@@ -558,14 +572,14 @@  discard block
 block discarded – undo
558 572
 		{
559 573
 			unset($context['search_fields']['email']);
560 574
 			$context['search_defaults'] = array('name');
561
-		}
562
-		else
575
+		} else
563 576
 		{
564 577
 			$context['search_defaults'] = array('name', 'email');
565 578
 		}
566 579
 
567
-		foreach ($context['custom_search_fields'] as $field)
568
-			$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
580
+		foreach ($context['custom_search_fields'] as $field) {
581
+					$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
582
+		}
569 583
 
570 584
 		$context['sub_template'] = 'search';
571 585
 		$context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : '');
@@ -607,12 +621,14 @@  discard block
 block discarded – undo
607 621
 	$smcFunc['db_free_result']($result);
608 622
 
609 623
 	// Avoid division by zero...
610
-	if ($most_posts == 0)
611
-		$most_posts = 1;
624
+	if ($most_posts == 0) {
625
+			$most_posts = 1;
626
+	}
612 627
 
613 628
 	$members = array();
614
-	while ($row = $smcFunc['db_fetch_assoc']($request))
615
-		$members[] = $row['id_member'];
629
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
630
+			$members[] = $row['id_member'];
631
+	}
616 632
 
617 633
 	// Load all the members for display.
618 634
 	loadMemberData($members);
@@ -620,8 +636,9 @@  discard block
 block discarded – undo
620 636
 	$context['members'] = array();
621 637
 	foreach ($members as $member)
622 638
 	{
623
-		if (!loadMemberContext($member))
624
-			continue;
639
+		if (!loadMemberContext($member)) {
640
+					continue;
641
+		}
625 642
 
626 643
 		$context['members'][$member] = $memberContext[$member];
627 644
 		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
@@ -639,8 +656,9 @@  discard block
 block discarded – undo
639 656
 					$fieldOptions = explode(',', $column['options']);
640 657
 					foreach ($fieldOptions as $k => $v)
641 658
 					{
642
-						if (empty($currentKey))
643
-							$currentKey = $v === $value ? $k : 0;
659
+						if (empty($currentKey)) {
660
+													$currentKey = $v === $value ? $k : 0;
661
+						}
644 662
 					}
645 663
 				}
646 664
 
@@ -651,21 +669,22 @@  discard block
 block discarded – undo
651 669
 					continue;
652 670
 				}
653 671
 
654
-				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key]))
655
-					$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
656
-
657
-				elseif ($column['type'] == 'check')
658
-					$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
672
+				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) {
673
+									$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
674
+				} elseif ($column['type'] == 'check') {
675
+									$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
676
+				}
659 677
 
660 678
 				// Enclosing the user input within some other text?
661
-				if (!empty($column['enclose']))
662
-					$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
679
+				if (!empty($column['enclose'])) {
680
+									$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
663 681
 						'{SCRIPTURL}' => $scripturl,
664 682
 						'{IMAGES_URL}' => $settings['images_url'],
665 683
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
666 684
 						'{INPUT}' => $context['members'][$member]['options'][$key],
667 685
 						'{KEY}' => $currentKey
668 686
 					));
687
+				}
669 688
 			}
670 689
 		}
671 690
 	}
@@ -707,17 +726,17 @@  discard block
 block discarded – undo
707 726
 		);
708 727
 
709 728
 		// Get the right sort method depending on the cust field type.
710
-		if ($row['field_type'] != 'check')
711
-			$cpf['columns'][$row['col_name']]['sort'] = array(
729
+		if ($row['field_type'] != 'check') {
730
+					$cpf['columns'][$row['col_name']]['sort'] = array(
712 731
 				'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, \'\') DESC',
713 732
 				'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, \'\') ASC'
714 733
 			);
715
-
716
-		else
717
-			$cpf['columns'][$row['col_name']]['sort'] = array(
734
+		} else {
735
+					$cpf['columns'][$row['col_name']]['sort'] = array(
718 736
 				'down' => 't' . $row['col_name'] . '.value DESC',
719 737
 				'up' => 't' . $row['col_name'] . '.value ASC'
720 738
 			);
739
+		}
721 740
 
722 741
 		$cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)';
723 742
 	}
Please login to merge, or discard this patch.