Completed
Push — release-2.1 ( 08aa48...ab4516 )
by Mathias
06:51
created
Sources/News.php 1 patch
Braces   +239 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -53,8 +55,9 @@  discard block
 block discarded – undo
53 55
 	if (!empty($_REQUEST['c']) && empty($board))
54 56
 	{
55 57
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
56
-		foreach ($_REQUEST['c'] as $i => $c)
57
-			$_REQUEST['c'][$i] = (int) $c;
58
+		foreach ($_REQUEST['c'] as $i => $c) {
59
+					$_REQUEST['c'][$i] = (int) $c;
60
+		}
58 61
 
59 62
 		if (count($_REQUEST['c']) == 1)
60 63
 		{
@@ -90,18 +93,20 @@  discard block
 block discarded – undo
90 93
 		}
91 94
 		$smcFunc['db_free_result']($request);
92 95
 
93
-		if (!empty($boards))
94
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
96
+		if (!empty($boards)) {
97
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
98
+		}
95 99
 
96 100
 		// Try to limit the number of messages we look through.
97
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
98
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
99
-	}
100
-	elseif (!empty($_REQUEST['boards']))
101
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
102
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
103
+		}
104
+	} elseif (!empty($_REQUEST['boards']))
101 105
 	{
102 106
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
103
-		foreach ($_REQUEST['boards'] as $i => $b)
104
-			$_REQUEST['boards'][$i] = (int) $b;
107
+		foreach ($_REQUEST['boards'] as $i => $b) {
108
+					$_REQUEST['boards'][$i] = (int) $b;
109
+		}
105 110
 
106 111
 		$request = $smcFunc['db_query']('', '
107 112
 			SELECT b.id_board, b.num_posts, b.name
@@ -117,29 +122,32 @@  discard block
 block discarded – undo
117 122
 
118 123
 		// Either the board specified doesn't exist or you have no access.
119 124
 		$num_boards = $smcFunc['db_num_rows']($request);
120
-		if ($num_boards == 0)
121
-			fatal_lang_error('no_board');
125
+		if ($num_boards == 0) {
126
+					fatal_lang_error('no_board');
127
+		}
122 128
 
123 129
 		$total_posts = 0;
124 130
 		$boards = array();
125 131
 		while ($row = $smcFunc['db_fetch_assoc']($request))
126 132
 		{
127
-			if ($num_boards == 1)
128
-				$feed_title = ' - ' . strip_tags($row['name']);
133
+			if ($num_boards == 1) {
134
+							$feed_title = ' - ' . strip_tags($row['name']);
135
+			}
129 136
 
130 137
 			$boards[] = $row['id_board'];
131 138
 			$total_posts += $row['num_posts'];
132 139
 		}
133 140
 		$smcFunc['db_free_result']($request);
134 141
 
135
-		if (!empty($boards))
136
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
142
+		if (!empty($boards)) {
143
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
144
+		}
137 145
 
138 146
 		// The more boards, the more we're going to look through...
139
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
140
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
141
-	}
142
-	elseif (!empty($board))
147
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
148
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
149
+		}
150
+	} elseif (!empty($board))
143 151
 	{
144 152
 		$request = $smcFunc['db_query']('', '
145 153
 			SELECT num_posts
@@ -158,10 +166,10 @@  discard block
 block discarded – undo
158 166
 		$query_this_board = 'b.id_board = ' . $board;
159 167
 
160 168
 		// Try to look through just a few messages, if at all possible.
161
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
162
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
163
-	}
164
-	else
169
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
170
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
171
+		}
172
+	} else
165 173
 	{
166 174
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
167 175
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -184,30 +192,35 @@  discard block
 block discarded – undo
184 192
 	// Easy adding of sub actions
185 193
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
186 194
 
187
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
188
-		$_GET['sa'] = 'recent';
195
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
196
+			$_GET['sa'] = 'recent';
197
+	}
189 198
 
190 199
 	// We only want some information, not all of it.
191 200
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
192
-	foreach (array('board', 'boards', 'c') as $var)
193
-		if (isset($_REQUEST[$var]))
201
+	foreach (array('board', 'boards', 'c') as $var) {
202
+			if (isset($_REQUEST[$var]))
194 203
 			$cachekey[] = $_REQUEST[$var];
204
+	}
195 205
 	$cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
196 206
 	$cache_t = microtime();
197 207
 
198 208
 	// Get the associative array representing the xml.
199
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
200
-		$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
209
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
210
+			$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
211
+	}
201 212
 	if (empty($xml))
202 213
 	{
203 214
 		$call = call_helper($subActions[$_GET['sa']][0], true);
204 215
 
205
-		if (!empty($call))
206
-			$xml = call_user_func($call, $xml_format);
216
+		if (!empty($call)) {
217
+					$xml = call_user_func($call, $xml_format);
218
+		}
207 219
 
208 220
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
209
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
210
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
221
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
222
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
223
+		}
211 224
 	}
212 225
 
213 226
 	$feed_title = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_title) ? $feed_title : '');
@@ -218,19 +231,21 @@  discard block
 block discarded – undo
218 231
 
219 232
 	// This is an xml file....
220 233
 	ob_end_clean();
221
-	if (!empty($modSettings['enableCompressedOutput']))
222
-		@ob_start('ob_gzhandler');
223
-	else
224
-		ob_start();
234
+	if (!empty($modSettings['enableCompressedOutput'])) {
235
+			@ob_start('ob_gzhandler');
236
+	} else {
237
+			ob_start();
238
+	}
225 239
 
226
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
227
-		header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
228
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
229
-		header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
230
-	elseif ($xml_format == 'atom')
231
-		header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
232
-	elseif ($xml_format == 'rdf')
233
-		header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
240
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
241
+			header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
242
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
243
+			header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
244
+	} elseif ($xml_format == 'atom') {
245
+			header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
246
+	} elseif ($xml_format == 'rdf') {
247
+			header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
248
+	}
234 249
 
235 250
 	// First, output the xml header.
236 251
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -247,8 +262,9 @@  discard block
 block discarded – undo
247 262
 		<description>', cdata_parse(strip_tags($txt['xml_rss_desc'])), '</description>';
248 263
 
249 264
 		// RSS2 calls for this.
250
-		if ($xml_format == 'rss2')
251
-			echo '<atom:link rel="self" type="application/rss+xml" href="', $scripturl, '?action=.xml', !empty($_GET['sa']) ? ';sa=' . $_GET['sa'] : '', ';type=rss2" />';
265
+		if ($xml_format == 'rss2') {
266
+					echo '<atom:link rel="self" type="application/rss+xml" href="', $scripturl, '?action=.xml', !empty($_GET['sa']) ? ';sa=' . $_GET['sa'] : '', ';type=rss2" />';
267
+		}
252 268
 
253 269
 		// Output all of the associative array, start indenting with 2 tabs, and name everything "item".
254 270
 		dumpTags($xml, 2, 'item', $xml_format);
@@ -257,12 +273,12 @@  discard block
 block discarded – undo
257 273
 		echo '
258 274
 	</channel>
259 275
 </rss>';
260
-	}
261
-	elseif ($xml_format == 'atom')
276
+	} elseif ($xml_format == 'atom')
262 277
 	{
263
-		foreach ($_REQUEST as $var => $val)
264
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
278
+		foreach ($_REQUEST as $var => $val) {
279
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
265 280
 				$url_parts[] = $var . '=' . (is_array($_REQUEST[$var]) ? implode(',', $_REQUEST[$var]) : $_REQUEST[$var]);
281
+		}
266 282
 
267 283
 		echo '
268 284
 <feed xmlns="http://www.w3.org/2005/Atom">
@@ -283,8 +299,7 @@  discard block
 block discarded – undo
283 299
 
284 300
 		echo '
285 301
 </feed>';
286
-	}
287
-	elseif ($xml_format == 'rdf')
302
+	} elseif ($xml_format == 'rdf')
288 303
 	{
289 304
 		echo '
290 305
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
@@ -295,9 +310,10 @@  discard block
 block discarded – undo
295 310
 		<items>
296 311
 			<rdf:Seq>';
297 312
 
298
-		foreach ($xml as $item)
299
-			echo '
313
+		foreach ($xml as $item) {
314
+					echo '
300 315
 				<rdf:li rdf:resource="', $item['link'], '" />';
316
+		}
301 317
 
302 318
 		echo '
303 319
 			</rdf:Seq>
@@ -337,13 +353,15 @@  discard block
 block discarded – undo
337 353
 {
338 354
 	global $modSettings, $context, $scripturl;
339 355
 
340
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
341
-		return $val;
356
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
357
+			return $val;
358
+	}
342 359
 
343 360
 	call_integration_hook('integrate_fix_url', array(&$val));
344 361
 
345
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
346
-		return $val;
362
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
363
+			return $val;
364
+	}
347 365
 
348 366
 	$val = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function ($m) use ($scripturl)
349 367
 		{
@@ -365,8 +383,9 @@  discard block
 block discarded – undo
365 383
 	global $smcFunc;
366 384
 
367 385
 	// Do we even need to do this?
368
-	if (strpbrk($data, '<>&') == false)
369
-		return $data;
386
+	if (strpbrk($data, '<>&') == false) {
387
+			return $data;
388
+	}
370 389
 
371 390
 	$cdata = '<![CDATA[';
372 391
 
@@ -376,49 +395,55 @@  discard block
 block discarded – undo
376 395
 			$smcFunc['strpos']($data, '&', $pos),
377 396
 			$smcFunc['strpos']($data, ']', $pos),
378 397
 		);
379
-		if ($ns != '')
380
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
398
+		if ($ns != '') {
399
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
400
+		}
381 401
 		foreach ($positions as $k => $dummy)
382 402
 		{
383
-			if ($dummy === false)
384
-				unset($positions[$k]);
403
+			if ($dummy === false) {
404
+							unset($positions[$k]);
405
+			}
385 406
 		}
386 407
 
387 408
 		$old = $pos;
388 409
 		$pos = empty($positions) ? $n : min($positions);
389 410
 
390
-		if ($pos - $old > 0)
391
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
392
-		if ($pos >= $n)
393
-			break;
411
+		if ($pos - $old > 0) {
412
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
413
+		}
414
+		if ($pos >= $n) {
415
+					break;
416
+		}
394 417
 
395 418
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
396 419
 		{
397 420
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
398
-			if ($pos2 === false)
399
-				$pos2 = $n;
400
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
401
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
402
-			else
403
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
421
+			if ($pos2 === false) {
422
+							$pos2 = $n;
423
+			}
424
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
425
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
426
+			} else {
427
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
428
+			}
404 429
 			$pos = $pos2 + 1;
405
-		}
406
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
430
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
407 431
 		{
408 432
 			$cdata .= ']]>&#093;<![CDATA[';
409 433
 			$pos++;
410
-		}
411
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
434
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
412 435
 		{
413 436
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
414
-			if ($pos2 === false)
415
-				$pos2 = $n;
437
+			if ($pos2 === false) {
438
+							$pos2 = $n;
439
+			}
416 440
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
417 441
 
418
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
419
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
420
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
421
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
442
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
443
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
444
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
445
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
446
+			}
422 447
 
423 448
 			$pos = $pos2 + 1;
424 449
 		}
@@ -456,19 +481,22 @@  discard block
 block discarded – undo
456 481
 		'gender',
457 482
 		'blurb',
458 483
 	);
459
-	if ($xml_format != 'atom')
460
-		$keysToCdata[] = 'category';
484
+	if ($xml_format != 'atom') {
485
+			$keysToCdata[] = 'category';
486
+	}
461 487
 
462 488
 	// For every array in the data...
463 489
 	foreach ($data as $key => $val)
464 490
 	{
465 491
 		// Skip it, it's been set to null.
466
-		if ($val === null)
467
-			continue;
492
+		if ($val === null) {
493
+					continue;
494
+		}
468 495
 
469 496
 		// If the value should maybe be CDATA, do that now.
470
-		if (!is_array($val) && in_array($key, $keysToCdata))
471
-			$val = cdata_parse($val);
497
+		if (!is_array($val) && in_array($key, $keysToCdata)) {
498
+					$val = cdata_parse($val);
499
+		}
472 500
 
473 501
 		// If a tag was passed, use it instead of the key.
474 502
 		$key = isset($tag) ? $tag : $key;
@@ -484,11 +512,11 @@  discard block
 block discarded – undo
484 512
 		}
485 513
 
486 514
 		// If it's empty/0/nothing simply output an empty tag.
487
-		if ($val == '')
488
-			echo '<', $key, ' />';
489
-		elseif ($xml_format == 'atom' && $key == 'category')
490
-			echo '<', $key, ' term="', $val, '" />';
491
-		else
515
+		if ($val == '') {
516
+					echo '<', $key, ' />';
517
+		} elseif ($xml_format == 'atom' && $key == 'category') {
518
+					echo '<', $key, ' term="', $val, '" />';
519
+		} else
492 520
 		{
493 521
 			// Beginning tag.
494 522
 			if ($xml_format == 'rdf' && $key == 'item' && isset($val['link']))
@@ -496,11 +524,11 @@  discard block
 block discarded – undo
496 524
 				echo '<', $key, ' rdf:about="', fix_possible_url($val['link']), '">';
497 525
 				echo "\n", str_repeat("\t", $i + 1);
498 526
 				echo '<dc:format>text/html</dc:format>';
527
+			} elseif ($xml_format == 'atom' && $key == 'summary') {
528
+							echo '<', $key, ' type="html">';
529
+			} else {
530
+							echo '<', $key, '>';
499 531
 			}
500
-			elseif ($xml_format == 'atom' && $key == 'summary')
501
-				echo '<', $key, ' type="html">';
502
-			else
503
-				echo '<', $key, '>';
504 532
 
505 533
 			// The element's value.
506 534
 			if (is_array($val))
@@ -510,11 +538,13 @@  discard block
 block discarded – undo
510 538
 				echo "\n", str_repeat("\t", $i);
511 539
 			}
512 540
 			// A string with returns in it.... show this as a multiline element.
513
-			elseif (strpos($val, "\n") !== false || preg_match('~<br ?/?' . '>~', $val) !== false)
514
-				echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i);
541
+			elseif (strpos($val, "\n") !== false || preg_match('~<br ?/?' . '>~', $val) !== false) {
542
+							echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i);
543
+			}
515 544
 			// A simple string.
516
-			else
517
-				echo fix_possible_url($val);
545
+			else {
546
+							echo fix_possible_url($val);
547
+			}
518 548
 
519 549
 			// Ending tag.
520 550
 			echo '</', $key, '>';
@@ -534,8 +564,9 @@  discard block
 block discarded – undo
534 564
 {
535 565
 	global $scripturl, $smcFunc;
536 566
 
537
-	if (!allowedTo('view_mlist'))
538
-		return array();
567
+	if (!allowedTo('view_mlist')) {
568
+			return array();
569
+	}
539 570
 
540 571
 	// Find the most recent members.
541 572
 	$request = $smcFunc['db_query']('', '
@@ -551,35 +582,37 @@  discard block
 block discarded – undo
551 582
 	while ($row = $smcFunc['db_fetch_assoc']($request))
552 583
 	{
553 584
 		// Make the data look rss-ish.
554
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
555
-			$data[] = array(
585
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
586
+					$data[] = array(
556 587
 				'title' => $row['real_name'],
557 588
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
558 589
 				'comments' => $scripturl . '?action=pm;sa=send;u=' . $row['id_member'],
559 590
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['date_registered']),
560 591
 				'guid' => $scripturl . '?action=profile;u=' . $row['id_member'],
561 592
 			);
562
-		elseif ($xml_format == 'rdf')
563
-			$data[] = array(
593
+		} elseif ($xml_format == 'rdf') {
594
+					$data[] = array(
564 595
 				'title' => $row['real_name'],
565 596
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
566 597
 			);
567
-		elseif ($xml_format == 'atom')
568
-			$data[] = array(
598
+		} elseif ($xml_format == 'atom') {
599
+					$data[] = array(
569 600
 				'title' => $row['real_name'],
570 601
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
571 602
 				'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['date_registered']),
572 603
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['last_login']),
573 604
 				'id' => $scripturl . '?action=profile;u=' . $row['id_member'],
574 605
 			);
606
+		}
575 607
 		// More logical format for the data, but harder to apply.
576
-		else
577
-			$data[] = array(
608
+		else {
609
+					$data[] = array(
578 610
 				'name' => $row['real_name'],
579 611
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['date_registered']))),
580 612
 				'id' => $row['id_member'],
581 613
 				'link' => $scripturl . '?action=profile;u=' . $row['id_member']
582 614
 			);
615
+		}
583 616
 	}
584 617
 	$smcFunc['db_free_result']($request);
585 618
 
@@ -640,22 +673,24 @@  discard block
 block discarded – undo
640 673
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
641 674
 		{
642 675
 			$smcFunc['db_free_result']($request);
643
-			if (empty($_REQUEST['boards']) && empty($board))
644
-				unset($context['optimize_msg']['lowest']);
645
-			else
646
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
676
+			if (empty($_REQUEST['boards']) && empty($board)) {
677
+							unset($context['optimize_msg']['lowest']);
678
+			} else {
679
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
680
+			}
647 681
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
648 682
 			$loops++;
683
+		} else {
684
+					$done = true;
649 685
 		}
650
-		else
651
-			$done = true;
652 686
 	}
653 687
 	$data = array();
654 688
 	while ($row = $smcFunc['db_fetch_assoc']($request))
655 689
 	{
656 690
 		// Limit the length of the message, if the option is set.
657
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
658
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
691
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
692
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
693
+		}
659 694
 
660 695
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
661 696
 
@@ -663,8 +698,8 @@  discard block
 block discarded – undo
663 698
 		censorText($row['subject']);
664 699
 
665 700
 		// Being news, this actually makes sense in rss format.
666
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
667
-			$data[] = array(
701
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
702
+					$data[] = array(
668 703
 				'title' => $row['subject'],
669 704
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
670 705
 				'description' => $row['body'],
@@ -674,14 +709,14 @@  discard block
 block discarded – undo
674 709
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
675 710
 				'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
676 711
 			);
677
-		elseif ($xml_format == 'rdf')
678
-			$data[] = array(
712
+		} elseif ($xml_format == 'rdf') {
713
+					$data[] = array(
679 714
 				'title' => $row['subject'],
680 715
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
681 716
 				'description' => $row['body'],
682 717
 			);
683
-		elseif ($xml_format == 'atom')
684
-			$data[] = array(
718
+		} elseif ($xml_format == 'atom') {
719
+					$data[] = array(
685 720
 				'title' => $row['subject'],
686 721
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
687 722
 				'summary' => $row['body'],
@@ -695,9 +730,10 @@  discard block
 block discarded – undo
695 730
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
696 731
 				'id' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
697 732
 			);
733
+		}
698 734
 		// The biggest difference here is more information.
699
-		else
700
-			$data[] = array(
735
+		else {
736
+					$data[] = array(
701 737
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['poster_time']))),
702 738
 				'id' => $row['id_topic'],
703 739
 				'subject' => $row['subject'],
@@ -715,6 +751,7 @@  discard block
 block discarded – undo
715 751
 				),
716 752
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
717 753
 			);
754
+		}
718 755
 	}
719 756
 	$smcFunc['db_free_result']($request);
720 757
 
@@ -761,22 +798,25 @@  discard block
 block discarded – undo
761 798
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
762 799
 		{
763 800
 			$smcFunc['db_free_result']($request);
764
-			if (empty($_REQUEST['boards']) && empty($board))
765
-				unset($context['optimize_msg']['lowest']);
766
-			else
767
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
801
+			if (empty($_REQUEST['boards']) && empty($board)) {
802
+							unset($context['optimize_msg']['lowest']);
803
+			} else {
804
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
805
+			}
768 806
 			$loops++;
807
+		} else {
808
+					$done = true;
769 809
 		}
770
-		else
771
-			$done = true;
772 810
 	}
773 811
 	$messages = array();
774
-	while ($row = $smcFunc['db_fetch_assoc']($request))
775
-		$messages[] = $row['id_msg'];
812
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
813
+			$messages[] = $row['id_msg'];
814
+	}
776 815
 	$smcFunc['db_free_result']($request);
777 816
 
778
-	if (empty($messages))
779
-		return array();
817
+	if (empty($messages)) {
818
+			return array();
819
+	}
780 820
 
781 821
 	// Find the most recent posts this user can see.
782 822
 	$request = $smcFunc['db_query']('', '
@@ -806,8 +846,9 @@  discard block
 block discarded – undo
806 846
 	while ($row = $smcFunc['db_fetch_assoc']($request))
807 847
 	{
808 848
 		// Limit the length of the message, if the option is set.
809
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
810
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
849
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
850
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
851
+		}
811 852
 
812 853
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
813 854
 
@@ -815,8 +856,8 @@  discard block
 block discarded – undo
815 856
 		censorText($row['subject']);
816 857
 
817 858
 		// Doesn't work as well as news, but it kinda does..
818
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
819
-			$data[] = array(
859
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
860
+					$data[] = array(
820 861
 				'title' => $row['subject'],
821 862
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
822 863
 				'description' => $row['body'],
@@ -826,14 +867,14 @@  discard block
 block discarded – undo
826 867
 				'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
827 868
 				'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
828 869
 			);
829
-		elseif ($xml_format == 'rdf')
830
-			$data[] = array(
870
+		} elseif ($xml_format == 'rdf') {
871
+					$data[] = array(
831 872
 				'title' => $row['subject'],
832 873
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
833 874
 				'description' => $row['body'],
834 875
 			);
835
-		elseif ($xml_format == 'atom')
836
-			$data[] = array(
876
+		} elseif ($xml_format == 'atom') {
877
+					$data[] = array(
837 878
 				'title' => $row['subject'],
838 879
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
839 880
 				'summary' => $row['body'],
@@ -847,9 +888,10 @@  discard block
 block discarded – undo
847 888
 				'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
848 889
 				'id' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
849 890
 			);
891
+		}
850 892
 		// A lot of information here.  Should be enough to please the rss-ers.
851
-		else
852
-			$data[] = array(
893
+		else {
894
+					$data[] = array(
853 895
 				'time' => $smcFunc['htmlspecialchars'](strip_tags(timeformat($row['poster_time']))),
854 896
 				'id' => $row['id_msg'],
855 897
 				'subject' => $row['subject'],
@@ -876,6 +918,7 @@  discard block
 block discarded – undo
876 918
 				),
877 919
 				'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
878 920
 			);
921
+		}
879 922
 	}
880 923
 	$smcFunc['db_free_result']($request);
881 924
 
@@ -895,20 +938,22 @@  discard block
 block discarded – undo
895 938
 	global $scripturl, $memberContext, $user_profile, $user_info;
896 939
 
897 940
 	// You must input a valid user....
898
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
899
-		return array();
941
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
942
+			return array();
943
+	}
900 944
 
901 945
 	// Make sure the id is a number and not "I like trying to hack the database".
902 946
 	$_GET['u'] = (int) $_GET['u'];
903 947
 	// Load the member's contextual information!
904
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
905
-		return array();
948
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
949
+			return array();
950
+	}
906 951
 
907 952
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
908 953
 	$profile = &$memberContext[$_GET['u']];
909 954
 
910
-	if ($xml_format == 'rss' || $xml_format == 'rss2')
911
-		$data = array(array(
955
+	if ($xml_format == 'rss' || $xml_format == 'rss2') {
956
+			$data = array(array(
912 957
 			'title' => $profile['name'],
913 958
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
914 959
 			'description' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
@@ -916,14 +961,14 @@  discard block
 block discarded – undo
916 961
 			'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered']),
917 962
 			'guid' => $scripturl . '?action=profile;u=' . $profile['id'],
918 963
 		));
919
-	elseif ($xml_format == 'rdf')
920
-		$data = array(array(
964
+	} elseif ($xml_format == 'rdf') {
965
+			$data = array(array(
921 966
 			'title' => $profile['name'],
922 967
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
923 968
 			'description' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
924 969
 		));
925
-	elseif ($xml_format == 'atom')
926
-		$data[] = array(
970
+	} elseif ($xml_format == 'atom') {
971
+			$data[] = array(
927 972
 			'title' => $profile['name'],
928 973
 			'link' => $scripturl . '?action=profile;u=' . $profile['id'],
929 974
 			'summary' => isset($profile['group']) ? $profile['group'] : $profile['post_group'],
@@ -937,7 +982,7 @@  discard block
 block discarded – undo
937 982
 			'id' => $scripturl . '?action=profile;u=' . $profile['id'],
938 983
 			'logo' => !empty($profile['avatar']) ? $profile['avatar']['url'] : '',
939 984
 		);
940
-	else
985
+	} else
941 986
 	{
942 987
 		$data = array(
943 988
 			'username' => $user_info['is_admin'] || $user_info['id'] == $profile['id'] ? $profile['username'] : '',
@@ -951,34 +996,43 @@  discard block
 block discarded – undo
951 996
 		);
952 997
 
953 998
 		// Everything below here might not be set, and thus maybe shouldn't be displayed.
954
-		if ($profile['gender']['name'] != '')
955
-			$data['gender'] = $profile['gender']['name'];
999
+		if ($profile['gender']['name'] != '') {
1000
+					$data['gender'] = $profile['gender']['name'];
1001
+		}
956 1002
 
957
-		if ($profile['avatar']['name'] != '')
958
-			$data['avatar'] = $profile['avatar']['url'];
1003
+		if ($profile['avatar']['name'] != '') {
1004
+					$data['avatar'] = $profile['avatar']['url'];
1005
+		}
959 1006
 
960 1007
 		// If they are online, show an empty tag... no reason to put anything inside it.
961
-		if ($profile['online']['is_online'])
962
-			$data['online'] = '';
963
-
964
-		if ($profile['signature'] != '')
965
-			$data['signature'] = $profile['signature'];
966
-		if ($profile['blurb'] != '')
967
-			$data['blurb'] = $profile['blurb'];
968
-		if ($profile['title'] != '')
969
-			$data['title'] = $profile['title'];
970
-
971
-		if ($profile['website']['title'] != '')
972
-			$data['website'] = array(
1008
+		if ($profile['online']['is_online']) {
1009
+					$data['online'] = '';
1010
+		}
1011
+
1012
+		if ($profile['signature'] != '') {
1013
+					$data['signature'] = $profile['signature'];
1014
+		}
1015
+		if ($profile['blurb'] != '') {
1016
+					$data['blurb'] = $profile['blurb'];
1017
+		}
1018
+		if ($profile['title'] != '') {
1019
+					$data['title'] = $profile['title'];
1020
+		}
1021
+
1022
+		if ($profile['website']['title'] != '') {
1023
+					$data['website'] = array(
973 1024
 				'title' => $profile['website']['title'],
974 1025
 				'link' => $profile['website']['url']
975 1026
 			);
1027
+		}
976 1028
 
977
-		if ($profile['group'] != '')
978
-			$data['position'] = $profile['group'];
1029
+		if ($profile['group'] != '') {
1030
+					$data['position'] = $profile['group'];
1031
+		}
979 1032
 
980
-		if ($profile['show_email'])
981
-			$data['email'] = $profile['email'];
1033
+		if ($profile['show_email']) {
1034
+					$data['email'] = $profile['email'];
1035
+		}
982 1036
 
983 1037
 		if (!empty($profile['birth_date']) && substr($profile['birth_date'], 0, 4) != '0000')
984 1038
 		{
Please login to merge, or discard this patch.
Sources/ModerationCenter.php 1 patch
Braces   +139 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Entry point for the moderation center.
@@ -26,8 +27,9 @@  discard block
 block discarded – undo
26 27
 	global $txt, $context, $scripturl, $modSettings, $user_info, $sourcedir, $options;
27 28
 
28 29
 	// Don't run this twice... and don't conflict with the admin bar.
29
-	if (isset($context['admin_area']))
30
-		return;
30
+	if (isset($context['admin_area'])) {
31
+			return;
32
+	}
31 33
 
32 34
 	$context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1';
33 35
 	$context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1';
@@ -35,8 +37,9 @@  discard block
 block discarded – undo
35 37
 	$context['can_moderate_users'] = allowedTo('moderate_forum');
36 38
 
37 39
 	// Everyone using this area must be allowed here!
38
-	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users'])
39
-		isAllowedTo('access_mod_center');
40
+	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) {
41
+			isAllowedTo('access_mod_center');
42
+	}
40 43
 
41 44
 	// We're gonna want a menu of some kind.
42 45
 	require_once($sourcedir . '/Subs-Menu.php');
@@ -195,8 +198,9 @@  discard block
 block discarded – undo
195 198
 	unset($moderation_areas);
196 199
 
197 200
 	// We got something - didn't we? DIDN'T WE!
198
-	if ($mod_include_data == false)
199
-		fatal_lang_error('no_access', false);
201
+	if ($mod_include_data == false) {
202
+			fatal_lang_error('no_access', false);
203
+	}
200 204
 
201 205
 	// Retain the ID information in case required by a subaction.
202 206
 	$context['moderation_menu_id'] = $context['max_menu_id'];
@@ -219,22 +223,25 @@  discard block
 block discarded – undo
219 223
 		'url' => $scripturl . '?action=moderate',
220 224
 		'name' => $txt['moderation_center'],
221 225
 	);
222
-	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
223
-		$context['linktree'][] = array(
226
+	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') {
227
+			$context['linktree'][] = array(
224 228
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
225 229
 			'name' => $mod_include_data['label'],
226 230
 		);
227
-	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
228
-		$context['linktree'][] = array(
231
+	}
232
+	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) {
233
+			$context['linktree'][] = array(
229 234
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
230 235
 			'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
231 236
 		);
237
+	}
232 238
 
233 239
 	// Now - finally - the bit before the encore - the main performance of course!
234 240
 	if (!$dont_call)
235 241
 	{
236
-		if (isset($mod_include_data['file']))
237
-			require_once($sourcedir . '/' . $mod_include_data['file']);
242
+		if (isset($mod_include_data['file'])) {
243
+					require_once($sourcedir . '/' . $mod_include_data['file']);
244
+		}
238 245
 
239 246
 		call_helper($mod_include_data['function']);
240 247
 	}
@@ -259,8 +266,9 @@  discard block
 block discarded – undo
259 266
 	// Load what blocks the user actually can see...
260 267
 	$valid_blocks = array();
261 268
 
262
-	if ($context['can_moderate_groups'])
263
-		$valid_blocks['g'] = 'GroupRequests';
269
+	if ($context['can_moderate_groups']) {
270
+			$valid_blocks['g'] = 'GroupRequests';
271
+	}
264 272
 	if ($context['can_moderate_boards'])
265 273
 	{
266 274
 		$valid_blocks['r'] = 'ReportedPosts';
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	if ($context['can_moderate_users'])
270 278
 	{
271 279
 		// This falls under the category of moderating users as well...
272
-		if (!$context['can_moderate_boards'])
273
-			$valid_blocks['w'] = 'WatchedUsers';
280
+		if (!$context['can_moderate_boards']) {
281
+					$valid_blocks['w'] = 'WatchedUsers';
282
+		}
274 283
 
275 284
 		$valid_blocks['rm'] = 'ReportedMembers';
276 285
 	}
@@ -281,8 +290,9 @@  discard block
 block discarded – undo
281 290
 	foreach ($valid_blocks as $k => $block)
282 291
 	{
283 292
 		$block = 'ModBlock' . $block;
284
-		if (function_exists($block))
285
-			$context['mod_blocks'][] = $block();
293
+		if (function_exists($block)) {
294
+					$context['mod_blocks'][] = $block();
295
+		}
286 296
 	}
287 297
 
288 298
 	$context['admin_prefs'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array();
@@ -309,8 +319,9 @@  discard block
 block discarded – undo
309 319
 			)
310 320
 		);
311 321
 		$watched_users = array();
312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
313
-			$watched_users[] = $row;
322
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
323
+					$watched_users[] = $row;
324
+		}
314 325
 		$smcFunc['db_free_result']($request);
315 326
 
316 327
 		cache_put_data('recent_user_watches', $watched_users, 240);
@@ -402,8 +413,9 @@  discard block
 block discarded – undo
402 413
 			$note_owner = $smcFunc['db_num_rows']($get_owner);
403 414
 			$smcFunc['db_free_result']($get_owner);
404 415
 
405
-			if(empty($note_owner))
406
-				fatal_lang_error('mc_notes_delete_own', false);
416
+			if(empty($note_owner)) {
417
+							fatal_lang_error('mc_notes_delete_own', false);
418
+			}
407 419
 		}
408 420
 
409 421
 		// Lets delete it.
@@ -460,12 +472,14 @@  discard block
 block discarded – undo
460 472
 			)
461 473
 		);
462 474
 		$moderator_notes = array();
463
-		while ($row = $smcFunc['db_fetch_assoc']($request))
464
-			$moderator_notes[] = $row;
475
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
476
+					$moderator_notes[] = $row;
477
+		}
465 478
 		$smcFunc['db_free_result']($request);
466 479
 
467
-		if ($offset == 0)
468
-			cache_put_data('moderator_notes', $moderator_notes, 240);
480
+		if ($offset == 0) {
481
+					cache_put_data('moderator_notes', $moderator_notes, 240);
482
+		}
469 483
 	}
470 484
 
471 485
 	// Lets construct a page index.
@@ -504,8 +518,9 @@  discard block
 block discarded – undo
504 518
 	// Got the info already?
505 519
 	$cachekey = md5(json_encode($user_info['mod_cache']['bq']));
506 520
 	$context['reported_posts'] = array();
507
-	if ($user_info['mod_cache']['bq'] == '0=1')
508
-		return 'reported_posts_block';
521
+	if ($user_info['mod_cache']['bq'] == '0=1') {
522
+			return 'reported_posts_block';
523
+	}
509 524
 
510 525
 	if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
511 526
 	{
@@ -529,8 +544,9 @@  discard block
 block discarded – undo
529 544
 			)
530 545
 		);
531 546
 		$reported_posts = array();
532
-		while ($row = $smcFunc['db_fetch_assoc']($request))
533
-			$reported_posts[] = $row;
547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
548
+					$reported_posts[] = $row;
549
+		}
534 550
 		$smcFunc['db_free_result']($request);
535 551
 
536 552
 		// Cache it.
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 
569 585
 	$context['group_requests'] = array();
570 586
 	// Make sure they can even moderate someone!
571
-	if ($user_info['mod_cache']['gq'] == '0=1')
572
-		return 'group_requests_block';
587
+	if ($user_info['mod_cache']['gq'] == '0=1') {
588
+			return 'group_requests_block';
589
+	}
573 590
 
574 591
 	// What requests are outstanding?
575 592
 	$request = $smcFunc['db_query']('', '
@@ -618,8 +635,9 @@  discard block
 block discarded – undo
618 635
 	// Got the info already?
619 636
 	$cachekey = md5(json_encode((int) allowedTo('moderate_forum')));
620 637
 	$context['reported_users'] = array();
621
-	if (!allowedTo('moderate_forum'))
622
-		return 'reported_users_block';
638
+	if (!allowedTo('moderate_forum')) {
639
+			return 'reported_users_block';
640
+	}
623 641
 
624 642
 	if (($reported_users = cache_get_data('reported_users_' . $cachekey, 90)) === null)
625 643
 	{
@@ -642,8 +660,9 @@  discard block
 block discarded – undo
642 660
 			)
643 661
 		);
644 662
 		$reported_users = array();
645
-		while ($row = $smcFunc['db_fetch_assoc']($request))
646
-			$reported_users[] = $row;
663
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
664
+					$reported_users[] = $row;
665
+		}
647 666
 		$smcFunc['db_free_result']($request);
648 667
 
649 668
 		// Cache it.
@@ -691,8 +710,9 @@  discard block
 block discarded – undo
691 710
 	isAllowedTo('moderate_forum');
692 711
 
693 712
 	// Are they wanting to view a particular report?
694
-	if (!empty($_REQUEST['report']))
695
-		return MemberReport();
713
+	if (!empty($_REQUEST['report'])) {
714
+			return MemberReport();
715
+	}
696 716
 
697 717
 	// Set up the comforting bits...
698 718
 	$context['page_title'] = $txt['mc_reported_members'];
@@ -746,15 +766,15 @@  discard block
 block discarded – undo
746 766
 		// Time to update.
747 767
 		updateSettings(array('last_mod_report_action' => time()));
748 768
 		recountOpenReports('members');
749
-	}
750
-	elseif (isset($_POST['close']) && isset($_POST['close_selected']))
769
+	} elseif (isset($_POST['close']) && isset($_POST['close_selected']))
751 770
 	{
752 771
 		checkSession();
753 772
 
754 773
 		// All the ones to update...
755 774
 		$toClose = array();
756
-		foreach ($_POST['close'] as $rid)
757
-			$toClose[] = (int) $rid;
775
+		foreach ($_POST['close'] as $rid) {
776
+					$toClose[] = (int) $rid;
777
+		}
758 778
 
759 779
 		if (!empty($toClose))
760 780
 		{
@@ -907,8 +927,9 @@  discard block
 block discarded – undo
907 927
 	global $context, $user_info;
908 928
 
909 929
 	// You need to be allowed to moderate groups...
910
-	if ($user_info['mod_cache']['gq'] == '0=1')
911
-		isAllowedTo('manage_membergroups');
930
+	if ($user_info['mod_cache']['gq'] == '0=1') {
931
+			isAllowedTo('manage_membergroups');
932
+	}
912 933
 
913 934
 	// Load the group templates.
914 935
 	loadTemplate('ModerationCenter');
@@ -919,8 +940,9 @@  discard block
 block discarded – undo
919 940
 		'view' => 'ViewGroups',
920 941
 	);
921 942
 
922
-	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']]))
923
-		$_GET['sa'] = 'view';
943
+	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
944
+			$_GET['sa'] = 'view';
945
+	}
924 946
 	$context['sub_action'] = $_GET['sa'];
925 947
 
926 948
 	// Call the relevant function.
@@ -950,8 +972,9 @@  discard block
 block discarded – undo
950 972
 			'id_notice' => $id_notice,
951 973
 		)
952 974
 	);
953
-	if ($smcFunc['db_num_rows']($request) == 0)
954
-		fatal_lang_error('no_access', false);
975
+	if ($smcFunc['db_num_rows']($request) == 0) {
976
+			fatal_lang_error('no_access', false);
977
+	}
955 978
 	list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
956 979
 	$smcFunc['db_free_result']($request);
957 980
 
@@ -988,18 +1011,20 @@  discard block
 block discarded – undo
988 1011
 		checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
989 1012
 
990 1013
 		$toDelete = array();
991
-		if (!is_array($_REQUEST['delete']))
992
-			$toDelete[] = (int) $_REQUEST['delete'];
993
-		else
994
-			foreach ($_REQUEST['delete'] as $did)
1014
+		if (!is_array($_REQUEST['delete'])) {
1015
+					$toDelete[] = (int) $_REQUEST['delete'];
1016
+		} else {
1017
+					foreach ($_REQUEST['delete'] as $did)
995 1018
 				$toDelete[] = (int) $did;
1019
+		}
996 1020
 
997 1021
 		if (!empty($toDelete))
998 1022
 		{
999 1023
 			require_once($sourcedir . '/RemoveTopic.php');
1000 1024
 			// If they don't have permission we'll let it error - either way no chance of a security slip here!
1001
-			foreach ($toDelete as $did)
1002
-				removeMessage($did);
1025
+			foreach ($toDelete as $did) {
1026
+							removeMessage($did);
1027
+			}
1003 1028
 		}
1004 1029
 	}
1005 1030
 
@@ -1008,20 +1033,21 @@  discard block
 block discarded – undo
1008 1033
 	{
1009 1034
 		$approve_query = '';
1010 1035
 		$delete_boards = array();
1011
-	}
1012
-	else
1036
+	} else
1013 1037
 	{
1014 1038
 		// Still obey permissions!
1015 1039
 		$approve_boards = boardsAllowedTo('approve_posts');
1016 1040
 		$delete_boards = boardsAllowedTo('delete_any');
1017 1041
 
1018
-		if ($approve_boards == array(0))
1019
-			$approve_query = '';
1020
-		elseif (!empty($approve_boards))
1021
-			$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1042
+		if ($approve_boards == array(0)) {
1043
+					$approve_query = '';
1044
+		} elseif (!empty($approve_boards)) {
1045
+					$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1046
+		}
1022 1047
 		// Nada, zip, etc...
1023
-		else
1024
-			$approve_query = ' AND 1=0';
1048
+		else {
1049
+					$approve_query = ' AND 1=0';
1050
+		}
1025 1051
 	}
1026 1052
 
1027 1053
 	require_once($sourcedir . '/Subs-List.php');
@@ -1120,10 +1146,11 @@  discard block
 block discarded – undo
1120 1146
 				'data' => array(
1121 1147
 					'function' => function ($member) use ($scripturl)
1122 1148
 					{
1123
-						if ($member['last_post_id'])
1124
-							return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1125
-						else
1126
-							return $member['last_post'];
1149
+						if ($member['last_post_id']) {
1150
+													return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1151
+						} else {
1152
+													return $member['last_post'];
1153
+						}
1127 1154
 					},
1128 1155
 				),
1129 1156
 			),
@@ -1251,8 +1278,9 @@  discard block
 block discarded – undo
1251 1278
 			)
1252 1279
 		);
1253 1280
 		$latest_posts = array();
1254
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1255
-			$latest_posts[$row['id_member']] = $row['last_post_id'];
1281
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1282
+					$latest_posts[$row['id_member']] = $row['last_post_id'];
1283
+		}
1256 1284
 
1257 1285
 		if (!empty($latest_posts))
1258 1286
 		{
@@ -1443,15 +1471,17 @@  discard block
 block discarded – undo
1443 1471
 	// Setup the direction stuff...
1444 1472
 	$context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'member';
1445 1473
 
1446
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
1447
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1448
-	else
1449
-		$search_params_string = $search_params['string'];
1474
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
1475
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1476
+	} else {
1477
+			$search_params_string = $search_params['string'];
1478
+	}
1450 1479
 
1451
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
1452
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1453
-	else
1454
-		$search_params_type = $search_params['type'];
1480
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
1481
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1482
+	} else {
1483
+			$search_params_type = $search_params['type'];
1484
+	}
1455 1485
 
1456 1486
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
1457 1487
 	$search_params = array(
@@ -1535,9 +1565,10 @@  discard block
 block discarded – undo
1535 1565
 								' . $rowData['reason'] . '
1536 1566
 							</div>';
1537 1567
 
1538
-						if (!empty($rowData['id_notice']))
1539
-							$output .= '
1568
+						if (!empty($rowData['id_notice'])) {
1569
+													$output .= '
1540 1570
 								&nbsp;<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $rowData['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" class="new_win" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>';
1571
+						}
1541 1572
 						return $output;
1542 1573
 					},
1543 1574
 				),
@@ -1655,9 +1686,9 @@  discard block
 block discarded – undo
1655 1686
 	global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
1656 1687
 
1657 1688
 	// Submitting a new one?
1658
-	if (isset($_POST['add']))
1659
-		return ModifyWarningTemplate();
1660
-	elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1689
+	if (isset($_POST['add'])) {
1690
+			return ModifyWarningTemplate();
1691
+	} elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1661 1692
 	{
1662 1693
 		checkSession();
1663 1694
 		validateToken('mod-wt');
@@ -1676,8 +1707,9 @@  discard block
 block discarded – undo
1676 1707
 				'current_member' => $user_info['id'],
1677 1708
 			)
1678 1709
 		);
1679
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1680
-			logAction('delete_warn_template', array('template' => $row['recipient_name']));
1710
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1711
+					logAction('delete_warn_template', array('template' => $row['recipient_name']));
1712
+		}
1681 1713
 		$smcFunc['db_free_result']($request);
1682 1714
 
1683 1715
 		// Do the deletes.
@@ -1968,16 +2000,18 @@  discard block
 block discarded – undo
1968 2000
 				);
1969 2001
 
1970 2002
 				// If it wasn't visible and now is they've effectively added it.
1971
-				if ($context['template_data']['personal'] && !$recipient_id)
1972
-					logAction('add_warn_template', array('template' => $_POST['template_title']));
2003
+				if ($context['template_data']['personal'] && !$recipient_id) {
2004
+									logAction('add_warn_template', array('template' => $_POST['template_title']));
2005
+				}
1973 2006
 				// Conversely if they made it personal it's a delete.
1974
-				elseif (!$context['template_data']['personal'] && $recipient_id)
1975
-					logAction('delete_warn_template', array('template' => $_POST['template_title']));
2007
+				elseif (!$context['template_data']['personal'] && $recipient_id) {
2008
+									logAction('delete_warn_template', array('template' => $_POST['template_title']));
2009
+				}
1976 2010
 				// Otherwise just an edit.
1977
-				else
1978
-					logAction('modify_warn_template', array('template' => $_POST['template_title']));
1979
-			}
1980
-			else
2011
+				else {
2012
+									logAction('modify_warn_template', array('template' => $_POST['template_title']));
2013
+				}
2014
+			} else
1981 2015
 			{
1982 2016
 				$smcFunc['db_insert']('',
1983 2017
 					'{db_prefix}log_comments',
@@ -1997,17 +2031,18 @@  discard block
 block discarded – undo
1997 2031
 
1998 2032
 			// Get out of town...
1999 2033
 			redirectexit('action=moderate;area=warnings;sa=templates');
2000
-		}
2001
-		else
2034
+		} else
2002 2035
 		{
2003 2036
 			$context['warning_errors'] = array();
2004 2037
 			$context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
2005 2038
 			$context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
2006 2039
 			$context['template_data']['personal'] = !empty($_POST['make_personal']);
2007
-			if (empty($_POST['template_title']))
2008
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2009
-			if (empty($_POST['template_body']))
2010
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2040
+			if (empty($_POST['template_title'])) {
2041
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2042
+			}
2043
+			if (empty($_POST['template_body'])) {
2044
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2045
+			}
2011 2046
 		}
2012 2047
 	}
2013 2048
 
@@ -2054,8 +2089,9 @@  discard block
 block discarded – undo
2054 2089
 		// Now check other options!
2055 2090
 		$pref_binary = 0;
2056 2091
 
2057
-		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
2058
-			$pref_binary |= 4;
2092
+		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) {
2093
+					$pref_binary |= 4;
2094
+		}
2059 2095
 
2060 2096
 		// Put it all together.
2061 2097
 		$mod_prefs = '0||' . $pref_binary;
@@ -2079,9 +2115,10 @@  discard block
 block discarded – undo
2079 2115
 	unset($_SESSION['moderate_time']);
2080 2116
 
2081 2117
 	// Clean any moderator tokens as well.
2082
-	foreach ($_SESSION['token'] as $key => $token)
2083
-		if (strpos($key, '-mod') !== false)
2118
+	foreach ($_SESSION['token'] as $key => $token) {
2119
+			if (strpos($key, '-mod') !== false)
2084 2120
 			unset($_SESSION['token'][$key]);
2121
+	}
2085 2122
 
2086 2123
 	redirectexit();
2087 2124
 }
Please login to merge, or discard this patch.
Sources/Class-Graphics.php 1 patch
Braces   +90 added lines, -62 removed lines patch added patch discarded remove patch
@@ -19,8 +19,9 @@  discard block
 block discarded – undo
19 19
  * @version 2.1 Beta 3
20 20
  */
21 21
 
22
-if (!defined('SMF'))
22
+if (!defined('SMF')) {
23 23
 	die('No direct access...');
24
+}
24 25
 
25 26
 /**
26 27
  * Class gif_lzw_compression
@@ -52,13 +53,15 @@  discard block
 block discarded – undo
52 53
 
53 54
 		$this->LZWCommand($data, true);
54 55
 
55
-		while (($iIndex = $this->LZWCommand($data, false)) >= 0)
56
-			$ret .= chr($iIndex);
56
+		while (($iIndex = $this->LZWCommand($data, false)) >= 0) {
57
+					$ret .= chr($iIndex);
58
+		}
57 59
 
58 60
 		$datLen = $stLen - strlen($data);
59 61
 
60
-		if ($iIndex != -2)
61
-			return false;
62
+		if ($iIndex != -2) {
63
+					return false;
64
+		}
62 65
 
63 66
 		return $ret;
64 67
 	}
@@ -140,8 +143,9 @@  discard block
 block discarded – undo
140 143
 				return $this->FirstCode;
141 144
 			}
142 145
 
143
-			if ($Code == $this->EndCode)
144
-				return -2;
146
+			if ($Code == $this->EndCode) {
147
+							return -2;
148
+			}
145 149
 
146 150
 			$InCode = $Code;
147 151
 			if ($Code >= $this->MaxCode)
@@ -156,8 +160,10 @@  discard block
 block discarded – undo
156 160
 				$this->Stack[$this->sp] = $this->Vals[$Code];
157 161
 				$this->sp++;
158 162
 
159
-				if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error!
163
+				if ($Code == $this->Next[$Code]) {
164
+					// Circular table entry, big GIF Error!
160 165
 					return -1;
166
+				}
161 167
 
162 168
 				$Code = $this->Next[$Code];
163 169
 			}
@@ -207,8 +213,9 @@  discard block
 block discarded – undo
207 213
 			if ($this->Done)
208 214
 			{
209 215
 				// Ran off the end of my bits...
210
-				if ($this->CurBit >= $this->LastBit)
211
-					return 0;
216
+				if ($this->CurBit >= $this->LastBit) {
217
+									return 0;
218
+				}
212 219
 
213 220
 				return -1;
214 221
 			}
@@ -221,13 +228,14 @@  discard block
 block discarded – undo
221 228
 
222 229
 			if ($count)
223 230
 			{
224
-				for ($i = 0; $i < $count; $i++)
225
-					$this->Buf[2 + $i] = ord($data{$i});
231
+				for ($i = 0; $i < $count; $i++) {
232
+									$this->Buf[2 + $i] = ord($data{$i});
233
+				}
226 234
 
227 235
 				$data = substr($data, $count);
236
+			} else {
237
+							$this->Done = 1;
228 238
 			}
229
-			else
230
-				$this->Done = 1;
231 239
 
232 240
 			$this->LastByte = 2 + $count;
233 241
 			$this->CurBit = ($this->CurBit - $this->LastBit) + 16;
@@ -235,8 +243,9 @@  discard block
 block discarded – undo
235 243
 		}
236 244
 
237 245
 		$iRet = 0;
238
-		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++)
239
-			$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
246
+		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) {
247
+					$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
248
+		}
240 249
 
241 250
 		$this->CurBit += $this->CodeSize;
242 251
 		return $iRet;
@@ -261,8 +270,9 @@  discard block
 block discarded – undo
261 270
 		for ($i = 0; $i < $num; $i++)
262 271
 		{
263 272
 			$rgb = substr($lpData, $i * 3, 3);
264
-			if (strlen($rgb) < 3)
265
-				return false;
273
+			if (strlen($rgb) < 3) {
274
+							return false;
275
+			}
266 276
 
267 277
 			$this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]);
268 278
 			$this->m_nColors++;
@@ -329,13 +339,15 @@  discard block
 block discarded – undo
329 339
 		$hdrLen = 0;
330 340
 
331 341
 		$this->m_lpVer = substr($lpData, 0, 6);
332
-		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a'))
333
-			return false;
342
+		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) {
343
+					return false;
344
+		}
334 345
 
335 346
 		list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4)));
336 347
 
337
-		if (!$this->m_nWidth || !$this->m_nHeight)
338
-			return false;
348
+		if (!$this->m_nWidth || !$this->m_nHeight) {
349
+					return false;
350
+		}
339 351
 
340 352
 		$b = ord(substr($lpData, 10, 1));
341 353
 		$this->m_bGlobalClr  = ($b & 0x80) ? true : false;
@@ -349,8 +361,9 @@  discard block
 block discarded – undo
349 361
 		if ($this->m_bGlobalClr)
350 362
 		{
351 363
 			$this->m_colorTable = new gif_color_table();
352
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
353
-				return false;
364
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
365
+							return false;
366
+			}
354 367
 
355 368
 			$hdrLen += 3 * $this->m_nTableSize;
356 369
 		}
@@ -377,8 +390,9 @@  discard block
 block discarded – undo
377 390
 		// Get the width/height/etc. from the header.
378 391
 		list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8)));
379 392
 
380
-		if (!$this->m_nWidth || !$this->m_nHeight)
381
-			return false;
393
+		if (!$this->m_nWidth || !$this->m_nHeight) {
394
+					return false;
395
+		}
382 396
 
383 397
 		$b = ord($lpData[8]);
384 398
 		$this->m_bLocalClr  = ($b & 0x80) ? true : false;
@@ -390,8 +404,9 @@  discard block
 block discarded – undo
390 404
 		if ($this->m_bLocalClr)
391 405
 		{
392 406
 			$this->m_colorTable = new gif_color_table();
393
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
394
-				return false;
407
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
408
+							return false;
409
+			}
395 410
 
396 411
 			$hdrLen += 3 * $this->m_nTableSize;
397 412
 		}
@@ -427,8 +442,9 @@  discard block
 block discarded – undo
427 442
 			// Extension...
428 443
 			case 0x21:
429 444
 				$len = 0;
430
-				if (!$this->skipExt($data, $len))
431
-					return false;
445
+				if (!$this->skipExt($data, $len)) {
446
+									return false;
447
+				}
432 448
 
433 449
 				$datLen += $len;
434 450
 				break;
@@ -437,22 +453,25 @@  discard block
 block discarded – undo
437 453
 			case 0x2C:
438 454
 				// Load the header and color table.
439 455
 				$len = 0;
440
-				if (!$this->m_gih->load($data, $len))
441
-					return false;
456
+				if (!$this->m_gih->load($data, $len)) {
457
+									return false;
458
+				}
442 459
 
443 460
 				$data = substr($data, $len);
444 461
 				$datLen += $len;
445 462
 
446 463
 				// Decompress the data, and ride on home ;).
447 464
 				$len = 0;
448
-				if (!($this->m_data = $this->m_lzw->decompress($data, $len)))
449
-					return false;
465
+				if (!($this->m_data = $this->m_lzw->decompress($data, $len))) {
466
+									return false;
467
+				}
450 468
 
451 469
 				$data = substr($data, $len);
452 470
 				$datLen += $len;
453 471
 
454
-				if ($this->m_gih->m_bInterlace)
455
-					$this->deInterlace();
472
+				if ($this->m_gih->m_bInterlace) {
473
+									$this->deInterlace();
474
+				}
456 475
 
457 476
 				return true;
458 477
 
@@ -572,17 +591,20 @@  discard block
 block discarded – undo
572 591
 
573 592
 	public function loadFile($filename, $iIndex)
574 593
 	{
575
-		if ($iIndex < 0)
576
-			return false;
594
+		if ($iIndex < 0) {
595
+					return false;
596
+		}
577 597
 
578 598
 		$this->data = @file_get_contents($filename);
579
-		if ($this->data === false)
580
-			return false;
599
+		if ($this->data === false) {
600
+					return false;
601
+		}
581 602
 
582 603
 		// Tell the header to load up....
583 604
 		$len = 0;
584
-		if (!$this->header->load($this->data, $len))
585
-			return false;
605
+		if (!$this->header->load($this->data, $len)) {
606
+					return false;
607
+		}
586 608
 
587 609
 		$this->data = substr($this->data, $len);
588 610
 
@@ -590,8 +612,9 @@  discard block
 block discarded – undo
590 612
 		for ($j = 0; $j <= $iIndex; $j++)
591 613
 		{
592 614
 			$imgLen = 0;
593
-			if (!$this->image->load($this->data, $imgLen))
594
-				return false;
615
+			if (!$this->image->load($this->data, $imgLen)) {
616
+							return false;
617
+			}
595 618
 
596 619
 			$this->data = substr($this->data, $imgLen);
597 620
 		}
@@ -602,8 +625,9 @@  discard block
 block discarded – undo
602 625
 
603 626
 	public function get_png_data($background_color)
604 627
 	{
605
-		if (!$this->loaded)
606
-			return false;
628
+		if (!$this->loaded) {
629
+					return false;
630
+		}
607 631
 
608 632
 		// Prepare the color table.
609 633
 		if ($this->image->m_gih->m_bLocalClr)
@@ -611,25 +635,26 @@  discard block
 block discarded – undo
611 635
 			$colors = $this->image->m_gih->m_nTableSize;
612 636
 			$pal = $this->image->m_gih->m_colorTable->toString();
613 637
 
614
-			if ($background_color != -1)
615
-				$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
616
-		}
617
-		elseif ($this->header->m_bGlobalClr)
638
+			if ($background_color != -1) {
639
+							$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
640
+			}
641
+		} elseif ($this->header->m_bGlobalClr)
618 642
 		{
619 643
 			$colors = $this->header->m_nTableSize;
620 644
 			$pal = $this->header->m_colorTable->toString();
621 645
 
622
-			if ($background_color != -1)
623
-				$background_color = $this->header->m_colorTable->colorIndex($background_color);
624
-		}
625
-		else
646
+			if ($background_color != -1) {
647
+							$background_color = $this->header->m_colorTable->colorIndex($background_color);
648
+			}
649
+		} else
626 650
 		{
627 651
 			$colors = 0;
628 652
 			$background_color = -1;
629 653
 		}
630 654
 
631
-		if ($background_color == -1)
632
-			$background_color = $this->header->m_nBgColor;
655
+		if ($background_color == -1) {
656
+					$background_color = $this->header->m_nBgColor;
657
+		}
633 658
 
634 659
 		$data = &$this->image->m_data;
635 660
 		$header = &$this->image->m_gih;
@@ -645,11 +670,13 @@  discard block
 block discarded – undo
645 670
 			for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++)
646 671
 			{
647 672
 				// Is this in the proper range?  If so, get the specific pixel data...
648
-				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight))
649
-					$bmp .= $data{$i};
673
+				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) {
674
+									$bmp .= $data{$i};
675
+				}
650 676
 				// Otherwise, this is background...
651
-				else
652
-					$bmp .= chr($background_color);
677
+				else {
678
+									$bmp .= chr($background_color);
679
+				}
653 680
 			}
654 681
 		}
655 682
 
@@ -678,8 +705,9 @@  discard block
 block discarded – undo
678 705
 			$tmp = 'tRNS';
679 706
 
680 707
 			// Stick each color on - full transparency or none.
681
-			for ($i = 0; $i < $colors; $i++)
682
-				$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
708
+			for ($i = 0; $i < $colors; $i++) {
709
+							$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
710
+			}
683 711
 
684 712
 			$out .= $tmp . pack('N', smf_crc32($tmp));
685 713
 		}
Please login to merge, or discard this patch.
Sources/Subs-Boards.php 1 patch
Braces   +247 added lines, -175 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Mark a board or multiple boards read.
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 	global $user_info, $modSettings, $smcFunc;
29 30
 
30 31
 	// Force $boards to be an array.
31
-	if (!is_array($boards))
32
-		$boards = array($boards);
33
-	else
34
-		$boards = array_unique($boards);
32
+	if (!is_array($boards)) {
33
+			$boards = array($boards);
34
+	} else {
35
+			$boards = array_unique($boards);
36
+	}
35 37
 
36 38
 	// No boards, nothing to mark as read.
37
-	if (empty($boards))
38
-		return;
39
+	if (empty($boards)) {
40
+			return;
41
+	}
39 42
 
40 43
 	// Allow the user to mark a board as unread.
41 44
 	if ($unread)
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	else
66 69
 	{
67 70
 		$markRead = array();
68
-		foreach ($boards as $board)
69
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
71
+		foreach ($boards as $board) {
72
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
73
+		}
70 74
 
71 75
 		// Update log_mark_read and log_boards.
72 76
 		$smcFunc['db_insert']('replace',
@@ -99,8 +103,9 @@  discard block
 block discarded – undo
99 103
 	list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
100 104
 	$smcFunc['db_free_result']($result);
101 105
 
102
-	if (empty($lowest_topic))
103
-		return;
106
+	if (empty($lowest_topic)) {
107
+			return;
108
+	}
104 109
 
105 110
 	// @todo SLOW This query seems to eat it sometimes.
106 111
 	$result = $smcFunc['db_query']('', '
@@ -118,12 +123,13 @@  discard block
 block discarded – undo
118 123
 		)
119 124
 	);
120 125
 	$topics = array();
121
-	while ($row = $smcFunc['db_fetch_assoc']($result))
122
-		$topics[] = $row['id_topic'];
126
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
127
+			$topics[] = $row['id_topic'];
128
+	}
123 129
 	$smcFunc['db_free_result']($result);
124 130
 
125
-	if (!empty($topics))
126
-		$smcFunc['db_query']('', '
131
+	if (!empty($topics)) {
132
+			$smcFunc['db_query']('', '
127 133
 			DELETE FROM {db_prefix}log_topics
128 134
 			WHERE id_member = {int:current_member}
129 135
 				AND id_topic IN ({array_int:topic_list})',
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 				'topic_list' => $topics,
133 139
 			)
134 140
 		);
135
-}
141
+	}
142
+	}
136 143
 
137 144
 /**
138 145
  * Mark one or more boards as read.
@@ -157,23 +164,26 @@  discard block
 block discarded – undo
157 164
 			)
158 165
 		);
159 166
 		$boards = array();
160
-		while ($row = $smcFunc['db_fetch_assoc']($result))
161
-			$boards[] = $row['id_board'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
168
+					$boards[] = $row['id_board'];
169
+		}
162 170
 		$smcFunc['db_free_result']($result);
163 171
 
164
-		if (!empty($boards))
165
-			markBoardsRead($boards, isset($_REQUEST['unread']));
172
+		if (!empty($boards)) {
173
+					markBoardsRead($boards, isset($_REQUEST['unread']));
174
+		}
166 175
 
167 176
 		$_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
168
-		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
169
-			redirectexit('action=unread');
177
+		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) {
178
+					redirectexit('action=unread');
179
+		}
170 180
 
171
-		if (isset($_SESSION['topicseen_cache']))
172
-			$_SESSION['topicseen_cache'] = array();
181
+		if (isset($_SESSION['topicseen_cache'])) {
182
+					$_SESSION['topicseen_cache'] = array();
183
+		}
173 184
 
174 185
 		redirectexit();
175
-	}
176
-	elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
186
+	} elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
177 187
 	{
178 188
 		// Make sure all the topics are integers!
179 189
 		$topics = array_map('intval', explode('-', $_REQUEST['topics']));
@@ -189,13 +199,15 @@  discard block
 block discarded – undo
189 199
 			)
190 200
 		);
191 201
 		$logged_topics = array();
192
-		while ($row = $smcFunc['db_fetch_assoc']($request))
193
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
203
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
204
+		}
194 205
 		$smcFunc['db_free_result']($request);
195 206
 
196 207
 		$markRead = array();
197
-		foreach ($topics as $id_topic)
198
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
208
+		foreach ($topics as $id_topic) {
209
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
210
+		}
199 211
 
200 212
 		$smcFunc['db_insert']('replace',
201 213
 			'{db_prefix}log_topics',
@@ -204,8 +216,9 @@  discard block
 block discarded – undo
204 216
 			array('id_member', 'id_topic')
205 217
 		);
206 218
 
207
-		if (isset($_SESSION['topicseen_cache']))
208
-			$_SESSION['topicseen_cache'] = array();
219
+		if (isset($_SESSION['topicseen_cache'])) {
220
+					$_SESSION['topicseen_cache'] = array();
221
+		}
209 222
 
210 223
 		redirectexit('action=unreadreplies');
211 224
 	}
@@ -230,11 +243,13 @@  discard block
 block discarded – undo
230 243
 		if (!empty($_GET['t']))
231 244
 		{
232 245
 			// If they read the whole topic, go back to the beginning.
233
-			if ($_GET['t'] >= $topicinfo['id_last_msg'])
234
-				$earlyMsg = 0;
246
+			if ($_GET['t'] >= $topicinfo['id_last_msg']) {
247
+							$earlyMsg = 0;
248
+			}
235 249
 			// If they want to mark the whole thing read, same.
236
-			elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
237
-				$earlyMsg = 0;
250
+			elseif ($_GET['t'] <= $topicinfo['id_first_msg']) {
251
+							$earlyMsg = 0;
252
+			}
238 253
 			// Otherwise, get the latest message before the named one.
239 254
 			else
240 255
 			{
@@ -255,9 +270,9 @@  discard block
 block discarded – undo
255 270
 			}
256 271
 		}
257 272
 		// Marking read from first page?  That's the whole topic.
258
-		elseif ($_REQUEST['start'] == 0)
259
-			$earlyMsg = 0;
260
-		else
273
+		elseif ($_REQUEST['start'] == 0) {
274
+					$earlyMsg = 0;
275
+		} else
261 276
 		{
262 277
 			$result = $smcFunc['db_query']('', '
263 278
 				SELECT id_msg
@@ -285,8 +300,7 @@  discard block
 block discarded – undo
285 300
 		);
286 301
 
287 302
 		redirectexit('board=' . $board . '.0');
288
-	}
289
-	else
303
+	} else
290 304
 	{
291 305
 		$categories = array();
292 306
 		$boards = array();
@@ -294,17 +308,20 @@  discard block
 block discarded – undo
294 308
 		if (isset($_REQUEST['c']))
295 309
 		{
296 310
 			$_REQUEST['c'] = explode(',', $_REQUEST['c']);
297
-			foreach ($_REQUEST['c'] as $c)
298
-				$categories[] = (int) $c;
311
+			foreach ($_REQUEST['c'] as $c) {
312
+							$categories[] = (int) $c;
313
+			}
299 314
 		}
300 315
 		if (isset($_REQUEST['boards']))
301 316
 		{
302 317
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
303
-			foreach ($_REQUEST['boards'] as $b)
304
-				$boards[] = (int) $b;
318
+			foreach ($_REQUEST['boards'] as $b) {
319
+							$boards[] = (int) $b;
320
+			}
321
+		}
322
+		if (!empty($board)) {
323
+					$boards[] = (int) $board;
305 324
 		}
306
-		if (!empty($board))
307
-			$boards[] = (int) $board;
308 325
 
309 326
 		if (isset($_REQUEST['children']) && !empty($boards))
310 327
 		{
@@ -324,9 +341,10 @@  discard block
 block discarded – undo
324 341
 					'board_list' => $boards,
325 342
 				)
326 343
 			);
327
-			while ($row = $smcFunc['db_fetch_assoc']($request))
328
-				if (in_array($row['id_parent'], $boards))
344
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
345
+							if (in_array($row['id_parent'], $boards))
329 346
 					$boards[] = $row['id_board'];
347
+			}
330 348
 			$smcFunc['db_free_result']($request);
331 349
 		}
332 350
 
@@ -343,8 +361,9 @@  discard block
 block discarded – undo
343 361
 			$clauseParameters['board_list'] = $boards;
344 362
 		}
345 363
 
346
-		if (empty($clauses))
347
-			redirectexit();
364
+		if (empty($clauses)) {
365
+					redirectexit();
366
+		}
348 367
 
349 368
 		$request = $smcFunc['db_query']('', '
350 369
 			SELECT b.id_board
@@ -355,19 +374,22 @@  discard block
 block discarded – undo
355 374
 			))
356 375
 		);
357 376
 		$boards = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$boards[] = $row['id_board'];
377
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
378
+					$boards[] = $row['id_board'];
379
+		}
360 380
 		$smcFunc['db_free_result']($request);
361 381
 
362
-		if (empty($boards))
363
-			redirectexit();
382
+		if (empty($boards)) {
383
+					redirectexit();
384
+		}
364 385
 
365 386
 		markBoardsRead($boards, isset($_REQUEST['unread']));
366 387
 
367 388
 		foreach ($boards as $b)
368 389
 		{
369
-			if (isset($_SESSION['topicseen_cache'][$b]))
370
-				$_SESSION['topicseen_cache'][$b] = array();
390
+			if (isset($_SESSION['topicseen_cache'][$b])) {
391
+							$_SESSION['topicseen_cache'][$b] = array();
392
+			}
371 393
 		}
372 394
 
373 395
 		if (!isset($_REQUEST['unread']))
@@ -385,8 +407,9 @@  discard block
 block discarded – undo
385 407
 			if ($smcFunc['db_num_rows']($result) > 0)
386 408
 			{
387 409
 				$logBoardInserts = '';
388
-				while ($row = $smcFunc['db_fetch_assoc']($result))
389
-					$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
410
+				while ($row = $smcFunc['db_fetch_assoc']($result)) {
411
+									$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
412
+				}
390 413
 
391 414
 				$smcFunc['db_insert']('replace',
392 415
 					'{db_prefix}log_boards',
@@ -397,17 +420,18 @@  discard block
 block discarded – undo
397 420
 			}
398 421
 			$smcFunc['db_free_result']($result);
399 422
 
400
-			if (empty($board))
401
-				redirectexit();
402
-			else
403
-				redirectexit('board=' . $board . '.0');
404
-		}
405
-		else
423
+			if (empty($board)) {
424
+							redirectexit();
425
+			} else {
426
+							redirectexit('board=' . $board . '.0');
427
+			}
428
+		} else
406 429
 		{
407
-			if (empty($board_info['parent']))
408
-				redirectexit();
409
-			else
410
-				redirectexit('board=' . $board_info['parent'] . '.0');
430
+			if (empty($board_info['parent'])) {
431
+							redirectexit();
432
+			} else {
433
+							redirectexit('board=' . $board_info['parent'] . '.0');
434
+			}
411 435
 		}
412 436
 	}
413 437
 }
@@ -432,11 +456,13 @@  discard block
 block discarded – undo
432 456
 			'selected_message' => (int) $messageID,
433 457
 		)
434 458
 	);
435
-	if ($smcFunc['db_num_rows']($result) > 0)
436
-		list ($memberID) = $smcFunc['db_fetch_row']($result);
459
+	if ($smcFunc['db_num_rows']($result) > 0) {
460
+			list ($memberID) = $smcFunc['db_fetch_row']($result);
461
+	}
437 462
 	// The message doesn't even exist.
438
-	else
439
-		$memberID = 0;
463
+	else {
464
+			$memberID = 0;
465
+	}
440 466
 	$smcFunc['db_free_result']($result);
441 467
 
442 468
 	return (int) $memberID;
@@ -457,8 +483,9 @@  discard block
 block discarded – undo
457 483
 	getBoardTree();
458 484
 
459 485
 	// Make sure given boards and categories exist.
460
-	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
461
-		fatal_lang_error('no_board');
486
+	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) {
487
+			fatal_lang_error('no_board');
488
+	}
462 489
 
463 490
 	$id = $board_id;
464 491
 	call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
@@ -486,8 +513,9 @@  discard block
 block discarded – undo
486 513
 			$child_level = 0;
487 514
 			$id_parent = 0;
488 515
 			$after = 0;
489
-			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
490
-				$after = max($after, $boards[$id_board]['order']);
516
+			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) {
517
+							$after = max($after, $boards[$id_board]['order']);
518
+			}
491 519
 		}
492 520
 
493 521
 		// Make the board a child of a given board.
@@ -498,17 +526,19 @@  discard block
 block discarded – undo
498 526
 			$id_parent = $boardOptions['target_board'];
499 527
 
500 528
 			// People can be creative, in many ways...
501
-			if (isChildOf($id_parent, $board_id))
502
-				fatal_lang_error('mboards_parent_own_child_error', false);
503
-			elseif ($id_parent == $board_id)
504
-				fatal_lang_error('mboards_board_own_child_error', false);
529
+			if (isChildOf($id_parent, $board_id)) {
530
+							fatal_lang_error('mboards_parent_own_child_error', false);
531
+			} elseif ($id_parent == $board_id) {
532
+							fatal_lang_error('mboards_board_own_child_error', false);
533
+			}
505 534
 
506 535
 			$after = $boards[$boardOptions['target_board']]['order'];
507 536
 
508 537
 			// Check if there are already children and (if so) get the max board order.
509
-			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
510
-				foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
538
+			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) {
539
+							foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
511 540
 					$after = max($after, $boards[$childBoard_id]['order']);
541
+			}
512 542
 		}
513 543
 
514 544
 		// Place a board before or after another board, on the same child level.
@@ -521,8 +551,9 @@  discard block
 block discarded – undo
521 551
 		}
522 552
 
523 553
 		// Oops...?
524
-		else
525
-			trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
554
+		else {
555
+					trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
556
+		}
526 557
 
527 558
 		// Get a list of children of this board.
528 559
 		$childList = array();
@@ -531,14 +562,16 @@  discard block
 block discarded – undo
531 562
 		// See if there are changes that affect children.
532 563
 		$childUpdates = array();
533 564
 		$levelDiff = $child_level - $boards[$board_id]['level'];
534
-		if ($levelDiff != 0)
535
-			$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
536
-		if ($id_cat != $boards[$board_id]['category'])
537
-			$childUpdates[] = 'id_cat = {int:category}';
565
+		if ($levelDiff != 0) {
566
+					$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
567
+		}
568
+		if ($id_cat != $boards[$board_id]['category']) {
569
+					$childUpdates[] = 'id_cat = {int:category}';
570
+		}
538 571
 
539 572
 		// Fix the children of this board.
540
-		if (!empty($childList) && !empty($childUpdates))
541
-			$smcFunc['db_query']('', '
573
+		if (!empty($childList) && !empty($childUpdates)) {
574
+					$smcFunc['db_query']('', '
542 575
 				UPDATE {db_prefix}boards
543 576
 				SET ' . implode(',
544 577
 					', $childUpdates) . '
@@ -549,6 +582,7 @@  discard block
 block discarded – undo
549 582
 					'level_diff' => $levelDiff,
550 583
 				)
551 584
 			);
585
+		}
552 586
 
553 587
 		// Make some room for this spot.
554 588
 		$smcFunc['db_query']('', '
@@ -644,8 +678,8 @@  discard block
 block discarded – undo
644 678
 	call_integration_hook('integrate_modify_board', array($id, &$boardUpdates, &$boardUpdateParameters));
645 679
 
646 680
 	// Do the updates (if any).
647
-	if (!empty($boardUpdates))
648
-		$request = $smcFunc['db_query']('', '
681
+	if (!empty($boardUpdates)) {
682
+			$request = $smcFunc['db_query']('', '
649 683
 			UPDATE {db_prefix}boards
650 684
 			SET
651 685
 				' . implode(',
@@ -655,6 +689,7 @@  discard block
 block discarded – undo
655 689
 				'selected_board' => $board_id,
656 690
 			))
657 691
 		);
692
+	}
658 693
 
659 694
 	// Set moderators of this board.
660 695
 	if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
@@ -679,13 +714,15 @@  discard block
 block discarded – undo
679 714
 			{
680 715
 				$moderators[$k] = trim($moderators[$k]);
681 716
 
682
-				if (strlen($moderators[$k]) == 0)
683
-					unset($moderators[$k]);
717
+				if (strlen($moderators[$k]) == 0) {
718
+									unset($moderators[$k]);
719
+				}
684 720
 			}
685 721
 
686 722
 			// Find all the id_member's for the member_name's in the list.
687
-			if (empty($boardOptions['moderators']))
688
-				$boardOptions['moderators'] = array();
723
+			if (empty($boardOptions['moderators'])) {
724
+							$boardOptions['moderators'] = array();
725
+			}
689 726
 			if (!empty($moderators))
690 727
 			{
691 728
 				$request = $smcFunc['db_query']('', '
@@ -698,8 +735,9 @@  discard block
 block discarded – undo
698 735
 						'limit' => count($moderators),
699 736
 					)
700 737
 				);
701
-				while ($row = $smcFunc['db_fetch_assoc']($request))
702
-					$boardOptions['moderators'][] = $row['id_member'];
738
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
739
+									$boardOptions['moderators'][] = $row['id_member'];
740
+				}
703 741
 				$smcFunc['db_free_result']($request);
704 742
 			}
705 743
 		}
@@ -708,8 +746,9 @@  discard block
 block discarded – undo
708 746
 		if (!empty($boardOptions['moderators']))
709 747
 		{
710 748
 			$inserts = array();
711
-			foreach ($boardOptions['moderators'] as $moderator)
712
-				$inserts[] = array($board_id, $moderator);
749
+			foreach ($boardOptions['moderators'] as $moderator) {
750
+							$inserts[] = array($board_id, $moderator);
751
+			}
713 752
 
714 753
 			$smcFunc['db_insert']('insert',
715 754
 				'{db_prefix}moderators',
@@ -739,14 +778,16 @@  discard block
 block discarded – undo
739 778
 			{
740 779
 				$moderator_groups[$k] = trim($moderator_groups[$k]);
741 780
 
742
-				if (strlen($moderator_groups[$k]) == 0)
743
-					unset($moderator_groups[$k]);
781
+				if (strlen($moderator_groups[$k]) == 0) {
782
+									unset($moderator_groups[$k]);
783
+				}
744 784
 			}
745 785
 
746 786
 			/* 	Find all the id_group's for all the group names in the list
747 787
 				But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
748
-			if (empty($boardOptions['moderator_groups']))
749
-				$boardOptions['moderator_groups'] = array();
788
+			if (empty($boardOptions['moderator_groups'])) {
789
+							$boardOptions['moderator_groups'] = array();
790
+			}
750 791
 			if (!empty($moderator_groups))
751 792
 			{
752 793
 				$request = $smcFunc['db_query']('', '
@@ -777,8 +818,9 @@  discard block
 block discarded – undo
777 818
 		if (!empty($boardOptions['moderator_groups']))
778 819
 		{
779 820
 			$inserts = array();
780
-			foreach ($boardOptions['moderator_groups'] as $moderator_group)
781
-				$inserts[] = array($board_id, $moderator_group);
821
+			foreach ($boardOptions['moderator_groups'] as $moderator_group) {
822
+							$inserts[] = array($board_id, $moderator_group);
823
+			}
782 824
 
783 825
 			$smcFunc['db_insert']('insert',
784 826
 				'{db_prefix}moderator_groups',
@@ -792,14 +834,16 @@  discard block
 block discarded – undo
792 834
 		updateSettings(array('settings_updated' => time()));
793 835
 	}
794 836
 
795
-	if (isset($boardOptions['move_to']))
796
-		reorderBoards();
837
+	if (isset($boardOptions['move_to'])) {
838
+			reorderBoards();
839
+	}
797 840
 
798 841
 	clean_cache('data');
799 842
 
800
-	if (empty($boardOptions['dont_log']))
801
-		logAction('edit_board', array('board' => $board_id), 'admin');
802
-}
843
+	if (empty($boardOptions['dont_log'])) {
844
+			logAction('edit_board', array('board' => $board_id), 'admin');
845
+	}
846
+	}
803 847
 
804 848
 /**
805 849
  * Create a new board and set its properties and position.
@@ -815,11 +859,13 @@  discard block
 block discarded – undo
815 859
 	global $boards, $smcFunc;
816 860
 
817 861
 	// Trigger an error if one of the required values is not set.
818
-	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
819
-		trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
862
+	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) {
863
+			trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
864
+	}
820 865
 
821
-	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
822
-		trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
866
+	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) {
867
+			trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
868
+	}
823 869
 
824 870
 	// Set every optional value to its default value.
825 871
 	$boardOptions += array(
@@ -853,8 +899,9 @@  discard block
 block discarded – undo
853 899
 	);
854 900
 	$board_id = $smcFunc['db_insert_id']('{db_prefix}boards', 'id_board');
855 901
 
856
-	if (empty($board_id))
857
-		return 0;
902
+	if (empty($board_id)) {
903
+			return 0;
904
+	}
858 905
 
859 906
 	// Change the board according to the given specifications.
860 907
 	modifyBoard($board_id, $boardOptions);
@@ -917,8 +964,9 @@  discard block
 block discarded – undo
917 964
 	global $sourcedir, $boards, $smcFunc;
918 965
 
919 966
 	// No boards to delete? Return!
920
-	if (empty($boards_to_remove))
921
-		return;
967
+	if (empty($boards_to_remove)) {
968
+			return;
969
+	}
922 970
 
923 971
 	getBoardTree();
924 972
 
@@ -929,12 +977,14 @@  discard block
 block discarded – undo
929 977
 	{
930 978
 		// Get a list of the child boards that will also be removed.
931 979
 		$child_boards_to_remove = array();
932
-		foreach ($boards_to_remove as $board_to_remove)
933
-			recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
980
+		foreach ($boards_to_remove as $board_to_remove) {
981
+					recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
982
+		}
934 983
 
935 984
 		// Merge the children with their parents.
936
-		if (!empty($child_boards_to_remove))
937
-			$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
985
+		if (!empty($child_boards_to_remove)) {
986
+					$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
987
+		}
938 988
 	}
939 989
 	// Move the children to a safe home.
940 990
 	else
@@ -942,10 +992,11 @@  discard block
 block discarded – undo
942 992
 		foreach ($boards_to_remove as $id_board)
943 993
 		{
944 994
 			// @todo Separate category?
945
-			if ($moveChildrenTo === 0)
946
-				fixChildren($id_board, 0, 0);
947
-			else
948
-				fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
995
+			if ($moveChildrenTo === 0) {
996
+							fixChildren($id_board, 0, 0);
997
+			} else {
998
+							fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
999
+			}
949 1000
 		}
950 1001
 	}
951 1002
 
@@ -959,8 +1010,9 @@  discard block
 block discarded – undo
959 1010
 		)
960 1011
 	);
961 1012
 	$topics = array();
962
-	while ($row = $smcFunc['db_fetch_assoc']($request))
963
-		$topics[] = $row['id_topic'];
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$topics[] = $row['id_topic'];
1015
+	}
964 1016
 	$smcFunc['db_free_result']($request);
965 1017
 
966 1018
 	require_once($sourcedir . '/RemoveTopic.php');
@@ -1048,8 +1100,9 @@  discard block
 block discarded – undo
1048 1100
 	clean_cache('data');
1049 1101
 
1050 1102
 	// Let's do some serious logging.
1051
-	foreach ($boards_to_remove as $id_board)
1052
-		logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1103
+	foreach ($boards_to_remove as $id_board) {
1104
+			logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1105
+	}
1053 1106
 
1054 1107
 	reorderBoards();
1055 1108
 }
@@ -1068,8 +1121,8 @@  discard block
 block discarded – undo
1068 1121
 	$board_order = 0;
1069 1122
 	foreach ($cat_tree as $catID => $dummy)
1070 1123
 	{
1071
-		foreach ($boardList[$catID] as $boardID)
1072
-			if ($boards[$boardID]['order'] != ++$board_order)
1124
+		foreach ($boardList[$catID] as $boardID) {
1125
+					if ($boards[$boardID]['order'] != ++$board_order)
1073 1126
 				$smcFunc['db_query']('', '
1074 1127
 					UPDATE {db_prefix}boards
1075 1128
 					SET board_order = {int:new_order}
@@ -1079,6 +1132,7 @@  discard block
 block discarded – undo
1079 1132
 						'selected_board' => $boardID,
1080 1133
 					)
1081 1134
 				);
1135
+		}
1082 1136
 	}
1083 1137
 
1084 1138
 	// Empty the board order cache
@@ -1107,8 +1161,9 @@  discard block
 block discarded – undo
1107 1161
 		)
1108 1162
 	);
1109 1163
 	$children = array();
1110
-	while ($row = $smcFunc['db_fetch_assoc']($result))
1111
-		$children[] = $row['id_board'];
1164
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
1165
+			$children[] = $row['id_board'];
1166
+	}
1112 1167
 	$smcFunc['db_free_result']($result);
1113 1168
 
1114 1169
 	// ...and set it to a new parent and child_level.
@@ -1124,9 +1179,10 @@  discard block
 block discarded – undo
1124 1179
 	);
1125 1180
 
1126 1181
 	// Recursively fix the children of the children.
1127
-	foreach ($children as $child)
1128
-		fixChildren($child, $newLevel + 1, $child);
1129
-}
1182
+	foreach ($children as $child) {
1183
+			fixChildren($child, $newLevel + 1, $child);
1184
+	}
1185
+	}
1130 1186
 
1131 1187
 /**
1132 1188
  * Tries to load up the entire board order and category very very quickly
@@ -1143,8 +1199,9 @@  discard block
 block discarded – undo
1143 1199
 		'boards' => array(),
1144 1200
 	);
1145 1201
 
1146
-	if (!empty($tree_order['boards']))
1147
-		return $tree_order;
1202
+	if (!empty($tree_order['boards'])) {
1203
+			return $tree_order;
1204
+	}
1148 1205
 
1149 1206
 	if (($cached = cache_get_data('board_order', 86400)) !== null)
1150 1207
 	{
@@ -1160,8 +1217,9 @@  discard block
 block discarded – undo
1160 1217
 	);
1161 1218
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1219
 	{
1163
-		if (!in_array($row['id_cat'], $tree_order['cats']))
1164
-			$tree_order['cats'][] = $row['id_cat'];
1220
+		if (!in_array($row['id_cat'], $tree_order['cats'])) {
1221
+					$tree_order['cats'][] = $row['id_cat'];
1222
+		}
1165 1223
 		$tree_order['boards'][] = $row['id_board'];
1166 1224
 	}
1167 1225
 	$smcFunc['db_free_result']($request);
@@ -1181,16 +1239,19 @@  discard block
 block discarded – undo
1181 1239
 	$tree = getTreeOrder();
1182 1240
 
1183 1241
 	$ordered = array();
1184
-	foreach ($tree['boards'] as $board)
1185
-		if (!empty($boards[$board]))
1242
+	foreach ($tree['boards'] as $board) {
1243
+			if (!empty($boards[$board]))
1186 1244
 		{
1187 1245
 			$ordered[$board] = $boards[$board];
1246
+	}
1188 1247
 
1189
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards']))
1190
-				sortBoards($ordered[$board]['boards']);
1248
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) {
1249
+							sortBoards($ordered[$board]['boards']);
1250
+			}
1191 1251
 
1192
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['children']))
1193
-				sortBoards($ordered[$board]['children']);
1252
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) {
1253
+							sortBoards($ordered[$board]['children']);
1254
+			}
1194 1255
 		}
1195 1256
 
1196 1257
 	$boards = $ordered;
@@ -1206,12 +1267,14 @@  discard block
 block discarded – undo
1206 1267
 	$tree = getTreeOrder();
1207 1268
 
1208 1269
 	$ordered = array();
1209
-	foreach ($tree['cats'] as $cat)
1210
-		if (!empty($categories[$cat]))
1270
+	foreach ($tree['cats'] as $cat) {
1271
+			if (!empty($categories[$cat]))
1211 1272
 		{
1212 1273
 			$ordered[$cat] = $categories[$cat];
1213
-			if (!empty($ordered[$cat]['boards']))
1214
-				sortBoards($ordered[$cat]['boards']);
1274
+	}
1275
+			if (!empty($ordered[$cat]['boards'])) {
1276
+							sortBoards($ordered[$cat]['boards']);
1277
+			}
1215 1278
 		}
1216 1279
 
1217 1280
 	$categories = $ordered;
@@ -1227,8 +1290,9 @@  discard block
 block discarded – undo
1227 1290
 {
1228 1291
 	global $smcFunc, $scripturl, $txt;
1229 1292
 
1230
-	if (empty($boards))
1231
-		return array();
1293
+	if (empty($boards)) {
1294
+			return array();
1295
+	}
1232 1296
 
1233 1297
 	$request = $smcFunc['db_query']('', '
1234 1298
 		SELECT mem.id_member, mem.real_name, mo.id_board
@@ -1242,8 +1306,9 @@  discard block
 block discarded – undo
1242 1306
 	$moderators = array();
1243 1307
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1244 1308
 	{
1245
-		if (empty($moderators[$row['id_board']]))
1246
-			$moderators[$row['id_board']] = array();
1309
+		if (empty($moderators[$row['id_board']])) {
1310
+					$moderators[$row['id_board']] = array();
1311
+		}
1247 1312
 
1248 1313
 		$moderators[$row['id_board']][] = array(
1249 1314
 			'id' => $row['id_member'],
@@ -1267,8 +1332,9 @@  discard block
 block discarded – undo
1267 1332
 {
1268 1333
 	global $smcFunc, $scripturl, $txt;
1269 1334
 
1270
-	if (empty($boards))
1271
-		return array();
1335
+	if (empty($boards)) {
1336
+			return array();
1337
+	}
1272 1338
 
1273 1339
 	$request = $smcFunc['db_query']('', '
1274 1340
 		SELECT mg.id_group, mg.group_name, bg.id_board
@@ -1282,8 +1348,9 @@  discard block
 block discarded – undo
1282 1348
 	$groups = array();
1283 1349
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1284 1350
 	{
1285
-		if (empty($groups[$row['id_board']]))
1286
-			$groups[$row['id_board']] = array();
1351
+		if (empty($groups[$row['id_board']])) {
1352
+					$groups[$row['id_board']] = array();
1353
+		}
1287 1354
 
1288 1355
 		$groups[$row['id_board']][] = array(
1289 1356
 			'id' => $row['id_group'],
@@ -1345,8 +1412,9 @@  discard block
 block discarded – undo
1345 1412
 
1346 1413
 		if (!empty($row['id_board']))
1347 1414
 		{
1348
-			if ($row['child_level'] != $curLevel)
1349
-				$prevBoard = 0;
1415
+			if ($row['child_level'] != $curLevel) {
1416
+							$prevBoard = 0;
1417
+			}
1350 1418
 
1351 1419
 			$boards[$row['id_board']] = array(
1352 1420
 				'id' => $row['id_board'],
@@ -1378,16 +1446,16 @@  discard block
 block discarded – undo
1378 1446
 					'children' => array()
1379 1447
 				);
1380 1448
 				$boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
1381
-			}
1382
-			else
1449
+			} else
1383 1450
 			{
1384 1451
 				// Parent doesn't exist!
1385
-				if (!isset($boards[$row['id_parent']]['tree']))
1386
-					fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1452
+				if (!isset($boards[$row['id_parent']]['tree'])) {
1453
+									fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1454
+				}
1387 1455
 
1388 1456
 				// Wrong childlevel...we can silently fix this...
1389
-				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
1390
-					$smcFunc['db_query']('', '
1457
+				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) {
1458
+									$smcFunc['db_query']('', '
1391 1459
 						UPDATE {db_prefix}boards
1392 1460
 						SET child_level = {int:new_child_level}
1393 1461
 						WHERE id_board = {int:selected_board}',
@@ -1396,6 +1464,7 @@  discard block
 block discarded – undo
1396 1464
 							'selected_board' => $row['id_board'],
1397 1465
 						)
1398 1466
 					);
1467
+				}
1399 1468
 
1400 1469
 				$boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
1401 1470
 					'node' => &$boards[$row['id_board']],
@@ -1426,8 +1495,9 @@  discard block
 block discarded – undo
1426 1495
  */
1427 1496
 function recursiveBoards(&$_boardList, &$_tree)
1428 1497
 {
1429
-	if (empty($_tree['children']))
1430
-		return;
1498
+	if (empty($_tree['children'])) {
1499
+			return;
1500
+	}
1431 1501
 
1432 1502
 	foreach ($_tree['children'] as $id => $node)
1433 1503
 	{
@@ -1446,11 +1516,13 @@  discard block
 block discarded – undo
1446 1516
 {
1447 1517
 	global $boards;
1448 1518
 
1449
-	if (empty($boards[$child]['parent']))
1450
-		return false;
1519
+	if (empty($boards[$child]['parent'])) {
1520
+			return false;
1521
+	}
1451 1522
 
1452
-	if ($boards[$child]['parent'] == $parent)
1453
-		return true;
1523
+	if ($boards[$child]['parent'] == $parent) {
1524
+			return true;
1525
+	}
1454 1526
 
1455 1527
 	return isChildOf($boards[$child]['parent'], $parent);
1456 1528
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +860 added lines, -648 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// Try to load it from the cache first; it'll never get cached if the setting is off.
37 39
 	if (($modSettings = cache_get_data('modSettings', 90)) == null)
@@ -43,27 +45,35 @@  discard block
 block discarded – undo
43 45
 			)
44 46
 		);
45 47
 		$modSettings = array();
46
-		if (!$request)
47
-			display_db_error();
48
-		while ($row = $smcFunc['db_fetch_row']($request))
49
-			$modSettings[$row[0]] = $row[1];
48
+		if (!$request) {
49
+					display_db_error();
50
+		}
51
+		while ($row = $smcFunc['db_fetch_row']($request)) {
52
+					$modSettings[$row[0]] = $row[1];
53
+		}
50 54
 		$smcFunc['db_free_result']($request);
51 55
 
52 56
 		// Do a few things to protect against missing settings or settings with invalid values...
53
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
54
-			$modSettings['defaultMaxTopics'] = 20;
55
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
56
-			$modSettings['defaultMaxMessages'] = 15;
57
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
58
-			$modSettings['defaultMaxMembers'] = 30;
59
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
60
-			$modSettings['defaultMaxListItems'] = 15;
57
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
58
+					$modSettings['defaultMaxTopics'] = 20;
59
+		}
60
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
61
+					$modSettings['defaultMaxMessages'] = 15;
62
+		}
63
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
64
+					$modSettings['defaultMaxMembers'] = 30;
65
+		}
66
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
67
+					$modSettings['defaultMaxListItems'] = 15;
68
+		}
61 69
 
62
-		if (!is_array($modSettings['attachmentUploadDir']))
63
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
70
+		if (!is_array($modSettings['attachmentUploadDir'])) {
71
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
72
+		}
64 73
 
65
-		if (!empty($cache_enable))
66
-			cache_put_data('modSettings', $modSettings, 90);
74
+		if (!empty($cache_enable)) {
75
+					cache_put_data('modSettings', $modSettings, 90);
76
+		}
67 77
 	}
68 78
 
69 79
 	$modSettings['cache_enable'] = $cache_enable;
@@ -83,8 +93,9 @@  discard block
 block discarded – undo
83 93
 		};
84 94
 	$fix_utf8mb4 = function ($string) use ($utf8)
85 95
 	{
86
-		if (!$utf8)
87
-			return $string;
96
+		if (!$utf8) {
97
+					return $string;
98
+		}
88 99
 
89 100
 		$i = 0;
90 101
 		$len = strlen($string);
@@ -96,18 +107,15 @@  discard block
 block discarded – undo
96 107
 			{
97 108
 				$new_string .= $string[$i];
98 109
 				$i++;
99
-			}
100
-			elseif ($ord < 224)
110
+			} elseif ($ord < 224)
101 111
 			{
102 112
 				$new_string .= $string[$i] . $string[$i+1];
103 113
 				$i += 2;
104
-			}
105
-			elseif ($ord < 240)
114
+			} elseif ($ord < 240)
106 115
 			{
107 116
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
108 117
 				$i += 3;
109
-			}
110
-			elseif ($ord < 248)
118
+			} elseif ($ord < 248)
111 119
 			{
112 120
 				// Magic happens.
113 121
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -151,8 +159,7 @@  discard block
 block discarded – undo
151 159
 			{
152 160
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
153 161
 				return is_int($result) ? $result + $offset : false;
154
-			}
155
-			else
162
+			} else
156 163
 			{
157 164
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
158 165
 				$needle_size = count($needle_arr);
@@ -161,8 +168,9 @@  discard block
 block discarded – undo
161 168
 				while ((int) $result === $result)
162 169
 				{
163 170
 					$offset += $result;
164
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
165
-						return $offset;
171
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
172
+											return $offset;
173
+					}
166 174
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
167 175
 				}
168 176
 				return false;
@@ -200,8 +208,9 @@  discard block
 block discarded – undo
200 208
 			$string = $ent_check($string);
201 209
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
202 210
 			$string = $matches[0];
203
-			while (strlen($string) > $length)
204
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
211
+			while (strlen($string) > $length) {
212
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
213
+			}
205 214
 			return $string;
206 215
 		},
207 216
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -211,15 +220,17 @@  discard block
 block discarded – undo
211 220
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
212 221
 		{
213 222
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
214
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
215
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
223
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
224
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
225
+			}
216 226
 			return implode('', $words);
217 227
 		} : 'ucwords',
218 228
 	);
219 229
 
220 230
 	// Setting the timezone is a requirement for some functions.
221
-	if (isset($modSettings['default_timezone']))
222
-		date_default_timezone_set($modSettings['default_timezone']);
231
+	if (isset($modSettings['default_timezone'])) {
232
+			date_default_timezone_set($modSettings['default_timezone']);
233
+	}
223 234
 
224 235
 	// Check the load averages?
225 236
 	if (!empty($modSettings['loadavg_enable']))
@@ -227,22 +238,26 @@  discard block
 block discarded – undo
227 238
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
228 239
 		{
229 240
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
230
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
231
-				$modSettings['load_average'] = (float) $matches[1];
232
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
233
-				$modSettings['load_average'] = (float) $matches[1];
234
-			else
235
-				unset($modSettings['load_average']);
241
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
242
+							$modSettings['load_average'] = (float) $matches[1];
243
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
244
+							$modSettings['load_average'] = (float) $matches[1];
245
+			} else {
246
+							unset($modSettings['load_average']);
247
+			}
236 248
 
237
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
238
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
249
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
250
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
251
+			}
239 252
 		}
240 253
 
241
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
242
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
254
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
255
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
256
+		}
243 257
 
244
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
245
-			display_loadavg_error();
258
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
259
+					display_loadavg_error();
260
+		}
246 261
 	}
247 262
 
248 263
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -263,8 +278,9 @@  discard block
 block discarded – undo
263 278
 	if (defined('SMF_INTEGRATION_SETTINGS'))
264 279
 	{
265 280
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
266
-		foreach ($integration_settings as $hook => $function)
267
-			add_integration_function($hook, $function, '', false);
281
+		foreach ($integration_settings as $hook => $function) {
282
+					add_integration_function($hook, $function, '', false);
283
+		}
268 284
 	}
269 285
 
270 286
 	// Any files to pre include?
@@ -274,8 +290,9 @@  discard block
 block discarded – undo
274 290
 		foreach ($pre_includes as $include)
275 291
 		{
276 292
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
277
-			if (file_exists($include))
278
-				require_once($include);
293
+			if (file_exists($include)) {
294
+							require_once($include);
295
+			}
279 296
 		}
280 297
 	}
281 298
 
@@ -379,27 +396,28 @@  discard block
 block discarded – undo
379 396
 				break;
380 397
 			}
381 398
 		}
399
+	} else {
400
+			$id_member = 0;
382 401
 	}
383
-	else
384
-		$id_member = 0;
385 402
 
386 403
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
387 404
 	{
388 405
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
389 406
 
390
-		if (empty($cookie_data))
391
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
407
+		if (empty($cookie_data)) {
408
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
409
+		}
392 410
 
393 411
 		list ($id_member, $password) = $cookie_data;
394 412
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
395
-	}
396
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
413
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
397 414
 	{
398 415
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
399 416
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
400 417
 
401
-		if (empty($cookie_data))
402
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
418
+		if (empty($cookie_data)) {
419
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
420
+		}
403 421
 
404 422
 		list ($id_member, $password, $login_span) = $cookie_data;
405 423
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -424,30 +442,34 @@  discard block
 block discarded – undo
424 442
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
425 443
 			$smcFunc['db_free_result']($request);
426 444
 
427
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
428
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
445
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
446
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
447
+			}
429 448
 
430
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
431
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
449
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
450
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
451
+			}
432 452
 		}
433 453
 
434 454
 		// Did we find 'im?  If not, junk it.
435 455
 		if (!empty($user_settings))
436 456
 		{
437 457
 			// As much as the password should be right, we can assume the integration set things up.
438
-			if (!empty($already_verified) && $already_verified === true)
439
-				$check = true;
458
+			if (!empty($already_verified) && $already_verified === true) {
459
+							$check = true;
460
+			}
440 461
 			// SHA-512 hash should be 128 characters long.
441
-			elseif (strlen($password) == 128)
442
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
443
-			else
444
-				$check = false;
462
+			elseif (strlen($password) == 128) {
463
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
+			} else {
465
+							$check = false;
466
+			}
445 467
 
446 468
 			// Wrong password or not activated - either way, you're going nowhere.
447 469
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
470
+		} else {
471
+					$id_member = 0;
448 472
 		}
449
-		else
450
-			$id_member = 0;
451 473
 
452 474
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
453 475
 		if (!$id_member)
@@ -469,13 +491,15 @@  discard block
 block discarded – undo
469 491
 				{
470 492
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
471 493
 
472
-					if (is_null($tfa_data))
473
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
494
+					if (is_null($tfa_data)) {
495
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
496
+					}
474 497
 
475 498
 					list ($tfamember, $tfasecret) = $tfa_data;
476 499
 
477
-					if ((int) $tfamember != $id_member)
478
-						$tfasecret = null;
500
+					if ((int) $tfamember != $id_member) {
501
+											$tfasecret = null;
502
+					}
479 503
 				}
480 504
 
481 505
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -495,10 +519,12 @@  discard block
 block discarded – undo
495 519
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
496 520
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
497 521
 		{
498
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
522
+			if ($modSettings['tfa_mode'] == 2) {
523
+				//only do this if we are just forcing SOME membergroups
499 524
 			{
500 525
 				//Build an array of ALL user membergroups.
501 526
 				$full_groups = array($user_settings['id_group']);
527
+			}
502 528
 				if (!empty($user_settings['additional_groups']))
503 529
 				{
504 530
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -518,15 +544,17 @@  discard block
 block discarded – undo
518 544
 				);
519 545
 				$row = $smcFunc['db_fetch_assoc']($request);
520 546
 				$smcFunc['db_free_result']($request);
547
+			} else {
548
+							$row['total'] = 1;
521 549
 			}
522
-			else
523
-				$row['total'] = 1; //simplifies logics in the next "if"
550
+			//simplifies logics in the next "if"
524 551
 
525 552
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
526 553
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
527 554
 
528
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
529
-				redirectexit('action=profile;area=tfasetup;forced');
555
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
556
+							redirectexit('action=profile;area=tfasetup;forced');
557
+			}
530 558
 		}
531 559
 	}
532 560
 
@@ -563,33 +591,37 @@  discard block
 block discarded – undo
563 591
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
564 592
 				$user_settings['last_login'] = time();
565 593
 
566
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
567
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
594
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
595
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
596
+				}
568 597
 
569
-				if (!empty($modSettings['cache_enable']))
570
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
598
+				if (!empty($modSettings['cache_enable'])) {
599
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
600
+				}
571 601
 			}
602
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
603
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
572 604
 		}
573
-		elseif (empty($_SESSION['id_msg_last_visit']))
574
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
575 605
 
576 606
 		$username = $user_settings['member_name'];
577 607
 
578
-		if (empty($user_settings['additional_groups']))
579
-			$user_info = array(
608
+		if (empty($user_settings['additional_groups'])) {
609
+					$user_info = array(
580 610
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
581 611
 			);
582
-		else
583
-			$user_info = array(
612
+		} else {
613
+					$user_info = array(
584 614
 				'groups' => array_merge(
585 615
 					array($user_settings['id_group'], $user_settings['id_post_group']),
586 616
 					explode(',', $user_settings['additional_groups'])
587 617
 				)
588 618
 			);
619
+		}
589 620
 
590 621
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
591
-		foreach ($user_info['groups'] as $k => $v)
592
-			$user_info['groups'][$k] = (int) $v;
622
+		foreach ($user_info['groups'] as $k => $v) {
623
+					$user_info['groups'][$k] = (int) $v;
624
+		}
593 625
 
594 626
 		// This is a logged in user, so definitely not a spider.
595 627
 		$user_info['possibly_robot'] = false;
@@ -603,8 +635,7 @@  discard block
 block discarded – undo
603 635
 			$time_system = new DateTime('now', $tz_system);
604 636
 			$time_user = new DateTime('now', $tz_user);
605 637
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
606
-		}
607
-		else
638
+		} else
608 639
 		{
609 640
 			// !!! Compatibility.
610 641
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -618,16 +649,18 @@  discard block
 block discarded – undo
618 649
 		$user_info = array('groups' => array(-1));
619 650
 		$user_settings = array();
620 651
 
621
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
622
-			$_COOKIE[$cookiename] = '';
652
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
653
+					$_COOKIE[$cookiename] = '';
654
+		}
623 655
 
624 656
 		// Expire the 2FA cookie
625 657
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
626 658
 		{
627 659
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
628 660
 
629
-			if (is_null($tfa_data))
630
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
661
+			if (is_null($tfa_data)) {
662
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
663
+			}
631 664
 
632 665
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
633 666
 
@@ -639,19 +672,20 @@  discard block
 block discarded – undo
639 672
 		}
640 673
 
641 674
 		// Create a login token if it doesn't exist yet.
642
-		if (!isset($_SESSION['token']['post-login']))
643
-			createToken('login');
644
-		else
645
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
675
+		if (!isset($_SESSION['token']['post-login'])) {
676
+					createToken('login');
677
+		} else {
678
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
679
+		}
646 680
 
647 681
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
648 682
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
649 683
 		{
650 684
 			require_once($sourcedir . '/ManageSearchEngines.php');
651 685
 			$user_info['possibly_robot'] = SpiderCheck();
686
+		} elseif (!empty($modSettings['spider_mode'])) {
687
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
652 688
 		}
653
-		elseif (!empty($modSettings['spider_mode']))
654
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
655 689
 		// If we haven't turned on proper spider hunts then have a guess!
656 690
 		else
657 691
 		{
@@ -699,8 +733,9 @@  discard block
 block discarded – undo
699 733
 	$user_info['groups'] = array_unique($user_info['groups']);
700 734
 
701 735
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
702
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
703
-		unset($user_info['ignoreboards'][$tmp]);
736
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
737
+			unset($user_info['ignoreboards'][$tmp]);
738
+	}
704 739
 
705 740
 	// Allow the user to change their language.
706 741
 	if (!empty($modSettings['userLanguage']))
@@ -713,31 +748,36 @@  discard block
 block discarded – undo
713 748
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
714 749
 
715 750
 			// Make it permanent for members.
716
-			if (!empty($user_info['id']))
717
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
718
-			else
719
-				$_SESSION['language'] = $user_info['language'];
751
+			if (!empty($user_info['id'])) {
752
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
753
+			} else {
754
+							$_SESSION['language'] = $user_info['language'];
755
+			}
756
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
757
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
720 758
 		}
721
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
722
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
723 759
 	}
724 760
 
725 761
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
726
-	if ($user_info['is_admin'])
727
-		$user_info['query_see_board'] = '1=1';
762
+	if ($user_info['is_admin']) {
763
+			$user_info['query_see_board'] = '1=1';
764
+	}
728 765
 	// Otherwise just the groups in $user_info['groups'].
729
-	else
730
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
766
+	else {
767
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
768
+	}
731 769
 
732 770
 	// Build the list of boards they WANT to see.
733 771
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
734 772
 
735 773
 	// If they aren't ignoring any boards then they want to see all the boards they can see
736
-	if (empty($user_info['ignoreboards']))
737
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
774
+	if (empty($user_info['ignoreboards'])) {
775
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
776
+	}
738 777
 	// Ok I guess they don't want to see all the boards
739
-	else
740
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
778
+	else {
779
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
780
+	}
741 781
 
742 782
 	call_integration_hook('integrate_user_info');
743 783
 }
@@ -795,9 +835,9 @@  discard block
 block discarded – undo
795 835
 		}
796 836
 
797 837
 		// Remember redirection is the key to avoiding fallout from your bosses.
798
-		if (!empty($topic))
799
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
800
-		else
838
+		if (!empty($topic)) {
839
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
840
+		} else
801 841
 		{
802 842
 			loadPermissions();
803 843
 			loadTheme();
@@ -815,10 +855,11 @@  discard block
 block discarded – undo
815 855
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
816 856
 	{
817 857
 		// @todo SLOW?
818
-		if (!empty($topic))
819
-			$temp = cache_get_data('topic_board-' . $topic, 120);
820
-		else
821
-			$temp = cache_get_data('board-' . $board, 120);
858
+		if (!empty($topic)) {
859
+					$temp = cache_get_data('topic_board-' . $topic, 120);
860
+		} else {
861
+					$temp = cache_get_data('board-' . $board, 120);
862
+		}
822 863
 
823 864
 		if (!empty($temp))
824 865
 		{
@@ -856,8 +897,9 @@  discard block
 block discarded – undo
856 897
 			$row = $smcFunc['db_fetch_assoc']($request);
857 898
 
858 899
 			// Set the current board.
859
-			if (!empty($row['id_board']))
860
-				$board = $row['id_board'];
900
+			if (!empty($row['id_board'])) {
901
+							$board = $row['id_board'];
902
+			}
861 903
 
862 904
 			// Basic operating information. (globals... :/)
863 905
 			$board_info = array(
@@ -893,21 +935,23 @@  discard block
 block discarded – undo
893 935
 
894 936
 			do
895 937
 			{
896
-				if (!empty($row['id_moderator']))
897
-					$board_info['moderators'][$row['id_moderator']] = array(
938
+				if (!empty($row['id_moderator'])) {
939
+									$board_info['moderators'][$row['id_moderator']] = array(
898 940
 						'id' => $row['id_moderator'],
899 941
 						'name' => $row['real_name'],
900 942
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
901 943
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
902 944
 					);
945
+				}
903 946
 
904
-				if (!empty($row['id_moderator_group']))
905
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
947
+				if (!empty($row['id_moderator_group'])) {
948
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
906 949
 						'id' => $row['id_moderator_group'],
907 950
 						'name' => $row['group_name'],
908 951
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
909 952
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
910 953
 					);
954
+				}
911 955
 			}
912 956
 			while ($row = $smcFunc['db_fetch_assoc']($request));
913 957
 
@@ -939,12 +983,12 @@  discard block
 block discarded – undo
939 983
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
940 984
 			{
941 985
 				// @todo SLOW?
942
-				if (!empty($topic))
943
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
986
+				if (!empty($topic)) {
987
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				}
944 989
 				cache_put_data('board-' . $board, $board_info, 120);
945 990
 			}
946
-		}
947
-		else
991
+		} else
948 992
 		{
949 993
 			// Otherwise the topic is invalid, there are no moderators, etc.
950 994
 			$board_info = array(
@@ -958,8 +1002,9 @@  discard block
 block discarded – undo
958 1002
 		$smcFunc['db_free_result']($request);
959 1003
 	}
960 1004
 
961
-	if (!empty($topic))
962
-		$_GET['board'] = (int) $board;
1005
+	if (!empty($topic)) {
1006
+			$_GET['board'] = (int) $board;
1007
+	}
963 1008
 
964 1009
 	if (!empty($board))
965 1010
 	{
@@ -969,10 +1014,12 @@  discard block
 block discarded – undo
969 1014
 		// Now check if the user is a moderator.
970 1015
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
971 1016
 
972
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
973
-			$board_info['error'] = 'access';
974
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
975
-			$board_info['error'] = 'access';
1017
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1018
+					$board_info['error'] = 'access';
1019
+		}
1020
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1021
+					$board_info['error'] = 'access';
1022
+		}
976 1023
 
977 1024
 		// Build up the linktree.
978 1025
 		$context['linktree'] = array_merge(
@@ -995,8 +1042,9 @@  discard block
 block discarded – undo
995 1042
 	$context['current_board'] = $board;
996 1043
 
997 1044
 	// No posting in redirection boards!
998
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
999
-		$board_info['error'] == 'post_in_redirect';
1045
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1046
+			$board_info['error'] == 'post_in_redirect';
1047
+	}
1000 1048
 
1001 1049
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1002 1050
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1022,24 +1070,23 @@  discard block
 block discarded – undo
1022 1070
 			ob_end_clean();
1023 1071
 			header('HTTP/1.1 403 Forbidden');
1024 1072
 			die;
1025
-		}
1026
-		elseif ($board_info['error'] == 'post_in_redirect')
1073
+		} elseif ($board_info['error'] == 'post_in_redirect')
1027 1074
 		{
1028 1075
 			// Slightly different error message here...
1029 1076
 			fatal_lang_error('cannot_post_redirect', false);
1030
-		}
1031
-		elseif ($user_info['is_guest'])
1077
+		} elseif ($user_info['is_guest'])
1032 1078
 		{
1033 1079
 			loadLanguage('Errors');
1034 1080
 			is_not_guest($txt['topic_gone']);
1081
+		} else {
1082
+					fatal_lang_error('topic_gone', false);
1035 1083
 		}
1036
-		else
1037
-			fatal_lang_error('topic_gone', false);
1038 1084
 	}
1039 1085
 
1040
-	if ($user_info['is_mod'])
1041
-		$user_info['groups'][] = 3;
1042
-}
1086
+	if ($user_info['is_mod']) {
1087
+			$user_info['groups'][] = 3;
1088
+	}
1089
+	}
1043 1090
 
1044 1091
 /**
1045 1092
  * Load this user's permissions.
@@ -1060,8 +1107,9 @@  discard block
 block discarded – undo
1060 1107
 		asort($cache_groups);
1061 1108
 		$cache_groups = implode(',', $cache_groups);
1062 1109
 		// If it's a spider then cache it different.
1063
-		if ($user_info['possibly_robot'])
1064
-			$cache_groups .= '-spider';
1110
+		if ($user_info['possibly_robot']) {
1111
+					$cache_groups .= '-spider';
1112
+		}
1065 1113
 
1066 1114
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1067 1115
 		{
@@ -1069,9 +1117,9 @@  discard block
 block discarded – undo
1069 1117
 			banPermissions();
1070 1118
 
1071 1119
 			return;
1120
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1121
+					list ($user_info['permissions'], $removals) = $temp;
1072 1122
 		}
1073
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1074
-			list ($user_info['permissions'], $removals) = $temp;
1075 1123
 	}
1076 1124
 
1077 1125
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1093,23 +1141,26 @@  discard block
 block discarded – undo
1093 1141
 		$removals = array();
1094 1142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1095 1143
 		{
1096
-			if (empty($row['add_deny']))
1097
-				$removals[] = $row['permission'];
1098
-			else
1099
-				$user_info['permissions'][] = $row['permission'];
1144
+			if (empty($row['add_deny'])) {
1145
+							$removals[] = $row['permission'];
1146
+			} else {
1147
+							$user_info['permissions'][] = $row['permission'];
1148
+			}
1100 1149
 		}
1101 1150
 		$smcFunc['db_free_result']($request);
1102 1151
 
1103
-		if (isset($cache_groups))
1104
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1152
+		if (isset($cache_groups)) {
1153
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		}
1105 1155
 	}
1106 1156
 
1107 1157
 	// Get the board permissions.
1108 1158
 	if (!empty($board))
1109 1159
 	{
1110 1160
 		// Make sure the board (if any) has been loaded by loadBoard().
1111
-		if (!isset($board_info['profile']))
1112
-			fatal_lang_error('no_board');
1161
+		if (!isset($board_info['profile'])) {
1162
+					fatal_lang_error('no_board');
1163
+		}
1113 1164
 
1114 1165
 		$request = $smcFunc['db_query']('', '
1115 1166
 			SELECT permission, add_deny
@@ -1125,20 +1176,23 @@  discard block
 block discarded – undo
1125 1176
 		);
1126 1177
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1127 1178
 		{
1128
-			if (empty($row['add_deny']))
1129
-				$removals[] = $row['permission'];
1130
-			else
1131
-				$user_info['permissions'][] = $row['permission'];
1179
+			if (empty($row['add_deny'])) {
1180
+							$removals[] = $row['permission'];
1181
+			} else {
1182
+							$user_info['permissions'][] = $row['permission'];
1183
+			}
1132 1184
 		}
1133 1185
 		$smcFunc['db_free_result']($request);
1134 1186
 	}
1135 1187
 
1136 1188
 	// Remove all the permissions they shouldn't have ;).
1137
-	if (!empty($modSettings['permission_enable_deny']))
1138
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1189
+	if (!empty($modSettings['permission_enable_deny'])) {
1190
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	}
1139 1192
 
1140
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1141
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1193
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1194
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	}
1142 1196
 
1143 1197
 	// Banned?  Watch, don't touch..
1144 1198
 	banPermissions();
@@ -1150,17 +1204,18 @@  discard block
 block discarded – undo
1150 1204
 		{
1151 1205
 			require_once($sourcedir . '/Subs-Auth.php');
1152 1206
 			rebuildModCache();
1207
+		} else {
1208
+					$user_info['mod_cache'] = $_SESSION['mc'];
1153 1209
 		}
1154
-		else
1155
-			$user_info['mod_cache'] = $_SESSION['mc'];
1156 1210
 
1157 1211
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1158 1212
 		// For example this drastically simplifies certain changes to the profile area.
1159 1213
 		$user_info['permissions'][] = 'is_not_guest';
1160 1214
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1161 1215
 		$user_info['permissions'][] = 'profile_view_own';
1162
-		if (in_array('profile_view', $user_info['permissions']))
1163
-			$user_info['permissions'][] = 'profile_view_any';
1216
+		if (in_array('profile_view', $user_info['permissions'])) {
1217
+					$user_info['permissions'][] = 'profile_view_any';
1218
+		}
1164 1219
 	}
1165 1220
 }
1166 1221
 
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1179 1234
 
1180 1235
 	// Can't just look for no users :P.
1181
-	if (empty($users))
1182
-		return array();
1236
+	if (empty($users)) {
1237
+			return array();
1238
+	}
1183 1239
 
1184 1240
 	// Pass the set value
1185 1241
 	$context['loadMemberContext_set'] = $set;
@@ -1194,8 +1250,9 @@  discard block
 block discarded – undo
1194 1250
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1195 1251
 		{
1196 1252
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1197
-			if ($data == null)
1198
-				continue;
1253
+			if ($data == null) {
1254
+							continue;
1255
+			}
1199 1256
 
1200 1257
 			$loaded_ids[] = $data['id_member'];
1201 1258
 			$user_profile[$data['id_member']] = $data;
@@ -1259,13 +1316,16 @@  discard block
 block discarded – undo
1259 1316
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1260 1317
 		{
1261 1318
 			// Take care of proxying avatar if required, do this here for maximum reach
1262
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1263
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1319
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1320
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1321
+			}
1264 1322
 
1265
-			if ( isset($row['member_ip']) )
1266
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1267
-			if ( isset($row['member_ip2']) )
1268
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1323
+			if ( isset($row['member_ip']) ) {
1324
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1325
+			}
1326
+			if ( isset($row['member_ip2']) ) {
1327
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1328
+			}
1269 1329
 			$new_loaded_ids[] = $row['id_member'];
1270 1330
 			$loaded_ids[] = $row['id_member'];
1271 1331
 			$row['options'] = array();
@@ -1284,8 +1344,9 @@  discard block
 block discarded – undo
1284 1344
 				'loaded_ids' => $new_loaded_ids,
1285 1345
 			)
1286 1346
 		);
1287
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1288
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1347
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1348
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1349
+		}
1289 1350
 		$smcFunc['db_free_result']($request);
1290 1351
 	}
1291 1352
 
@@ -1296,10 +1357,11 @@  discard block
 block discarded – undo
1296 1357
 	{
1297 1358
 		foreach ($loaded_ids as $a_member)
1298 1359
 		{
1299
-			if (!empty($user_profile[$a_member]['additional_groups']))
1300
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1301
-			else
1302
-				$groups = array($user_profile[$a_member]['id_group']);
1360
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1361
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1362
+			} else {
1363
+							$groups = array($user_profile[$a_member]['id_group']);
1364
+			}
1303 1365
 
1304 1366
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1305 1367
 
@@ -1312,8 +1374,9 @@  discard block
 block discarded – undo
1312 1374
 
1313 1375
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1314 1376
 	{
1315
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1316
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1377
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1378
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1379
+		}
1317 1380
 	}
1318 1381
 
1319 1382
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1339,14 +1402,17 @@  discard block
 block discarded – undo
1339 1402
 		foreach ($temp_mods as $id)
1340 1403
 		{
1341 1404
 			// By popular demand, don't show admins or global moderators as moderators.
1342
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1343
-				$user_profile[$id]['member_group'] = $row['member_group'];
1405
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1406
+							$user_profile[$id]['member_group'] = $row['member_group'];
1407
+			}
1344 1408
 
1345 1409
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1346
-			if (!empty($row['icons']))
1347
-				$user_profile[$id]['icons'] = $row['icons'];
1348
-			if (!empty($row['member_group_color']))
1349
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1410
+			if (!empty($row['icons'])) {
1411
+							$user_profile[$id]['icons'] = $row['icons'];
1412
+			}
1413
+			if (!empty($row['member_group_color'])) {
1414
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1415
+			}
1350 1416
 		}
1351 1417
 	}
1352 1418
 
@@ -1368,12 +1434,14 @@  discard block
 block discarded – undo
1368 1434
 	static $loadedLanguages = array();
1369 1435
 
1370 1436
 	// If this person's data is already loaded, skip it.
1371
-	if (isset($dataLoaded[$user]))
1372
-		return true;
1437
+	if (isset($dataLoaded[$user])) {
1438
+			return true;
1439
+	}
1373 1440
 
1374 1441
 	// We can't load guests or members not loaded by loadMemberData()!
1375
-	if ($user == 0)
1376
-		return false;
1442
+	if ($user == 0) {
1443
+			return false;
1444
+	}
1377 1445
 	if (!isset($user_profile[$user]))
1378 1446
 	{
1379 1447
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1399,12 +1467,16 @@  discard block
 block discarded – undo
1399 1467
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1400 1468
 
1401 1469
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1402
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1470
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1471
+		//icon is set and exists
1403 1472
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1404
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1473
+	} elseif (isset($profile['icons'][1])) {
1474
+		//icon is set and doesn't exist, fallback to default
1405 1475
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1406
-	else //not set, bye bye
1476
+	} else {
1477
+		//not set, bye bye
1407 1478
 		$group_icon_url = '';
1479
+	}
1408 1480
 
1409 1481
 	// These minimal values are always loaded
1410 1482
 	$memberContext[$user] = array(
@@ -1423,8 +1495,9 @@  discard block
 block discarded – undo
1423 1495
 	if ($context['loadMemberContext_set'] != 'minimal')
1424 1496
 	{
1425 1497
 		// Go the extra mile and load the user's native language name.
1426
-		if (empty($loadedLanguages))
1427
-			$loadedLanguages = getLanguages();
1498
+		if (empty($loadedLanguages)) {
1499
+					$loadedLanguages = getLanguages();
1500
+		}
1428 1501
 
1429 1502
 		$memberContext[$user] += array(
1430 1503
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1478,31 +1551,33 @@  discard block
 block discarded – undo
1478 1551
 	{
1479 1552
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1480 1553
 		{
1481
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1482
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1483
-			else
1484
-				$image = get_gravatar_url($profile['email_address']);
1485
-		}
1486
-		else
1554
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1555
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1556
+			} else {
1557
+							$image = get_gravatar_url($profile['email_address']);
1558
+			}
1559
+		} else
1487 1560
 		{
1488 1561
 			// So it's stored in the member table?
1489 1562
 			if (!empty($profile['avatar']))
1490 1563
 			{
1491 1564
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1565
+			} elseif (!empty($profile['filename'])) {
1566
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1492 1567
 			}
1493
-			elseif (!empty($profile['filename']))
1494
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1495 1568
 			// Right... no avatar...use the default one
1496
-			else
1497
-				$image = $modSettings['avatar_url'] . '/default.png';
1569
+			else {
1570
+							$image = $modSettings['avatar_url'] . '/default.png';
1571
+			}
1498 1572
 		}
1499
-		if (!empty($image))
1500
-			$memberContext[$user]['avatar'] = array(
1573
+		if (!empty($image)) {
1574
+					$memberContext[$user]['avatar'] = array(
1501 1575
 				'name' => $profile['avatar'],
1502 1576
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1503 1577
 				'href' => $image,
1504 1578
 				'url' => $image,
1505 1579
 			);
1580
+		}
1506 1581
 	}
1507 1582
 
1508 1583
 	// Are we also loading the members custom fields into context?
@@ -1510,35 +1585,41 @@  discard block
 block discarded – undo
1510 1585
 	{
1511 1586
 		$memberContext[$user]['custom_fields'] = array();
1512 1587
 
1513
-		if (!isset($context['display_fields']))
1514
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1588
+		if (!isset($context['display_fields'])) {
1589
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1590
+		}
1515 1591
 
1516 1592
 		foreach ($context['display_fields'] as $custom)
1517 1593
 		{
1518
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1519
-				continue;
1594
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1595
+							continue;
1596
+			}
1520 1597
 
1521 1598
 			$value = $profile['options'][$custom['col_name']];
1522 1599
 
1523 1600
 			// Don't show the "disabled" option for the "gender" field.
1524
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1525
-				continue;
1601
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1602
+							continue;
1603
+			}
1526 1604
 
1527 1605
 			// BBC?
1528
-			if ($custom['bbc'])
1529
-				$value = parse_bbc($value);
1606
+			if ($custom['bbc']) {
1607
+							$value = parse_bbc($value);
1608
+			}
1530 1609
 			// ... or checkbox?
1531
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1532
-				$value = $value ? $txt['yes'] : $txt['no'];
1610
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1611
+							$value = $value ? $txt['yes'] : $txt['no'];
1612
+			}
1533 1613
 
1534 1614
 			// Enclosing the user input within some other text?
1535
-			if (!empty($custom['enclose']))
1536
-				$value = strtr($custom['enclose'], array(
1615
+			if (!empty($custom['enclose'])) {
1616
+							$value = strtr($custom['enclose'], array(
1537 1617
 					'{SCRIPTURL}' => $scripturl,
1538 1618
 					'{IMAGES_URL}' => $settings['images_url'],
1539 1619
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1540 1620
 					'{INPUT}' => $value,
1541 1621
 				));
1622
+			}
1542 1623
 
1543 1624
 			$memberContext[$user]['custom_fields'][] = array(
1544 1625
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1565,8 +1646,9 @@  discard block
 block discarded – undo
1565 1646
 	global $smcFunc, $txt, $scripturl, $settings;
1566 1647
 
1567 1648
 	// Do not waste my time...
1568
-	if (empty($users) || empty($params))
1569
-		return false;
1649
+	if (empty($users) || empty($params)) {
1650
+			return false;
1651
+	}
1570 1652
 
1571 1653
 	// Make sure it's an array.
1572 1654
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1590,31 +1672,36 @@  discard block
 block discarded – undo
1590 1672
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1591 1673
 	{
1592 1674
 		// BBC?
1593
-		if (!empty($row['bbc']))
1594
-			$row['value'] = parse_bbc($row['value']);
1675
+		if (!empty($row['bbc'])) {
1676
+					$row['value'] = parse_bbc($row['value']);
1677
+		}
1595 1678
 
1596 1679
 		// ... or checkbox?
1597
-		elseif (isset($row['type']) && $row['type'] == 'check')
1598
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1680
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1681
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1682
+		}
1599 1683
 
1600 1684
 		// Enclosing the user input within some other text?
1601
-		if (!empty($row['enclose']))
1602
-			$row['value'] = strtr($row['enclose'], array(
1685
+		if (!empty($row['enclose'])) {
1686
+					$row['value'] = strtr($row['enclose'], array(
1603 1687
 				'{SCRIPTURL}' => $scripturl,
1604 1688
 				'{IMAGES_URL}' => $settings['images_url'],
1605 1689
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1606 1690
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1607 1691
 			));
1692
+		}
1608 1693
 
1609 1694
 		// Send a simple array if there is just 1 param
1610
-		if (count($params) == 1)
1611
-			$return[$row['id_member']] = $row;
1695
+		if (count($params) == 1) {
1696
+					$return[$row['id_member']] = $row;
1697
+		}
1612 1698
 
1613 1699
 		// More than 1? knock yourself out...
1614 1700
 		else
1615 1701
 		{
1616
-			if (!isset($return[$row['id_member']]))
1617
-				$return[$row['id_member']] = array();
1702
+			if (!isset($return[$row['id_member']])) {
1703
+							$return[$row['id_member']] = array();
1704
+			}
1618 1705
 
1619 1706
 			$return[$row['id_member']][$row['variable']] = $row;
1620 1707
 		}
@@ -1648,8 +1735,9 @@  discard block
 block discarded – undo
1648 1735
 	global $context;
1649 1736
 
1650 1737
 	// Don't know any browser!
1651
-	if (empty($context['browser']))
1652
-		detectBrowser();
1738
+	if (empty($context['browser'])) {
1739
+			detectBrowser();
1740
+	}
1653 1741
 
1654 1742
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1655 1743
 }
@@ -1667,8 +1755,9 @@  discard block
 block discarded – undo
1667 1755
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1668 1756
 
1669 1757
 	// The theme was specified by parameter.
1670
-	if (!empty($id_theme))
1671
-		$id_theme = (int) $id_theme;
1758
+	if (!empty($id_theme)) {
1759
+			$id_theme = (int) $id_theme;
1760
+	}
1672 1761
 	// The theme was specified by REQUEST.
1673 1762
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1674 1763
 	{
@@ -1676,51 +1765,58 @@  discard block
 block discarded – undo
1676 1765
 		$_SESSION['id_theme'] = $id_theme;
1677 1766
 	}
1678 1767
 	// The theme was specified by REQUEST... previously.
1679
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1680
-		$id_theme = (int) $_SESSION['id_theme'];
1768
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1769
+			$id_theme = (int) $_SESSION['id_theme'];
1770
+	}
1681 1771
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1682
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1683
-		$id_theme = $user_info['theme'];
1772
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1773
+			$id_theme = $user_info['theme'];
1774
+	}
1684 1775
 	// The theme was specified by the board.
1685
-	elseif (!empty($board_info['theme']))
1686
-		$id_theme = $board_info['theme'];
1776
+	elseif (!empty($board_info['theme'])) {
1777
+			$id_theme = $board_info['theme'];
1778
+	}
1687 1779
 	// The theme is the forum's default.
1688
-	else
1689
-		$id_theme = $modSettings['theme_guests'];
1780
+	else {
1781
+			$id_theme = $modSettings['theme_guests'];
1782
+	}
1690 1783
 
1691 1784
 	// Verify the id_theme... no foul play.
1692 1785
 	// Always allow the board specific theme, if they are overriding.
1693
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1694
-		$id_theme = $board_info['theme'];
1786
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1787
+			$id_theme = $board_info['theme'];
1788
+	}
1695 1789
 	// If they have specified a particular theme to use with SSI allow it to be used.
1696
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1697
-		$id_theme = (int) $id_theme;
1698
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1790
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1791
+			$id_theme = (int) $id_theme;
1792
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1699 1793
 	{
1700 1794
 		$themes = explode(',', $modSettings['enableThemes']);
1701
-		if (!in_array($id_theme, $themes))
1702
-			$id_theme = $modSettings['theme_guests'];
1703
-		else
1795
+		if (!in_array($id_theme, $themes)) {
1796
+					$id_theme = $modSettings['theme_guests'];
1797
+		} else {
1798
+					$id_theme = (int) $id_theme;
1799
+		}
1800
+	} else {
1704 1801
 			$id_theme = (int) $id_theme;
1705 1802
 	}
1706
-	else
1707
-		$id_theme = (int) $id_theme;
1708 1803
 
1709 1804
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1710 1805
 
1711 1806
 	// Disable image proxy if we don't have SSL enabled
1712
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1713
-		$image_proxy_enabled = false;
1807
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1808
+			$image_proxy_enabled = false;
1809
+	}
1714 1810
 
1715 1811
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1716 1812
 	{
1717 1813
 		$themeData = $temp;
1718 1814
 		$flag = true;
1815
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1816
+			$themeData = $temp + array($member => array());
1817
+	} else {
1818
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1719 1819
 	}
1720
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1721
-		$themeData = $temp + array($member => array());
1722
-	else
1723
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1724 1820
 
1725 1821
 	if (empty($flag))
1726 1822
 	{
@@ -1739,31 +1835,37 @@  discard block
 block discarded – undo
1739 1835
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1740 1836
 		{
1741 1837
 			// There are just things we shouldn't be able to change as members.
1742
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1743
-				continue;
1838
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1839
+							continue;
1840
+			}
1744 1841
 
1745 1842
 			// If this is the theme_dir of the default theme, store it.
1746
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1747
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1843
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1844
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1845
+			}
1748 1846
 
1749 1847
 			// If this isn't set yet, is a theme option, or is not the default theme..
1750
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1751
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1848
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1849
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1850
+			}
1752 1851
 		}
1753 1852
 		$smcFunc['db_free_result']($result);
1754 1853
 
1755
-		if (!empty($themeData[-1]))
1756
-			foreach ($themeData[-1] as $k => $v)
1854
+		if (!empty($themeData[-1])) {
1855
+					foreach ($themeData[-1] as $k => $v)
1757 1856
 			{
1758 1857
 				if (!isset($themeData[$member][$k]))
1759 1858
 					$themeData[$member][$k] = $v;
1859
+		}
1760 1860
 			}
1761 1861
 
1762
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1763
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1862
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1863
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1864
+		}
1764 1865
 		// Only if we didn't already load that part of the cache...
1765
-		elseif (!isset($temp))
1766
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1866
+		elseif (!isset($temp)) {
1867
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1868
+		}
1767 1869
 	}
1768 1870
 
1769 1871
 	$settings = $themeData[0];
@@ -1780,20 +1882,24 @@  discard block
 block discarded – undo
1780 1882
 	$settings['template_dirs'][] = $settings['theme_dir'];
1781 1883
 
1782 1884
 	// Based on theme (if there is one).
1783
-	if (!empty($settings['base_theme_dir']))
1784
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1885
+	if (!empty($settings['base_theme_dir'])) {
1886
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1887
+	}
1785 1888
 
1786 1889
 	// Lastly the default theme.
1787
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1788
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1890
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1891
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1892
+	}
1789 1893
 
1790
-	if (!$initialize)
1791
-		return;
1894
+	if (!$initialize) {
1895
+			return;
1896
+	}
1792 1897
 
1793 1898
 	// Check to see if we're forcing SSL
1794 1899
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1795
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1796
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1900
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1901
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1902
+	}
1797 1903
 
1798 1904
 	// Check to see if they're accessing it from the wrong place.
1799 1905
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1801,8 +1907,9 @@  discard block
 block discarded – undo
1801 1907
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1802 1908
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1803 1909
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1804
-		if ($temp != '/')
1805
-			$detected_url .= $temp;
1910
+		if ($temp != '/') {
1911
+					$detected_url .= $temp;
1912
+		}
1806 1913
 	}
1807 1914
 	if (isset($detected_url) && $detected_url != $boardurl)
1808 1915
 	{
@@ -1814,8 +1921,9 @@  discard block
 block discarded – undo
1814 1921
 			foreach ($aliases as $alias)
1815 1922
 			{
1816 1923
 				// Rip off all the boring parts, spaces, etc.
1817
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1818
-					$do_fix = true;
1924
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1925
+									$do_fix = true;
1926
+				}
1819 1927
 			}
1820 1928
 		}
1821 1929
 
@@ -1823,20 +1931,22 @@  discard block
 block discarded – undo
1823 1931
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1824 1932
 		{
1825 1933
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1826
-			if (empty($_GET))
1827
-				redirectexit('wwwRedirect');
1828
-			else
1934
+			if (empty($_GET)) {
1935
+							redirectexit('wwwRedirect');
1936
+			} else
1829 1937
 			{
1830 1938
 				list ($k, $v) = each($_GET);
1831 1939
 
1832
-				if ($k != 'wwwRedirect')
1833
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1940
+				if ($k != 'wwwRedirect') {
1941
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1942
+				}
1834 1943
 			}
1835 1944
 		}
1836 1945
 
1837 1946
 		// #3 is just a check for SSL...
1838
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1839
-			$do_fix = true;
1947
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1948
+					$do_fix = true;
1949
+		}
1840 1950
 
1841 1951
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1842 1952
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1870,8 +1980,9 @@  discard block
 block discarded – undo
1870 1980
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1871 1981
 				}
1872 1982
 			}
1873
-			foreach ($context['linktree'] as $k => $dummy)
1874
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1983
+			foreach ($context['linktree'] as $k => $dummy) {
1984
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1985
+			}
1875 1986
 		}
1876 1987
 	}
1877 1988
 	// Set up the contextual user array.
@@ -1890,16 +2001,16 @@  discard block
 block discarded – undo
1890 2001
 			'email' => $user_info['email'],
1891 2002
 			'ignoreusers' => $user_info['ignoreusers'],
1892 2003
 		);
1893
-		if (!$context['user']['is_guest'])
1894
-			$context['user']['name'] = $user_info['name'];
1895
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1896
-			$context['user']['name'] = $txt['guest_title'];
2004
+		if (!$context['user']['is_guest']) {
2005
+					$context['user']['name'] = $user_info['name'];
2006
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2007
+					$context['user']['name'] = $txt['guest_title'];
2008
+		}
1897 2009
 
1898 2010
 		// Determine the current smiley set.
1899 2011
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1900 2012
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1901
-	}
1902
-	else
2013
+	} else
1903 2014
 	{
1904 2015
 		$context['user'] = array(
1905 2016
 			'id' => -1,
@@ -1915,18 +2026,24 @@  discard block
 block discarded – undo
1915 2026
 	}
1916 2027
 
1917 2028
 	// Some basic information...
1918
-	if (!isset($context['html_headers']))
1919
-		$context['html_headers'] = '';
1920
-	if (!isset($context['javascript_files']))
1921
-		$context['javascript_files'] = array();
1922
-	if (!isset($context['css_files']))
1923
-		$context['css_files'] = array();
1924
-	if (!isset($context['css_header']))
1925
-		$context['css_header'] = array();
1926
-	if (!isset($context['javascript_inline']))
1927
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1928
-	if (!isset($context['javascript_vars']))
1929
-		$context['javascript_vars'] = array();
2029
+	if (!isset($context['html_headers'])) {
2030
+			$context['html_headers'] = '';
2031
+	}
2032
+	if (!isset($context['javascript_files'])) {
2033
+			$context['javascript_files'] = array();
2034
+	}
2035
+	if (!isset($context['css_files'])) {
2036
+			$context['css_files'] = array();
2037
+	}
2038
+	if (!isset($context['css_header'])) {
2039
+			$context['css_header'] = array();
2040
+	}
2041
+	if (!isset($context['javascript_inline'])) {
2042
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2043
+	}
2044
+	if (!isset($context['javascript_vars'])) {
2045
+			$context['javascript_vars'] = array();
2046
+	}
1930 2047
 
1931 2048
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1932 2049
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1938,8 +2055,9 @@  discard block
 block discarded – undo
1938 2055
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1939 2056
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1940 2057
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1941
-	if (isset($modSettings['load_average']))
1942
-		$context['load_average'] = $modSettings['load_average'];
2058
+	if (isset($modSettings['load_average'])) {
2059
+			$context['load_average'] = $modSettings['load_average'];
2060
+	}
1943 2061
 
1944 2062
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1945 2063
 	detectBrowser();
@@ -1953,8 +2071,9 @@  discard block
 block discarded – undo
1953 2071
 	// This allows sticking some HTML on the page output - useful for controls.
1954 2072
 	$context['insert_after_template'] = '';
1955 2073
 
1956
-	if (!isset($txt))
1957
-		$txt = array();
2074
+	if (!isset($txt)) {
2075
+			$txt = array();
2076
+	}
1958 2077
 
1959 2078
 	$simpleActions = array(
1960 2079
 		'findmember',
@@ -2000,9 +2119,10 @@  discard block
 block discarded – undo
2000 2119
 
2001 2120
 	// See if theres any extra param to check.
2002 2121
 	$requiresXML = false;
2003
-	foreach ($extraParams as $key => $extra)
2004
-		if (isset($_REQUEST[$extra]))
2122
+	foreach ($extraParams as $key => $extra) {
2123
+			if (isset($_REQUEST[$extra]))
2005 2124
 			$requiresXML = true;
2125
+	}
2006 2126
 
2007 2127
 	// Output is fully XML, so no need for the index template.
2008 2128
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2017,37 +2137,39 @@  discard block
 block discarded – undo
2017 2137
 	{
2018 2138
 		loadLanguage('index+Modifications');
2019 2139
 		$context['template_layers'] = array();
2020
-	}
2021
-
2022
-	else
2140
+	} else
2023 2141
 	{
2024 2142
 		// Custom templates to load, or just default?
2025
-		if (isset($settings['theme_templates']))
2026
-			$templates = explode(',', $settings['theme_templates']);
2027
-		else
2028
-			$templates = array('index');
2143
+		if (isset($settings['theme_templates'])) {
2144
+					$templates = explode(',', $settings['theme_templates']);
2145
+		} else {
2146
+					$templates = array('index');
2147
+		}
2029 2148
 
2030 2149
 		// Load each template...
2031
-		foreach ($templates as $template)
2032
-			loadTemplate($template);
2150
+		foreach ($templates as $template) {
2151
+					loadTemplate($template);
2152
+		}
2033 2153
 
2034 2154
 		// ...and attempt to load their associated language files.
2035 2155
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2036 2156
 		loadLanguage($required_files, '', false);
2037 2157
 
2038 2158
 		// Custom template layers?
2039
-		if (isset($settings['theme_layers']))
2040
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2041
-		else
2042
-			$context['template_layers'] = array('html', 'body');
2159
+		if (isset($settings['theme_layers'])) {
2160
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2161
+		} else {
2162
+					$context['template_layers'] = array('html', 'body');
2163
+		}
2043 2164
 	}
2044 2165
 
2045 2166
 	// Initialize the theme.
2046 2167
 	loadSubTemplate('init', 'ignore');
2047 2168
 
2048 2169
 	// Allow overriding the board wide time/number formats.
2049
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2050
-		$user_info['time_format'] = $txt['time_format'];
2170
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2171
+			$user_info['time_format'] = $txt['time_format'];
2172
+	}
2051 2173
 
2052 2174
 	// Set the character set from the template.
2053 2175
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2055,12 +2177,14 @@  discard block
 block discarded – undo
2055 2177
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2056 2178
 
2057 2179
 	// Guests may still need a name.
2058
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2059
-		$context['user']['name'] = $txt['guest_title'];
2180
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2181
+			$context['user']['name'] = $txt['guest_title'];
2182
+	}
2060 2183
 
2061 2184
 	// Any theme-related strings that need to be loaded?
2062
-	if (!empty($settings['require_theme_strings']))
2063
-		loadLanguage('ThemeStrings', '', false);
2185
+	if (!empty($settings['require_theme_strings'])) {
2186
+			loadLanguage('ThemeStrings', '', false);
2187
+	}
2064 2188
 
2065 2189
 	// Make a special URL for the language.
2066 2190
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2071,8 +2195,9 @@  discard block
 block discarded – undo
2071 2195
 	// Here is my luvly Responsive CSS
2072 2196
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2073 2197
 
2074
-	if ($context['right_to_left'])
2075
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2198
+	if ($context['right_to_left']) {
2199
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2200
+	}
2076 2201
 
2077 2202
 	// We allow theme variants, because we're cool.
2078 2203
 	$context['theme_variant'] = '';
@@ -2080,14 +2205,17 @@  discard block
 block discarded – undo
2080 2205
 	if (!empty($settings['theme_variants']))
2081 2206
 	{
2082 2207
 		// Overriding - for previews and that ilk.
2083
-		if (!empty($_REQUEST['variant']))
2084
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2208
+		if (!empty($_REQUEST['variant'])) {
2209
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2210
+		}
2085 2211
 		// User selection?
2086
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2087
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2212
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2213
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2214
+		}
2088 2215
 		// If not a user variant, select the default.
2089
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2090
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2216
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2217
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2218
+		}
2091 2219
 
2092 2220
 		// Do this to keep things easier in the templates.
2093 2221
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2096,20 +2224,23 @@  discard block
 block discarded – undo
2096 2224
 		if (!empty($context['theme_variant']))
2097 2225
 		{
2098 2226
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2099
-			if ($context['right_to_left'])
2100
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2227
+			if ($context['right_to_left']) {
2228
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2229
+			}
2101 2230
 		}
2102 2231
 	}
2103 2232
 
2104 2233
 	// Let's be compatible with old themes!
2105
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2106
-		$context['template_layers'] = array('main');
2234
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2235
+			$context['template_layers'] = array('main');
2236
+	}
2107 2237
 
2108 2238
 	$context['tabindex'] = 1;
2109 2239
 
2110 2240
 	// Compatibility.
2111
-	if (!isset($settings['theme_version']))
2112
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2241
+	if (!isset($settings['theme_version'])) {
2242
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2243
+	}
2113 2244
 
2114 2245
 	// Default JS variables for use in every theme
2115 2246
 	$context['javascript_vars'] = array(
@@ -2128,18 +2259,18 @@  discard block
 block discarded – undo
2128 2259
 	);
2129 2260
 
2130 2261
 	// Add the JQuery library to the list of files to load.
2131
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2132
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2133
-
2134
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2135
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2136
-
2137
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2138
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2262
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2263
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2264
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2265
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2266
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2267
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2268
+	}
2139 2269
 
2140 2270
 	// Auto loading? template_javascript() will take care of the local half of this.
2141
-	else
2142
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2271
+	else {
2272
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2273
+	}
2143 2274
 
2144 2275
 	// Queue our JQuery plugins!
2145 2276
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2162,12 +2293,12 @@  discard block
 block discarded – undo
2162 2293
 			require_once($sourcedir . '/ScheduledTasks.php');
2163 2294
 
2164 2295
 			// What to do, what to do?!
2165
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2166
-				AutoTask();
2167
-			else
2168
-				ReduceMailQueue();
2169
-		}
2170
-		else
2296
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2297
+							AutoTask();
2298
+			} else {
2299
+							ReduceMailQueue();
2300
+			}
2301
+		} else
2171 2302
 		{
2172 2303
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2173 2304
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2218,8 +2349,9 @@  discard block
 block discarded – undo
2218 2349
 		foreach ($theme_includes as $include)
2219 2350
 		{
2220 2351
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2221
-			if (file_exists($include))
2222
-				require_once($include);
2352
+			if (file_exists($include)) {
2353
+							require_once($include);
2354
+			}
2223 2355
 		}
2224 2356
 	}
2225 2357
 
@@ -2249,16 +2381,19 @@  discard block
 block discarded – undo
2249 2381
 	// Do any style sheets first, cause we're easy with those.
2250 2382
 	if (!empty($style_sheets))
2251 2383
 	{
2252
-		if (!is_array($style_sheets))
2253
-			$style_sheets = array($style_sheets);
2384
+		if (!is_array($style_sheets)) {
2385
+					$style_sheets = array($style_sheets);
2386
+		}
2254 2387
 
2255
-		foreach ($style_sheets as $sheet)
2256
-			loadCSSFile($sheet . '.css', array(), $sheet);
2388
+		foreach ($style_sheets as $sheet) {
2389
+					loadCSSFile($sheet . '.css', array(), $sheet);
2390
+		}
2257 2391
 	}
2258 2392
 
2259 2393
 	// No template to load?
2260
-	if ($template_name === false)
2261
-		return true;
2394
+	if ($template_name === false) {
2395
+			return true;
2396
+	}
2262 2397
 
2263 2398
 	$loaded = false;
2264 2399
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2273,12 +2408,14 @@  discard block
 block discarded – undo
2273 2408
 
2274 2409
 	if ($loaded)
2275 2410
 	{
2276
-		if ($db_show_debug === true)
2277
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2411
+		if ($db_show_debug === true) {
2412
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2413
+		}
2278 2414
 
2279 2415
 		// If they have specified an initialization function for this template, go ahead and call it now.
2280
-		if (function_exists('template_' . $template_name . '_init'))
2281
-			call_user_func('template_' . $template_name . '_init');
2416
+		if (function_exists('template_' . $template_name . '_init')) {
2417
+					call_user_func('template_' . $template_name . '_init');
2418
+		}
2282 2419
 	}
2283 2420
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2284 2421
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2298,13 +2435,14 @@  discard block
 block discarded – undo
2298 2435
 		loadTemplate($template_name);
2299 2436
 	}
2300 2437
 	// Cause an error otherwise.
2301
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2302
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2303
-	elseif ($fatal)
2304
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2305
-	else
2306
-		return false;
2307
-}
2438
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2439
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2440
+	} elseif ($fatal) {
2441
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2442
+	} else {
2443
+			return false;
2444
+	}
2445
+	}
2308 2446
 
2309 2447
 
2310 2448
 /**
@@ -2323,17 +2461,19 @@  discard block
 block discarded – undo
2323 2461
 {
2324 2462
 	global $context, $txt, $db_show_debug;
2325 2463
 
2326
-	if ($db_show_debug === true)
2327
-		$context['debug']['sub_templates'][] = $sub_template_name;
2464
+	if ($db_show_debug === true) {
2465
+			$context['debug']['sub_templates'][] = $sub_template_name;
2466
+	}
2328 2467
 
2329 2468
 	// Figure out what the template function is named.
2330 2469
 	$theme_function = 'template_' . $sub_template_name;
2331
-	if (function_exists($theme_function))
2332
-		$theme_function();
2333
-	elseif ($fatal === false)
2334
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2335
-	elseif ($fatal !== 'ignore')
2336
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2470
+	if (function_exists($theme_function)) {
2471
+			$theme_function();
2472
+	} elseif ($fatal === false) {
2473
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2474
+	} elseif ($fatal !== 'ignore') {
2475
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2476
+	}
2337 2477
 
2338 2478
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2339 2479
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2370,8 +2510,9 @@  discard block
 block discarded – undo
2370 2510
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2371 2511
 
2372 2512
 	// If this is an external file, automatically set this to false.
2373
-	if (!empty($params['external']))
2374
-		$params['minimize'] = false;
2513
+	if (!empty($params['external'])) {
2514
+			$params['minimize'] = false;
2515
+	}
2375 2516
 
2376 2517
 	// Account for shorthand like admin.css?alp21 filenames
2377 2518
 	$has_seed = strpos($fileName, '.css?');
@@ -2388,13 +2529,10 @@  discard block
 block discarded – undo
2388 2529
 			{
2389 2530
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2390 2531
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2532
+			} else {
2533
+							$fileUrl = false;
2391 2534
 			}
2392
-
2393
-			else
2394
-				$fileUrl = false;
2395
-		}
2396
-
2397
-		else
2535
+		} else
2398 2536
 		{
2399 2537
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2400 2538
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2409,12 +2547,14 @@  discard block
 block discarded – undo
2409 2547
 	}
2410 2548
 
2411 2549
 	// Add it to the array for use in the template
2412
-	if (!empty($fileName))
2413
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2550
+	if (!empty($fileName)) {
2551
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2552
+	}
2414 2553
 
2415
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2416
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2417
-}
2554
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2555
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2556
+	}
2557
+	}
2418 2558
 
2419 2559
 /**
2420 2560
  * Add a block of inline css code to be executed later
@@ -2431,8 +2571,9 @@  discard block
 block discarded – undo
2431 2571
 	global $context;
2432 2572
 
2433 2573
 	// Gotta add something...
2434
-	if (empty($css))
2435
-		return false;
2574
+	if (empty($css)) {
2575
+			return false;
2576
+	}
2436 2577
 
2437 2578
 	$context['css_header'][] = $css;
2438 2579
 }
@@ -2467,8 +2608,9 @@  discard block
 block discarded – undo
2467 2608
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2468 2609
 
2469 2610
 	// If this is an external file, automatically set this to false.
2470
-	if (!empty($params['external']))
2471
-		$params['minimize'] = false;
2611
+	if (!empty($params['external'])) {
2612
+			$params['minimize'] = false;
2613
+	}
2472 2614
 
2473 2615
 	// Account for shorthand like admin.js?alp21 filenames
2474 2616
 	$has_seed = strpos($fileName, '.js?');
@@ -2485,16 +2627,12 @@  discard block
 block discarded – undo
2485 2627
 			{
2486 2628
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2487 2629
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2488
-			}
2489
-
2490
-			else
2630
+			} else
2491 2631
 			{
2492 2632
 				$fileUrl = false;
2493 2633
 				$filePath = false;
2494 2634
 			}
2495
-		}
2496
-
2497
-		else
2635
+		} else
2498 2636
 		{
2499 2637
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2500 2638
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2509,9 +2647,10 @@  discard block
 block discarded – undo
2509 2647
 	}
2510 2648
 
2511 2649
 	// Add it to the array for use in the template
2512
-	if (!empty($fileName))
2513
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2514
-}
2650
+	if (!empty($fileName)) {
2651
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2652
+	}
2653
+	}
2515 2654
 
2516 2655
 /**
2517 2656
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2525,9 +2664,10 @@  discard block
 block discarded – undo
2525 2664
 {
2526 2665
 	global $context;
2527 2666
 
2528
-	if (!empty($key) && (!empty($value) || $value === '0'))
2529
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2530
-}
2667
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2668
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2669
+	}
2670
+	}
2531 2671
 
2532 2672
 /**
2533 2673
  * Add a block of inline Javascript code to be executed later
@@ -2544,8 +2684,9 @@  discard block
 block discarded – undo
2544 2684
 {
2545 2685
 	global $context;
2546 2686
 
2547
-	if (empty($javascript))
2548
-		return false;
2687
+	if (empty($javascript)) {
2688
+			return false;
2689
+	}
2549 2690
 
2550 2691
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2551 2692
 }
@@ -2566,15 +2707,18 @@  discard block
 block discarded – undo
2566 2707
 	static $already_loaded = array();
2567 2708
 
2568 2709
 	// Default to the user's language.
2569
-	if ($lang == '')
2570
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2710
+	if ($lang == '') {
2711
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2712
+	}
2571 2713
 
2572 2714
 	// Do we want the English version of language file as fallback?
2573
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2574
-		loadLanguage($template_name, 'english', false);
2715
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2716
+			loadLanguage($template_name, 'english', false);
2717
+	}
2575 2718
 
2576
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2577
-		return $lang;
2719
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2720
+			return $lang;
2721
+	}
2578 2722
 
2579 2723
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2580 2724
 	if (empty($settings['default_theme_dir']))
@@ -2585,8 +2729,9 @@  discard block
 block discarded – undo
2585 2729
 
2586 2730
 	// What theme are we in?
2587 2731
 	$theme_name = basename($settings['theme_url']);
2588
-	if (empty($theme_name))
2589
-		$theme_name = 'unknown';
2732
+	if (empty($theme_name)) {
2733
+			$theme_name = 'unknown';
2734
+	}
2590 2735
 
2591 2736
 	// For each file open it up and write it out!
2592 2737
 	foreach (explode('+', $template_name) as $template)
@@ -2665,8 +2810,9 @@  discard block
 block discarded – undo
2665 2810
 	}
2666 2811
 
2667 2812
 	// Keep track of what we're up to soldier.
2668
-	if ($db_show_debug === true)
2669
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2813
+	if ($db_show_debug === true) {
2814
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2815
+	}
2670 2816
 
2671 2817
 	// Remember what we have loaded, and in which language.
2672 2818
 	$already_loaded[$template_name] = $lang;
@@ -2712,8 +2858,9 @@  discard block
 block discarded – undo
2712 2858
 				)
2713 2859
 			);
2714 2860
 			// In the EXTREMELY unlikely event this happens, give an error message.
2715
-			if ($smcFunc['db_num_rows']($result) == 0)
2716
-				fatal_lang_error('parent_not_found', 'critical');
2861
+			if ($smcFunc['db_num_rows']($result) == 0) {
2862
+							fatal_lang_error('parent_not_found', 'critical');
2863
+			}
2717 2864
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2718 2865
 			{
2719 2866
 				if (!isset($boards[$row['id_board']]))
@@ -2730,8 +2877,8 @@  discard block
 block discarded – undo
2730 2877
 					);
2731 2878
 				}
2732 2879
 				// If a moderator exists for this board, add that moderator for all children too.
2733
-				if (!empty($row['id_moderator']))
2734
-					foreach ($boards as $id => $dummy)
2880
+				if (!empty($row['id_moderator'])) {
2881
+									foreach ($boards as $id => $dummy)
2735 2882
 					{
2736 2883
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2737 2884
 							'id' => $row['id_moderator'],
@@ -2739,11 +2886,12 @@  discard block
 block discarded – undo
2739 2886
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2740 2887
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2741 2888
 						);
2889
+				}
2742 2890
 					}
2743 2891
 
2744 2892
 				// If a moderator group exists for this board, add that moderator group for all children too
2745
-				if (!empty($row['id_moderator_group']))
2746
-					foreach ($boards as $id => $dummy)
2893
+				if (!empty($row['id_moderator_group'])) {
2894
+									foreach ($boards as $id => $dummy)
2747 2895
 					{
2748 2896
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2749 2897
 							'id' => $row['id_moderator_group'],
@@ -2751,6 +2899,7 @@  discard block
 block discarded – undo
2751 2899
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2752 2900
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2753 2901
 						);
2902
+				}
2754 2903
 					}
2755 2904
 			}
2756 2905
 			$smcFunc['db_free_result']($result);
@@ -2778,23 +2927,27 @@  discard block
 block discarded – undo
2778 2927
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2779 2928
 	{
2780 2929
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2781
-		if (empty($smcFunc['ucwords']))
2782
-			reloadSettings();
2930
+		if (empty($smcFunc['ucwords'])) {
2931
+					reloadSettings();
2932
+		}
2783 2933
 
2784 2934
 		// If we don't have our theme information yet, let's get it.
2785
-		if (empty($settings['default_theme_dir']))
2786
-			loadTheme(0, false);
2935
+		if (empty($settings['default_theme_dir'])) {
2936
+					loadTheme(0, false);
2937
+		}
2787 2938
 
2788 2939
 		// Default language directories to try.
2789 2940
 		$language_directories = array(
2790 2941
 			$settings['default_theme_dir'] . '/languages',
2791 2942
 		);
2792
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2793
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2943
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2944
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2945
+		}
2794 2946
 
2795 2947
 		// We possibly have a base theme directory.
2796
-		if (!empty($settings['base_theme_dir']))
2797
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2948
+		if (!empty($settings['base_theme_dir'])) {
2949
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2950
+		}
2798 2951
 
2799 2952
 		// Remove any duplicates.
2800 2953
 		$language_directories = array_unique($language_directories);
@@ -2808,20 +2961,21 @@  discard block
 block discarded – undo
2808 2961
 		foreach ($language_directories as $language_dir)
2809 2962
 		{
2810 2963
 			// Can't look in here... doesn't exist!
2811
-			if (!file_exists($language_dir))
2812
-				continue;
2964
+			if (!file_exists($language_dir)) {
2965
+							continue;
2966
+			}
2813 2967
 
2814 2968
 			$dir = dir($language_dir);
2815 2969
 			while ($entry = $dir->read())
2816 2970
 			{
2817 2971
 				// Look for the index language file....
2818
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2819
-					continue;
2820
-
2821
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2822
-					$langName = $langList[$matches[1]];
2972
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2973
+									continue;
2974
+				}
2823 2975
 
2824
-				else
2976
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2977
+									$langName = $langList[$matches[1]];
2978
+				} else
2825 2979
 				{
2826 2980
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2827 2981
 
@@ -2864,20 +3018,23 @@  discard block
 block discarded – undo
2864 3018
 		}
2865 3019
 
2866 3020
 		// Do we need to store the lang list?
2867
-		if (empty($langList))
2868
-			updateSettings(array('langList' => json_encode($catchLang)));
3021
+		if (empty($langList)) {
3022
+					updateSettings(array('langList' => json_encode($catchLang)));
3023
+		}
2869 3024
 
2870 3025
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2871 3026
 		if ($favor_utf8)
2872 3027
 		{
2873
-			foreach ($context['languages'] as $lang)
2874
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3028
+			foreach ($context['languages'] as $lang) {
3029
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2875 3030
 					unset($context['languages'][$lang['filename']]);
3031
+			}
2876 3032
 		}
2877 3033
 
2878 3034
 		// Let's cash in on this deal.
2879
-		if (!empty($modSettings['cache_enable']))
2880
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3035
+		if (!empty($modSettings['cache_enable'])) {
3036
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3037
+		}
2881 3038
 	}
2882 3039
 
2883 3040
 	return $context['languages'];
@@ -2900,8 +3057,9 @@  discard block
 block discarded – undo
2900 3057
 	global $modSettings, $options, $txt;
2901 3058
 	static $censor_vulgar = null, $censor_proper;
2902 3059
 
2903
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2904
-		return $text;
3060
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3061
+			return $text;
3062
+	}
2905 3063
 
2906 3064
 	// If they haven't yet been loaded, load them.
2907 3065
 	if ($censor_vulgar == null)
@@ -2929,9 +3087,9 @@  discard block
 block discarded – undo
2929 3087
 	{
2930 3088
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2931 3089
 		$text = $func($censor_vulgar, $censor_proper, $text);
3090
+	} else {
3091
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2932 3092
 	}
2933
-	else
2934
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2935 3093
 
2936 3094
 	return $text;
2937 3095
 }
@@ -2957,38 +3115,42 @@  discard block
 block discarded – undo
2957 3115
 	@ini_set('track_errors', '1');
2958 3116
 
2959 3117
 	// Don't include the file more than once, if $once is true.
2960
-	if ($once && in_array($filename, $templates))
2961
-		return;
3118
+	if ($once && in_array($filename, $templates)) {
3119
+			return;
3120
+	}
2962 3121
 	// Add this file to the include list, whether $once is true or not.
2963
-	else
2964
-		$templates[] = $filename;
3122
+	else {
3123
+			$templates[] = $filename;
3124
+	}
2965 3125
 
2966 3126
 	// Are we going to use eval?
2967 3127
 	if (empty($modSettings['disableTemplateEval']))
2968 3128
 	{
2969 3129
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2970 3130
 		$settings['current_include_filename'] = $filename;
2971
-	}
2972
-	else
3131
+	} else
2973 3132
 	{
2974 3133
 		$file_found = file_exists($filename);
2975 3134
 
2976
-		if ($once && $file_found)
2977
-			require_once($filename);
2978
-		elseif ($file_found)
2979
-			require($filename);
3135
+		if ($once && $file_found) {
3136
+					require_once($filename);
3137
+		} elseif ($file_found) {
3138
+					require($filename);
3139
+		}
2980 3140
 	}
2981 3141
 
2982 3142
 	if ($file_found !== true)
2983 3143
 	{
2984 3144
 		ob_end_clean();
2985
-		if (!empty($modSettings['enableCompressedOutput']))
2986
-			@ob_start('ob_gzhandler');
2987
-		else
2988
-			ob_start();
3145
+		if (!empty($modSettings['enableCompressedOutput'])) {
3146
+					@ob_start('ob_gzhandler');
3147
+		} else {
3148
+					ob_start();
3149
+		}
2989 3150
 
2990
-		if (isset($_GET['debug']))
2991
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3151
+		if (isset($_GET['debug'])) {
3152
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3153
+		}
2992 3154
 
2993 3155
 		// Don't cache error pages!!
2994 3156
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3007,12 +3169,13 @@  discard block
 block discarded – undo
3007 3169
 		echo '<!DOCTYPE html>
3008 3170
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3009 3171
 	<head>';
3010
-		if (isset($context['character_set']))
3011
-			echo '
3172
+		if (isset($context['character_set'])) {
3173
+					echo '
3012 3174
 		<meta charset="', $context['character_set'], '">';
3175
+		}
3013 3176
 
3014
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3015
-			echo '
3177
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3178
+					echo '
3016 3179
 		<title>', $mtitle, '</title>
3017 3180
 	</head>
3018 3181
 	<body>
@@ -3020,8 +3183,8 @@  discard block
 block discarded – undo
3020 3183
 		', $mmessage, '
3021 3184
 	</body>
3022 3185
 </html>';
3023
-		elseif (!allowedTo('admin_forum'))
3024
-			echo '
3186
+		} elseif (!allowedTo('admin_forum')) {
3187
+					echo '
3025 3188
 		<title>', $txt['template_parse_error'], '</title>
3026 3189
 	</head>
3027 3190
 	<body>
@@ -3029,15 +3192,17 @@  discard block
 block discarded – undo
3029 3192
 		', $txt['template_parse_error_message'], '
3030 3193
 	</body>
3031 3194
 </html>';
3032
-		else
3195
+		} else
3033 3196
 		{
3034 3197
 			require_once($sourcedir . '/Subs-Package.php');
3035 3198
 
3036 3199
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3037
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3038
-				$error = $php_errormsg;
3039
-			if (empty($error))
3040
-				$error = $txt['template_parse_errmsg'];
3200
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3201
+							$error = $php_errormsg;
3202
+			}
3203
+			if (empty($error)) {
3204
+							$error = $txt['template_parse_errmsg'];
3205
+			}
3041 3206
 
3042 3207
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3043 3208
 
@@ -3048,11 +3213,12 @@  discard block
 block discarded – undo
3048 3213
 		<h3>', $txt['template_parse_error'], '</h3>
3049 3214
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3050 3215
 
3051
-			if (!empty($error))
3052
-				echo '
3216
+			if (!empty($error)) {
3217
+							echo '
3053 3218
 		<hr>
3054 3219
 
3055 3220
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3221
+			}
3056 3222
 
3057 3223
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3058 3224
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3062,10 +3228,11 @@  discard block
 block discarded – undo
3062 3228
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3063 3229
 
3064 3230
 				// Fix the PHP code stuff...
3065
-				if (!isBrowser('gecko'))
3066
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3067
-				else
3068
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3231
+				if (!isBrowser('gecko')) {
3232
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3233
+				} else {
3234
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3235
+				}
3069 3236
 
3070 3237
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3071 3238
 				$j = -1;
@@ -3073,8 +3240,9 @@  discard block
 block discarded – undo
3073 3240
 				{
3074 3241
 					$j++;
3075 3242
 
3076
-					if (substr_count($line, '<br>') == 0)
3077
-						continue;
3243
+					if (substr_count($line, '<br>') == 0) {
3244
+											continue;
3245
+					}
3078 3246
 
3079 3247
 					$n = substr_count($line, '<br>');
3080 3248
 					for ($i = 0; $i < $n; $i++)
@@ -3093,38 +3261,42 @@  discard block
 block discarded – undo
3093 3261
 				// Figure out what the color coding was before...
3094 3262
 				$line = max($match[1] - 9, 1);
3095 3263
 				$last_line = '';
3096
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3097
-					if (strpos($data2[$line2], '<') !== false)
3264
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3265
+									if (strpos($data2[$line2], '<') !== false)
3098 3266
 					{
3099 3267
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3100 3268
 							$last_line = $color_match[1];
3269
+				}
3101 3270
 						break;
3102 3271
 					}
3103 3272
 
3104 3273
 				// Show the relevant lines...
3105 3274
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3106 3275
 				{
3107
-					if ($line == $match[1])
3108
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3276
+					if ($line == $match[1]) {
3277
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3278
+					}
3109 3279
 
3110 3280
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3111
-					if (isset($data2[$line]) && $data2[$line] != '')
3112
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3281
+					if (isset($data2[$line]) && $data2[$line] != '') {
3282
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3283
+					}
3113 3284
 
3114 3285
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3115 3286
 					{
3116 3287
 						$last_line = $color_match[1];
3117 3288
 						echo '</', substr($last_line, 1, 4), '>';
3289
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3290
+											$last_line = '';
3291
+					} elseif ($last_line != '' && $data2[$line] != '') {
3292
+											echo '</', substr($last_line, 1, 4), '>';
3118 3293
 					}
3119
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3120
-						$last_line = '';
3121
-					elseif ($last_line != '' && $data2[$line] != '')
3122
-						echo '</', substr($last_line, 1, 4), '>';
3123 3294
 
3124
-					if ($line == $match[1])
3125
-						echo '</pre></div><pre style="margin: 0;">';
3126
-					else
3127
-						echo "\n";
3295
+					if ($line == $match[1]) {
3296
+											echo '</pre></div><pre style="margin: 0;">';
3297
+					} else {
3298
+											echo "\n";
3299
+					}
3128 3300
 				}
3129 3301
 
3130 3302
 				echo '</pre></div>';
@@ -3148,8 +3320,9 @@  discard block
 block discarded – undo
3148 3320
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3149 3321
 
3150 3322
 	// Figure out what type of database we are using.
3151
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3152
-		$db_type = 'mysql';
3323
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3324
+			$db_type = 'mysql';
3325
+	}
3153 3326
 
3154 3327
 	// Load the file for the database.
3155 3328
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3157,8 +3330,9 @@  discard block
 block discarded – undo
3157 3330
 	$db_options = array();
3158 3331
 
3159 3332
 	// Add in the port if needed
3160
-	if (!empty($db_port))
3161
-		$db_options['port'] = $db_port;
3333
+	if (!empty($db_port)) {
3334
+			$db_options['port'] = $db_port;
3335
+	}
3162 3336
 
3163 3337
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3164 3338
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3177,13 +3351,15 @@  discard block
 block discarded – undo
3177 3351
 	}
3178 3352
 
3179 3353
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3180
-	if (!$db_connection)
3181
-		display_db_error();
3354
+	if (!$db_connection) {
3355
+			display_db_error();
3356
+	}
3182 3357
 
3183 3358
 	// If in SSI mode fix up the prefix.
3184
-	if (SMF == 'SSI')
3185
-		db_fix_prefix($db_prefix, $db_name);
3186
-}
3359
+	if (SMF == 'SSI') {
3360
+			db_fix_prefix($db_prefix, $db_name);
3361
+	}
3362
+	}
3187 3363
 
3188 3364
 /**
3189 3365
  * Try to retrieve a cache entry. On failure, call the appropriate function.
@@ -3201,8 +3377,9 @@  discard block
 block discarded – undo
3201 3377
 
3202 3378
 	// @todo Why are we doing this if caching is disabled?
3203 3379
 
3204
-	if (function_exists('call_integration_hook'))
3205
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3380
+	if (function_exists('call_integration_hook')) {
3381
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3382
+	}
3206 3383
 
3207 3384
 	/* Refresh the cache if either:
3208 3385
 		1. Caching is disabled.
@@ -3216,16 +3393,19 @@  discard block
 block discarded – undo
3216 3393
 		require_once($sourcedir . '/' . $file);
3217 3394
 		$cache_block = call_user_func_array($function, $params);
3218 3395
 
3219
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3220
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3396
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3397
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3398
+		}
3221 3399
 	}
3222 3400
 
3223 3401
 	// Some cached data may need a freshening up after retrieval.
3224
-	if (!empty($cache_block['post_retri_eval']))
3225
-		eval($cache_block['post_retri_eval']);
3402
+	if (!empty($cache_block['post_retri_eval'])) {
3403
+			eval($cache_block['post_retri_eval']);
3404
+	}
3226 3405
 
3227
-	if (function_exists('call_integration_hook'))
3228
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3406
+	if (function_exists('call_integration_hook')) {
3407
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3408
+	}
3229 3409
 
3230 3410
 	return $cache_block['data'];
3231 3411
 }
@@ -3253,8 +3433,9 @@  discard block
 block discarded – undo
3253 3433
 	global $cache_hits, $cache_count, $db_show_debug, $cachedir;
3254 3434
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3255 3435
 
3256
-	if (empty($cache_enable))
3257
-		return;
3436
+	if (empty($cache_enable)) {
3437
+			return;
3438
+	}
3258 3439
 
3259 3440
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3260 3441
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3273,10 +3454,12 @@  discard block
 block discarded – undo
3273 3454
 			if ((function_exists('memcached_set') || function_exists('memcache_set')) && isset($cache_memcached) && trim($cache_memcached) != '')
3274 3455
 			{
3275 3456
 				// Not connected yet?
3276
-				if (empty($memcached))
3277
-					get_memcached_server();
3278
-				if (!$memcached)
3279
-					return;
3457
+				if (empty($memcached)) {
3458
+									get_memcached_server();
3459
+				}
3460
+				if (!$memcached) {
3461
+									return;
3462
+				}
3280 3463
 
3281 3464
 				memcache_set($memcached, $key, $value, 0, $ttl);
3282 3465
 			}
@@ -3286,10 +3469,11 @@  discard block
 block discarded – undo
3286 3469
 			if (function_exists('apc_store'))
3287 3470
 			{
3288 3471
 				// An extended key is needed to counteract a bug in APC.
3289
-				if ($value === null)
3290
-					apc_delete($key . 'smf');
3291
-				else
3292
-					apc_store($key . 'smf', $value, $ttl);
3472
+				if ($value === null) {
3473
+									apc_delete($key . 'smf');
3474
+				} else {
3475
+									apc_store($key . 'smf', $value, $ttl);
3476
+				}
3293 3477
 			}
3294 3478
 			break;
3295 3479
 		case 'apcu':
@@ -3297,57 +3481,65 @@  discard block
 block discarded – undo
3297 3481
 			if (function_exists('apcu_store'))
3298 3482
 			{
3299 3483
 				// Not sure if this bug exists in APCu or not?
3300
-				if ($value === null)
3301
-					apcu_delete($key . 'smf');
3302
-				else
3303
-					apcu_store($key . 'smf', $value, $ttl);
3484
+				if ($value === null) {
3485
+									apcu_delete($key . 'smf');
3486
+				} else {
3487
+									apcu_store($key . 'smf', $value, $ttl);
3488
+				}
3304 3489
 			}
3305 3490
 			break;
3306 3491
 		case 'zend':
3307 3492
 			// Zend Platform/ZPS/etc.
3308
-			if (function_exists('zend_shm_cache_store'))
3309
-				zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3310
-			elseif (function_exists('output_cache_put'))
3311
-				output_cache_put($key, $value);
3493
+			if (function_exists('zend_shm_cache_store')) {
3494
+							zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3495
+			} elseif (function_exists('output_cache_put')) {
3496
+							output_cache_put($key, $value);
3497
+			}
3312 3498
 			break;
3313 3499
 		case 'xcache':
3314 3500
 			if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0)
3315 3501
 			{
3316
-				if ($value === null)
3317
-					xcache_unset($key);
3318
-				else
3319
-					xcache_set($key, $value, $ttl);
3502
+				if ($value === null) {
3503
+									xcache_unset($key);
3504
+				} else {
3505
+									xcache_set($key, $value, $ttl);
3506
+				}
3320 3507
 			}
3321 3508
 			break;
3322 3509
 		default:
3323 3510
 			// Otherwise custom cache?
3324
-			if ($value === null)
3325
-				@unlink($cachedir . '/data_' . $key . '.php');
3326
-			else
3511
+			if ($value === null) {
3512
+							@unlink($cachedir . '/data_' . $key . '.php');
3513
+			} else
3327 3514
 			{
3328 3515
 				$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
3329 3516
 
3330 3517
 				// Write out the cache file, check that the cache write was successful; all the data must be written
3331 3518
 				// If it fails due to low diskspace, or other, remove the cache file
3332
-				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
3333
-					@unlink($cachedir . '/data_' . $key . '.php');
3519
+				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) {
3520
+									@unlink($cachedir . '/data_' . $key . '.php');
3521
+				}
3334 3522
 			}
3335 3523
 			break;
3336 3524
 	}
3337 3525
 
3338
-	if (function_exists('call_integration_hook'))
3339
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3526
+	if (function_exists('call_integration_hook')) {
3527
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3528
+	}
3340 3529
 
3341
-	if (isset($db_show_debug) && $db_show_debug === true)
3342
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3530
+	if (isset($db_show_debug) && $db_show_debug === true) {
3531
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3532
+	}
3343 3533
 
3344 3534
 	// Invalidate the opcode cache
3345
-	if (function_exists('opcache_invalidate'))
3346
-   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3535
+	if (function_exists('opcache_invalidate')) {
3536
+	   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3537
+	}
3347 3538
 
3348
-	if (function_exists('apc_delete_file'))
3349
-   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3350
-}
3539
+	if (function_exists('apc_delete_file')) {
3540
+	   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3541
+	}
3542
+	}
3351 3543
 
3352 3544
 /**
3353 3545
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3364,8 +3556,9 @@  discard block
 block discarded – undo
3364 3556
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug, $cachedir;
3365 3557
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3366 3558
 
3367
-	if (empty($cache_enable))
3368
-		return;
3559
+	if (empty($cache_enable)) {
3560
+			return;
3561
+	}
3369 3562
 
3370 3563
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3371 3564
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3384,37 +3577,42 @@  discard block
 block discarded – undo
3384 3577
 			if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($cache_memcached) && trim($cache_memcached) != '')
3385 3578
 			{
3386 3579
 				// Not connected yet?
3387
-				if (empty($memcached))
3388
-					get_memcached_server();
3580
+				if (empty($memcached)) {
3581
+									get_memcached_server();
3582
+				}
3389 3583
 				if (!$memcached)
3390 3584
 				{
3391 3585
 					$cache_misses_count = isset($cache_misses) ? $cache_misses + 1 : 1;
3392 3586
 					$value = null;
3587
+				} else {
3588
+									$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3393 3589
 				}
3394
-				else
3395
-					$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3396 3590
 			}
3397 3591
 			break;
3398 3592
 		case 'apc':
3399 3593
 			// This is the free APC from PECL.
3400
-			if (function_exists('apc_fetch'))
3401
-				$value = apc_fetch($key . 'smf');
3594
+			if (function_exists('apc_fetch')) {
3595
+							$value = apc_fetch($key . 'smf');
3596
+			}
3402 3597
 			break;
3403 3598
 		case 'apcu':
3404 3599
 			// APC User Cache. A continuation of the now-unsupported APC but without opcode cache
3405
-			if (function_exists('apcu_fetch'))
3406
-				$value = apcu_fetch($key . 'smf');
3600
+			if (function_exists('apcu_fetch')) {
3601
+							$value = apcu_fetch($key . 'smf');
3602
+			}
3407 3603
 			break;
3408 3604
 		case 'zend':
3409 3605
 			// Zend's pricey stuff.
3410
-			if (function_exists('zend_shm_cache_fetch'))
3411
-				$value = zend_shm_cache_fetch('SMF::' . $key);
3412
-			elseif (function_exists('output_cache_get'))
3413
-				$value = output_cache_get($key, $ttl);
3606
+			if (function_exists('zend_shm_cache_fetch')) {
3607
+							$value = zend_shm_cache_fetch('SMF::' . $key);
3608
+			} elseif (function_exists('output_cache_get')) {
3609
+							$value = output_cache_get($key, $ttl);
3610
+			}
3414 3611
 			break;
3415 3612
 		case 'xcache':
3416
-			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0)
3417
-				$value = xcache_get($key);
3613
+			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
3614
+							$value = xcache_get($key);
3615
+			}
3418 3616
 			break;
3419 3617
 		default:
3420 3618
 			// Otherwise it's SMF data!
@@ -3422,8 +3620,9 @@  discard block
 block discarded – undo
3422 3620
 			{
3423 3621
 				// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
3424 3622
 				// causing newer files to take effect a while later.
3425
-				if (function_exists('opcache_invalidate'))
3426
-					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3623
+				if (function_exists('opcache_invalidate')) {
3624
+									opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3625
+				}
3427 3626
 
3428 3627
 				// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
3429 3628
 				@include($cachedir . '/data_' . $key . '.php');
@@ -3443,16 +3642,18 @@  discard block
 block discarded – undo
3443 3642
 
3444 3643
 		if (empty($value))
3445 3644
 		{
3446
-			if (!isset($cache_misses))
3447
-				$cache_misses = array();
3645
+			if (!isset($cache_misses)) {
3646
+							$cache_misses = array();
3647
+			}
3448 3648
 
3449 3649
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3450 3650
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3451 3651
 		}
3452 3652
 	}
3453 3653
 
3454
-	if (function_exists('call_integration_hook') && isset($value))
3455
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3654
+	if (function_exists('call_integration_hook') && isset($value)) {
3655
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3656
+	}
3456 3657
 
3457 3658
 	return empty($value) ? null : smf_json_decode($value, true);
3458 3659
 }
@@ -3476,9 +3677,9 @@  discard block
 block discarded – undo
3476 3677
 	$port = 0;
3477 3678
 
3478 3679
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3479
-	if(strpos($server,'/') !== false)
3480
-		$host = $server;
3481
-	else
3680
+	if(strpos($server,'/') !== false) {
3681
+			$host = $server;
3682
+	} else
3482 3683
 	{
3483 3684
 		$server = explode(':', $server);
3484 3685
 		$host = $server[0];
@@ -3493,22 +3694,26 @@  discard block
 block discarded – undo
3493 3694
 	// Don't wait too long: yes, we want the server, but we might be able to run the query faster!
3494 3695
 	if (empty($db_persist))
3495 3696
 	{
3496
-		if ($cache === 'memcached')
3497
-			$memcached = memcached_connect($host, $port);
3498
-		if ($cache === 'memcache')
3499
-			$memcached = memcache_connect($host, $port);
3500
-	}
3501
-	else
3697
+		if ($cache === 'memcached') {
3698
+					$memcached = memcached_connect($host, $port);
3699
+		}
3700
+		if ($cache === 'memcache') {
3701
+					$memcached = memcache_connect($host, $port);
3702
+		}
3703
+	} else
3502 3704
 	{
3503
-		if ($cache === 'memcached')
3504
-			$memcached = memcached_pconnect($host, $port);
3505
-		if ($cache === 'memcache')
3506
-			$memcached = memcache_pconnect($host, $port);
3705
+		if ($cache === 'memcached') {
3706
+					$memcached = memcached_pconnect($host, $port);
3707
+		}
3708
+		if ($cache === 'memcache') {
3709
+					$memcached = memcache_pconnect($host, $port);
3710
+		}
3507 3711
 	}
3508 3712
 
3509
-	if (!$memcached && $level > 0)
3510
-		get_memcached_server($level - 1);
3511
-}
3713
+	if (!$memcached && $level > 0) {
3714
+			get_memcached_server($level - 1);
3715
+	}
3716
+	}
3512 3717
 
3513 3718
 /**
3514 3719
  * Helper function to set an array of data for an user's avatar.
@@ -3526,8 +3731,9 @@  discard block
 block discarded – undo
3526 3731
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3527 3732
 
3528 3733
 	// Come on!
3529
-	if (empty($data))
3530
-		return array();
3734
+	if (empty($data)) {
3735
+			return array();
3736
+	}
3531 3737
 
3532 3738
 	// Set a nice default var.
3533 3739
 	$image = '';
@@ -3535,11 +3741,11 @@  discard block
 block discarded – undo
3535 3741
 	// Gravatar has been set as mandatory!
3536 3742
 	if (!empty($modSettings['gravatarOverride']))
3537 3743
 	{
3538
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3539
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3540
-
3541
-		else if (!empty($data['email']))
3542
-			$image = get_gravatar_url($data['email']);
3744
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3745
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3746
+		} else if (!empty($data['email'])) {
3747
+					$image = get_gravatar_url($data['email']);
3748
+		}
3543 3749
 	}
3544 3750
 
3545 3751
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3551,54 +3757,60 @@  discard block
 block discarded – undo
3551 3757
 			// Gravatar.
3552 3758
 			if (stristr($data['avatar'], 'gravatar://'))
3553 3759
 			{
3554
-				if ($data['avatar'] == 'gravatar://')
3555
-					$image = get_gravatar_url($data['email']);
3556
-
3557
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3558
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3760
+				if ($data['avatar'] == 'gravatar://') {
3761
+									$image = get_gravatar_url($data['email']);
3762
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3763
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3764
+				}
3559 3765
 			}
3560 3766
 
3561 3767
 			// External url.
3562 3768
 			else
3563 3769
 			{
3564 3770
 				// Using ssl?
3565
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3566
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3771
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3772
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3773
+				}
3567 3774
 
3568 3775
 				// Just a plain external url.
3569
-				else
3570
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3776
+				else {
3777
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3778
+				}
3571 3779
 			}
3572 3780
 		}
3573 3781
 
3574 3782
 		// Perhaps this user has an attachment as avatar...
3575
-		else if (!empty($data['filename']))
3576
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3783
+		else if (!empty($data['filename'])) {
3784
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3785
+		}
3577 3786
 
3578 3787
 		// Right... no avatar... use our default image.
3579
-		else
3580
-			$image = $modSettings['avatar_url'] . '/default.png';
3788
+		else {
3789
+					$image = $modSettings['avatar_url'] . '/default.png';
3790
+		}
3581 3791
 	}
3582 3792
 
3583 3793
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3584 3794
 
3585 3795
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3586
-	if (!empty($image))
3587
-		return array(
3796
+	if (!empty($image)) {
3797
+			return array(
3588 3798
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3589 3799
 			'image' => '<img class="avatar" src="' . $image . '" />',
3590 3800
 			'href' => $image,
3591 3801
 			'url' => $image,
3592 3802
 		);
3803
+	}
3593 3804
 
3594 3805
 	// Fallback to make life easier for everyone...
3595
-	else
3596
-		return array(
3806
+	else {
3807
+			return array(
3597 3808
 			'name' => '',
3598 3809
 			'image' => '',
3599 3810
 			'href' => '',
3600 3811
 			'url' => '',
3601 3812
 		);
3602
-}
3813
+	}
3814
+	}
3603 3815
 
3604 3816
 ?>
3605 3817
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/SearchAPI-Standard.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Standard non full index, non custom index search
Please login to merge, or discard this patch.
Sources/ManageMembergroups.php 1 patch
Braces   +131 added lines, -90 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 
20 21
 /**
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
45 46
 
46 47
 	// Is it elsewhere?
47
-	if (isset($subActions[$_REQUEST['sa']][2]))
48
-		require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
48
+	if (isset($subActions[$_REQUEST['sa']][2])) {
49
+			require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
50
+	}
49 51
 
50 52
 	// Do the permission check, you might not be allowed her.
51 53
 	isAllowedTo($subActions[$_REQUEST['sa']][1]);
@@ -104,19 +106,20 @@  discard block
 block discarded – undo
104 106
 					'function' => function ($rowData) use ($scripturl)
105 107
 					{
106 108
 						// Since the moderator group has no explicit members, no link is needed.
107
-						if ($rowData['id_group'] == 3)
108
-							$group_name = $rowData['group_name'];
109
-						else
109
+						if ($rowData['id_group'] == 3) {
110
+													$group_name = $rowData['group_name'];
111
+						} else
110 112
 						{
111 113
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
112 114
 							$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
113 115
 						}
114 116
 
115 117
 						// Add a help option for moderator and administrator.
116
-						if ($rowData['id_group'] == 1)
117
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
-						elseif ($rowData['id_group'] == 3)
119
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
+						if ($rowData['id_group'] == 1) {
119
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
120
+						} elseif ($rowData['id_group'] == 3) {
121
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
122
+						}
120 123
 
121 124
 						return $group_name;
122 125
 					},
@@ -330,12 +333,14 @@  discard block
 block discarded – undo
330 333
 		call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
331 334
 
332 335
 		// Update the post groups now, if this is a post group!
333
-		if (isset($_POST['min_posts']))
334
-			updateStats('postgroups');
336
+		if (isset($_POST['min_posts'])) {
337
+					updateStats('postgroups');
338
+		}
335 339
 
336 340
 		// You cannot set permissions for post groups if they are disabled.
337
-		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
338
-			$_POST['perm_type'] = '';
341
+		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
342
+					$_POST['perm_type'] = '';
343
+		}
339 344
 
340 345
 		if ($_POST['perm_type'] == 'predefined')
341 346
 		{
@@ -365,8 +370,9 @@  discard block
 block discarded – undo
365 370
 				$smcFunc['db_free_result']($request);
366 371
 
367 372
 				// Protected groups are... well, protected!
368
-				if ($copy_type == 1)
369
-					fatal_lang_error('membergroup_does_not_exist');
373
+				if ($copy_type == 1) {
374
+									fatal_lang_error('membergroup_does_not_exist');
375
+				}
370 376
 			}
371 377
 
372 378
 			// Don't allow copying of a real priviledged person!
@@ -384,18 +390,20 @@  discard block
 block discarded – undo
384 390
 			$inserts = array();
385 391
 			while ($row = $smcFunc['db_fetch_assoc']($request))
386 392
 			{
387
-				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
388
-					$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
393
+				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) {
394
+									$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
395
+				}
389 396
 			}
390 397
 			$smcFunc['db_free_result']($request);
391 398
 
392
-			if (!empty($inserts))
393
-				$smcFunc['db_insert']('insert',
399
+			if (!empty($inserts)) {
400
+							$smcFunc['db_insert']('insert',
394 401
 					'{db_prefix}permissions',
395 402
 					array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
396 403
 					$inserts,
397 404
 					array('id_group', 'permission')
398 405
 				);
406
+			}
399 407
 
400 408
 			$request = $smcFunc['db_query']('', '
401 409
 				SELECT id_profile, permission, add_deny
@@ -406,17 +414,19 @@  discard block
 block discarded – undo
406 414
 				)
407 415
 			);
408 416
 			$inserts = array();
409
-			while ($row = $smcFunc['db_fetch_assoc']($request))
410
-				$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
417
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
418
+							$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
419
+			}
411 420
 			$smcFunc['db_free_result']($request);
412 421
 
413
-			if (!empty($inserts))
414
-				$smcFunc['db_insert']('insert',
422
+			if (!empty($inserts)) {
423
+							$smcFunc['db_insert']('insert',
415 424
 					'{db_prefix}board_permissions',
416 425
 					array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
417 426
 					$inserts,
418 427
 					array('id_group', 'id_profile', 'permission')
419 428
 				);
429
+			}
420 430
 
421 431
 			// Also get some membergroup information if we're copying and not copying from guests...
422 432
 			if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
@@ -469,14 +479,15 @@  discard block
 block discarded – undo
469 479
 		$changed_boards['allow'] = array();
470 480
 		$changed_boards['deny'] = array();
471 481
 		$changed_boards['ignore'] = array();
472
-		foreach ($accesses as $group_id => $action)
473
-			$changed_boards[$action][] = (int) $group_id;
482
+		foreach ($accesses as $group_id => $action) {
483
+					$changed_boards[$action][] = (int) $group_id;
484
+		}
474 485
 
475 486
 		foreach (array('allow', 'deny') as $board_action)
476 487
 		{
477 488
 			// Only do this if they have special access requirements.
478
-			if (!empty($changed_boards[$board_action]))
479
-				$smcFunc['db_query']('', '
489
+			if (!empty($changed_boards[$board_action])) {
490
+							$smcFunc['db_query']('', '
480 491
 					UPDATE {db_prefix}boards
481 492
 					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
482 493
 					WHERE id_board IN ({array_int:board_list})',
@@ -488,11 +499,13 @@  discard block
 block discarded – undo
488 499
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
489 500
 					)
490 501
 				);
502
+			}
491 503
 		}
492 504
 
493 505
 		// If this is joinable then set it to show group membership in people's profiles.
494
-		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
495
-			updateSettings(array('show_group_membership' => 1));
506
+		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
507
+					updateSettings(array('show_group_membership' => 1));
508
+		}
496 509
 
497 510
 		// Rebuild the group cache.
498 511
 		updateSettings(array(
@@ -513,8 +526,9 @@  discard block
 block discarded – undo
513 526
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
514 527
 	$context['allow_protected'] = allowedTo('admin_forum');
515 528
 
516
-	if (!empty($modSettings['deny_boards_access']))
517
-		loadLanguage('ManagePermissions');
529
+	if (!empty($modSettings['deny_boards_access'])) {
530
+			loadLanguage('ManagePermissions');
531
+	}
518 532
 
519 533
 	$result = $smcFunc['db_query']('', '
520 534
 		SELECT id_group, group_name
@@ -531,11 +545,12 @@  discard block
 block discarded – undo
531 545
 		)
532 546
 	);
533 547
 	$context['groups'] = array();
534
-	while ($row = $smcFunc['db_fetch_assoc']($result))
535
-		$context['groups'][] = array(
548
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
549
+			$context['groups'][] = array(
536 550
 			'id' => $row['id_group'],
537 551
 			'name' => $row['group_name']
538 552
 		);
553
+	}
539 554
 	$smcFunc['db_free_result']($result);
540 555
 
541 556
 	$request = $smcFunc['db_query']('', '
@@ -552,12 +567,13 @@  discard block
 block discarded – undo
552 567
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 568
 	{
554 569
 		// This category hasn't been set up yet..
555
-		if (!isset($context['categories'][$row['id_cat']]))
556
-			$context['categories'][$row['id_cat']] = array(
570
+		if (!isset($context['categories'][$row['id_cat']])) {
571
+					$context['categories'][$row['id_cat']] = array(
557 572
 				'id' => $row['id_cat'],
558 573
 				'name' => $row['cat_name'],
559 574
 				'boards' => array()
560 575
 			);
576
+		}
561 577
 
562 578
 		// Set this board up, and let the template know when it's a child.  (indent them..)
563 579
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -605,8 +621,9 @@  discard block
 block discarded – undo
605 621
 	require_once($sourcedir . '/Subs-Membergroups.php');
606 622
 	$result = deleteMembergroups((int) $_REQUEST['group']);
607 623
 	// Need to throw a warning if it went wrong, but this is the only one we have a message for...
608
-	if ($result === 'group_cannot_delete_sub')
609
-		fatal_lang_error('membergroups_cannot_delete_paid', false);
624
+	if ($result === 'group_cannot_delete_sub') {
625
+			fatal_lang_error('membergroups_cannot_delete_paid', false);
626
+	}
610 627
 
611 628
 	// Go back to the membergroup index.
612 629
 	redirectexit('action=admin;area=membergroups;');
@@ -628,8 +645,9 @@  discard block
 block discarded – undo
628 645
 
629 646
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
630 647
 
631
-	if (!empty($modSettings['deny_boards_access']))
632
-		loadLanguage('ManagePermissions');
648
+	if (!empty($modSettings['deny_boards_access'])) {
649
+			loadLanguage('ManagePermissions');
650
+	}
633 651
 
634 652
 	// Make sure this group is editable.
635 653
 	if (!empty($_REQUEST['group']))
@@ -651,8 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Now, do we have a valid id?
654
-	if (empty($_REQUEST['group']))
655
-		fatal_lang_error('membergroup_does_not_exist', false);
672
+	if (empty($_REQUEST['group'])) {
673
+			fatal_lang_error('membergroup_does_not_exist', false);
674
+	}
656 675
 
657 676
 	// People who can manage boards are a bit special.
658 677
 	require_once($sourcedir . '/Subs-Members.php');
@@ -683,8 +702,9 @@  discard block
 block discarded – undo
683 702
 		require_once($sourcedir . '/Subs-Membergroups.php');
684 703
 		$result = deleteMembergroups($_REQUEST['group']);
685 704
 		// Need to throw a warning if it went wrong, but this is the only one we have a message for...
686
-		if ($result === 'group_cannot_delete_sub')
687
-			fatal_lang_error('membergroups_cannot_delete_paid', false);
705
+		if ($result === 'group_cannot_delete_sub') {
706
+					fatal_lang_error('membergroups_cannot_delete_paid', false);
707
+		}
688 708
 
689 709
 		redirectexit('action=admin;area=membergroups;');
690 710
 	}
@@ -761,16 +781,18 @@  discard block
 block discarded – undo
761 781
 				$request = $smcFunc['db_query']('', '
762 782
 					SELECT id_board
763 783
 					FROM {db_prefix}boards');
764
-				while ($row = $smcFunc['db_fetch_assoc']($request))
765
-					$accesses[(int) $row['id_board']] = 'allow';
784
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
785
+									$accesses[(int) $row['id_board']] = 'allow';
786
+				}
766 787
 				$smcFunc['db_free_result']($request);
767 788
 			}
768 789
 
769 790
 			$changed_boards['allow'] = array();
770 791
 			$changed_boards['deny'] = array();
771 792
 			$changed_boards['ignore'] = array();
772
-			foreach ($accesses as $group_id => $action)
773
-				$changed_boards[$action][] = (int) $group_id;
793
+			foreach ($accesses as $group_id => $action) {
794
+							$changed_boards[$action][] = (int) $group_id;
795
+			}
774 796
 
775 797
 			foreach (array('allow', 'deny') as $board_action)
776 798
 			{
@@ -786,8 +808,8 @@  discard block
 block discarded – undo
786 808
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
787 809
 					)
788 810
 				);
789
-				while ($row = $smcFunc['db_fetch_assoc']($request))
790
-					$smcFunc['db_query']('', '
811
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
812
+									$smcFunc['db_query']('', '
791 813
 						UPDATE {db_prefix}boards
792 814
 						SET {raw:column} = {string:member_group_access}
793 815
 						WHERE id_board = {int:current_board}',
@@ -797,11 +819,12 @@  discard block
 block discarded – undo
797 819
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
798 820
 						)
799 821
 					);
822
+				}
800 823
 				$smcFunc['db_free_result']($request);
801 824
 
802 825
 				// Add the membergroup to all boards that hadn't been set yet.
803
-				if (!empty($changed_boards[$board_action]))
804
-					$smcFunc['db_query']('', '
826
+				if (!empty($changed_boards[$board_action])) {
827
+									$smcFunc['db_query']('', '
805 828
 						UPDATE {db_prefix}boards
806 829
 						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
807 830
 						WHERE id_board IN ({array_int:board_list})
@@ -815,6 +838,7 @@  discard block
 block discarded – undo
815 838
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
816 839
 						)
817 840
 					);
841
+				}
818 842
 			}
819 843
 		}
820 844
 
@@ -840,12 +864,14 @@  discard block
 block discarded – undo
840 864
 				)
841 865
 			);
842 866
 			$updates = array();
843
-			while ($row = $smcFunc['db_fetch_assoc']($request))
844
-				$updates[$row['additional_groups']][] = $row['id_member'];
867
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
868
+							$updates[$row['additional_groups']][] = $row['id_member'];
869
+			}
845 870
 			$smcFunc['db_free_result']($request);
846 871
 
847
-			foreach ($updates as $additional_groups => $memberArray)
848
-				updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
872
+			foreach ($updates as $additional_groups => $memberArray) {
873
+							updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
874
+			}
849 875
 
850 876
 			// Sorry, but post groups can't moderate boards
851 877
 			$request = $smcFunc['db_query']('', '
@@ -855,8 +881,7 @@  discard block
 block discarded – undo
855 881
 					'current_group' => (int) $_REQUEST['group'],
856 882
 				)
857 883
 			);
858
-		}
859
-		elseif ($_REQUEST['group'] != 3)
884
+		} elseif ($_REQUEST['group'] != 3)
860 885
 		{
861 886
 			// Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
862 887
 			if ($_POST['group_hidden'] == 2)
@@ -871,8 +896,9 @@  discard block
 block discarded – undo
871 896
 					)
872 897
 				);
873 898
 				$updates = array();
874
-				while ($row = $smcFunc['db_fetch_assoc']($request))
875
-					$updates[$row['additional_groups']][] = $row['id_member'];
899
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
900
+									$updates[$row['additional_groups']][] = $row['id_member'];
901
+				}
876 902
 				$smcFunc['db_free_result']($request);
877 903
 
878 904
 				foreach ($updates as $additional_groups => $memberArray)
@@ -914,8 +940,9 @@  discard block
 block discarded – undo
914 940
 			$smcFunc['db_free_result']($request);
915 941
 
916 942
 			// Do we need to update the setting?
917
-			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
918
-				updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
943
+			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) {
944
+							updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
945
+			}
919 946
 		}
920 947
 
921 948
 		// Do we need to set inherited permissions?
@@ -948,8 +975,9 @@  discard block
 block discarded – undo
948 975
 				{
949 976
 					$moderators[$k] = trim($moderators[$k]);
950 977
 
951
-					if (strlen($moderators[$k]) == 0)
952
-						unset($moderators[$k]);
978
+					if (strlen($moderators[$k]) == 0) {
979
+											unset($moderators[$k]);
980
+					}
953 981
 				}
954 982
 
955 983
 				// Find all the id_member's for the member_name's in the list.
@@ -965,8 +993,9 @@  discard block
 block discarded – undo
965 993
 							'count' => count($moderators),
966 994
 						)
967 995
 					);
968
-					while ($row = $smcFunc['db_fetch_assoc']($request))
969
-						$group_moderators[] = $row['id_member'];
996
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
997
+											$group_moderators[] = $row['id_member'];
998
+					}
970 999
 					$smcFunc['db_free_result']($request);
971 1000
 				}
972 1001
 			}
@@ -974,8 +1003,9 @@  discard block
 block discarded – undo
974 1003
 			if (!empty($_POST['moderator_list']))
975 1004
 			{
976 1005
 				$moderators = array();
977
-				foreach ($_POST['moderator_list'] as $moderator)
978
-					$moderators[] = (int) $moderator;
1006
+				foreach ($_POST['moderator_list'] as $moderator) {
1007
+									$moderators[] = (int) $moderator;
1008
+				}
979 1009
 
980 1010
 				if (!empty($moderators))
981 1011
 				{
@@ -989,8 +1019,9 @@  discard block
 block discarded – undo
989 1019
 							'num_moderators' => count($moderators),
990 1020
 						)
991 1021
 					);
992
-					while ($row = $smcFunc['db_fetch_assoc']($request))
993
-						$group_moderators[] = $row['id_member'];
1022
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
1023
+											$group_moderators[] = $row['id_member'];
1024
+					}
994 1025
 					$smcFunc['db_free_result']($request);
995 1026
 				}
996 1027
 			}
@@ -1002,8 +1033,9 @@  discard block
 block discarded – undo
1002 1033
 			if (!empty($group_moderators))
1003 1034
 			{
1004 1035
 				$mod_insert = array();
1005
-				foreach ($group_moderators as $moderator)
1006
-					$mod_insert[] = array($_REQUEST['group'], $moderator);
1036
+				foreach ($group_moderators as $moderator) {
1037
+									$mod_insert[] = array($_REQUEST['group'], $moderator);
1038
+				}
1007 1039
 
1008 1040
 				$smcFunc['db_insert']('insert',
1009 1041
 					'{db_prefix}group_moderators',
@@ -1037,8 +1069,9 @@  discard block
 block discarded – undo
1037 1069
 			'current_group' => (int) $_REQUEST['group'],
1038 1070
 		)
1039 1071
 	);
1040
-	if ($smcFunc['db_num_rows']($request) == 0)
1041
-		fatal_lang_error('membergroup_does_not_exist', false);
1072
+	if ($smcFunc['db_num_rows']($request) == 0) {
1073
+			fatal_lang_error('membergroup_does_not_exist', false);
1074
+	}
1042 1075
 	$row = $smcFunc['db_fetch_assoc']($request);
1043 1076
 	$smcFunc['db_free_result']($request);
1044 1077
 
@@ -1075,14 +1108,16 @@  discard block
 block discarded – undo
1075 1108
 		)
1076 1109
 	);
1077 1110
 	$context['group']['moderators'] = array();
1078
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1079
-		$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1111
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1112
+			$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1113
+	}
1080 1114
 	$smcFunc['db_free_result']($request);
1081 1115
 
1082 1116
 	$context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
1083 1117
 
1084
-	if (!empty($context['group']['moderators']))
1085
-		list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1118
+	if (!empty($context['group']['moderators'])) {
1119
+			list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1120
+	}
1086 1121
 
1087 1122
 	// Get a list of boards this membergroup is allowed to see.
1088 1123
 	$context['boards'] = array();
@@ -1102,12 +1137,13 @@  discard block
 block discarded – undo
1102 1137
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1103 1138
 		{
1104 1139
 			// This category hasn't been set up yet..
1105
-			if (!isset($context['categories'][$row['id_cat']]))
1106
-				$context['categories'][$row['id_cat']] = array(
1140
+			if (!isset($context['categories'][$row['id_cat']])) {
1141
+							$context['categories'][$row['id_cat']] = array(
1107 1142
 					'id' => $row['id_cat'],
1108 1143
 					'name' => $row['cat_name'],
1109 1144
 					'boards' => array()
1110 1145
 				);
1146
+			}
1111 1147
 
1112 1148
 			// Set this board up, and let the template know when it's a child.  (indent them..)
1113 1149
 			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -1135,8 +1171,9 @@  discard block
 block discarded – undo
1135 1171
 		}
1136 1172
 
1137 1173
 		$max_boards = ceil(count($temp_boards) / 2);
1138
-		if ($max_boards == 1)
1139
-			$max_boards = 2;
1174
+		if ($max_boards == 1) {
1175
+					$max_boards = 2;
1176
+		}
1140 1177
 	}
1141 1178
 
1142 1179
 	// Get a list of all the image formats we can select.
@@ -1159,19 +1196,22 @@  discard block
 block discarded – undo
1159 1196
 				$image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value);
1160 1197
 
1161 1198
 				// If this is bigger than 128 in width or 32 in height, skip this one.
1162
-				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
1163
-					continue;
1199
+				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) {
1200
+									continue;
1201
+				}
1164 1202
 
1165 1203
 				// Else it's valid. Add it in.
1166
-				else
1167
-					$context['possible_icons'][] = $value;
1204
+				else {
1205
+									$context['possible_icons'][] = $value;
1206
+				}
1168 1207
 			}
1169 1208
 		}
1170 1209
 	}
1171 1210
 
1172 1211
 	// Insert our JS, if we have possible icons.
1173
-	if (!empty($context['possible_icons']))
1174
-		loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1212
+	if (!empty($context['possible_icons'])) {
1213
+			loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown');
1214
+	}
1175 1215
 
1176 1216
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
1177 1217
 
@@ -1193,8 +1233,9 @@  discard block
 block discarded – undo
1193 1233
 		)
1194 1234
 	);
1195 1235
 	$context['inheritable_groups'] = array();
1196
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1197
-		$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1236
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1237
+			$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1238
+	}
1198 1239
 	$smcFunc['db_free_result']($request);
1199 1240
 
1200 1241
 	call_integration_hook('integrate_view_membergroup');
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" class="new_win" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = smf_json_decode($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = smf_json_decode($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Poll.php 1 patch
Braces   +163 added lines, -119 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Allow the user to vote.
@@ -51,8 +52,9 @@  discard block
 block discarded – undo
51 52
 			'not_guest' => 0,
52 53
 		)
53 54
 	);
54
-	if ($smcFunc['db_num_rows']($request) == 0)
55
-		fatal_lang_error('poll_error', false);
55
+	if ($smcFunc['db_num_rows']($request) == 0) {
56
+			fatal_lang_error('poll_error', false);
57
+	}
56 58
 	$row = $smcFunc['db_fetch_assoc']($request);
57 59
 	$smcFunc['db_free_result']($request);
58 60
 
@@ -60,8 +62,9 @@  discard block
 block discarded – undo
60 62
 	if ($user_info['is_guest'])
61 63
 	{
62 64
 		// Guest voting disabled?
63
-		if (!$row['guest_vote'])
64
-			fatal_lang_error('guest_vote_disabled');
65
+		if (!$row['guest_vote']) {
66
+					fatal_lang_error('guest_vote_disabled');
67
+		}
65 68
 		// Guest already voted?
66 69
 		elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false)
67 70
 		{
@@ -71,32 +74,36 @@  discard block
 block discarded – undo
71 74
 			foreach ($guestinfo as $i => $guestvoted)
72 75
 			{
73 76
 				$guestvoted = explode(',', $guestvoted);
74
-				if ($guestvoted[0] == $row['id_poll'])
75
-					break;
77
+				if ($guestvoted[0] == $row['id_poll']) {
78
+									break;
79
+				}
76 80
 			}
77 81
 			// Has the poll been reset since guest voted?
78 82
 			if ($row['reset_poll'] > $guestvoted[1])
79 83
 			{
80 84
 				// Remove the poll info from the cookie to allow guest to vote again
81 85
 				unset($guestinfo[$i]);
82
-				if (!empty($guestinfo))
83
-					$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
84
-				else
85
-					unset($_COOKIE['guest_poll_vote']);
86
+				if (!empty($guestinfo)) {
87
+									$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
88
+				} else {
89
+									unset($_COOKIE['guest_poll_vote']);
90
+				}
91
+			} else {
92
+							fatal_lang_error('poll_error', false);
86 93
 			}
87
-			else
88
-				fatal_lang_error('poll_error', false);
89 94
 			unset($guestinfo, $guestvoted, $i);
90 95
 		}
91 96
 	}
92 97
 
93 98
 	// Is voting locked or has it expired?
94
-	if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
95
-		fatal_lang_error('poll_error', false);
99
+	if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
100
+			fatal_lang_error('poll_error', false);
101
+	}
96 102
 
97 103
 	// If they have already voted and aren't allowed to change their vote - hence they are outta here!
98
-	if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote']))
99
-		fatal_lang_error('poll_error', false);
104
+	if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) {
105
+			fatal_lang_error('poll_error', false);
106
+	}
100 107
 	// Otherwise if they can change their vote yet they haven't sent any options... remove their vote and redirect.
101 108
 	elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options']))
102 109
 	{
@@ -114,8 +121,9 @@  discard block
 block discarded – undo
114 121
 				'id_poll' => $row['id_poll'],
115 122
 			)
116 123
 		);
117
-		while ($choice = $smcFunc['db_fetch_row']($request))
118
-			$pollOptions[] = $choice[0];
124
+		while ($choice = $smcFunc['db_fetch_row']($request)) {
125
+					$pollOptions[] = $choice[0];
126
+		}
119 127
 		$smcFunc['db_free_result']($request);
120 128
 
121 129
 		// Just skip it if they had voted for nothing before.
@@ -148,19 +156,22 @@  discard block
 block discarded – undo
148 156
 		}
149 157
 
150 158
 		// Redirect back to the topic so the user can vote again!
151
-		if (empty($_POST['options']))
152
-			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
159
+		if (empty($_POST['options'])) {
160
+					redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
161
+		}
153 162
 	}
154 163
 
155 164
 	checkSession('request');
156 165
 
157 166
 	// Make sure the option(s) are valid.
158
-	if (empty($_POST['options']))
159
-		fatal_lang_error('didnt_select_vote', false);
167
+	if (empty($_POST['options'])) {
168
+			fatal_lang_error('didnt_select_vote', false);
169
+	}
160 170
 
161 171
 	// Too many options checked!
162
-	if (count($_REQUEST['options']) > $row['max_votes'])
163
-		fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
172
+	if (count($_REQUEST['options']) > $row['max_votes']) {
173
+			fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
174
+	}
164 175
 
165 176
 	$pollOptions = array();
166 177
 	$inserts = array();
@@ -250,24 +261,30 @@  discard block
 block discarded – undo
250 261
 	list ($memberID, $pollID, $voting_locked) = $smcFunc['db_fetch_row']($request);
251 262
 
252 263
 	// If the user _can_ modify the poll....
253
-	if (!allowedTo('poll_lock_any'))
254
-		isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any'));
264
+	if (!allowedTo('poll_lock_any')) {
265
+			isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any'));
266
+	}
255 267
 
256 268
 	// It's been locked by a non-moderator.
257
-	if ($voting_locked == '1')
258
-		$voting_locked = '0';
269
+	if ($voting_locked == '1') {
270
+			$voting_locked = '0';
271
+	}
259 272
 	// Locked by a moderator, and this is a moderator.
260
-	elseif ($voting_locked == '2' && allowedTo('moderate_board'))
261
-		$voting_locked = '0';
273
+	elseif ($voting_locked == '2' && allowedTo('moderate_board')) {
274
+			$voting_locked = '0';
275
+	}
262 276
 	// Sorry, a moderator locked it.
263
-	elseif ($voting_locked == '2' && !allowedTo('moderate_board'))
264
-		fatal_lang_error('locked_by_admin', 'user');
277
+	elseif ($voting_locked == '2' && !allowedTo('moderate_board')) {
278
+			fatal_lang_error('locked_by_admin', 'user');
279
+	}
265 280
 	// A moderator *is* locking it.
266
-	elseif ($voting_locked == '0' && allowedTo('moderate_board'))
267
-		$voting_locked = '2';
281
+	elseif ($voting_locked == '0' && allowedTo('moderate_board')) {
282
+			$voting_locked = '2';
283
+	}
268 284
 	// Well, it's gonna be locked one way or another otherwise...
269
-	else
270
-		$voting_locked = '1';
285
+	else {
286
+			$voting_locked = '1';
287
+	}
271 288
 
272 289
 	// Lock!  *Poof* - no one can vote.
273 290
 	$smcFunc['db_query']('', '
@@ -302,8 +319,9 @@  discard block
 block discarded – undo
302 319
 {
303 320
 	global $txt, $user_info, $context, $topic, $board, $smcFunc, $sourcedir, $scripturl;
304 321
 
305
-	if (empty($topic))
306
-		fatal_lang_error('no_access', false);
322
+	if (empty($topic)) {
323
+			fatal_lang_error('no_access', false);
324
+	}
307 325
 
308 326
 	loadLanguage('Post');
309 327
 	loadTemplate('Poll');
@@ -327,24 +345,28 @@  discard block
 block discarded – undo
327 345
 	);
328 346
 
329 347
 	// Assume the the topic exists, right?
330
-	if ($smcFunc['db_num_rows']($request) == 0)
331
-		fatal_lang_error('no_board');
348
+	if ($smcFunc['db_num_rows']($request) == 0) {
349
+			fatal_lang_error('no_board');
350
+	}
332 351
 	// Get the poll information.
333 352
 	$pollinfo = $smcFunc['db_fetch_assoc']($request);
334 353
 	$smcFunc['db_free_result']($request);
335 354
 
336 355
 	// If we are adding a new poll - make sure that there isn't already a poll there.
337
-	if (!$context['is_edit'] && !empty($pollinfo['id_poll']))
338
-		fatal_lang_error('poll_already_exists');
356
+	if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) {
357
+			fatal_lang_error('poll_already_exists');
358
+	}
339 359
 	// Otherwise, if we're editing it, it does exist I assume?
340
-	elseif ($context['is_edit'] && empty($pollinfo['id_poll']))
341
-		fatal_lang_error('poll_not_found');
360
+	elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) {
361
+			fatal_lang_error('poll_not_found');
362
+	}
342 363
 
343 364
 	// Can you do this?
344
-	if ($context['is_edit'] && !allowedTo('poll_edit_any'))
345
-		isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
346
-	elseif (!$context['is_edit'] && !allowedTo('poll_add_any'))
347
-		isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any'));
365
+	if ($context['is_edit'] && !allowedTo('poll_edit_any')) {
366
+			isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
367
+	} elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) {
368
+			isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any'));
369
+	}
348 370
 	$context['can_moderate_poll'] = isset($_REQUEST['add']) ? true : allowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
349 371
 
350 372
 	// Do we enable guest voting?
@@ -386,12 +408,14 @@  discard block
 block discarded – undo
386 408
 			while ($row = $smcFunc['db_fetch_assoc']($request))
387 409
 			{
388 410
 				// Get the highest id so we can add more without reusing.
389
-				if ($row['id_choice'] >= $last_id)
390
-					$last_id = $row['id_choice'] + 1;
411
+				if ($row['id_choice'] >= $last_id) {
412
+									$last_id = $row['id_choice'] + 1;
413
+				}
391 414
 
392 415
 				// They cleared this by either omitting it or emptying it.
393
-				if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '')
394
-					continue;
416
+				if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') {
417
+									continue;
418
+				}
395 419
 
396 420
 				censorText($row['label']);
397 421
 
@@ -409,9 +433,10 @@  discard block
 block discarded – undo
409 433
 
410 434
 		// Work out how many options we have, so we get the 'is_last' field right...
411 435
 		$totalPostOptions = 0;
412
-		foreach ($_POST['options'] as $id => $label)
413
-			if ($label != '')
436
+		foreach ($_POST['options'] as $id => $label) {
437
+					if ($label != '')
414 438
 				$totalPostOptions++;
439
+		}
415 440
 
416 441
 		$count = 1;
417 442
 		// If an option exists, update it.  If it is new, add it - but don't reuse ids!
@@ -420,30 +445,32 @@  discard block
 block discarded – undo
420 445
 			$label = $smcFunc['htmlspecialchars']($label);
421 446
 			censorText($label);
422 447
 
423
-			if (isset($context['choices'][$id]))
424
-				$context['choices'][$id]['label'] = $label;
425
-			elseif ($label != '')
426
-				$context['choices'][] = array(
448
+			if (isset($context['choices'][$id])) {
449
+							$context['choices'][$id]['label'] = $label;
450
+			} elseif ($label != '') {
451
+							$context['choices'][] = array(
427 452
 					'id' => $last_id++,
428 453
 					'number' => $number++,
429 454
 					'label' => $label,
430 455
 					'votes' => -1,
431 456
 					'is_last' => $count++ == $totalPostOptions && $totalPostOptions > 1 ? true : false,
432 457
 				);
458
+			}
433 459
 		}
434 460
 
435 461
 		// Make sure we have two choices for sure!
436 462
 		if ($totalPostOptions < 2)
437 463
 		{
438 464
 			// Need two?
439
-			if ($totalPostOptions == 0)
440
-				$context['choices'][] = array(
465
+			if ($totalPostOptions == 0) {
466
+							$context['choices'][] = array(
441 467
 					'id' => $last_id++,
442 468
 					'number' => $number++,
443 469
 					'label' => '',
444 470
 					'votes' => -1,
445 471
 					'is_last' => false
446 472
 				);
473
+			}
447 474
 			$poll_errors[] = 'poll_few';
448 475
 		}
449 476
 
@@ -458,12 +485,14 @@  discard block
 block discarded – undo
458 485
 
459 486
 		$context['last_choice_id'] = $last_id;
460 487
 
461
-		if ($context['can_moderate_poll'])
462
-			$context['poll']['expiration'] = $_POST['poll_expire'];
488
+		if ($context['can_moderate_poll']) {
489
+					$context['poll']['expiration'] = $_POST['poll_expire'];
490
+		}
463 491
 
464 492
 		// Check the question/option count for errors.
465
-		if (trim($_POST['question']) == '' && empty($context['poll_error']))
466
-			$poll_errors[] = 'no_question';
493
+		if (trim($_POST['question']) == '' && empty($context['poll_error'])) {
494
+					$poll_errors[] = 'no_question';
495
+		}
467 496
 
468 497
 		// No check is needed, since nothing is really posted.
469 498
 		checkSubmitOnce('free');
@@ -480,8 +509,7 @@  discard block
 block discarded – undo
480 509
 				$context['poll_error']['messages'][] = $txt['error_' . $poll_error];
481 510
 			}
482 511
 		}
483
-	}
484
-	else
512
+	} else
485 513
 	{
486 514
 		// Basic theme info...
487 515
 		$context['poll'] = array(
@@ -596,18 +624,22 @@  discard block
 block discarded – undo
596 624
 	global $user_info, $smcFunc, $sourcedir;
597 625
 
598 626
 	// Sneaking off, are we?
599
-	if (empty($_POST))
600
-		redirectexit('action=editpoll;topic=' . $topic . '.0');
627
+	if (empty($_POST)) {
628
+			redirectexit('action=editpoll;topic=' . $topic . '.0');
629
+	}
601 630
 
602
-	if (checkSession('post', '', false) != '')
603
-		$poll_errors[] = 'session_timeout';
631
+	if (checkSession('post', '', false) != '') {
632
+			$poll_errors[] = 'session_timeout';
633
+	}
604 634
 
605
-	if (isset($_POST['preview']))
606
-		return EditPoll();
635
+	if (isset($_POST['preview'])) {
636
+			return EditPoll();
637
+	}
607 638
 
608 639
 	// HACKERS (!!) can't edit :P.
609
-	if (empty($topic))
610
-		fatal_lang_error('no_access', false);
640
+	if (empty($topic)) {
641
+			fatal_lang_error('no_access', false);
642
+	}
611 643
 
612 644
 	// Is this a new poll, or editing an existing?
613 645
 	$isEdit = isset($_REQUEST['add']) ? 0 : 1;
@@ -623,23 +655,27 @@  discard block
 block discarded – undo
623 655
 			'current_topic' => $topic,
624 656
 		)
625 657
 	);
626
-	if ($smcFunc['db_num_rows']($request) == 0)
627
-		fatal_lang_error('no_board');
658
+	if ($smcFunc['db_num_rows']($request) == 0) {
659
+			fatal_lang_error('no_board');
660
+	}
628 661
 	$bcinfo = $smcFunc['db_fetch_assoc']($request);
629 662
 	$smcFunc['db_free_result']($request);
630 663
 
631 664
 	// Check their adding/editing is valid.
632
-	if (!$isEdit && !empty($bcinfo['id_poll']))
633
-		fatal_lang_error('poll_already_exists');
665
+	if (!$isEdit && !empty($bcinfo['id_poll'])) {
666
+			fatal_lang_error('poll_already_exists');
667
+	}
634 668
 	// Are we editing a poll which doesn't exist?
635
-	elseif ($isEdit && empty($bcinfo['id_poll']))
636
-		fatal_lang_error('poll_not_found');
669
+	elseif ($isEdit && empty($bcinfo['id_poll'])) {
670
+			fatal_lang_error('poll_not_found');
671
+	}
637 672
 
638 673
 	// Check if they have the power to add or edit the poll.
639
-	if ($isEdit && !allowedTo('poll_edit_any'))
640
-		isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any'));
641
-	elseif (!$isEdit && !allowedTo('poll_add_any'))
642
-		isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any'));
674
+	if ($isEdit && !allowedTo('poll_edit_any')) {
675
+			isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any'));
676
+	} elseif (!$isEdit && !allowedTo('poll_add_any')) {
677
+			isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any'));
678
+	}
643 679
 
644 680
 	$optionCount = 0;
645 681
 	$idCount = 0;
@@ -652,14 +688,16 @@  discard block
 block discarded – undo
652 688
 			$idCount = max($idCount, $k);
653 689
 		}
654 690
 	}
655
-	if ($optionCount < 2)
656
-		$poll_errors[] = 'poll_few';
657
-	elseif ($optionCount > 256 || $idCount > 255)
658
-		$poll_errors[] = 'poll_many';
691
+	if ($optionCount < 2) {
692
+			$poll_errors[] = 'poll_few';
693
+	} elseif ($optionCount > 256 || $idCount > 255) {
694
+			$poll_errors[] = 'poll_many';
695
+	}
659 696
 
660 697
 	// Also - ensure they are not removing the question.
661
-	if (trim($_POST['question']) == '')
662
-		$poll_errors[] = 'no_question';
698
+	if (trim($_POST['question']) == '') {
699
+			$poll_errors[] = 'no_question';
700
+	}
663 701
 
664 702
 	// Got any errors to report?
665 703
 	if (!empty($poll_errors))
@@ -695,8 +733,9 @@  discard block
 block discarded – undo
695 733
 	{
696 734
 		require_once($sourcedir . '/Subs-Members.php');
697 735
 		$allowedGroups = groupsAllowedTo('poll_vote', $board);
698
-		if (!in_array(-1, $allowedGroups['allowed']))
699
-			$_POST['poll_guest_vote'] = 0;
736
+		if (!in_array(-1, $allowedGroups['allowed'])) {
737
+					$_POST['poll_guest_vote'] = 0;
738
+		}
700 739
 	}
701 740
 
702 741
 	// Ensure that the number options allowed makes sense, and the expiration date is valid.
@@ -704,17 +743,19 @@  discard block
 block discarded – undo
704 743
 	{
705 744
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
706 745
 
707
-		if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
708
-			$_POST['poll_hide'] = 1;
709
-		elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24)))
710
-			$_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24;
711
-		else
712
-			$_POST['poll_expire'] = $bcinfo['expire_time'];
746
+		if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
747
+					$_POST['poll_hide'] = 1;
748
+		} elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) {
749
+					$_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24;
750
+		} else {
751
+					$_POST['poll_expire'] = $bcinfo['expire_time'];
752
+		}
713 753
 
714
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
715
-			$_POST['poll_max_votes'] = 1;
716
-		else
717
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
754
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
755
+					$_POST['poll_max_votes'] = 1;
756
+		} else {
757
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
758
+		}
718 759
 	}
719 760
 
720 761
 	// If we're editing, let's commit the changes.
@@ -781,8 +822,9 @@  discard block
 block discarded – undo
781 822
 		)
782 823
 	);
783 824
 	$choices = array();
784
-	while ($row = $smcFunc['db_fetch_assoc']($request))
785
-		$choices[] = $row['id_choice'];
825
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
826
+			$choices[] = $row['id_choice'];
827
+	}
786 828
 	$smcFunc['db_free_result']($request);
787 829
 
788 830
 	$delete_options = array();
@@ -795,8 +837,9 @@  discard block
 block discarded – undo
795 837
 		if (trim($option) == '')
796 838
 		{
797 839
 			// They want it deleted.  Bye.
798
-			if (in_array($k, $choices))
799
-				$delete_options[] = $k;
840
+			if (in_array($k, $choices)) {
841
+							$delete_options[] = $k;
842
+			}
800 843
 
801 844
 			// Skip the rest...
802 845
 			continue;
@@ -806,8 +849,8 @@  discard block
 block discarded – undo
806 849
 		$option = $smcFunc['htmlspecialchars']($option);
807 850
 
808 851
 		// If it's already there, update it.  If it's not... add it.
809
-		if (in_array($k, $choices))
810
-			$smcFunc['db_query']('', '
852
+		if (in_array($k, $choices)) {
853
+					$smcFunc['db_query']('', '
811 854
 				UPDATE {db_prefix}poll_choices
812 855
 				SET label = {string:option_name}
813 856
 				WHERE id_poll = {int:id_poll}
@@ -818,8 +861,8 @@  discard block
 block discarded – undo
818 861
 					'option_name' => $option,
819 862
 				)
820 863
 			);
821
-		else
822
-			$smcFunc['db_insert']('',
864
+		} else {
865
+					$smcFunc['db_insert']('',
823 866
 				'{db_prefix}poll_choices',
824 867
 				array(
825 868
 					'id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255', 'votes' => 'int',
@@ -829,6 +872,7 @@  discard block
 block discarded – undo
829 872
 				),
830 873
 				array()
831 874
 			);
875
+		}
832 876
 	}
833 877
 
834 878
 	// I'm sorry, but... well, no one was choosing you.  Poor options, I'll put you out of your misery.
@@ -894,13 +938,11 @@  discard block
 block discarded – undo
894 938
 	{
895 939
 		// Added a poll
896 940
 		logAction('add_poll', array('topic' => $topic));
897
-	}
898
-	elseif (isset($_REQUEST['deletevotes']))
941
+	} elseif (isset($_REQUEST['deletevotes']))
899 942
 	{
900 943
 		// Reset votes
901 944
 		logAction('reset_poll', array('topic' => $topic));
902
-	}
903
-	else
945
+	} else
904 946
 	{
905 947
 		// Something else
906 948
 		logAction('editpoll', array('topic' => $topic));
@@ -923,8 +965,9 @@  discard block
 block discarded – undo
923 965
 	global $topic, $user_info, $smcFunc;
924 966
 
925 967
 	// Make sure the topic is not empty.
926
-	if (empty($topic))
927
-		fatal_lang_error('no_access', false);
968
+	if (empty($topic)) {
969
+			fatal_lang_error('no_access', false);
970
+	}
928 971
 
929 972
 	// Verify the session.
930 973
 	checkSession('get');
@@ -942,8 +985,9 @@  discard block
 block discarded – undo
942 985
 				'current_topic' => $topic,
943 986
 			)
944 987
 		);
945
-		if ($smcFunc['db_num_rows']($request) == 0)
946
-			fatal_lang_error('no_access', false);
988
+		if ($smcFunc['db_num_rows']($request) == 0) {
989
+					fatal_lang_error('no_access', false);
990
+		}
947 991
 		list ($topicStarter, $pollStarter) = $smcFunc['db_fetch_row']($request);
948 992
 		$smcFunc['db_free_result']($request);
949 993
 
Please login to merge, or discard this patch.