Completed
Push — release-2.1 ( 15f485...ae1be0 )
by Mathias
08:27
created
Sources/Who.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 						'Shitiz "Dragooon" Garg',
590 590
 						'Karl "RegularExpression" Benson',
591 591
 						'Matthew "Labradoodle-360" Kerle',
592
-						$user_info['is_admin'] ? 'Matt "Grudge" Wolf': 'Grudge',
592
+						$user_info['is_admin'] ? 'Matt "Grudge" Wolf' : 'Grudge',
593 593
 						'Michael "Thantos" Miller',
594 594
 						'Norv',
595 595
 						'Peter "Arantor" Spicer',
@@ -813,13 +813,13 @@  discard block
 block discarded – undo
813 813
 			$credit_info = smf_json_decode($row['credits'], true);
814 814
 
815 815
 			$copyright = empty($credit_info['copyright']) ? '' : $txt['credits_copyright'] . ' © ' . $smcFunc['htmlspecialchars']($credit_info['copyright']);
816
-			$license = empty($credit_info['license']) ? '' : $txt['credits_license'] . ': ' . (!empty($credit_info['licenseurl']) ? '<a href="'. $smcFunc['htmlspecialchars']($credit_info['licenseurl']) .'">'. $smcFunc['htmlspecialchars']($credit_info['license']) .'</a>' : $smcFunc['htmlspecialchars']($credit_info['license']));
816
+			$license = empty($credit_info['license']) ? '' : $txt['credits_license'] . ': ' . (!empty($credit_info['licenseurl']) ? '<a href="' . $smcFunc['htmlspecialchars']($credit_info['licenseurl']) . '">' . $smcFunc['htmlspecialchars']($credit_info['license']) . '</a>' : $smcFunc['htmlspecialchars']($credit_info['license']));
817 817
 			$version = $txt['credits_version'] . ' ' . $row['version'];
818 818
 			$title = (empty($credit_info['title']) ? $row['name'] : $smcFunc['htmlspecialchars']($credit_info['title'])) . ': ' . $version;
819 819
 
820 820
 			// build this one out and stash it away
821 821
 			$mod_name = empty($credit_info['url']) ? $title : '<a href="' . $credit_info['url'] . '">' . $title . '</a>';
822
-			$mods[] = $mod_name . (!empty($license) ? ' | ' . $license  : '') . (!empty($copyright) ? ' | ' . $copyright  : '');
822
+			$mods[] = $mod_name . (!empty($license) ? ' | ' . $license : '') . (!empty($copyright) ? ' | ' . $copyright : '');
823 823
 		}
824 824
 		cache_put_data('mods_credits', $mods, 86400);
825 825
 	}
Please login to merge, or discard this patch.
Braces   +126 added lines, -95 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
  * Who's online, and what are they doing?
@@ -35,8 +36,9 @@  discard block
 block discarded – undo
35 36
 	isAllowedTo('who_view');
36 37
 
37 38
 	// You can't do anything if this is off.
38
-	if (empty($modSettings['who_enabled']))
39
-		fatal_lang_error('who_off', false);
39
+	if (empty($modSettings['who_enabled'])) {
40
+			fatal_lang_error('who_off', false);
41
+	}
40 42
 
41 43
 	// Load the 'Who' template.
42 44
 	loadTemplate('Who');
@@ -71,9 +73,9 @@  discard block
 block discarded – undo
71 73
 		$show_methods['spiders'] = '(lo.id_member = 0 AND lo.id_spider > 0)';
72 74
 		$show_methods['guests'] = '(lo.id_member = 0 AND lo.id_spider = 0)';
73 75
 		$context['show_methods']['spiders'] = $txt['who_show_spiders_only'];
76
+	} elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders') {
77
+			unset($_SESSION['who_online_filter']);
74 78
 	}
75
-	elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders')
76
-		unset($_SESSION['who_online_filter']);
77 79
 
78 80
 	// Does the user prefer a different sort direction?
79 81
 	if (isset($_REQUEST['sort']) && isset($sort_methods[$_REQUEST['sort']]))
@@ -97,20 +99,24 @@  discard block
 block discarded – undo
97 99
 	$context['sort_direction'] = isset($_REQUEST['asc']) || (isset($_REQUEST['sort_dir']) && $_REQUEST['sort_dir'] == 'asc') ? 'up' : 'down';
98 100
 
99 101
 	$conditions = array();
100
-	if (!allowedTo('moderate_forum'))
101
-		$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
102
+	if (!allowedTo('moderate_forum')) {
103
+			$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
104
+	}
102 105
 
103 106
 	// Fallback to top filter?
104
-	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top']))
105
-		$_REQUEST['show'] = $_REQUEST['show_top'];
107
+	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top'])) {
108
+			$_REQUEST['show'] = $_REQUEST['show_top'];
109
+	}
106 110
 	// Does the user wish to apply a filter?
107
-	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']]))
108
-		$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
111
+	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']])) {
112
+			$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
113
+	}
109 114
 	// Perhaps we saved a filter earlier in the session?
110
-	elseif (isset($_SESSION['who_online_filter']))
111
-		$context['show_by'] = $_SESSION['who_online_filter'];
112
-	else
113
-		$context['show_by'] = 'members';
115
+	elseif (isset($_SESSION['who_online_filter'])) {
116
+			$context['show_by'] = $_SESSION['who_online_filter'];
117
+	} else {
118
+			$context['show_by'] = 'members';
119
+	}
114 120
 
115 121
 	$conditions[] = $show_methods[$context['show_by']];
116 122
 
@@ -156,8 +162,9 @@  discard block
 block discarded – undo
156 162
 	while ($row = $smcFunc['db_fetch_assoc']($request))
157 163
 	{
158 164
 		$actions = smf_json_decode($row['url'], true);
159
-		if ($actions === false)
160
-			continue;
165
+		if ($actions === false) {
166
+					continue;
167
+		}
161 168
 
162 169
 		// Send the information to the template.
163 170
 		$context['members'][$row['session']] = array(
@@ -195,8 +202,8 @@  discard block
 block discarded – undo
195 202
 	$spiderContext = array();
196 203
 	if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache']))
197 204
 	{
198
-		foreach (smf_json_decode($modSettings['spider_name_cache'], true) as $id => $name)
199
-			$spiderContext[$id] = array(
205
+		foreach (smf_json_decode($modSettings['spider_name_cache'], true) as $id => $name) {
206
+					$spiderContext[$id] = array(
200 207
 				'id' => 0,
201 208
 				'name' => $name,
202 209
 				'group' => $txt['spiders'],
@@ -205,6 +212,7 @@  discard block
 block discarded – undo
205 212
 				'email' => $name,
206 213
 				'is_guest' => true
207 214
 			);
215
+		}
208 216
 	}
209 217
 
210 218
 	$url_data = determineActions($url_data);
@@ -219,16 +227,18 @@  discard block
 block discarded – undo
219 227
 	// Put it in the context variables.
220 228
 	foreach ($context['members'] as $i => $member)
221 229
 	{
222
-		if ($member['id'] != 0)
223
-			$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
230
+		if ($member['id'] != 0) {
231
+					$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
232
+		}
224 233
 
225 234
 		// Keep the IP that came from the database.
226 235
 		$memberContext[$member['id']]['ip'] = $member['ip'];
227 236
 		$context['members'][$i]['action'] = isset($url_data[$i]) ? $url_data[$i] : $txt['who_hidden'];
228
-		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']]))
229
-			$context['members'][$i] += $spiderContext[$member['id_spider']];
230
-		else
231
-			$context['members'][$i] += $memberContext[$member['id']];
237
+		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']])) {
238
+					$context['members'][$i] += $spiderContext[$member['id_spider']];
239
+		} else {
240
+					$context['members'][$i] += $memberContext[$member['id']];
241
+		}
232 242
 	}
233 243
 
234 244
 	// Some people can't send personal messages...
@@ -263,8 +273,9 @@  discard block
 block discarded – undo
263 273
 {
264 274
 	global $txt, $user_info, $modSettings, $smcFunc;
265 275
 
266
-	if (!allowedTo('who_view'))
267
-		return array();
276
+	if (!allowedTo('who_view')) {
277
+			return array();
278
+	}
268 279
 	loadLanguage('Who');
269 280
 
270 281
 	// Actions that require a specific permission level.
@@ -292,10 +303,11 @@  discard block
 block discarded – undo
292 303
 	);
293 304
 	call_integration_hook('who_allowed', array(&$allowedActions));
294 305
 
295
-	if (!is_array($urls))
296
-		$url_list = array(array($urls, $user_info['id']));
297
-	else
298
-		$url_list = $urls;
306
+	if (!is_array($urls)) {
307
+			$url_list = array(array($urls, $user_info['id']));
308
+	} else {
309
+			$url_list = $urls;
310
+	}
299 311
 
300 312
 	// These are done to later query these in large chunks. (instead of one by one.)
301 313
 	$topic_ids = array();
@@ -307,12 +319,14 @@  discard block
 block discarded – undo
307 319
 	{
308 320
 		// Get the request parameters..
309 321
 		$actions = smf_json_decode($url[0], true);
310
-		if ($actions === false)
311
-			continue;
322
+		if ($actions === false) {
323
+					continue;
324
+		}
312 325
 
313 326
 		// If it's the admin or moderation center, and there is an area set, use that instead.
314
-		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area']))
315
-			$actions['action'] = $actions['area'];
327
+		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area'])) {
328
+					$actions['action'] = $actions['area'];
329
+		}
316 330
 
317 331
 		// Check if there was no action or the action is display.
318 332
 		if (!isset($actions['action']) || $actions['action'] == 'display')
@@ -332,12 +346,14 @@  discard block
 block discarded – undo
332 346
 				$board_ids[$actions['board']][$k] = $txt['who_board'];
333 347
 			}
334 348
 			// It's the board index!!  It must be!
335
-			else
336
-				$data[$k] = $txt['who_index'];
349
+			else {
350
+							$data[$k] = $txt['who_index'];
351
+			}
337 352
 		}
338 353
 		// Probably an error or some goon?
339
-		elseif ($actions['action'] == '')
340
-			$data[$k] = $txt['who_index'];
354
+		elseif ($actions['action'] == '') {
355
+					$data[$k] = $txt['who_index'];
356
+		}
341 357
 		// Some other normal action...?
342 358
 		else
343 359
 		{
@@ -345,23 +361,25 @@  discard block
 block discarded – undo
345 361
 			if ($actions['action'] == 'profile')
346 362
 			{
347 363
 				// Whose?  Their own?
348
-				if (empty($actions['u']))
349
-					$actions['u'] = $url[1];
364
+				if (empty($actions['u'])) {
365
+									$actions['u'] = $url[1];
366
+				}
350 367
 
351 368
 				$data[$k] = $txt['who_hidden'];
352 369
 				$profile_ids[(int) $actions['u']][$k] = $actions['u'] == $url[1] ? $txt['who_viewownprofile'] : $txt['who_viewprofile'];
353
-			}
354
-			elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
370
+			} elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
355 371
 			{
356 372
 				$data[$k] = $txt['who_hidden'];
357 373
 				$board_ids[(int) $actions['board']][$k] = isset($actions['poll']) ? $txt['who_poll'] : $txt['who_post'];
358 374
 			}
359 375
 			// A subaction anyone can view... if the language string is there, show it.
360
-			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']]))
361
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
376
+			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']])) {
377
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
378
+			}
362 379
 			// An action any old fellow can look at. (if ['whoall_' . $action] exists, we know everyone can see it.)
363
-			elseif (isset($txt['whoall_' . $actions['action']]))
364
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
380
+			elseif (isset($txt['whoall_' . $actions['action']])) {
381
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
382
+			}
365 383
 			// Viewable if and only if they can see the board...
366 384
 			elseif (isset($txt['whotopic_' . $actions['action']]))
367 385
 			{
@@ -370,8 +388,7 @@  discard block
 block discarded – undo
370 388
 
371 389
 				$data[$k] = $txt['who_hidden'];
372 390
 				$topic_ids[$topic][$k] = $txt['whotopic_' . $actions['action']];
373
-			}
374
-			elseif (isset($txt['whopost_' . $actions['action']]))
391
+			} elseif (isset($txt['whopost_' . $actions['action']]))
375 392
 			{
376 393
 				// Find out what message they are accessing.
377 394
 				$msgid = (int) (isset($actions['msg']) ? $actions['msg'] : (isset($actions['quote']) ? $actions['quote'] : 0));
@@ -394,41 +411,46 @@  discard block
 block discarded – undo
394 411
 				$data[$k] = sprintf($txt['whopost_' . $actions['action']], $id_topic, $subject);
395 412
 				$smcFunc['db_free_result']($result);
396 413
 
397
-				if (empty($id_topic))
398
-					$data[$k] = $txt['who_hidden'];
414
+				if (empty($id_topic)) {
415
+									$data[$k] = $txt['who_hidden'];
416
+				}
399 417
 			}
400 418
 			// Viewable only by administrators.. (if it starts with whoadmin, it's admin only!)
401
-			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']]))
402
-				$data[$k] = $txt['whoadmin_' . $actions['action']];
419
+			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']])) {
420
+							$data[$k] = $txt['whoadmin_' . $actions['action']];
421
+			}
403 422
 			// Viewable by permission level.
404 423
 			elseif (isset($allowedActions[$actions['action']]))
405 424
 			{
406
-				if (allowedTo($allowedActions[$actions['action']]))
407
-					$data[$k] = $txt['whoallow_' . $actions['action']];
408
-				elseif (in_array('moderate_forum', $allowedActions[$actions['action']]))
409
-					$data[$k] = $txt['who_moderate'];
410
-				elseif (in_array('admin_forum', $allowedActions[$actions['action']]))
411
-					$data[$k] = $txt['who_admin'];
412
-				else
413
-					$data[$k] = $txt['who_hidden'];
425
+				if (allowedTo($allowedActions[$actions['action']])) {
426
+									$data[$k] = $txt['whoallow_' . $actions['action']];
427
+				} elseif (in_array('moderate_forum', $allowedActions[$actions['action']])) {
428
+									$data[$k] = $txt['who_moderate'];
429
+				} elseif (in_array('admin_forum', $allowedActions[$actions['action']])) {
430
+									$data[$k] = $txt['who_admin'];
431
+				} else {
432
+									$data[$k] = $txt['who_hidden'];
433
+				}
434
+			} elseif (!empty($actions['action'])) {
435
+							$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
436
+			} else {
437
+							$data[$k] = $txt['who_unknown'];
414 438
 			}
415
-			elseif (!empty($actions['action']))
416
-				$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
417
-			else
418
-				$data[$k] = $txt['who_unknown'];
419 439
 		}
420 440
 
421 441
 		if (isset($actions['error']))
422 442
 		{
423
-			if (isset($txt[$actions['error']]))
424
-				$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
425
-			elseif ($actions['error'] == 'guest_login')
426
-				$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
427
-			else
428
-				$error_message = str_replace('"', '&quot;', $actions['error']);
429
-
430
-			if (!empty($error_message))
431
-				$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
443
+			if (isset($txt[$actions['error']])) {
444
+							$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
445
+			} elseif ($actions['error'] == 'guest_login') {
446
+							$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
447
+			} else {
448
+							$error_message = str_replace('"', '&quot;', $actions['error']);
449
+			}
450
+
451
+			if (!empty($error_message)) {
452
+							$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
453
+			}
432 454
 		}
433 455
 
434 456
 		// Maybe the action is integrated into another system?
@@ -439,12 +461,15 @@  discard block
 block discarded – undo
439 461
 				if (!empty($integrate_action))
440 462
 				{
441 463
 					$data[$k] = $integrate_action;
442
-					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k]))
443
-						$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
444
-					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k]))
445
-						$board_ids[(int) $actions['board']][$k] = $integrate_action;
446
-					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k]))
447
-						$profile_ids[(int) $actions['u']][$k] = $integrate_action;
464
+					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k])) {
465
+											$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
466
+					}
467
+					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k])) {
468
+											$board_ids[(int) $actions['board']][$k] = $integrate_action;
469
+					}
470
+					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k])) {
471
+											$profile_ids[(int) $actions['u']][$k] = $integrate_action;
472
+					}
448 473
 					break;
449 474
 				}
450 475
 			}
@@ -472,8 +497,9 @@  discard block
 block discarded – undo
472 497
 		while ($row = $smcFunc['db_fetch_assoc']($result))
473 498
 		{
474 499
 			// Show the topic's subject for each of the actions.
475
-			foreach ($topic_ids[$row['id_topic']] as $k => $session_text)
476
-				$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
500
+			foreach ($topic_ids[$row['id_topic']] as $k => $session_text) {
501
+							$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
502
+			}
477 503
 		}
478 504
 		$smcFunc['db_free_result']($result);
479 505
 	}
@@ -495,8 +521,9 @@  discard block
 block discarded – undo
495 521
 		while ($row = $smcFunc['db_fetch_assoc']($result))
496 522
 		{
497 523
 			// Put the board name into the string for each member...
498
-			foreach ($board_ids[$row['id_board']] as $k => $session_text)
499
-				$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
524
+			foreach ($board_ids[$row['id_board']] as $k => $session_text) {
525
+							$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
526
+			}
500 527
 		}
501 528
 		$smcFunc['db_free_result']($result);
502 529
 	}
@@ -518,23 +545,26 @@  discard block
 block discarded – undo
518 545
 		while ($row = $smcFunc['db_fetch_assoc']($result))
519 546
 		{
520 547
 			// If they aren't allowed to view this person's profile, skip it.
521
-			if (!$allow_view_any && ($user_info['id'] != $row['id_member']))
522
-				continue;
548
+			if (!$allow_view_any && ($user_info['id'] != $row['id_member'])) {
549
+							continue;
550
+			}
523 551
 
524 552
 			// Set their action on each - session/text to sprintf.
525
-			foreach ($profile_ids[$row['id_member']] as $k => $session_text)
526
-				$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
553
+			foreach ($profile_ids[$row['id_member']] as $k => $session_text) {
554
+							$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
555
+			}
527 556
 		}
528 557
 		$smcFunc['db_free_result']($result);
529 558
 	}
530 559
 
531 560
 	call_integration_hook('whos_online_after', array(&$urls, &$data));
532 561
 
533
-	if (!is_array($urls))
534
-		return isset($data[0]) ? $data[0] : false;
535
-	else
536
-		return $data;
537
-}
562
+	if (!is_array($urls)) {
563
+			return isset($data[0]) ? $data[0] : false;
564
+	} else {
565
+			return $data;
566
+	}
567
+	}
538 568
 
539 569
 /**
540 570
  * It prepares credit and copyright information for the credits page or the admin page
@@ -709,8 +739,8 @@  discard block
 block discarded – undo
709 739
 	);
710 740
 
711 741
 	// Give the translators some credit for their hard work.
712
-	if (!empty($txt['translation_credits']))
713
-		$context['credits'][] = array(
742
+	if (!empty($txt['translation_credits'])) {
743
+			$context['credits'][] = array(
714 744
 			'title' => $txt['credits_groups_translation'],
715 745
 			'groups' => array(
716 746
 				array(
@@ -719,6 +749,7 @@  discard block
 block discarded – undo
719 749
 				),
720 750
 			),
721 751
 		);
752
+	}
722 753
 
723 754
 	$context['credits'][] = array(
724 755
 		'title' => $txt['credits_special'],
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -673,7 +673,7 @@
 block discarded – undo
673 673
 						'Nikola &quot;Dzonny&quot; Novakovi&cacute;',
674 674
 						// Localizers
675 675
 						'Dr. Deejay',
676
-                        			'd3vcho',
676
+									'd3vcho',
677 677
 						// Former Localizers
678 678
 						'Relyana',
679 679
 					),
Please login to merge, or discard this patch.
Sources/Printpage.php 1 patch
Braces   +30 added lines, -23 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
  * Format a topic to be printer friendly.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $board_info, $smcFunc, $modSettings;
33 34
 
34 35
 	// Redirect to the boardindex if no valid topic id is provided.
35
-	if (empty($topic))
36
-		redirectexit();
36
+	if (empty($topic)) {
37
+			redirectexit();
38
+	}
37 39
 
38 40
 	if (!empty($modSettings['disable_print_topic']))
39 41
 	{
@@ -59,8 +61,9 @@  discard block
 block discarded – undo
59 61
 		)
60 62
 	);
61 63
 	// Redirect to the boardindex if no valid topic id is provided.
62
-	if ($smcFunc['db_num_rows']($request) == 0)
63
-		redirectexit();
64
+	if ($smcFunc['db_num_rows']($request) == 0) {
65
+			redirectexit();
66
+	}
64 67
 	$row = $smcFunc['db_fetch_assoc']($request);
65 68
 	$smcFunc['db_free_result']($request);
66 69
 
@@ -134,20 +137,21 @@  discard block
 block discarded – undo
134 137
 				foreach ($guestinfo as $i => $guestvoted)
135 138
 				{
136 139
 					$guestvoted = explode(',', $guestvoted);
137
-					if ($guestvoted[0] == $row['id_poll'])
138
-						break;
140
+					if ($guestvoted[0] == $row['id_poll']) {
141
+											break;
142
+					}
139 143
 				}
140 144
 				// Has the poll been reset since guest voted?
141 145
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
142 146
 				{
143 147
 					// Remove the poll info from the cookie to allow guest to vote again
144 148
 					unset($guestinfo[$i]);
145
-					if (!empty($guestinfo))
146
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
147
-					else
148
-						unset($_COOKIE['guest_poll_vote']);
149
-				}
150
-				else
149
+					if (!empty($guestinfo)) {
150
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
151
+					} else {
152
+											unset($_COOKIE['guest_poll_vote']);
153
+					}
154
+				} else
151 155
 				{
152 156
 					// What did they vote for?
153 157
 					unset($guestvoted[0], $guestvoted[1]);
@@ -233,8 +237,9 @@  discard block
 block discarded – undo
233 237
 	$context['poster_name'] = $row['poster_name'];
234 238
 	$context['post_time'] = timeformat($row['poster_time'], false);
235 239
 	$context['parent_boards'] = array();
236
-	foreach ($board_info['parent_boards'] as $parent)
237
-		$context['parent_boards'][] = $parent['name'];
240
+	foreach ($board_info['parent_boards'] as $parent) {
241
+			$context['parent_boards'][] = $parent['name'];
242
+	}
238 243
 
239 244
 	// Split the topics up so we can print them.
240 245
 	$request = $smcFunc['db_query']('', '
@@ -266,8 +271,9 @@  discard block
 block discarded – undo
266 271
 			'id_msg' => $row['id_msg'],
267 272
 		);
268 273
 
269
-		if (!isset($context['topic_subject']))
270
-			$context['topic_subject'] = $row['subject'];
274
+		if (!isset($context['topic_subject'])) {
275
+					$context['topic_subject'] = $row['subject'];
276
+		}
271 277
 	}
272 278
 	$smcFunc['db_free_result']($request);
273 279
 
@@ -275,8 +281,9 @@  discard block
 block discarded – undo
275 281
 	if (isset($_REQUEST['images']) && !empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
276 282
 	{
277 283
 		$messages = array();
278
-		foreach ($context['posts'] as $temp)
279
-			$messages[] = $temp['id_msg'];
284
+		foreach ($context['posts'] as $temp) {
285
+					$messages[] = $temp['id_msg'];
286
+		}
280 287
 
281 288
 		// build the request
282 289
 		$request = $smcFunc['db_query']('', '
@@ -295,8 +302,9 @@  discard block
 block discarded – undo
295 302
 		while ($row = $smcFunc['db_fetch_assoc']($request))
296 303
 		{
297 304
 			$temp[$row['id_attach']] = $row;
298
-			if (!isset($context['printattach'][$row['id_msg']]))
299
-				$context['printattach'][$row['id_msg']] = array();
305
+			if (!isset($context['printattach'][$row['id_msg']])) {
306
+							$context['printattach'][$row['id_msg']] = array();
307
+			}
300 308
 		}
301 309
 		$smcFunc['db_free_result']($request);
302 310
 		ksort($temp);
@@ -313,8 +321,7 @@  discard block
 block discarded – undo
313 321
 						$row['height'] = floor($row['height'] * ($modSettings['max_image_width'] / $row['width']));
314 322
 						$row['width'] = $modSettings['max_image_width'];
315 323
 					}
316
-				}
317
-				elseif (!empty($modSettings['max_image_width']))
324
+				} elseif (!empty($modSettings['max_image_width']))
318 325
 				{
319 326
 					if ($row['height'] > $modSettings['max_image_height'])
320 327
 					{
Please login to merge, or discard this patch.
Sources/Reminder.php 1 patch
Braces   +66 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 3
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * This is the controlling delegator
@@ -38,13 +39,15 @@  discard block
 block discarded – undo
38 39
 	);
39 40
 
40 41
 	// Any subaction?  If none, fall through to the main template, which will ask for one.
41
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
42
-		call_helper($subActions[$_REQUEST['sa']]);
42
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
43
+			call_helper($subActions[$_REQUEST['sa']]);
44
+	}
43 45
 
44 46
 	// Creating a one time token.
45
-	else
46
-		createToken('remind');
47
-}
47
+	else {
48
+			createToken('remind');
49
+	}
50
+	}
48 51
 
49 52
 /**
50 53
  * Allows the user to pick how they wish to be reminded
@@ -62,8 +65,7 @@  discard block
 block discarded – undo
62 65
 	{
63 66
 		$where = 'id_member = {int:id_member}';
64 67
 		$where_params['id_member'] = (int) $_REQUEST['uid'];
65
-	}
66
-	elseif (isset($_POST['user']) && $_POST['user'] != '')
68
+	} elseif (isset($_POST['user']) && $_POST['user'] != '')
67 69
 	{
68 70
 		$where = 'member_name = {string:member_name}';
69 71
 		$where_params['member_name'] = $_POST['user'];
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 	}
72 74
 
73 75
 	// You must enter a username/email address.
74
-	if (empty($where))
75
-		fatal_lang_error('username_no_exist', false);
76
+	if (empty($where)) {
77
+			fatal_lang_error('username_no_exist', false);
78
+	}
76 79
 
77 80
 	// Make sure we are not being slammed
78 81
 	// Don't call this if you're coming from the "Choose a reminder type" page - otherwise you'll likely get an error
@@ -101,8 +104,9 @@  discard block
 block discarded – undo
101 104
 			LIMIT 1',
102 105
 			$where_params
103 106
 		);
104
-		if ($smcFunc['db_num_rows']($request) == 0)
105
-			fatal_lang_error('no_user_with_email', false);
107
+		if ($smcFunc['db_num_rows']($request) == 0) {
108
+					fatal_lang_error('no_user_with_email', false);
109
+		}
106 110
 	}
107 111
 
108 112
 	$row = $smcFunc['db_fetch_assoc']($request);
@@ -112,16 +116,18 @@  discard block
 block discarded – undo
112 116
 	if ($row['is_activated'] != 1)
113 117
 	{
114 118
 		// Awaiting approval...
115
-		if (trim($row['validation_code']) == '')
116
-			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
117
-		else
118
-			fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
119
+		if (trim($row['validation_code']) == '') {
120
+					fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
121
+		} else {
122
+					fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
123
+		}
119 124
 	}
120 125
 
121 126
 	// You can't get emailed if you have no email address.
122 127
 	$row['email_address'] = trim($row['email_address']);
123
-	if ($row['email_address'] == '')
124
-		fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
128
+	if ($row['email_address'] == '') {
129
+			fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
130
+	}
125 131
 
126 132
 	// If they have no secret question then they can only get emailed the item, or they are requesting the email, send them an email.
127 133
 	if (empty($row['secret_question']) || (isset($_POST['reminder_type']) && $_POST['reminder_type'] == 'email'))
@@ -176,8 +182,9 @@  discard block
 block discarded – undo
176 182
 	loadLanguage('Login');
177 183
 
178 184
 	// You need a code!
179
-	if (!isset($_REQUEST['code']))
180
-		fatal_lang_error('no_access', false);
185
+	if (!isset($_REQUEST['code'])) {
186
+			fatal_lang_error('no_access', false);
187
+	}
181 188
 
182 189
 	// Fill the context array.
183 190
 	$context += array(
@@ -203,16 +210,19 @@  discard block
 block discarded – undo
203 210
 	checkSession();
204 211
 	validateToken('remind-sp');
205 212
 
206
-	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2']))
207
-		fatal_lang_error('no_access', false);
213
+	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2'])) {
214
+			fatal_lang_error('no_access', false);
215
+	}
208 216
 
209 217
 	$_POST['u'] = (int) $_POST['u'];
210 218
 
211
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
212
-		fatal_lang_error('passwords_dont_match', false);
219
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
220
+			fatal_lang_error('passwords_dont_match', false);
221
+	}
213 222
 
214
-	if ($_POST['passwrd1'] == '')
215
-		fatal_lang_error('no_password', false);
223
+	if ($_POST['passwrd1'] == '') {
224
+			fatal_lang_error('no_password', false);
225
+	}
216 226
 
217 227
 	loadLanguage('Login');
218 228
 
@@ -232,8 +242,9 @@  discard block
 block discarded – undo
232 242
 	);
233 243
 
234 244
 	// Does this user exist at all?
235
-	if ($smcFunc['db_num_rows']($request) == 0)
236
-		fatal_lang_error('invalid_userid', false);
245
+	if ($smcFunc['db_num_rows']($request) == 0) {
246
+			fatal_lang_error('invalid_userid', false);
247
+	}
237 248
 
238 249
 	list ($realCode, $username, $email, $flood_value) = $smcFunc['db_fetch_row']($request);
239 250
 	$smcFunc['db_free_result']($request);
@@ -243,8 +254,9 @@  discard block
 block discarded – undo
243 254
 	$passwordError = validatePassword($_POST['passwrd1'], $username, array($email));
244 255
 
245 256
 	// What - it's not?
246
-	if ($passwordError != null)
247
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
257
+	if ($passwordError != null) {
258
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
259
+	}
248 260
 
249 261
 	require_once($sourcedir . '/LogInOut.php');
250 262
 
@@ -291,8 +303,9 @@  discard block
 block discarded – undo
291 303
 	loadLanguage('Login');
292 304
 
293 305
 	// Check they entered something...
294
-	if (empty($_REQUEST['uid']))
295
-		fatal_lang_error('username_no_exist', false);
306
+	if (empty($_REQUEST['uid'])) {
307
+			fatal_lang_error('username_no_exist', false);
308
+	}
296 309
 
297 310
 	// Get the stuff....
298 311
 	$request = $smcFunc['db_query']('', '
@@ -304,15 +317,17 @@  discard block
 block discarded – undo
304 317
 			'id_member' => (int) $_REQUEST['uid'],
305 318
 		)
306 319
 	);
307
-	if ($smcFunc['db_num_rows']($request) == 0)
308
-		fatal_lang_error('username_no_exist', false);
320
+	if ($smcFunc['db_num_rows']($request) == 0) {
321
+			fatal_lang_error('username_no_exist', false);
322
+	}
309 323
 
310 324
 	$row = $smcFunc['db_fetch_assoc']($request);
311 325
 	$smcFunc['db_free_result']($request);
312 326
 
313 327
 	// If there is NO secret question - then throw an error.
314
-	if (trim($row['secret_question']) == '')
315
-		fatal_lang_error('registration_no_secret_question', false);
328
+	if (trim($row['secret_question']) == '') {
329
+			fatal_lang_error('registration_no_secret_question', false);
330
+	}
316 331
 
317 332
 	// Ask for the answer...
318 333
 	$context['remind_user'] = $row['id_member'];
@@ -335,8 +350,9 @@  discard block
 block discarded – undo
335 350
 	validateToken('remind-sai');
336 351
 
337 352
 	// Hacker?  How did you get this far without an email or username?
338
-	if (empty($_REQUEST['uid']))
339
-		fatal_lang_error('username_no_exist', false);
353
+	if (empty($_REQUEST['uid'])) {
354
+			fatal_lang_error('username_no_exist', false);
355
+	}
340 356
 
341 357
 	loadLanguage('Login');
342 358
 
@@ -350,8 +366,9 @@  discard block
 block discarded – undo
350 366
 			'id_member' => $_REQUEST['uid'],
351 367
 		)
352 368
 	);
353
-	if ($smcFunc['db_num_rows']($request) == 0)
354
-		fatal_lang_error('username_no_exist', false);
369
+	if ($smcFunc['db_num_rows']($request) == 0) {
370
+			fatal_lang_error('username_no_exist', false);
371
+	}
355 372
 
356 373
 	$row = $smcFunc['db_fetch_assoc']($request);
357 374
 	$smcFunc['db_free_result']($request);
@@ -364,20 +381,23 @@  discard block
 block discarded – undo
364 381
 	}
365 382
 
366 383
 	// You can't use a blank one!
367
-	if (strlen(trim($_POST['passwrd1'])) === 0)
368
-		fatal_lang_error('no_password', false);
384
+	if (strlen(trim($_POST['passwrd1'])) === 0) {
385
+			fatal_lang_error('no_password', false);
386
+	}
369 387
 
370 388
 	// They have to be the same too.
371
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
372
-		fatal_lang_error('passwords_dont_match', false);
389
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
390
+			fatal_lang_error('passwords_dont_match', false);
391
+	}
373 392
 
374 393
 	// Make sure they have a strong enough password.
375 394
 	require_once($sourcedir . '/Subs-Auth.php');
376 395
 	$passwordError = validatePassword($_POST['passwrd1'], $row['member_name'], array($row['email_address']));
377 396
 
378 397
 	// Invalid?
379
-	if ($passwordError != null)
380
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
398
+	if ($passwordError != null) {
399
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
400
+	}
381 401
 
382 402
 	// Alright, so long as 'yer sure.
383 403
 	updateMemberData($row['id_member'], array('passwd' => hash_password($row['member_name'], $_POST['passwrd1'])));
Please login to merge, or discard this patch.
Sources/Subs-Categories.php 1 patch
Braces   +44 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Edit the position and properties of a category.
@@ -42,8 +43,9 @@  discard block
 block discarded – undo
42 43
 		$cat_order = array();
43 44
 
44 45
 		// Setting 'move_after' to '0' moves the category to the top.
45
-		if ($catOptions['move_after'] == 0)
46
-			$cats[] = $category_id;
46
+		if ($catOptions['move_after'] == 0) {
47
+					$cats[] = $category_id;
48
+		}
47 49
 
48 50
 		// Grab the categories sorted by cat_order.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -55,17 +57,19 @@  discard block
 block discarded – undo
55 57
 		);
56 58
 		while ($row = $smcFunc['db_fetch_assoc']($request))
57 59
 		{
58
-			if ($row['id_cat'] != $category_id)
59
-				$cats[] = $row['id_cat'];
60
-			if ($row['id_cat'] == $catOptions['move_after'])
61
-				$cats[] = $category_id;
60
+			if ($row['id_cat'] != $category_id) {
61
+							$cats[] = $row['id_cat'];
62
+			}
63
+			if ($row['id_cat'] == $catOptions['move_after']) {
64
+							$cats[] = $category_id;
65
+			}
62 66
 			$cat_order[$row['id_cat']] = $row['cat_order'];
63 67
 		}
64 68
 		$smcFunc['db_free_result']($request);
65 69
 
66 70
 		// Set the new order for the categories.
67
-		foreach ($cats as $index => $cat)
68
-			if ($index != $cat_order[$cat])
71
+		foreach ($cats as $index => $cat) {
72
+					if ($index != $cat_order[$cat])
69 73
 				$smcFunc['db_query']('', '
70 74
 					UPDATE {db_prefix}categories
71 75
 					SET cat_order = {int:new_order}
@@ -75,6 +79,7 @@  discard block
 block discarded – undo
75 79
 						'current_category' => $cat,
76 80
 					)
77 81
 				);
82
+		}
78 83
 
79 84
 		// If the category order changed, so did the board order.
80 85
 		require_once($sourcedir . '/Subs-Boards.php');
@@ -117,8 +122,9 @@  discard block
 block discarded – undo
117 122
 			))
118 123
 		);
119 124
 
120
-		if (empty($catOptions['dont_log']))
121
-			logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
125
+		if (empty($catOptions['dont_log'])) {
126
+					logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
127
+		}
122 128
 	}
123 129
 }
124 130
 
@@ -135,16 +141,20 @@  discard block
 block discarded – undo
135 141
 	global $smcFunc;
136 142
 
137 143
 	// Check required values.
138
-	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '')
139
-		trigger_error('createCategory(): A category name is required', E_USER_ERROR);
144
+	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') {
145
+			trigger_error('createCategory(): A category name is required', E_USER_ERROR);
146
+	}
140 147
 
141 148
 	// Set default values.
142
-	if (!isset($catOptions['cat_desc']))
143
-		$catOptions['cat_desc'] = '';
144
-	if (!isset($catOptions['move_after']))
145
-		$catOptions['move_after'] = 0;
146
-	if (!isset($catOptions['is_collapsible']))
147
-		$catOptions['is_collapsible'] = true;
149
+	if (!isset($catOptions['cat_desc'])) {
150
+			$catOptions['cat_desc'] = '';
151
+	}
152
+	if (!isset($catOptions['move_after'])) {
153
+			$catOptions['move_after'] = 0;
154
+	}
155
+	if (!isset($catOptions['is_collapsible'])) {
156
+			$catOptions['is_collapsible'] = true;
157
+	}
148 158
 	// Don't log an edit right after.
149 159
 	$catOptions['dont_log'] = true;
150 160
 
@@ -212,21 +222,24 @@  discard block
 block discarded – undo
212 222
 			)
213 223
 		);
214 224
 		$boards_inside = array();
215
-		while ($row = $smcFunc['db_fetch_assoc']($request))
216
-			$boards_inside[] = $row['id_board'];
225
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
226
+					$boards_inside[] = $row['id_board'];
227
+		}
217 228
 		$smcFunc['db_free_result']($request);
218 229
 
219
-		if (!empty($boards_inside))
220
-			deleteBoards($boards_inside, null);
230
+		if (!empty($boards_inside)) {
231
+					deleteBoards($boards_inside, null);
232
+		}
221 233
 	}
222 234
 
223 235
 	// Make sure the safe category is really safe.
224
-	elseif (in_array($moveBoardsTo, $categories))
225
-		trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
236
+	elseif (in_array($moveBoardsTo, $categories)) {
237
+			trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
238
+	}
226 239
 
227 240
 	// Move the boards inside the categories to a safe category.
228
-	else
229
-		$smcFunc['db_query']('', '
241
+	else {
242
+			$smcFunc['db_query']('', '
230 243
 			UPDATE {db_prefix}boards
231 244
 			SET id_cat = {int:new_parent_cat}
232 245
 			WHERE id_cat IN ({array_int:category_list})',
@@ -235,6 +248,7 @@  discard block
 block discarded – undo
235 248
 				'new_parent_cat' => $moveBoardsTo,
236 249
 			)
237 250
 		);
251
+	}
238 252
 
239 253
 	// Do the deletion of the category itself
240 254
 	$smcFunc['db_query']('', '
@@ -246,8 +260,9 @@  discard block
 block discarded – undo
246 260
 	);
247 261
 
248 262
 	// Log what we've done.
249
-	foreach ($categories as $category)
250
-		logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
263
+	foreach ($categories as $category) {
264
+			logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
265
+	}
251 266
 
252 267
 	// Get all boards back into the right order.
253 268
 	reorderBoards();
Please login to merge, or discard this patch.
Sources/Subs-Compat.php 1 patch
Braces   +27 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 3
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 
23 24
 /**
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 function sha1_smf($str)
29 30
 {
30 31
 	// If we have mhash loaded in, use it instead!
31
-	if (function_exists('mhash') && defined('MHASH_SHA1'))
32
-		return bin2hex(mhash(MHASH_SHA1, $str));
32
+	if (function_exists('mhash') && defined('MHASH_SHA1')) {
33
+			return bin2hex(mhash(MHASH_SHA1, $str));
34
+	}
33 35
 
34 36
 	$nblk = (strlen($str) + 8 >> 6) + 1;
35 37
 	$blks = array_pad(array(), $nblk * 16, 0);
36 38
 
37
-	for ($i = 0; $i < strlen($str); $i++)
38
-		$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
39
+	for ($i = 0; $i < strlen($str); $i++) {
40
+			$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
41
+	}
39 42
 
40 43
 	$blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
41 44
 
@@ -70,10 +73,11 @@  discard block
 block discarded – undo
70 73
 
71 74
 		for ($j = 0; $j < 80; $j++)
72 75
 		{
73
-			if ($j < 16)
74
-				$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
75
-			else
76
-				$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
76
+			if ($j < 16) {
77
+							$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
78
+			} else {
79
+							$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
80
+			}
77 81
 
78 82
 			$t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j);
79 83
 			$e = $d;
@@ -103,12 +107,15 @@  discard block
 block discarded – undo
103 107
  */
104 108
 function sha1_ft($t, $b, $c, $d)
105 109
 {
106
-	if ($t < 20)
107
-		return ($b & $c) | ((~$b) & $d);
108
-	if ($t < 40)
109
-		return $b ^ $c ^ $d;
110
-	if ($t < 60)
111
-		return ($b & $c) | ($b & $d) | ($c & $d);
110
+	if ($t < 20) {
111
+			return ($b & $c) | ((~$b) & $d);
112
+	}
113
+	if ($t < 40) {
114
+			return $b ^ $c ^ $d;
115
+	}
116
+	if ($t < 60) {
117
+			return ($b & $c) | ($b & $d) | ($c & $d);
118
+	}
112 119
 
113 120
 	return $b ^ $c ^ $d;
114 121
 }
@@ -132,10 +139,11 @@  discard block
 block discarded – undo
132 139
 function sha1_rol($num, $cnt)
133 140
 {
134 141
 	// Unfortunately, PHP uses unsigned 32-bit longs only.  So we have to kludge it a bit.
135
-	if ($num & 0x80000000)
136
-		$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
137
-	else
138
-		$a = $num >> (32 - $cnt);
142
+	if ($num & 0x80000000) {
143
+			$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
144
+	} else {
145
+			$a = $num >> (32 - $cnt);
146
+	}
139 147
 
140 148
 	return ($num << $cnt) | $a;
141 149
 }
Please login to merge, or discard this patch.
Sources/ManageScheduledTasks.php 1 patch
Braces   +54 added lines, -38 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
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -40,10 +41,11 @@  discard block
 block discarded – undo
40 41
 	);
41 42
 
42 43
 	// We need to find what's the action.
43
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
44
-		$context['sub_action'] = $_REQUEST['sa'];
45
-	else
46
-		$context['sub_action'] = 'tasks';
44
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
45
+			$context['sub_action'] = $_REQUEST['sa'];
46
+	} else {
47
+			$context['sub_action'] = 'tasks';
48
+	}
47 49
 
48 50
 	// Now for the lovely tabs. That we all love.
49 51
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -90,9 +92,10 @@  discard block
 block discarded – undo
90 92
 
91 93
 		// Enable and disable as required.
92 94
 		$enablers = array(0);
93
-		foreach ($_POST['enable_task'] as $id => $enabled)
94
-			if ($enabled)
95
+		foreach ($_POST['enable_task'] as $id => $enabled) {
96
+					if ($enabled)
95 97
 				$enablers[] = (int) $id;
98
+		}
96 99
 
97 100
 		// Do the update!
98 101
 		$smcFunc['db_query']('', '
@@ -130,8 +133,9 @@  discard block
 block discarded – undo
130 133
 
131 134
 		// Lets figure out which ones they want to run.
132 135
 		$tasks = array();
133
-		foreach ($_POST['run_task'] as $task => $dummy)
134
-			$tasks[] = (int) $task;
136
+		foreach ($_POST['run_task'] as $task => $dummy) {
137
+					$tasks[] = (int) $task;
138
+		}
135 139
 
136 140
 		// Load up the tasks.
137 141
 		$request = $smcFunc['db_query']('', '
@@ -151,36 +155,41 @@  discard block
 block discarded – undo
151 155
 		while ($row = $smcFunc['db_fetch_assoc']($request))
152 156
 		{
153 157
 			// What kind of task are we handling?
154
-			if (!empty($row['callable']))
155
-				$task_string = $row['callable'];
158
+			if (!empty($row['callable'])) {
159
+							$task_string = $row['callable'];
160
+			}
156 161
 
157 162
 			// Default SMF task or old mods?
158
-			elseif (function_exists('scheduled_' . $row['task']))
159
-				$task_string = 'scheduled_' . $row['task'];
163
+			elseif (function_exists('scheduled_' . $row['task'])) {
164
+							$task_string = 'scheduled_' . $row['task'];
165
+			}
160 166
 
161 167
 			// One last resource, the task name.
162
-			elseif (!empty($row['task']))
163
-				$task_string = $row['task'];
168
+			elseif (!empty($row['task'])) {
169
+							$task_string = $row['task'];
170
+			}
164 171
 
165 172
 			$start_time = microtime();
166 173
 			// The functions got to exist for us to use it.
167
-			if (empty($task_string))
168
-				continue;
174
+			if (empty($task_string)) {
175
+							continue;
176
+			}
169 177
 
170 178
 			// Try to stop a timeout, this would be bad...
171 179
 			@set_time_limit(300);
172
-			if (function_exists('apache_reset_timeout'))
173
-				@apache_reset_timeout();
180
+			if (function_exists('apache_reset_timeout')) {
181
+							@apache_reset_timeout();
182
+			}
174 183
 
175 184
 			// Get the callable.
176 185
 			$callable_task = call_helper($task_string, true);
177 186
 
178 187
 			// Perform the task.
179
-			if (!empty($callable_task))
180
-				$completed = call_user_func($callable_task);
181
-
182
-			else
183
-				$completed = false;
188
+			if (!empty($callable_task)) {
189
+							$completed = call_user_func($callable_task);
190
+			} else {
191
+							$completed = false;
192
+			}
184 193
 
185 194
 			// Log that we did it ;)
186 195
 			if ($completed)
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 		$smcFunc['db_free_result']($request);
198 207
 
199 208
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
200
-		if (!empty($context['scheduled_errors']))
201
-			$_SESSION['st_error'] = $context['scheduled_errors'];
209
+		if (!empty($context['scheduled_errors'])) {
210
+					$_SESSION['st_error'] = $context['scheduled_errors'];
211
+		}
202 212
 
203 213
 		redirectexit('action=admin;area=scheduledtasks;done');
204 214
 	}
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 	$context['server_time'] = timeformat(time(), false, 'server');
371 381
 
372 382
 	// Cleaning...
373
-	if (!isset($_GET['tid']))
374
-		fatal_lang_error('no_access', false);
383
+	if (!isset($_GET['tid'])) {
384
+			fatal_lang_error('no_access', false);
385
+	}
375 386
 	$_GET['tid'] = (int) $_GET['tid'];
376 387
 
377 388
 	// Saving?
@@ -387,10 +398,12 @@  discard block
 block discarded – undo
387 398
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
388 399
 
389 400
 		// If a half is empty then assume zero offset!
390
-		if (!isset($matches[2]) || $matches[2] > 59)
391
-			$matches[2] = 0;
392
-		if (!isset($matches[1]) || $matches[1] > 23)
393
-			$matches[1] = 0;
401
+		if (!isset($matches[2]) || $matches[2] > 59) {
402
+					$matches[2] = 0;
403
+		}
404
+		if (!isset($matches[1]) || $matches[1] > 23) {
405
+					$matches[1] = 0;
406
+		}
394 407
 
395 408
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
396 409
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -400,8 +413,9 @@  discard block
 block discarded – undo
400 413
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
401 414
 
402 415
 		// Don't allow one minute intervals.
403
-		if ($interval == 1 && $unit == 'm')
404
-			$interval = 2;
416
+		if ($interval == 1 && $unit == 'm') {
417
+					$interval = 2;
418
+		}
405 419
 
406 420
 		// Is it disabled?
407 421
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -439,8 +453,9 @@  discard block
 block discarded – undo
439 453
 	);
440 454
 
441 455
 	// Should never, ever, happen!
442
-	if ($smcFunc['db_num_rows']($request) == 0)
443
-		fatal_lang_error('no_access', false);
456
+	if ($smcFunc['db_num_rows']($request) == 0) {
457
+			fatal_lang_error('no_access', false);
458
+	}
444 459
 
445 460
 	while ($row = $smcFunc['db_fetch_assoc']($request))
446 461
 	{
@@ -598,13 +613,14 @@  discard block
 block discarded – undo
598 613
 		)
599 614
 	);
600 615
 	$log_entries = array();
601
-	while ($row = $smcFunc['db_fetch_assoc']($request))
602
-		$log_entries[] = array(
616
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
617
+			$log_entries[] = array(
603 618
 			'id' => $row['id_log'],
604 619
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
605 620
 			'time_run' => $row['time_run'],
606 621
 			'time_taken' => $row['time_taken'],
607 622
 		);
623
+	}
608 624
 	$smcFunc['db_free_result']($request);
609 625
 
610 626
 	return $log_entries;
Please login to merge, or discard this patch.
Sources/Recent.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	else
238 238
 	{
239 239
 		$query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
240
-					AND b.id_board != {int:recycle_board}' : ''). '
240
+					AND b.id_board != {int:recycle_board}' : '') . '
241 241
 					AND m.id_msg >= {int:max_id_msg}';
242 242
 		$query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6);
243 243
 		$query_parameters['recycle_board'] = $modSettings['recycle_board'];
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
 			);
1125 1125
 		else
1126 1126
 			$request = $smcFunc['db_query']('', '
1127
-				SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].'
1127
+				SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'] . '
1128 1128
 				FROM {db_prefix}topics AS t
1129 1129
 					INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
1130 1130
 					INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)') . (strpos($_REQUEST['sort'], 'mems.') === false ? '' : '
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 	if ($is_topics)
1392 1392
 	{
1393 1393
 		$context['recent_buttons'] = array(
1394
-			'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'.  $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
1394
+			'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
1395 1395
 		);
1396 1396
 
1397 1397
 		if ($context['showCheckboxes'])
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
 	elseif (!$is_topics && isset($context['topics_to_mark']))
1408 1408
 	{
1409 1409
 		$context['recent_buttons'] = array(
1410
-			'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read']  .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
1410
+			'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
1411 1411
 		);
1412 1412
 
1413 1413
 		if ($context['showCheckboxes'])
Please login to merge, or discard this patch.
Braces   +208 added lines, -170 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
  * Get the latest post made on the system
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 			'is_approved' => 1,
45 46
 		)
46 47
 	);
47
-	if ($smcFunc['db_num_rows']($request) == 0)
48
-		return array();
48
+	if ($smcFunc['db_num_rows']($request) == 0) {
49
+			return array();
50
+	}
49 51
 	$row = $smcFunc['db_fetch_assoc']($request);
50 52
 	$smcFunc['db_free_result']($request);
51 53
 
@@ -54,8 +56,9 @@  discard block
 block discarded – undo
54 56
 	censorText($row['body']);
55 57
 
56 58
 	$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => '&#10;')));
57
-	if ($smcFunc['strlen']($row['body']) > 128)
58
-		$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
59
+	if ($smcFunc['strlen']($row['body']) > 128) {
60
+			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
61
+	}
59 62
 
60 63
 	// Send the data.
61 64
 	return array(
@@ -83,15 +86,17 @@  discard block
 block discarded – undo
83 86
 
84 87
 	$context['is_redirect'] = false;
85 88
 
86
-	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95)
87
-		$_REQUEST['start'] = 95;
89
+	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) {
90
+			$_REQUEST['start'] = 95;
91
+	}
88 92
 
89 93
 	$query_parameters = array();
90 94
 	if (!empty($_REQUEST['c']) && empty($board))
91 95
 	{
92 96
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
93
-		foreach ($_REQUEST['c'] as $i => $c)
94
-			$_REQUEST['c'][$i] = (int) $c;
97
+		foreach ($_REQUEST['c'] as $i => $c) {
98
+					$_REQUEST['c'][$i] = (int) $c;
99
+		}
95 100
 
96 101
 		if (count($_REQUEST['c']) == 1)
97 102
 		{
@@ -107,8 +112,9 @@  discard block
 block discarded – undo
107 112
 			list ($name) = $smcFunc['db_fetch_row']($request);
108 113
 			$smcFunc['db_free_result']($request);
109 114
 
110
-			if (empty($name))
111
-				fatal_lang_error('no_access', false);
115
+			if (empty($name)) {
116
+							fatal_lang_error('no_access', false);
117
+			}
112 118
 
113 119
 			$context['linktree'][] = array(
114 120
 				'url' => $scripturl . '#c' . (int) $_REQUEST['c'],
@@ -140,8 +146,9 @@  discard block
 block discarded – undo
140 146
 		}
141 147
 		$smcFunc['db_free_result']($request);
142 148
 
143
-		if (empty($boards))
144
-			fatal_lang_error('error_no_boards_selected');
149
+		if (empty($boards)) {
150
+					fatal_lang_error('error_no_boards_selected');
151
+		}
145 152
 
146 153
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
147 154
 		$query_parameters['boards'] = $boards;
@@ -155,12 +162,12 @@  discard block
 block discarded – undo
155 162
 		}
156 163
 
157 164
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
158
-	}
159
-	elseif (!empty($_REQUEST['boards']))
165
+	} elseif (!empty($_REQUEST['boards']))
160 166
 	{
161 167
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
162
-		foreach ($_REQUEST['boards'] as $i => $b)
163
-			$_REQUEST['boards'][$i] = (int) $b;
168
+		foreach ($_REQUEST['boards'] as $i => $b) {
169
+					$_REQUEST['boards'][$i] = (int) $b;
170
+		}
164 171
 
165 172
 		$request = $smcFunc['db_query']('', '
166 173
 			SELECT b.id_board, b.num_posts
@@ -184,8 +191,9 @@  discard block
 block discarded – undo
184 191
 		}
185 192
 		$smcFunc['db_free_result']($request);
186 193
 
187
-		if (empty($boards))
188
-			fatal_lang_error('error_no_boards_selected');
194
+		if (empty($boards)) {
195
+					fatal_lang_error('error_no_boards_selected');
196
+		}
189 197
 
190 198
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
191 199
 		$query_parameters['boards'] = $boards;
@@ -199,8 +207,7 @@  discard block
 block discarded – undo
199 207
 		}
200 208
 
201 209
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
202
-	}
203
-	elseif (!empty($board))
210
+	} elseif (!empty($board))
204 211
 	{
205 212
 		$request = $smcFunc['db_query']('', '
206 213
 			SELECT num_posts, redirect
@@ -233,8 +240,7 @@  discard block
 block discarded – undo
233 240
 		}
234 241
 
235 242
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true);
236
-	}
237
-	else
243
+	} else
238 244
 	{
239 245
 		$query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
240 246
 					AND b.id_board != {int:recycle_board}' : ''). '
@@ -269,8 +275,9 @@  discard block
 block discarded – undo
269 275
 	);
270 276
 
271 277
 	// If you selected a redirection board, don't try getting posts for it...
272
-	if ($context['is_redirect'])
273
-		$messages = 0;
278
+	if ($context['is_redirect']) {
279
+			$messages = 0;
280
+	}
274 281
 
275 282
 	$key = 'recent-' . $user_info['id'] . '-' . md5(json_encode(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
276 283
 	if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null))
@@ -301,16 +308,18 @@  discard block
 block discarded – undo
301 308
 				$query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
302 309
 				$cache_results = true;
303 310
 				unset($query_parameters['max_id_msg']);
311
+			} else {
312
+							$done = true;
304 313
 			}
305
-			else
306
-				$done = true;
307 314
 		}
308 315
 		$messages = array();
309
-		while ($row = $smcFunc['db_fetch_assoc']($request))
310
-			$messages[] = $row['id_msg'];
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$messages[] = $row['id_msg'];
318
+		}
311 319
 		$smcFunc['db_free_result']($request);
312
-		if (!empty($cache_results))
313
-			cache_put_data($key, $messages, 120);
320
+		if (!empty($cache_results)) {
321
+					cache_put_data($key, $messages, 120);
322
+		}
314 323
 	}
315 324
 
316 325
 	// Nothing here... Or at least, nothing you can see...
@@ -397,8 +406,9 @@  discard block
 block discarded – undo
397 406
 			'css_class' => 'windowbg',
398 407
 		);
399 408
 
400
-		if ($user_info['id'] == $row['id_first_member'])
401
-			$board_ids['own'][$row['id_board']][] = $row['id_msg'];
409
+		if ($user_info['id'] == $row['id_first_member']) {
410
+					$board_ids['own'][$row['id_board']][] = $row['id_msg'];
411
+		}
402 412
 		$board_ids['any'][$row['id_board']][] = $row['id_msg'];
403 413
 	}
404 414
 	$smcFunc['db_free_result']($request);
@@ -424,20 +434,23 @@  discard block
 block discarded – undo
424 434
 			$boards = boardsAllowedTo($permission);
425 435
 
426 436
 			// If 0 is the only thing in the array, they can do it everywhere!
427
-			if (!empty($boards) && $boards[0] == 0)
428
-				$boards = array_keys($board_ids[$type]);
437
+			if (!empty($boards) && $boards[0] == 0) {
438
+							$boards = array_keys($board_ids[$type]);
439
+			}
429 440
 
430 441
 			// Go through the boards, and look for posts they can do this on.
431 442
 			foreach ($boards as $board_id)
432 443
 			{
433 444
 				// Hmm, they have permission, but there are no topics from that board on this page.
434
-				if (!isset($board_ids[$type][$board_id]))
435
-					continue;
445
+				if (!isset($board_ids[$type][$board_id])) {
446
+									continue;
447
+				}
436 448
 
437 449
 				// Okay, looks like they can do it for these posts.
438
-				foreach ($board_ids[$type][$board_id] as $counter)
439
-					if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
450
+				foreach ($board_ids[$type][$board_id] as $counter) {
451
+									if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
440 452
 						$context['posts'][$counter][$allowed] = true;
453
+				}
441 454
 			}
442 455
 		}
443 456
 	}
@@ -480,17 +493,19 @@  discard block
 block discarded – undo
480 493
 	$context['showing_all_topics'] = isset($_GET['all']);
481 494
 	$context['start'] = (int) $_REQUEST['start'];
482 495
 	$context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
483
-	if ($_REQUEST['action'] == 'unread')
484
-		$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
485
-	else
486
-		$context['page_title'] = $txt['unread_replies'];
496
+	if ($_REQUEST['action'] == 'unread') {
497
+			$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
498
+	} else {
499
+			$context['page_title'] = $txt['unread_replies'];
500
+	}
487 501
 
488
-	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread'])
489
-		fatal_lang_error('loadavg_allunread_disabled', false);
490
-	elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies'])
491
-		fatal_lang_error('loadavg_unreadreplies_disabled', false);
492
-	elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread'])
493
-		fatal_lang_error('loadavg_unread_disabled', false);
502
+	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) {
503
+			fatal_lang_error('loadavg_allunread_disabled', false);
504
+	} elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) {
505
+			fatal_lang_error('loadavg_unreadreplies_disabled', false);
506
+	} elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) {
507
+			fatal_lang_error('loadavg_unread_disabled', false);
508
+	}
494 509
 
495 510
 	// Parameters for the main query.
496 511
 	$query_parameters = array();
@@ -503,12 +518,14 @@  discard block
 block discarded – undo
503 518
 		if (!empty($_REQUEST['boards']))
504 519
 		{
505 520
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
506
-			foreach ($_REQUEST['boards'] as $b)
507
-				$boards[] = (int) $b;
521
+			foreach ($_REQUEST['boards'] as $b) {
522
+							$boards[] = (int) $b;
523
+			}
508 524
 		}
509 525
 
510
-		if (!empty($board))
511
-			$boards[] = (int) $board;
526
+		if (!empty($board)) {
527
+					$boards[] = (int) $board;
528
+		}
512 529
 
513 530
 		// The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them
514 531
 		$request = $smcFunc['db_query']('', '
@@ -525,30 +542,31 @@  discard block
 block discarded – undo
525 542
 			)
526 543
 		);
527 544
 
528
-		while ($row = $smcFunc['db_fetch_assoc']($request))
529
-			if (in_array($row['id_parent'], $boards))
545
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
546
+					if (in_array($row['id_parent'], $boards))
530 547
 				$boards[] = $row['id_board'];
548
+		}
531 549
 
532 550
 		$smcFunc['db_free_result']($request);
533 551
 
534
-		if (empty($boards))
535
-			fatal_lang_error('error_no_boards_selected');
552
+		if (empty($boards)) {
553
+					fatal_lang_error('error_no_boards_selected');
554
+		}
536 555
 
537 556
 		$query_this_board = 'id_board IN ({array_int:boards})';
538 557
 		$query_parameters['boards'] = $boards;
539 558
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
540
-	}
541
-	elseif (!empty($board))
559
+	} elseif (!empty($board))
542 560
 	{
543 561
 		$query_this_board = 'id_board = {int:board}';
544 562
 		$query_parameters['board'] = $board;
545 563
 		$context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
546
-	}
547
-	elseif (!empty($_REQUEST['boards']))
564
+	} elseif (!empty($_REQUEST['boards']))
548 565
 	{
549 566
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
550
-		foreach ($_REQUEST['boards'] as $i => $b)
551
-			$_REQUEST['boards'][$i] = (int) $b;
567
+		foreach ($_REQUEST['boards'] as $i => $b) {
568
+					$_REQUEST['boards'][$i] = (int) $b;
569
+		}
552 570
 
553 571
 		$request = $smcFunc['db_query']('', '
554 572
 			SELECT b.id_board
@@ -560,22 +578,24 @@  discard block
 block discarded – undo
560 578
 			)
561 579
 		);
562 580
 		$boards = array();
563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
564
-			$boards[] = $row['id_board'];
581
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
582
+					$boards[] = $row['id_board'];
583
+		}
565 584
 		$smcFunc['db_free_result']($request);
566 585
 
567
-		if (empty($boards))
568
-			fatal_lang_error('error_no_boards_selected');
586
+		if (empty($boards)) {
587
+					fatal_lang_error('error_no_boards_selected');
588
+		}
569 589
 
570 590
 		$query_this_board = 'id_board IN ({array_int:boards})';
571 591
 		$query_parameters['boards'] = $boards;
572 592
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
573
-	}
574
-	elseif (!empty($_REQUEST['c']))
593
+	} elseif (!empty($_REQUEST['c']))
575 594
 	{
576 595
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
577
-		foreach ($_REQUEST['c'] as $i => $c)
578
-			$_REQUEST['c'][$i] = (int) $c;
596
+		foreach ($_REQUEST['c'] as $i => $c) {
597
+					$_REQUEST['c'][$i] = (int) $c;
598
+		}
579 599
 
580 600
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
581 601
 		$request = $smcFunc['db_query']('', '
@@ -588,18 +608,19 @@  discard block
 block discarded – undo
588 608
 			)
589 609
 		);
590 610
 		$boards = array();
591
-		while ($row = $smcFunc['db_fetch_assoc']($request))
592
-			$boards[] = $row['id_board'];
611
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
612
+					$boards[] = $row['id_board'];
613
+		}
593 614
 		$smcFunc['db_free_result']($request);
594 615
 
595
-		if (empty($boards))
596
-			fatal_lang_error('error_no_boards_selected');
616
+		if (empty($boards)) {
617
+					fatal_lang_error('error_no_boards_selected');
618
+		}
597 619
 
598 620
 		$query_this_board = 'id_board IN ({array_int:boards})';
599 621
 		$query_parameters['boards'] = $boards;
600 622
 		$context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d';
601
-	}
602
-	else
623
+	} else
603 624
 	{
604 625
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
605 626
 		// Don't bother to show deleted posts!
@@ -613,12 +634,14 @@  discard block
 block discarded – undo
613 634
 			)
614 635
 		);
615 636
 		$boards = array();
616
-		while ($row = $smcFunc['db_fetch_assoc']($request))
617
-			$boards[] = $row['id_board'];
637
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
638
+					$boards[] = $row['id_board'];
639
+		}
618 640
 		$smcFunc['db_free_result']($request);
619 641
 
620
-		if (empty($boards))
621
-			fatal_lang_error('error_no_boards_available', false);
642
+		if (empty($boards)) {
643
+					fatal_lang_error('error_no_boards_available', false);
644
+		}
622 645
 
623 646
 		$query_this_board = 'id_board IN ({array_int:boards})';
624 647
 		$query_parameters['boards'] = $boards;
@@ -680,13 +703,14 @@  discard block
 block discarded – undo
680 703
 		'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies']
681 704
 	);
682 705
 
683
-	if ($context['showing_all_topics'])
684
-		$context['linktree'][] = array(
706
+	if ($context['showing_all_topics']) {
707
+			$context['linktree'][] = array(
685 708
 			'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
686 709
 			'name' => $txt['unread_topics_all']
687 710
 		);
688
-	else
689
-		$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
711
+	} else {
712
+			$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
713
+	}
690 714
 
691 715
 	loadTemplate('Recent');
692 716
 	loadTemplate('MessageIndex');
@@ -694,8 +718,9 @@  discard block
 block discarded – undo
694 718
 
695 719
 	// Setup the default topic icons... for checking they exist and the like ;)
696 720
 	$context['icon_sources'] = array();
697
-	foreach ($context['stable_icons'] as $icon)
698
-		$context['icon_sources'][$icon] = 'images_url';
721
+	foreach ($context['stable_icons'] as $icon) {
722
+			$context['icon_sources'][$icon] = 'images_url';
723
+	}
699 724
 
700 725
 	$is_topics = $_REQUEST['action'] == 'unread';
701 726
 
@@ -725,8 +750,7 @@  discard block
 block discarded – undo
725 750
 			);
726 751
 			list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
727 752
 			$smcFunc['db_free_result']($request);
728
-		}
729
-		else
753
+		} else
730 754
 		{
731 755
 			$request = $smcFunc['db_query']('', '
732 756
 				SELECT MIN(lmr.id_msg)
@@ -742,14 +766,14 @@  discard block
 block discarded – undo
742 766
 		}
743 767
 
744 768
 		// This is needed in case of topics marked unread.
745
-		if (empty($earliest_msg))
746
-			$earliest_msg = 0;
747
-		else
769
+		if (empty($earliest_msg)) {
770
+					$earliest_msg = 0;
771
+		} else
748 772
 		{
749 773
 			// Using caching, when possible, to ignore the below slow query.
750
-			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time())
751
-				$earliest_msg2 = $_SESSION['cached_log_time'][1];
752
-			else
774
+			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) {
775
+							$earliest_msg2 = $_SESSION['cached_log_time'][1];
776
+			} else
753 777
 			{
754 778
 				// This query is pretty slow, but it's needed to ensure nothing crucial is ignored.
755 779
 				$request = $smcFunc['db_query']('', '
@@ -764,8 +788,9 @@  discard block
 block discarded – undo
764 788
 				$smcFunc['db_free_result']($request);
765 789
 
766 790
 				// In theory this could be zero, if the first ever post is unread, so fudge it ;)
767
-				if ($earliest_msg2 == 0)
768
-					$earliest_msg2 = -1;
791
+				if ($earliest_msg2 == 0) {
792
+									$earliest_msg2 = -1;
793
+				}
769 794
 
770 795
 				$_SESSION['cached_log_time'] = array(time(), $earliest_msg2);
771 796
 			}
@@ -803,9 +828,9 @@  discard block
 block discarded – undo
803 828
 				'db_error_skip' => true,
804 829
 			))
805 830
 		) !== false;
831
+	} else {
832
+			$have_temp_table = false;
806 833
 	}
807
-	else
808
-		$have_temp_table = false;
809 834
 
810 835
 	if ($context['showing_all_topics'] && $have_temp_table)
811 836
 	{
@@ -851,14 +876,15 @@  discard block
 block discarded – undo
851 876
 
852 877
 			$context['topics'] = array();
853 878
 			$context['no_topic_listing'] = true;
854
-			if ($context['querystring_board_limits'] == ';start=%1$d')
855
-				$context['querystring_board_limits'] = '';
856
-			else
857
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
879
+			if ($context['querystring_board_limits'] == ';start=%1$d') {
880
+							$context['querystring_board_limits'] = '';
881
+			} else {
882
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
883
+			}
858 884
 			return;
885
+		} else {
886
+					$min_message = (int) $min_message;
859 887
 		}
860
-		else
861
-			$min_message = (int) $min_message;
862 888
 
863 889
 		$request = $smcFunc['db_query']('substring', '
864 890
 			SELECT ' . $select_clause . '
@@ -887,8 +913,7 @@  discard block
 block discarded – undo
887 913
 				'limit' => $context['topics_per_page'],
888 914
 			))
889 915
 		);
890
-	}
891
-	elseif ($is_topics)
916
+	} elseif ($is_topics)
892 917
 	{
893 918
 		$request = $smcFunc['db_query']('', '
894 919
 			SELECT COUNT(*), MIN(t.id_last_msg)
@@ -939,14 +964,15 @@  discard block
 block discarded – undo
939 964
 
940 965
 			$context['topics'] = array();
941 966
 			$context['no_topic_listing'] = true;
942
-			if ($context['querystring_board_limits'] == ';start=%d')
943
-				$context['querystring_board_limits'] = '';
944
-			else
945
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
967
+			if ($context['querystring_board_limits'] == ';start=%d') {
968
+							$context['querystring_board_limits'] = '';
969
+			} else {
970
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
971
+			}
946 972
 			return;
973
+		} else {
974
+					$min_message = (int) $min_message;
947 975
 		}
948
-		else
949
-			$min_message = (int) $min_message;
950 976
 
951 977
 		$request = $smcFunc['db_query']('substring', '
952 978
 			SELECT ' . $select_clause . '
@@ -976,8 +1002,7 @@  discard block
 block discarded – undo
976 1002
 				'limit' => $context['topics_per_page'],
977 1003
 			))
978 1004
 		);
979
-	}
980
-	else
1005
+	} else
981 1006
 	{
982 1007
 		if ($modSettings['totalMessages'] > 100000)
983 1008
 		{
@@ -1029,8 +1054,8 @@  discard block
 block discarded – undo
1029 1054
 			) !== false;
1030 1055
 
1031 1056
 			// If that worked, create a sample of the log_topics table too.
1032
-			if ($have_temp_table)
1033
-				$have_temp_table = $smcFunc['db_query']('', '
1057
+			if ($have_temp_table) {
1058
+							$have_temp_table = $smcFunc['db_query']('', '
1034 1059
 					CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in (
1035 1060
 						PRIMARY KEY (id_topic)
1036 1061
 					)
@@ -1043,6 +1068,7 @@  discard block
 block discarded – undo
1043 1068
 						'db_error_skip' => true,
1044 1069
 					)
1045 1070
 				) !== false;
1071
+			}
1046 1072
 		}
1047 1073
 
1048 1074
 		if (!empty($have_temp_table))
@@ -1058,8 +1084,7 @@  discard block
 block discarded – undo
1058 1084
 			);
1059 1085
 			list ($num_topics) = $smcFunc['db_fetch_row']($request);
1060 1086
 			$smcFunc['db_free_result']($request);
1061
-		}
1062
-		else
1087
+		} else
1063 1088
 		{
1064 1089
 			$request = $smcFunc['db_query']('unread_fetch_topic_count', '
1065 1090
 				SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg)
@@ -1100,15 +1125,16 @@  discard block
 block discarded – undo
1100 1125
 		{
1101 1126
 			$context['topics'] = array();
1102 1127
 			$context['no_topic_listing'] = true;
1103
-			if ($context['querystring_board_limits'] == ';start=%d')
1104
-				$context['querystring_board_limits'] = '';
1105
-			else
1106
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1128
+			if ($context['querystring_board_limits'] == ';start=%d') {
1129
+							$context['querystring_board_limits'] = '';
1130
+			} else {
1131
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1132
+			}
1107 1133
 			return;
1108 1134
 		}
1109 1135
 
1110
-		if (!empty($have_temp_table))
1111
-			$request = $smcFunc['db_query']('', '
1136
+		if (!empty($have_temp_table)) {
1137
+					$request = $smcFunc['db_query']('', '
1112 1138
 				SELECT t.id_topic
1113 1139
 				FROM {db_prefix}topics_posted_in AS t
1114 1140
 					LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic)
@@ -1122,8 +1148,8 @@  discard block
 block discarded – undo
1122 1148
 					'limit' => $context['topics_per_page'],
1123 1149
 				))
1124 1150
 			);
1125
-		else
1126
-			$request = $smcFunc['db_query']('', '
1151
+		} else {
1152
+					$request = $smcFunc['db_query']('', '
1127 1153
 				SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].'
1128 1154
 				FROM {db_prefix}topics AS t
1129 1155
 					INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
@@ -1147,10 +1173,12 @@  discard block
 block discarded – undo
1147 1173
 					'sort' => $_REQUEST['sort'],
1148 1174
 				))
1149 1175
 			);
1176
+		}
1150 1177
 
1151 1178
 		$topics = array();
1152
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1153
-			$topics[] = $row['id_topic'];
1179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1180
+					$topics[] = $row['id_topic'];
1181
+		}
1154 1182
 		$smcFunc['db_free_result']($request);
1155 1183
 
1156 1184
 		// Sanity... where have you gone?
@@ -1158,10 +1186,11 @@  discard block
 block discarded – undo
1158 1186
 		{
1159 1187
 			$context['topics'] = array();
1160 1188
 			$context['no_topic_listing'] = true;
1161
-			if ($context['querystring_board_limits'] == ';start=%d')
1162
-				$context['querystring_board_limits'] = '';
1163
-			else
1164
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1189
+			if ($context['querystring_board_limits'] == ';start=%d') {
1190
+							$context['querystring_board_limits'] = '';
1191
+			} else {
1192
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1193
+			}
1165 1194
 			return;
1166 1195
 		}
1167 1196
 
@@ -1195,8 +1224,9 @@  discard block
 block discarded – undo
1195 1224
 
1196 1225
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1197 1226
 	{
1198
-		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
1199
-			continue;
1227
+		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
1228
+					continue;
1229
+		}
1200 1230
 
1201 1231
 		$topic_ids[] = $row['id_topic'];
1202 1232
 
@@ -1204,11 +1234,13 @@  discard block
 block discarded – undo
1204 1234
 		{
1205 1235
 			// Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
1206 1236
 			$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
1207
-			if ($smcFunc['strlen']($row['first_body']) > 128)
1208
-				$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1237
+			if ($smcFunc['strlen']($row['first_body']) > 128) {
1238
+							$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1239
+			}
1209 1240
 			$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
1210
-			if ($smcFunc['strlen']($row['last_body']) > 128)
1211
-				$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1241
+			if ($smcFunc['strlen']($row['last_body']) > 128) {
1242
+							$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1243
+			}
1212 1244
 
1213 1245
 			// Censor the subject and message preview.
1214 1246
 			censorText($row['first_subject']);
@@ -1219,23 +1251,22 @@  discard block
 block discarded – undo
1219 1251
 			{
1220 1252
 				$row['last_subject'] = $row['first_subject'];
1221 1253
 				$row['last_body'] = $row['first_body'];
1222
-			}
1223
-			else
1254
+			} else
1224 1255
 			{
1225 1256
 				censorText($row['last_subject']);
1226 1257
 				censorText($row['last_body']);
1227 1258
 			}
1228
-		}
1229
-		else
1259
+		} else
1230 1260
 		{
1231 1261
 			$row['first_body'] = '';
1232 1262
 			$row['last_body'] = '';
1233 1263
 			censorText($row['first_subject']);
1234 1264
 
1235
-			if ($row['id_first_msg'] == $row['id_last_msg'])
1236
-				$row['last_subject'] = $row['first_subject'];
1237
-			else
1238
-				censorText($row['last_subject']);
1265
+			if ($row['id_first_msg'] == $row['id_last_msg']) {
1266
+							$row['last_subject'] = $row['first_subject'];
1267
+			} else {
1268
+							censorText($row['last_subject']);
1269
+			}
1239 1270
 		}
1240 1271
 
1241 1272
 		// Decide how many pages the topic should have.
@@ -1247,22 +1278,24 @@  discard block
 block discarded – undo
1247 1278
 			$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false);
1248 1279
 
1249 1280
 			// If we can use all, show all.
1250
-			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
1251
-				$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1281
+			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) {
1282
+							$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1283
+			}
1284
+		} else {
1285
+					$pages = '';
1252 1286
 		}
1253 1287
 
1254
-		else
1255
-			$pages = '';
1256
-
1257 1288
 		// We need to check the topic icons exist... you can never be too sure!
1258 1289
 		if (!empty($modSettings['messageIconChecks_enable']))
1259 1290
 		{
1260 1291
 			// First icon first... as you'd expect.
1261
-			if (!isset($context['icon_sources'][$row['first_icon']]))
1262
-				$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1292
+			if (!isset($context['icon_sources'][$row['first_icon']])) {
1293
+							$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1294
+			}
1263 1295
 			// Last icon... last... duh.
1264
-			if (!isset($context['icon_sources'][$row['last_icon']]))
1265
-				$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1296
+			if (!isset($context['icon_sources'][$row['last_icon']])) {
1297
+							$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1298
+			}
1266 1299
 		}
1267 1300
 
1268 1301
 		// Force the recycling icon if appropriate
@@ -1276,12 +1309,14 @@  discard block
 block discarded – undo
1276 1309
 		$colorClass = 'windowbg';
1277 1310
 
1278 1311
 		// Sticky topics should get a different color, too.
1279
-		if ($row['is_sticky'])
1280
-			$colorClass .= ' sticky';
1312
+		if ($row['is_sticky']) {
1313
+					$colorClass .= ' sticky';
1314
+		}
1281 1315
 
1282 1316
 		// Locked topics get special treatment as well.
1283
-		if ($row['locked'])
1284
-			$colorClass .= ' locked';
1317
+		if ($row['locked']) {
1318
+					$colorClass .= ' locked';
1319
+		}
1285 1320
 
1286 1321
 		// And build the array.
1287 1322
 		$context['topics'][$row['id_topic']] = array(
@@ -1378,8 +1413,9 @@  discard block
 block discarded – undo
1378 1413
 		);
1379 1414
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1380 1415
 		{
1381
-			if (empty($context['topics'][$row['id_topic']]['is_posted_in']))
1382
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1416
+			if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) {
1417
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1418
+			}
1383 1419
 		}
1384 1420
 		$smcFunc['db_free_result']($result);
1385 1421
 	}
@@ -1394,28 +1430,30 @@  discard block
 block discarded – undo
1394 1430
 			'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'.  $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
1395 1431
 		);
1396 1432
 
1397
-		if ($context['showCheckboxes'])
1398
-			$context['recent_buttons']['markselectread'] = array(
1433
+		if ($context['showCheckboxes']) {
1434
+					$context['recent_buttons']['markselectread'] = array(
1399 1435
 				'text' => 'quick_mod_markread',
1400 1436
 				'image' => 'markselectedread.png',
1401 1437
 				'url' => 'javascript:document.quickModForm.submit();',
1402 1438
 			);
1439
+		}
1403 1440
 
1404
-		if (!empty($context['topics']) && !$context['showing_all_topics'])
1405
-			$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1406
-	}
1407
-	elseif (!$is_topics && isset($context['topics_to_mark']))
1441
+		if (!empty($context['topics']) && !$context['showing_all_topics']) {
1442
+					$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1443
+		}
1444
+	} elseif (!$is_topics && isset($context['topics_to_mark']))
1408 1445
 	{
1409 1446
 		$context['recent_buttons'] = array(
1410 1447
 			'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read']  .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
1411 1448
 		);
1412 1449
 
1413
-		if ($context['showCheckboxes'])
1414
-			$context['recent_buttons']['markselectread'] = array(
1450
+		if ($context['showCheckboxes']) {
1451
+					$context['recent_buttons']['markselectread'] = array(
1415 1452
 				'text' => 'quick_mod_markread',
1416 1453
 				'image' => 'markselectedread.png',
1417 1454
 				'url' => 'javascript:document.quickModForm.submit();',
1418 1455
 			);
1456
+		}
1419 1457
 	}
1420 1458
 
1421 1459
 	// Allow mods to add additional buttons here
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5370,7 +5370,6 @@  discard block
 block discarded – undo
5370 5370
 
5371 5371
 /**
5372 5372
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5373
-
5374 5373
  * @param string $file The file/dir full path.
5375 5374
  * @param int $value Not needed, added for legacy reasons.
5376 5375
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5410,7 +5409,6 @@  discard block
 block discarded – undo
5410 5409
 
5411 5410
 /**
5412 5411
  * Wrapper function for json_decode() with error handling.
5413
-
5414 5412
  * @param string $json The string to decode.
5415 5413
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5416 5414
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1098 1098
 				),
1099 1099
 				'content' => '$1',
1100
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1100
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1101 1101
 				{
1102 1102
 					$returnContext = '';
1103 1103
 
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 						}
1133 1133
 
1134 1134
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1135
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1136 1136
 						else
1137 1137
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1138 1138
 					}
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 				'type' => 'unparsed_content',
1162 1162
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1163 1163
 				// @todo Maybe this can be simplified?
1164
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1164
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1165 1165
 				{
1166 1166
 					if (!isset($disabled['code']))
1167 1167
 					{
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 				'type' => 'unparsed_equals_content',
1199 1199
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1200 1200
 				// @todo Maybe this can be simplified?
1201
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1201
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1202 1202
 				{
1203 1203
 					if (!isset($disabled['code']))
1204 1204
 					{
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 				'type' => 'unparsed_content',
1243 1243
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1244 1244
 				// @todo Should this respect guest_hideContacts?
1245
-				'validate' => function (&$tag, &$data, $disabled)
1245
+				'validate' => function(&$tag, &$data, $disabled)
1246 1246
 				{
1247 1247
 					$data = strtr($data, array('<br>' => ''));
1248 1248
 				},
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 				'type' => 'unparsed_commas_content',
1262 1262
 				'test' => '\d+,\d+\]',
1263 1263
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264
-				'validate' => function (&$tag, &$data, $disabled)
1264
+				'validate' => function(&$tag, &$data, $disabled)
1265 1265
 				{
1266 1266
 					if (isset($disabled['url']))
1267 1267
 						$tag['content'] = '$1';
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1278 1278
 				'before' => '<div $1>',
1279 1279
 				'after' => '</div>',
1280
-				'validate' => function (&$tag, &$data, $disabled)
1280
+				'validate' => function(&$tag, &$data, $disabled)
1281 1281
 				{
1282 1282
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1283
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1327 1327
 				),
1328 1328
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1329
-				'validate' => function (&$tag, &$data, $disabled)
1329
+				'validate' => function(&$tag, &$data, $disabled)
1330 1330
 				{
1331 1331
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1332 1332
 
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 				'tag' => 'img',
1350 1350
 				'type' => 'unparsed_content',
1351 1351
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1352
-				'validate' => function (&$tag, &$data, $disabled)
1352
+				'validate' => function(&$tag, &$data, $disabled)
1353 1353
 				{
1354 1354
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1355 1355
 
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
 				'tag' => 'iurl',
1373 1373
 				'type' => 'unparsed_content',
1374 1374
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1375
-				'validate' => function (&$tag, &$data, $disabled)
1375
+				'validate' => function(&$tag, &$data, $disabled)
1376 1376
 				{
1377 1377
 					$data = strtr($data, array('<br>' => ''));
1378 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 				'quoted' => 'optional',
1387 1387
 				'before' => '<a href="$1" class="bbc_link">',
1388 1388
 				'after' => '</a>',
1389
-				'validate' => function (&$tag, &$data, $disabled)
1389
+				'validate' => function(&$tag, &$data, $disabled)
1390 1390
 				{
1391 1391
 					if (substr($data, 0, 1) == '#')
1392 1392
 						$data = '#post_' . substr($data, 1);
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 				'tag' => 'php',
1467 1467
 				'type' => 'unparsed_content',
1468 1468
 				'content' => '<span class="phpcode">$1</span>',
1469
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1469
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1470 1470
 				{
1471 1471
 					if (!isset($disabled['php']))
1472 1472
 					{
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
 				'test' => '[1-7]\]',
1565 1565
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1566 1566
 				'after' => '</span>',
1567
-				'validate' => function (&$tag, &$data, $disabled)
1567
+				'validate' => function(&$tag, &$data, $disabled)
1568 1568
 				{
1569 1569
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1570 1570
 					$data = $sizes[$data] . 'em';
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 				'tag' => 'time',
1603 1603
 				'type' => 'unparsed_content',
1604 1604
 				'content' => '$1',
1605
-				'validate' => function (&$tag, &$data, $disabled)
1605
+				'validate' => function(&$tag, &$data, $disabled)
1606 1606
 				{
1607 1607
 					if (is_numeric($data))
1608 1608
 						$data = timeformat($data);
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 				'tag' => 'url',
1631 1631
 				'type' => 'unparsed_content',
1632 1632
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1633
-				'validate' => function (&$tag, &$data, $disabled)
1633
+				'validate' => function(&$tag, &$data, $disabled)
1634 1634
 				{
1635 1635
 					$data = strtr($data, array('<br>' => ''));
1636 1636
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1644,7 +1644,7 @@  discard block
 block discarded – undo
1644 1644
 				'quoted' => 'optional',
1645 1645
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1646 1646
 				'after' => '</a>',
1647
-				'validate' => function (&$tag, &$data, $disabled)
1647
+				'validate' => function(&$tag, &$data, $disabled)
1648 1648
 				{
1649 1649
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650 1650
 					if (empty($scheme))
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 		{
1671 1671
 			if (isset($temp_bbc))
1672 1672
 				$bbc_codes = $temp_bbc;
1673
-			usort($codes, function ($a, $b) {
1673
+			usort($codes, function($a, $b) {
1674 1674
 				return strcmp($a['tag'], $b['tag']);
1675 1675
 			});
1676 1676
 			return $codes;
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
 										# a run of Unicode domain name characters and a dot
1909 1909
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1910 1910
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1911
-										(?:'. $modSettings['tld_regex'] .'|local)
1911
+										(?:'. $modSettings['tld_regex'] . '|local)
1912 1912
 									)
1913 1913
 									# followed by a non-domain character or end of line
1914 1914
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
 						)?
1977 1977
 						';
1978 1978
 
1979
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
1979
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
1980 1980
 							$url = array_shift($matches);
1981 1981
 
1982 1982
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2714 2714
 		{
2715 2715
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2716
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2716
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2717 2717
 
2718 2718
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2719 2719
 
@@ -2730,7 +2730,7 @@  discard block
 block discarded – undo
2730 2730
 
2731 2731
 	// Replace away!
2732 2732
 	$message = preg_replace_callback($smileyPregSearch,
2733
-		function ($matches) use ($smileyPregReplacements)
2733
+		function($matches) use ($smileyPregReplacements)
2734 2734
 		{
2735 2735
 			return $smileyPregReplacements[$matches[1]];
2736 2736
 		}, $message);
@@ -2796,13 +2796,13 @@  discard block
 block discarded – undo
2796 2796
 	{
2797 2797
 		if (defined('SID') && SID != '')
2798 2798
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799
-				function ($m) use ($scripturl)
2799
+				function($m) use ($scripturl)
2800 2800
 				{
2801
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2801
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2802 2802
 				}, $setLocation);
2803 2803
 		else
2804 2804
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805
-				function ($m) use ($scripturl)
2805
+				function($m) use ($scripturl)
2806 2806
 				{
2807 2807
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2808 2808
 				}, $setLocation);
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
 
3126 3126
 	// Add a generic "Are you sure?" confirmation message.
3127 3127
 	addInlineJavaScript('
3128
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3128
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3129 3129
 
3130 3130
 	// Now add the capping code for avatars.
3131 3131
 	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
@@ -3486,7 +3486,7 @@  discard block
 block discarded – undo
3486 3486
 
3487 3487
 		else
3488 3488
 			echo '
3489
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3489
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3490 3490
 	}
3491 3491
 
3492 3492
 	// Inline JavaScript - Actually useful some times!
@@ -3564,14 +3564,14 @@  discard block
 block discarded – undo
3564 3564
 
3565 3565
 		else
3566 3566
 			echo '
3567
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3567
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3568 3568
 	}
3569 3569
 
3570 3570
 	// Print the rest after the minified files.
3571 3571
 	if (!empty($normal))
3572 3572
 		foreach ($normal as $nf)
3573 3573
 			echo '
3574
-	<link rel="stylesheet" href="', $nf ,'">';
3574
+	<link rel="stylesheet" href="', $nf, '">';
3575 3575
 
3576 3576
 	if ($db_show_debug === true)
3577 3577
 	{
@@ -3587,7 +3587,7 @@  discard block
 block discarded – undo
3587 3587
 	<style>';
3588 3588
 
3589 3589
 		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3590
+			echo $css . '
3591 3591
 	';
3592 3592
 
3593 3593
 		echo'
@@ -3616,27 +3616,27 @@  discard block
 block discarded – undo
3616 3616
 		return false;
3617 3617
 
3618 3618
 	// Did we already did this?
3619
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3619
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3620 3620
 
3621 3621
 	// Already done?
3622 3622
 	if (!empty($toCache))
3623 3623
 		return true;
3624 3624
 
3625 3625
 	// No namespaces, sorry!
3626
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3626
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3627 3627
 
3628 3628
 	// Temp path.
3629
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3629
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3630 3630
 
3631 3631
 	// What kind of file are we going to create?
3632
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3632
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3633 3633
 
3634 3634
 	// File has to exists, if it isn't try to create it.
3635 3635
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3636 3636
 	{
3637 3637
 		loadLanguage('Errors');
3638 3638
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3639
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3639
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3640 3640
 
3641 3641
 		// The process failed so roll back to print each individual file.
3642 3642
 		return $data;
@@ -3671,14 +3671,14 @@  discard block
 block discarded – undo
3671 3671
 	{
3672 3672
 		loadLanguage('Errors');
3673 3673
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3674
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3674
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3675 3675
 
3676 3676
 		// The process failed so roll back to print each individual file.
3677 3677
 		return $data;
3678 3678
 	}
3679 3679
 
3680 3680
 	// And create a long lived cache entry.
3681
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3681
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3682 3682
 
3683 3683
 	return true;
3684 3684
 }
@@ -3738,7 +3738,7 @@  discard block
 block discarded – undo
3738 3738
 	else
3739 3739
 		$path = $modSettings['attachmentUploadDir'];
3740 3740
 
3741
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3741
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3742 3742
 }
3743 3743
 
3744 3744
 /**
@@ -3782,10 +3782,10 @@  discard block
 block discarded – undo
3782 3782
 		$valid_low = isValidIP($ip_parts[0]);
3783 3783
 		$valid_high = isValidIP($ip_parts[1]);
3784 3784
 		$count = 0;
3785
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3785
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3786 3786
 		$max = ($mode == ':' ? 'ffff' : '255');
3787 3787
 		$min = 0;
3788
-		if(!$valid_low)
3788
+		if (!$valid_low)
3789 3789
 		{
3790 3790
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3791 3791
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 		}
3800 3800
 
3801 3801
 		$count = 0;
3802
-		if(!$valid_high)
3802
+		if (!$valid_high)
3803 3803
 		{
3804 3804
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3805 3805
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3812,7 +3812,7 @@  discard block
 block discarded – undo
3812 3812
 			}
3813 3813
 		}
3814 3814
 
3815
-		if($valid_high && $valid_low)
3815
+		if ($valid_high && $valid_low)
3816 3816
 		{
3817 3817
 			$ip_array['low'] = $ip_parts[0];
3818 3818
 			$ip_array['high'] = $ip_parts[1];
@@ -3994,7 +3994,7 @@  discard block
 block discarded – undo
3994 3994
 		addInlineJavaScript('
3995 3995
 	var user_menus = new smc_PopupMenu();
3996 3996
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3997
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
3998 3998
 		if ($context['allow_pm'])
3999 3999
 			addInlineJavaScript('
4000 4000
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4619,7 +4619,7 @@  discard block
 block discarded – undo
4619 4619
 		// No? try a fallback to $sourcedir
4620 4620
 		else
4621 4621
 		{
4622
-			$absPath = $sourcedir .'/'. $file;
4622
+			$absPath = $sourcedir . '/' . $file;
4623 4623
 
4624 4624
 			if (file_exists($absPath))
4625 4625
 				require_once($absPath);
@@ -4700,15 +4700,15 @@  discard block
 block discarded – undo
4700 4700
 
4701 4701
 	// UTF-8 occurences of MS special characters
4702 4702
 	$findchars_utf8 = array(
4703
-		"\xe2\x80\x9a",	// single low-9 quotation mark
4704
-		"\xe2\x80\x9e",	// double low-9 quotation mark
4705
-		"\xe2\x80\xa6",	// horizontal ellipsis
4706
-		"\xe2\x80\x98",	// left single curly quote
4707
-		"\xe2\x80\x99",	// right single curly quote
4708
-		"\xe2\x80\x9c",	// left double curly quote
4709
-		"\xe2\x80\x9d",	// right double curly quote
4710
-		"\xe2\x80\x93",	// en dash
4711
-		"\xe2\x80\x94",	// em dash
4703
+		"\xe2\x80\x9a", // single low-9 quotation mark
4704
+		"\xe2\x80\x9e", // double low-9 quotation mark
4705
+		"\xe2\x80\xa6", // horizontal ellipsis
4706
+		"\xe2\x80\x98", // left single curly quote
4707
+		"\xe2\x80\x99", // right single curly quote
4708
+		"\xe2\x80\x9c", // left double curly quote
4709
+		"\xe2\x80\x9d", // right double curly quote
4710
+		"\xe2\x80\x93", // en dash
4711
+		"\xe2\x80\x94", // em dash
4712 4712
 	);
4713 4713
 
4714 4714
 	// windows 1252 / iso equivalents
@@ -4726,15 +4726,15 @@  discard block
 block discarded – undo
4726 4726
 
4727 4727
 	// safe replacements
4728 4728
 	$replacechars = array(
4729
-		',',	// &sbquo;
4730
-		',,',	// &bdquo;
4731
-		'...',	// &hellip;
4732
-		"'",	// &lsquo;
4733
-		"'",	// &rsquo;
4734
-		'"',	// &ldquo;
4735
-		'"',	// &rdquo;
4736
-		'-',	// &ndash;
4737
-		'--',	// &mdash;
4729
+		',', // &sbquo;
4730
+		',,', // &bdquo;
4731
+		'...', // &hellip;
4732
+		"'", // &lsquo;
4733
+		"'", // &rsquo;
4734
+		'"', // &ldquo;
4735
+		'"', // &rdquo;
4736
+		'-', // &ndash;
4737
+		'--', // &mdash;
4738 4738
 	);
4739 4739
 
4740 4740
 	if ($context['utf8'])
@@ -5152,7 +5152,7 @@  discard block
 block discarded – undo
5152 5152
  */
5153 5153
 function inet_dtop($bin)
5154 5154
 {
5155
-	if(empty($bin))
5155
+	if (empty($bin))
5156 5156
 		return '';
5157 5157
 
5158 5158
 	global $db_type;
@@ -5183,28 +5183,28 @@  discard block
 block discarded – undo
5183 5183
  */
5184 5184
 function _safe_serialize($value)
5185 5185
 {
5186
-	if(is_null($value))
5186
+	if (is_null($value))
5187 5187
 		return 'N;';
5188 5188
 
5189
-	if(is_bool($value))
5190
-		return 'b:'. (int) $value .';';
5189
+	if (is_bool($value))
5190
+		return 'b:' . (int) $value . ';';
5191 5191
 
5192
-	if(is_int($value))
5193
-		return 'i:'. $value .';';
5192
+	if (is_int($value))
5193
+		return 'i:' . $value . ';';
5194 5194
 
5195
-	if(is_float($value))
5196
-		return 'd:'. str_replace(',', '.', $value) .';';
5195
+	if (is_float($value))
5196
+		return 'd:' . str_replace(',', '.', $value) . ';';
5197 5197
 
5198
-	if(is_string($value))
5199
-		return 's:'. strlen($value) .':"'. $value .'";';
5198
+	if (is_string($value))
5199
+		return 's:' . strlen($value) . ':"' . $value . '";';
5200 5200
 
5201
-	if(is_array($value))
5201
+	if (is_array($value))
5202 5202
 	{
5203 5203
 		$out = '';
5204
-		foreach($value as $k => $v)
5204
+		foreach ($value as $k => $v)
5205 5205
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5206 5206
 
5207
-		return 'a:'. count($value) .':{'. $out .'}';
5207
+		return 'a:' . count($value) . ':{' . $out . '}';
5208 5208
 	}
5209 5209
 
5210 5210
 	// safe_serialize cannot serialize resources or objects.
@@ -5246,7 +5246,7 @@  discard block
 block discarded – undo
5246 5246
 function _safe_unserialize($str)
5247 5247
 {
5248 5248
 	// Input  is not a string.
5249
-	if(empty($str) || !is_string($str))
5249
+	if (empty($str) || !is_string($str))
5250 5250
 		return false;
5251 5251
 
5252 5252
 	$stack = array();
@@ -5260,40 +5260,40 @@  discard block
 block discarded – undo
5260 5260
 	 *   3 - in array, expecting value or another array
5261 5261
 	 */
5262 5262
 	$state = 0;
5263
-	while($state != 1)
5263
+	while ($state != 1)
5264 5264
 	{
5265 5265
 		$type = isset($str[0]) ? $str[0] : '';
5266
-		if($type == '}')
5266
+		if ($type == '}')
5267 5267
 			$str = substr($str, 1);
5268 5268
 
5269
-		else if($type == 'N' && $str[1] == ';')
5269
+		else if ($type == 'N' && $str[1] == ';')
5270 5270
 		{
5271 5271
 			$value = null;
5272 5272
 			$str = substr($str, 2);
5273 5273
 		}
5274
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5274
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5275 5275
 		{
5276 5276
 			$value = $matches[1] == '1' ? true : false;
5277 5277
 			$str = substr($str, 4);
5278 5278
 		}
5279
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5279
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5280 5280
 		{
5281
-			$value = (int)$matches[1];
5281
+			$value = (int) $matches[1];
5282 5282
 			$str = $matches[2];
5283 5283
 		}
5284
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5284
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5285 5285
 		{
5286
-			$value = (float)$matches[1];
5286
+			$value = (float) $matches[1];
5287 5287
 			$str = $matches[3];
5288 5288
 		}
5289
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5289
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5290 5290
 		{
5291
-			$value = substr($matches[2], 0, (int)$matches[1]);
5292
-			$str = substr($matches[2], (int)$matches[1] + 2);
5291
+			$value = substr($matches[2], 0, (int) $matches[1]);
5292
+			$str = substr($matches[2], (int) $matches[1] + 2);
5293 5293
 		}
5294
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5294
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5295 5295
 		{
5296
-			$expectedLength = (int)$matches[1];
5296
+			$expectedLength = (int) $matches[1];
5297 5297
 			$str = $matches[2];
5298 5298
 		}
5299 5299
 
@@ -5301,10 +5301,10 @@  discard block
 block discarded – undo
5301 5301
 		else
5302 5302
 			return false;
5303 5303
 
5304
-		switch($state)
5304
+		switch ($state)
5305 5305
 		{
5306 5306
 			case 3: // In array, expecting value or another array.
5307
-				if($type == 'a')
5307
+				if ($type == 'a')
5308 5308
 				{
5309 5309
 					$stack[] = &$list;
5310 5310
 					$list[$key] = array();
@@ -5313,7 +5313,7 @@  discard block
 block discarded – undo
5313 5313
 					$state = 2;
5314 5314
 					break;
5315 5315
 				}
5316
-				if($type != '}')
5316
+				if ($type != '}')
5317 5317
 				{
5318 5318
 					$list[$key] = $value;
5319 5319
 					$state = 2;
@@ -5324,29 +5324,29 @@  discard block
 block discarded – undo
5324 5324
 				return false;
5325 5325
 
5326 5326
 			case 2: // in array, expecting end of array or a key
5327
-				if($type == '}')
5327
+				if ($type == '}')
5328 5328
 				{
5329 5329
 					// Array size is less than expected.
5330
-					if(count($list) < end($expected))
5330
+					if (count($list) < end($expected))
5331 5331
 						return false;
5332 5332
 
5333 5333
 					unset($list);
5334
-					$list = &$stack[count($stack)-1];
5334
+					$list = &$stack[count($stack) - 1];
5335 5335
 					array_pop($stack);
5336 5336
 
5337 5337
 					// Go to terminal state if we're at the end of the root array.
5338 5338
 					array_pop($expected);
5339 5339
 
5340
-					if(count($expected) == 0)
5340
+					if (count($expected) == 0)
5341 5341
 						$state = 1;
5342 5342
 
5343 5343
 					break;
5344 5344
 				}
5345 5345
 
5346
-				if($type == 'i' || $type == 's')
5346
+				if ($type == 'i' || $type == 's')
5347 5347
 				{
5348 5348
 					// Array size exceeds expected length.
5349
-					if(count($list) >= end($expected))
5349
+					if (count($list) >= end($expected))
5350 5350
 						return false;
5351 5351
 
5352 5352
 					$key = $value;
@@ -5359,7 +5359,7 @@  discard block
 block discarded – undo
5359 5359
 
5360 5360
 			// Expecting array or value.
5361 5361
 			case 0:
5362
-				if($type == 'a')
5362
+				if ($type == 'a')
5363 5363
 				{
5364 5364
 					$data = array();
5365 5365
 					$list = &$data;
@@ -5368,7 +5368,7 @@  discard block
 block discarded – undo
5368 5368
 					break;
5369 5369
 				}
5370 5370
 
5371
-				if($type != '}')
5371
+				if ($type != '}')
5372 5372
 				{
5373 5373
 					$data = $value;
5374 5374
 					$state = 1;
@@ -5381,7 +5381,7 @@  discard block
 block discarded – undo
5381 5381
 	}
5382 5382
 
5383 5383
 	// Trailing data in input.
5384
-	if(!empty($str))
5384
+	if (!empty($str))
5385 5385
 		return false;
5386 5386
 
5387 5387
 	return $data;
@@ -5435,7 +5435,7 @@  discard block
 block discarded – undo
5435 5435
 	// Set different modes.
5436 5436
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5437 5437
 
5438
-	foreach($chmodValues as $val)
5438
+	foreach ($chmodValues as $val)
5439 5439
 	{
5440 5440
 		// If it's writable, break out of the loop.
5441 5441
 		if (is_writable($file))
@@ -5470,13 +5470,13 @@  discard block
 block discarded – undo
5470 5470
 	$returnArray = @json_decode($json, $returnAsArray);
5471 5471
 
5472 5472
 	// PHP 5.3 so no json_last_error_msg()
5473
-	switch(json_last_error())
5473
+	switch (json_last_error())
5474 5474
 	{
5475 5475
 		case JSON_ERROR_NONE:
5476 5476
 			$jsonError = false;
5477 5477
 			break;
5478 5478
 		case JSON_ERROR_DEPTH:
5479
-			$jsonError =  'JSON_ERROR_DEPTH';
5479
+			$jsonError = 'JSON_ERROR_DEPTH';
5480 5480
 			break;
5481 5481
 		case JSON_ERROR_STATE_MISMATCH:
5482 5482
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5504,10 +5504,10 @@  discard block
 block discarded – undo
5504 5504
 		loadLanguage('Errors');
5505 5505
 
5506 5506
 		if (!empty($jsonDebug))
5507
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5507
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5508 5508
 
5509 5509
 		else
5510
-			log_error($txt['json_'. $jsonError], 'critical');
5510
+			log_error($txt['json_' . $jsonError], 'critical');
5511 5511
 
5512 5512
 		// Everyone expects an array.
5513 5513
 		return array();
@@ -5611,7 +5611,7 @@  discard block
 block discarded – undo
5611 5611
 		});
5612 5612
 
5613 5613
 		// Convert Punycode to Unicode
5614
-		$tlds = array_map(function ($input) {
5614
+		$tlds = array_map(function($input) {
5615 5615
 			$prefix = 'xn--';
5616 5616
 			$safe_char = 0xFFFC;
5617 5617
 			$base = 36;
@@ -5627,7 +5627,7 @@  discard block
 block discarded – undo
5627 5627
 
5628 5628
 			foreach ($enco_parts as $encoded)
5629 5629
 			{
5630
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5630
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5631 5631
 				{
5632 5632
 					$output_parts[] = $encoded;
5633 5633
 					continue;
@@ -5638,7 +5638,7 @@  discard block
 block discarded – undo
5638 5638
 				$idx = 0;
5639 5639
 				$char = 0x80;
5640 5640
 				$decoded = array();
5641
-				$output='';
5641
+				$output = '';
5642 5642
 				$delim_pos = strrpos($encoded, '-');
5643 5643
 
5644 5644
 				if ($delim_pos > strlen($prefix))
@@ -5654,7 +5654,7 @@  discard block
 block discarded – undo
5654 5654
 
5655 5655
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5656 5656
 				{
5657
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5657
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5658 5658
 					{
5659 5659
 						$cp = ord($encoded{$enco_idx++});
5660 5660
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5695,15 +5695,15 @@  discard block
 block discarded – undo
5695 5695
 
5696 5696
 					// 2 bytes
5697 5697
 					elseif ($v < (1 << 11))
5698
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5698
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5699 5699
 
5700 5700
 					// 3 bytes
5701 5701
 					elseif ($v < (1 << 16))
5702
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5702
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5703 5703
 
5704 5704
 					// 4 bytes
5705 5705
 					elseif ($v < (1 << 21))
5706
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5706
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5707 5707
 
5708 5708
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5709 5709
 					else
@@ -5810,7 +5810,7 @@  discard block
 block discarded – undo
5810 5810
 	}
5811 5811
 
5812 5812
 	// This recursive function creates the index array from the strings
5813
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5813
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5814 5814
 	{
5815 5815
 		static $depth = 0;
5816 5816
 		$depth++;
@@ -5837,7 +5837,7 @@  discard block
 block discarded – undo
5837 5837
 	};
5838 5838
 
5839 5839
 	// This recursive function turns the index array into a regular expression
5840
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5840
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5841 5841
 	{
5842 5842
 		static $depth = 0;
5843 5843
 		$depth++;
@@ -5861,11 +5861,11 @@  discard block
 block discarded – undo
5861 5861
 
5862 5862
 				if (count(array_keys($value)) == 1)
5863 5863
 				{
5864
-					$new_key_array = explode('(?'.'>', $sub_regex);
5864
+					$new_key_array = explode('(?' . '>', $sub_regex);
5865 5865
 					$new_key .= $new_key_array[0];
5866 5866
 				}
5867 5867
 				else
5868
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5868
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5869 5869
 			}
5870 5870
 
5871 5871
 			if ($depth > 1)
@@ -5905,7 +5905,7 @@  discard block
 block discarded – undo
5905 5905
 		$index = $add_string_to_index($string, $index);
5906 5906
 
5907 5907
 	while (!empty($index))
5908
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5908
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5909 5909
 
5910 5910
 	// Restore PHP's internal character encoding to whatever it was originally
5911 5911
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -5527,7 +5527,7 @@  discard block
 block discarded – undo
5527 5527
  * It assumes the data is already a string.
5528 5528
  * @param string $data The data to print
5529 5529
  * @param string $type The content type. Defaults to Json.
5530
- * @return void
5530
+ * @return false|null
5531 5531
  */
5532 5532
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5533 5533
 {
Please login to merge, or discard this patch.
Braces   +1287 added lines, -957 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1281,10 +1345,11 @@  discard block
 block discarded – undo
1281 1345
 				{
1282 1346
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1347
 
1284
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1285
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1286
-					else
1287
-						$css = '';
1348
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1349
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1350
+					} else {
1351
+											$css = '';
1352
+					}
1288 1353
 
1289 1354
 					$data = $class . $css;
1290 1355
 				},
@@ -1334,14 +1399,16 @@  discard block
 block discarded – undo
1334 1399
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1335 1400
 					if ($image_proxy_enabled)
1336 1401
 					{
1337
-						if (empty($scheme))
1338
-							$data = 'http://' . ltrim($data, ':/');
1402
+						if (empty($scheme)) {
1403
+													$data = 'http://' . ltrim($data, ':/');
1404
+						}
1339 1405
 
1340
-						if ($scheme != 'https')
1341
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1406
+						if ($scheme != 'https') {
1407
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1408
+						}
1409
+					} elseif (empty($scheme)) {
1410
+											$data = '//' . ltrim($data, ':/');
1342 1411
 					}
1343
-					elseif (empty($scheme))
1344
-						$data = '//' . ltrim($data, ':/');
1345 1412
 				},
1346 1413
 				'disabled_content' => '($1)',
1347 1414
 			),
@@ -1357,14 +1424,16 @@  discard block
 block discarded – undo
1357 1424
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1358 1425
 					if ($image_proxy_enabled)
1359 1426
 					{
1360
-						if (empty($scheme))
1361
-							$data = 'http://' . ltrim($data, ':/');
1427
+						if (empty($scheme)) {
1428
+													$data = 'http://' . ltrim($data, ':/');
1429
+						}
1362 1430
 
1363
-						if ($scheme != 'https')
1364
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1431
+						if ($scheme != 'https') {
1432
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1433
+						}
1434
+					} elseif (empty($scheme)) {
1435
+											$data = '//' . ltrim($data, ':/');
1365 1436
 					}
1366
-					elseif (empty($scheme))
1367
-						$data = '//' . ltrim($data, ':/');
1368 1437
 				},
1369 1438
 				'disabled_content' => '($1)',
1370 1439
 			),
@@ -1376,8 +1445,9 @@  discard block
 block discarded – undo
1376 1445
 				{
1377 1446
 					$data = strtr($data, array('<br>' => ''));
1378 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1379
-					if (empty($scheme))
1380
-						$data = '//' . ltrim($data, ':/');
1448
+					if (empty($scheme)) {
1449
+											$data = '//' . ltrim($data, ':/');
1450
+					}
1381 1451
 				},
1382 1452
 			),
1383 1453
 			array(
@@ -1388,13 +1458,14 @@  discard block
 block discarded – undo
1388 1458
 				'after' => '</a>',
1389 1459
 				'validate' => function (&$tag, &$data, $disabled)
1390 1460
 				{
1391
-					if (substr($data, 0, 1) == '#')
1392
-						$data = '#post_' . substr($data, 1);
1393
-					else
1461
+					if (substr($data, 0, 1) == '#') {
1462
+											$data = '#post_' . substr($data, 1);
1463
+					} else
1394 1464
 					{
1395 1465
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1396
-						if (empty($scheme))
1397
-							$data = '//' . ltrim($data, ':/');
1466
+						if (empty($scheme)) {
1467
+													$data = '//' . ltrim($data, ':/');
1468
+						}
1398 1469
 					}
1399 1470
 				},
1400 1471
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1472,8 +1543,9 @@  discard block
 block discarded – undo
1472 1543
 					{
1473 1544
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1474 1545
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1475
-						if ($add_begin)
1476
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1546
+						if ($add_begin) {
1547
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1548
+						}
1477 1549
 					}
1478 1550
 				},
1479 1551
 				'block_level' => false,
@@ -1604,10 +1676,11 @@  discard block
 block discarded – undo
1604 1676
 				'content' => '$1',
1605 1677
 				'validate' => function (&$tag, &$data, $disabled)
1606 1678
 				{
1607
-					if (is_numeric($data))
1608
-						$data = timeformat($data);
1609
-					else
1610
-						$tag['content'] = '[time]$1[/time]';
1679
+					if (is_numeric($data)) {
1680
+											$data = timeformat($data);
1681
+					} else {
1682
+											$tag['content'] = '[time]$1[/time]';
1683
+					}
1611 1684
 				},
1612 1685
 			),
1613 1686
 			array(
@@ -1634,8 +1707,9 @@  discard block
 block discarded – undo
1634 1707
 				{
1635 1708
 					$data = strtr($data, array('<br>' => ''));
1636 1709
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1637
-					if (empty($scheme))
1638
-						$data = '//' . ltrim($data, ':/');
1710
+					if (empty($scheme)) {
1711
+											$data = '//' . ltrim($data, ':/');
1712
+					}
1639 1713
 				},
1640 1714
 			),
1641 1715
 			array(
@@ -1647,8 +1721,9 @@  discard block
 block discarded – undo
1647 1721
 				'validate' => function (&$tag, &$data, $disabled)
1648 1722
 				{
1649 1723
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650
-					if (empty($scheme))
1651
-						$data = '//' . ltrim($data, ':/');
1724
+					if (empty($scheme)) {
1725
+											$data = '//' . ltrim($data, ':/');
1726
+					}
1652 1727
 				},
1653 1728
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1654 1729
 				'disabled_after' => ' ($1)',
@@ -1668,8 +1743,9 @@  discard block
 block discarded – undo
1668 1743
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1669 1744
 		if ($message === false)
1670 1745
 		{
1671
-			if (isset($temp_bbc))
1672
-				$bbc_codes = $temp_bbc;
1746
+			if (isset($temp_bbc)) {
1747
+							$bbc_codes = $temp_bbc;
1748
+			}
1673 1749
 			usort($codes, function ($a, $b) {
1674 1750
 				return strcmp($a['tag'], $b['tag']);
1675 1751
 			});
@@ -1689,8 +1765,9 @@  discard block
 block discarded – undo
1689 1765
 		);
1690 1766
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1691 1767
 		{
1692
-			foreach ($itemcodes as $c => $dummy)
1693
-				$bbc_codes[$c] = array();
1768
+			foreach ($itemcodes as $c => $dummy) {
1769
+							$bbc_codes[$c] = array();
1770
+			}
1694 1771
 		}
1695 1772
 
1696 1773
 		// Shhhh!
@@ -1711,12 +1788,14 @@  discard block
 block discarded – undo
1711 1788
 		foreach ($codes as $code)
1712 1789
 		{
1713 1790
 			// Make it easier to process parameters later
1714
-			if (!empty($code['parameters']))
1715
-				ksort($code['parameters'], SORT_STRING);
1791
+			if (!empty($code['parameters'])) {
1792
+							ksort($code['parameters'], SORT_STRING);
1793
+			}
1716 1794
 
1717 1795
 			// If we are not doing every tag only do ones we are interested in.
1718
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1719
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1796
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1797
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1798
+			}
1720 1799
 		}
1721 1800
 		$codes = null;
1722 1801
 	}
@@ -1727,8 +1806,9 @@  discard block
 block discarded – undo
1727 1806
 		// It's likely this will change if the message is modified.
1728 1807
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1729 1808
 
1730
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1731
-			return $temp;
1809
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1810
+					return $temp;
1811
+		}
1732 1812
 
1733 1813
 		$cache_t = microtime();
1734 1814
 	}
@@ -1760,8 +1840,9 @@  discard block
 block discarded – undo
1760 1840
 		$disabled['flash'] = true;
1761 1841
 
1762 1842
 		// @todo Change maybe?
1763
-		if (!isset($_GET['images']))
1764
-			$disabled['img'] = true;
1843
+		if (!isset($_GET['images'])) {
1844
+					$disabled['img'] = true;
1845
+		}
1765 1846
 
1766 1847
 		// @todo Interface/setting to add more?
1767 1848
 	}
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1786 1867
 
1787 1868
 		// Failsafe.
1788
-		if ($pos === false || $last_pos > $pos)
1789
-			$pos = strlen($message) + 1;
1869
+		if ($pos === false || $last_pos > $pos) {
1870
+					$pos = strlen($message) + 1;
1871
+		}
1790 1872
 
1791 1873
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1792 1874
 		if ($last_pos < $pos - 1)
@@ -1805,8 +1887,9 @@  discard block
 block discarded – undo
1805 1887
 
1806 1888
 				// <br> should be empty.
1807 1889
 				$empty_tags = array('br', 'hr');
1808
-				foreach ($empty_tags as $tag)
1809
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1890
+				foreach ($empty_tags as $tag) {
1891
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1892
+				}
1810 1893
 
1811 1894
 				// b, u, i, s, pre... basic tags.
1812 1895
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1815,8 +1898,9 @@  discard block
 block discarded – undo
1815 1898
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1816 1899
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1817 1900
 
1818
-					if ($diff > 0)
1819
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1901
+					if ($diff > 0) {
1902
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1903
+					}
1820 1904
 				}
1821 1905
 
1822 1906
 				// Do <img ...> - with security... action= -> action-.
@@ -1829,8 +1913,9 @@  discard block
 block discarded – undo
1829 1913
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1830 1914
 
1831 1915
 						// Remove action= from the URL - no funny business, now.
1832
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1833
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1916
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1917
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1918
+						}
1834 1919
 
1835 1920
 						// Check if the image is larger than allowed.
1836 1921
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1851,9 +1936,9 @@  discard block
 block discarded – undo
1851 1936
 
1852 1937
 							// Set the new image tag.
1853 1938
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1939
+						} else {
1940
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1854 1941
 						}
1855
-						else
1856
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1857 1942
 					}
1858 1943
 
1859 1944
 					$data = strtr($data, $replaces);
@@ -1866,16 +1951,18 @@  discard block
 block discarded – undo
1866 1951
 				$no_autolink_area = false;
1867 1952
 				if (!empty($open_tags))
1868 1953
 				{
1869
-					foreach ($open_tags as $open_tag)
1870
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1954
+					foreach ($open_tags as $open_tag) {
1955
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1871 1956
 							$no_autolink_area = true;
1957
+					}
1872 1958
 				}
1873 1959
 
1874 1960
 				// Don't go backwards.
1875 1961
 				// @todo Don't think is the real solution....
1876 1962
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1877
-				if ($pos < $lastAutoPos)
1878
-					$no_autolink_area = true;
1963
+				if ($pos < $lastAutoPos) {
1964
+									$no_autolink_area = true;
1965
+				}
1879 1966
 				$lastAutoPos = $pos;
1880 1967
 
1881 1968
 				if (!$no_autolink_area)
@@ -1984,17 +2071,19 @@  discard block
 block discarded – undo
1984 2071
 							if ($scheme == 'mailto')
1985 2072
 							{
1986 2073
 								$email_address = str_replace('mailto:', '', $url);
1987
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1988
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1989
-								else
1990
-									return $url;
2074
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2075
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2076
+								} else {
2077
+																	return $url;
2078
+								}
1991 2079
 							}
1992 2080
 
1993 2081
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1994
-							if (empty($scheme))
1995
-								$fullUrl = '//' . ltrim($url, ':/');
1996
-							else
1997
-								$fullUrl = $url;
2082
+							if (empty($scheme)) {
2083
+															$fullUrl = '//' . ltrim($url, ':/');
2084
+							} else {
2085
+															$fullUrl = $url;
2086
+							}
1998 2087
 
1999 2088
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2000 2089
 						}, $data);
@@ -2043,16 +2132,18 @@  discard block
 block discarded – undo
2043 2132
 		}
2044 2133
 
2045 2134
 		// Are we there yet?  Are we there yet?
2046
-		if ($pos >= strlen($message) - 1)
2047
-			break;
2135
+		if ($pos >= strlen($message) - 1) {
2136
+					break;
2137
+		}
2048 2138
 
2049 2139
 		$tags = strtolower($message[$pos + 1]);
2050 2140
 
2051 2141
 		if ($tags == '/' && !empty($open_tags))
2052 2142
 		{
2053 2143
 			$pos2 = strpos($message, ']', $pos + 1);
2054
-			if ($pos2 == $pos + 2)
2055
-				continue;
2144
+			if ($pos2 == $pos + 2) {
2145
+							continue;
2146
+			}
2056 2147
 
2057 2148
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2058 2149
 
@@ -2062,8 +2153,9 @@  discard block
 block discarded – undo
2062 2153
 			do
2063 2154
 			{
2064 2155
 				$tag = array_pop($open_tags);
2065
-				if (!$tag)
2066
-					break;
2156
+				if (!$tag) {
2157
+									break;
2158
+				}
2067 2159
 
2068 2160
 				if (!empty($tag['block_level']))
2069 2161
 				{
@@ -2077,10 +2169,11 @@  discard block
 block discarded – undo
2077 2169
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2078 2170
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2079 2171
 					{
2080
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2081
-							if ($temp['tag'] == $look_for)
2172
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2173
+													if ($temp['tag'] == $look_for)
2082 2174
 							{
2083 2175
 								$block_level = !empty($temp['block_level']);
2176
+						}
2084 2177
 								break;
2085 2178
 							}
2086 2179
 					}
@@ -2102,15 +2195,15 @@  discard block
 block discarded – undo
2102 2195
 			{
2103 2196
 				$open_tags = $to_close;
2104 2197
 				continue;
2105
-			}
2106
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2198
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2107 2199
 			{
2108 2200
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2109 2201
 				{
2110
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2111
-						if ($temp['tag'] == $look_for)
2202
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2203
+											if ($temp['tag'] == $look_for)
2112 2204
 						{
2113 2205
 							$block_level = !empty($temp['block_level']);
2206
+					}
2114 2207
 							break;
2115 2208
 						}
2116 2209
 				}
@@ -2118,8 +2211,9 @@  discard block
 block discarded – undo
2118 2211
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2119 2212
 				if (!$block_level)
2120 2213
 				{
2121
-					foreach ($to_close as $tag)
2122
-						array_push($open_tags, $tag);
2214
+					foreach ($to_close as $tag) {
2215
+											array_push($open_tags, $tag);
2216
+					}
2123 2217
 					continue;
2124 2218
 				}
2125 2219
 			}
@@ -2132,14 +2226,17 @@  discard block
 block discarded – undo
2132 2226
 
2133 2227
 				// See the comment at the end of the big loop - just eating whitespace ;).
2134 2228
 				$whitespace_regex = '';
2135
-				if (!empty($tag['block_level']))
2136
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2229
+				if (!empty($tag['block_level'])) {
2230
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2231
+				}
2137 2232
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2138
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2139
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2233
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2234
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2235
+				}
2140 2236
 
2141
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2142
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2237
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2238
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2239
+				}
2143 2240
 			}
2144 2241
 
2145 2242
 			if (!empty($to_close))
@@ -2152,8 +2249,9 @@  discard block
 block discarded – undo
2152 2249
 		}
2153 2250
 
2154 2251
 		// No tags for this character, so just keep going (fastest possible course.)
2155
-		if (!isset($bbc_codes[$tags]))
2156
-			continue;
2252
+		if (!isset($bbc_codes[$tags])) {
2253
+					continue;
2254
+		}
2157 2255
 
2158 2256
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2159 2257
 		$tag = null;
@@ -2162,44 +2260,52 @@  discard block
 block discarded – undo
2162 2260
 			$pt_strlen = strlen($possible['tag']);
2163 2261
 
2164 2262
 			// Not a match?
2165
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2166
-				continue;
2263
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2264
+							continue;
2265
+			}
2167 2266
 
2168 2267
 			$next_c = $message[$pos + 1 + $pt_strlen];
2169 2268
 
2170 2269
 			// A test validation?
2171
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2172
-				continue;
2270
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2271
+							continue;
2272
+			}
2173 2273
 			// Do we want parameters?
2174 2274
 			elseif (!empty($possible['parameters']))
2175 2275
 			{
2176
-				if ($next_c != ' ')
2177
-					continue;
2178
-			}
2179
-			elseif (isset($possible['type']))
2276
+				if ($next_c != ' ') {
2277
+									continue;
2278
+				}
2279
+			} elseif (isset($possible['type']))
2180 2280
 			{
2181 2281
 				// Do we need an equal sign?
2182
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2183
-					continue;
2282
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2283
+									continue;
2284
+				}
2184 2285
 				// Maybe we just want a /...
2185
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2186
-					continue;
2286
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2287
+									continue;
2288
+				}
2187 2289
 				// An immediate ]?
2188
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2189
-					continue;
2290
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2291
+									continue;
2292
+				}
2190 2293
 			}
2191 2294
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2192
-			elseif ($next_c != ']')
2193
-				continue;
2295
+			elseif ($next_c != ']') {
2296
+							continue;
2297
+			}
2194 2298
 
2195 2299
 			// Check allowed tree?
2196
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2197
-				continue;
2198
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2199
-				continue;
2300
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2301
+							continue;
2302
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2303
+							continue;
2304
+			}
2200 2305
 			// If this is in the list of disallowed child tags, don't parse it.
2201
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2202
-				continue;
2306
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2307
+							continue;
2308
+			}
2203 2309
 
2204 2310
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2205 2311
 
@@ -2211,8 +2317,9 @@  discard block
 block discarded – undo
2211 2317
 				foreach ($open_tags as $open_quote)
2212 2318
 				{
2213 2319
 					// Every parent quote this quote has flips the styling
2214
-					if ($open_quote['tag'] == 'quote')
2215
-						$quote_alt = !$quote_alt;
2320
+					if ($open_quote['tag'] == 'quote') {
2321
+											$quote_alt = !$quote_alt;
2322
+					}
2216 2323
 				}
2217 2324
 				// Add a class to the quote to style alternating blockquotes
2218 2325
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2223,8 +2330,9 @@  discard block
 block discarded – undo
2223 2330
 			{
2224 2331
 				// Build a regular expression for each parameter for the current tag.
2225 2332
 				$preg = array();
2226
-				foreach ($possible['parameters'] as $p => $info)
2227
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2333
+				foreach ($possible['parameters'] as $p => $info) {
2334
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2335
+				}
2228 2336
 
2229 2337
 				// Extract the string that potentially holds our parameters.
2230 2338
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2244,24 +2352,27 @@  discard block
 block discarded – undo
2244 2352
 
2245 2353
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2246 2354
 
2247
-					if ($match)
2248
-						$blob_counter = count($blobs) + 1;
2355
+					if ($match) {
2356
+											$blob_counter = count($blobs) + 1;
2357
+					}
2249 2358
 				}
2250 2359
 
2251 2360
 				// Didn't match our parameter list, try the next possible.
2252
-				if (!$match)
2253
-					continue;
2361
+				if (!$match) {
2362
+									continue;
2363
+				}
2254 2364
 
2255 2365
 				$params = array();
2256 2366
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2257 2367
 				{
2258 2368
 					$key = strtok(ltrim($matches[$i]), '=');
2259
-					if (isset($possible['parameters'][$key]['value']))
2260
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2261
-					elseif (isset($possible['parameters'][$key]['validate']))
2262
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2263
-					else
2264
-						$params['{' . $key . '}'] = $matches[$i + 1];
2369
+					if (isset($possible['parameters'][$key]['value'])) {
2370
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2372
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
+					} else {
2374
+											$params['{' . $key . '}'] = $matches[$i + 1];
2375
+					}
2265 2376
 
2266 2377
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2267 2378
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2269,23 +2380,26 @@  discard block
 block discarded – undo
2269 2380
 
2270 2381
 				foreach ($possible['parameters'] as $p => $info)
2271 2382
 				{
2272
-					if (!isset($params['{' . $p . '}']))
2273
-						$params['{' . $p . '}'] = '';
2383
+					if (!isset($params['{' . $p . '}'])) {
2384
+											$params['{' . $p . '}'] = '';
2385
+					}
2274 2386
 				}
2275 2387
 
2276 2388
 				$tag = $possible;
2277 2389
 
2278 2390
 				// Put the parameters into the string.
2279
-				if (isset($tag['before']))
2280
-					$tag['before'] = strtr($tag['before'], $params);
2281
-				if (isset($tag['after']))
2282
-					$tag['after'] = strtr($tag['after'], $params);
2283
-				if (isset($tag['content']))
2284
-					$tag['content'] = strtr($tag['content'], $params);
2391
+				if (isset($tag['before'])) {
2392
+									$tag['before'] = strtr($tag['before'], $params);
2393
+				}
2394
+				if (isset($tag['after'])) {
2395
+									$tag['after'] = strtr($tag['after'], $params);
2396
+				}
2397
+				if (isset($tag['content'])) {
2398
+									$tag['content'] = strtr($tag['content'], $params);
2399
+				}
2285 2400
 
2286 2401
 				$pos1 += strlen($given_param_string);
2287
-			}
2288
-			else
2402
+			} else
2289 2403
 			{
2290 2404
 				$tag = $possible;
2291 2405
 				$params = array();
@@ -2296,8 +2410,9 @@  discard block
 block discarded – undo
2296 2410
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2297 2411
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2298 2412
 		{
2299
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2300
-				continue;
2413
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2414
+							continue;
2415
+			}
2301 2416
 
2302 2417
 			$tag = $itemcodes[$message[$pos + 1]];
2303 2418
 
@@ -2318,9 +2433,9 @@  discard block
 block discarded – undo
2318 2433
 			{
2319 2434
 				array_pop($open_tags);
2320 2435
 				$code = '</li>';
2436
+			} else {
2437
+							$code = '';
2321 2438
 			}
2322
-			else
2323
-				$code = '';
2324 2439
 
2325 2440
 			// Now we open a new tag.
2326 2441
 			$open_tags[] = array(
@@ -2367,12 +2482,14 @@  discard block
 block discarded – undo
2367 2482
 		}
2368 2483
 
2369 2484
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2370
-		if ($tag === null)
2371
-			continue;
2485
+		if ($tag === null) {
2486
+					continue;
2487
+		}
2372 2488
 
2373 2489
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2374
-		if (isset($inside['disallow_children']))
2375
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2490
+		if (isset($inside['disallow_children'])) {
2491
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2492
+		}
2376 2493
 
2377 2494
 		// Is this tag disabled?
2378 2495
 		if (isset($disabled[$tag['tag']]))
@@ -2382,14 +2499,13 @@  discard block
 block discarded – undo
2382 2499
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2383 2500
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2384 2501
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2385
-			}
2386
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2502
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2387 2503
 			{
2388 2504
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2389 2505
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2506
+			} else {
2507
+							$tag['content'] = $tag['disabled_content'];
2390 2508
 			}
2391
-			else
2392
-				$tag['content'] = $tag['disabled_content'];
2393 2509
 		}
2394 2510
 
2395 2511
 		// we use this a lot
@@ -2399,8 +2515,9 @@  discard block
 block discarded – undo
2399 2515
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2400 2516
 		{
2401 2517
 			$n = count($open_tags) - 1;
2402
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2403
-				$n--;
2518
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2519
+							$n--;
2520
+			}
2404 2521
 
2405 2522
 			// Close all the non block level tags so this tag isn't surrounded by them.
2406 2523
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2412,12 +2529,15 @@  discard block
 block discarded – undo
2412 2529
 
2413 2530
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2414 2531
 				$whitespace_regex = '';
2415
-				if (!empty($tag['block_level']))
2416
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2417
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2418
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2419
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2420
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2532
+				if (!empty($tag['block_level'])) {
2533
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2534
+				}
2535
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2536
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2537
+				}
2538
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2539
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2540
+				}
2421 2541
 
2422 2542
 				array_pop($open_tags);
2423 2543
 			}
@@ -2435,16 +2555,19 @@  discard block
 block discarded – undo
2435 2555
 		elseif ($tag['type'] == 'unparsed_content')
2436 2556
 		{
2437 2557
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2438
-			if ($pos2 === false)
2439
-				continue;
2558
+			if ($pos2 === false) {
2559
+							continue;
2560
+			}
2440 2561
 
2441 2562
 			$data = substr($message, $pos1, $pos2 - $pos1);
2442 2563
 
2443
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2444
-				$data = substr($data, 4);
2564
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2565
+							$data = substr($data, 4);
2566
+			}
2445 2567
 
2446
-			if (isset($tag['validate']))
2447
-				$tag['validate']($tag, $data, $disabled, $params);
2568
+			if (isset($tag['validate'])) {
2569
+							$tag['validate']($tag, $data, $disabled, $params);
2570
+			}
2448 2571
 
2449 2572
 			$code = strtr($tag['content'], array('$1' => $data));
2450 2573
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2460,34 +2583,40 @@  discard block
 block discarded – undo
2460 2583
 			if (isset($tag['quoted']))
2461 2584
 			{
2462 2585
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2463
-				if ($tag['quoted'] != 'optional' && !$quoted)
2464
-					continue;
2586
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2587
+									continue;
2588
+				}
2465 2589
 
2466
-				if ($quoted)
2467
-					$pos1 += 6;
2590
+				if ($quoted) {
2591
+									$pos1 += 6;
2592
+				}
2593
+			} else {
2594
+							$quoted = false;
2468 2595
 			}
2469
-			else
2470
-				$quoted = false;
2471 2596
 
2472 2597
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2473
-			if ($pos2 === false)
2474
-				continue;
2598
+			if ($pos2 === false) {
2599
+							continue;
2600
+			}
2475 2601
 
2476 2602
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2477
-			if ($pos3 === false)
2478
-				continue;
2603
+			if ($pos3 === false) {
2604
+							continue;
2605
+			}
2479 2606
 
2480 2607
 			$data = array(
2481 2608
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2482 2609
 				substr($message, $pos1, $pos2 - $pos1)
2483 2610
 			);
2484 2611
 
2485
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2486
-				$data[0] = substr($data[0], 4);
2612
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2613
+							$data[0] = substr($data[0], 4);
2614
+			}
2487 2615
 
2488 2616
 			// Validation for my parking, please!
2489
-			if (isset($tag['validate']))
2490
-				$tag['validate']($tag, $data, $disabled, $params);
2617
+			if (isset($tag['validate'])) {
2618
+							$tag['validate']($tag, $data, $disabled, $params);
2619
+			}
2491 2620
 
2492 2621
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2493 2622
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2504,23 +2633,27 @@  discard block
 block discarded – undo
2504 2633
 		elseif ($tag['type'] == 'unparsed_commas_content')
2505 2634
 		{
2506 2635
 			$pos2 = strpos($message, ']', $pos1);
2507
-			if ($pos2 === false)
2508
-				continue;
2636
+			if ($pos2 === false) {
2637
+							continue;
2638
+			}
2509 2639
 
2510 2640
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2511
-			if ($pos3 === false)
2512
-				continue;
2641
+			if ($pos3 === false) {
2642
+							continue;
2643
+			}
2513 2644
 
2514 2645
 			// We want $1 to be the content, and the rest to be csv.
2515 2646
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2516 2647
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2517 2648
 
2518
-			if (isset($tag['validate']))
2519
-				$tag['validate']($tag, $data, $disabled, $params);
2649
+			if (isset($tag['validate'])) {
2650
+							$tag['validate']($tag, $data, $disabled, $params);
2651
+			}
2520 2652
 
2521 2653
 			$code = $tag['content'];
2522
-			foreach ($data as $k => $d)
2523
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2524 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2525 2658
 			$pos += strlen($code) - 1 + 2;
2526 2659
 		}
@@ -2528,24 +2661,28 @@  discard block
 block discarded – undo
2528 2661
 		elseif ($tag['type'] == 'unparsed_commas')
2529 2662
 		{
2530 2663
 			$pos2 = strpos($message, ']', $pos1);
2531
-			if ($pos2 === false)
2532
-				continue;
2664
+			if ($pos2 === false) {
2665
+							continue;
2666
+			}
2533 2667
 
2534 2668
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2535 2669
 
2536
-			if (isset($tag['validate']))
2537
-				$tag['validate']($tag, $data, $disabled, $params);
2670
+			if (isset($tag['validate'])) {
2671
+							$tag['validate']($tag, $data, $disabled, $params);
2672
+			}
2538 2673
 
2539 2674
 			// Fix after, for disabled code mainly.
2540
-			foreach ($data as $k => $d)
2541
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2675
+			foreach ($data as $k => $d) {
2676
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2677
+			}
2542 2678
 
2543 2679
 			$open_tags[] = $tag;
2544 2680
 
2545 2681
 			// Replace them out, $1, $2, $3, $4, etc.
2546 2682
 			$code = $tag['before'];
2547
-			foreach ($data as $k => $d)
2548
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2683
+			foreach ($data as $k => $d) {
2684
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2685
+			}
2549 2686
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2550 2687
 			$pos += strlen($code) - 1 + 2;
2551 2688
 		}
@@ -2556,28 +2693,33 @@  discard block
 block discarded – undo
2556 2693
 			if (isset($tag['quoted']))
2557 2694
 			{
2558 2695
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2559
-				if ($tag['quoted'] != 'optional' && !$quoted)
2560
-					continue;
2696
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2697
+									continue;
2698
+				}
2561 2699
 
2562
-				if ($quoted)
2563
-					$pos1 += 6;
2700
+				if ($quoted) {
2701
+									$pos1 += 6;
2702
+				}
2703
+			} else {
2704
+							$quoted = false;
2564 2705
 			}
2565
-			else
2566
-				$quoted = false;
2567 2706
 
2568 2707
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2569
-			if ($pos2 === false)
2570
-				continue;
2708
+			if ($pos2 === false) {
2709
+							continue;
2710
+			}
2571 2711
 
2572 2712
 			$data = substr($message, $pos1, $pos2 - $pos1);
2573 2713
 
2574 2714
 			// Validation for my parking, please!
2575
-			if (isset($tag['validate']))
2576
-				$tag['validate']($tag, $data, $disabled, $params);
2715
+			if (isset($tag['validate'])) {
2716
+							$tag['validate']($tag, $data, $disabled, $params);
2717
+			}
2577 2718
 
2578 2719
 			// For parsed content, we must recurse to avoid security problems.
2579
-			if ($tag['type'] != 'unparsed_equals')
2580
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2720
+			if ($tag['type'] != 'unparsed_equals') {
2721
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2722
+			}
2581 2723
 
2582 2724
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2583 2725
 
@@ -2589,34 +2731,40 @@  discard block
 block discarded – undo
2589 2731
 		}
2590 2732
 
2591 2733
 		// If this is block level, eat any breaks after it.
2592
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2593
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2734
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2735
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2736
+		}
2594 2737
 
2595 2738
 		// Are we trimming outside this tag?
2596
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2597
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2739
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2740
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2741
+		}
2598 2742
 	}
2599 2743
 
2600 2744
 	// Close any remaining tags.
2601
-	while ($tag = array_pop($open_tags))
2602
-		$message .= "\n" . $tag['after'] . "\n";
2745
+	while ($tag = array_pop($open_tags)) {
2746
+			$message .= "\n" . $tag['after'] . "\n";
2747
+	}
2603 2748
 
2604 2749
 	// Parse the smileys within the parts where it can be done safely.
2605 2750
 	if ($smileys === true)
2606 2751
 	{
2607 2752
 		$message_parts = explode("\n", $message);
2608
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2609
-			parsesmileys($message_parts[$i]);
2753
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2754
+					parsesmileys($message_parts[$i]);
2755
+		}
2610 2756
 
2611 2757
 		$message = implode('', $message_parts);
2612 2758
 	}
2613 2759
 
2614 2760
 	// No smileys, just get rid of the markers.
2615
-	else
2616
-		$message = strtr($message, array("\n" => ''));
2761
+	else {
2762
+			$message = strtr($message, array("\n" => ''));
2763
+	}
2617 2764
 
2618
-	if ($message !== '' && $message[0] === ' ')
2619
-		$message = '&nbsp;' . substr($message, 1);
2765
+	if ($message !== '' && $message[0] === ' ') {
2766
+			$message = '&nbsp;' . substr($message, 1);
2767
+	}
2620 2768
 
2621 2769
 	// Cleanup whitespace.
2622 2770
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2625,15 +2773,16 @@  discard block
 block discarded – undo
2625 2773
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2626 2774
 
2627 2775
 	// Cache the output if it took some time...
2628
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2629
-		cache_put_data($cache_key, $message, 240);
2776
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2777
+			cache_put_data($cache_key, $message, 240);
2778
+	}
2630 2779
 
2631 2780
 	// If this was a force parse revert if needed.
2632 2781
 	if (!empty($parse_tags))
2633 2782
 	{
2634
-		if (empty($temp_bbc))
2635
-			$bbc_codes = array();
2636
-		else
2783
+		if (empty($temp_bbc)) {
2784
+					$bbc_codes = array();
2785
+		} else
2637 2786
 		{
2638 2787
 			$bbc_codes = $temp_bbc;
2639 2788
 			unset($temp_bbc);
@@ -2660,8 +2809,9 @@  discard block
 block discarded – undo
2660 2809
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2661 2810
 
2662 2811
 	// No smiley set at all?!
2663
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2664
-		return;
2812
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2813
+			return;
2814
+	}
2665 2815
 
2666 2816
 	// If smileyPregSearch hasn't been set, do it now.
2667 2817
 	if (empty($smileyPregSearch))
@@ -2672,8 +2822,7 @@  discard block
 block discarded – undo
2672 2822
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2673 2823
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2674 2824
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2675
-		}
2676
-		else
2825
+		} else
2677 2826
 		{
2678 2827
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2679 2828
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2697,9 +2846,9 @@  discard block
 block discarded – undo
2697 2846
 				$smcFunc['db_free_result']($result);
2698 2847
 
2699 2848
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2849
+			} else {
2850
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2700 2851
 			}
2701
-			else
2702
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2703 2852
 		}
2704 2853
 
2705 2854
 		// The non-breaking-space is a complex thing...
@@ -2776,35 +2925,41 @@  discard block
 block discarded – undo
2776 2925
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2777 2926
 
2778 2927
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2779
-	if (!empty($context['flush_mail']))
2780
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2928
+	if (!empty($context['flush_mail'])) {
2929
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2781 2930
 		AddMailQueue(true);
2931
+	}
2782 2932
 
2783 2933
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2784 2934
 
2785
-	if ($add)
2786
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2935
+	if ($add) {
2936
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2937
+	}
2787 2938
 
2788 2939
 	// Put the session ID in.
2789
-	if (defined('SID') && SID != '')
2790
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2940
+	if (defined('SID') && SID != '') {
2941
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2942
+	}
2791 2943
 	// Keep that debug in their for template debugging!
2792
-	elseif (isset($_GET['debug']))
2793
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2944
+	elseif (isset($_GET['debug'])) {
2945
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2946
+	}
2794 2947
 
2795 2948
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2796 2949
 	{
2797
-		if (defined('SID') && SID != '')
2798
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2950
+		if (defined('SID') && SID != '') {
2951
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799 2952
 				function ($m) use ($scripturl)
2800 2953
 				{
2801 2954
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2955
+		}
2802 2956
 				}, $setLocation);
2803
-		else
2804
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2957
+		else {
2958
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805 2959
 				function ($m) use ($scripturl)
2806 2960
 				{
2807 2961
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2962
+		}
2808 2963
 				}, $setLocation);
2809 2964
 	}
2810 2965
 
@@ -2815,8 +2970,9 @@  discard block
 block discarded – undo
2815 2970
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2816 2971
 
2817 2972
 	// Debugging.
2818
-	if (isset($db_show_debug) && $db_show_debug === true)
2819
-		$_SESSION['debug_redirect'] = $db_cache;
2973
+	if (isset($db_show_debug) && $db_show_debug === true) {
2974
+			$_SESSION['debug_redirect'] = $db_cache;
2975
+	}
2820 2976
 
2821 2977
 	obExit(false);
2822 2978
 }
@@ -2835,51 +2991,60 @@  discard block
 block discarded – undo
2835 2991
 
2836 2992
 	// Attempt to prevent a recursive loop.
2837 2993
 	++$level;
2838
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2839
-		exit;
2840
-	if ($from_fatal_error)
2841
-		$has_fatal_error = true;
2994
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2995
+			exit;
2996
+	}
2997
+	if ($from_fatal_error) {
2998
+			$has_fatal_error = true;
2999
+	}
2842 3000
 
2843 3001
 	// Clear out the stat cache.
2844 3002
 	trackStats();
2845 3003
 
2846 3004
 	// If we have mail to send, send it.
2847
-	if (!empty($context['flush_mail']))
2848
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3005
+	if (!empty($context['flush_mail'])) {
3006
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2849 3007
 		AddMailQueue(true);
3008
+	}
2850 3009
 
2851 3010
 	$do_header = $header === null ? !$header_done : $header;
2852
-	if ($do_footer === null)
2853
-		$do_footer = $do_header;
3011
+	if ($do_footer === null) {
3012
+			$do_footer = $do_header;
3013
+	}
2854 3014
 
2855 3015
 	// Has the template/header been done yet?
2856 3016
 	if ($do_header)
2857 3017
 	{
2858 3018
 		// Was the page title set last minute? Also update the HTML safe one.
2859
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2860
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3019
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3020
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3021
+		}
2861 3022
 
2862 3023
 		// Start up the session URL fixer.
2863 3024
 		ob_start('ob_sessrewrite');
2864 3025
 
2865
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2866
-			$buffers = explode(',', $settings['output_buffers']);
2867
-		elseif (!empty($settings['output_buffers']))
2868
-			$buffers = $settings['output_buffers'];
2869
-		else
2870
-			$buffers = array();
3026
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3027
+					$buffers = explode(',', $settings['output_buffers']);
3028
+		} elseif (!empty($settings['output_buffers'])) {
3029
+					$buffers = $settings['output_buffers'];
3030
+		} else {
3031
+					$buffers = array();
3032
+		}
2871 3033
 
2872
-		if (isset($modSettings['integrate_buffer']))
2873
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3034
+		if (isset($modSettings['integrate_buffer'])) {
3035
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3036
+		}
2874 3037
 
2875
-		if (!empty($buffers))
2876
-			foreach ($buffers as $function)
3038
+		if (!empty($buffers)) {
3039
+					foreach ($buffers as $function)
2877 3040
 			{
2878 3041
 				$call = call_helper($function, true);
3042
+		}
2879 3043
 
2880 3044
 				// Is it valid?
2881
-				if (!empty($call))
2882
-					ob_start($call);
3045
+				if (!empty($call)) {
3046
+									ob_start($call);
3047
+				}
2883 3048
 			}
2884 3049
 
2885 3050
 		// Display the screen in the logical order.
@@ -2891,8 +3056,9 @@  discard block
 block discarded – undo
2891 3056
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2892 3057
 
2893 3058
 		// Anything special to put out?
2894
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2895
-			echo $context['insert_after_template'];
3059
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3060
+					echo $context['insert_after_template'];
3061
+		}
2896 3062
 
2897 3063
 		// Just so we don't get caught in an endless loop of errors from the footer...
2898 3064
 		if (!$footer_done)
@@ -2901,14 +3067,16 @@  discard block
 block discarded – undo
2901 3067
 			template_footer();
2902 3068
 
2903 3069
 			// (since this is just debugging... it's okay that it's after </html>.)
2904
-			if (!isset($_REQUEST['xml']))
2905
-				displayDebug();
3070
+			if (!isset($_REQUEST['xml'])) {
3071
+							displayDebug();
3072
+			}
2906 3073
 		}
2907 3074
 	}
2908 3075
 
2909 3076
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2910
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2911
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3077
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3078
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3079
+	}
2912 3080
 
2913 3081
 	// For session check verification.... don't switch browsers...
2914 3082
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2917,9 +3085,10 @@  discard block
 block discarded – undo
2917 3085
 	call_integration_hook('integrate_exit', array($do_footer));
2918 3086
 
2919 3087
 	// Don't exit if we're coming from index.php; that will pass through normally.
2920
-	if (!$from_index)
2921
-		exit;
2922
-}
3088
+	if (!$from_index) {
3089
+			exit;
3090
+	}
3091
+	}
2923 3092
 
2924 3093
 /**
2925 3094
  * Get the size of a specified image with better error handling.
@@ -2938,8 +3107,9 @@  discard block
 block discarded – undo
2938 3107
 	$url = str_replace(' ', '%20', $url);
2939 3108
 
2940 3109
 	// Can we pull this from the cache... please please?
2941
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2942
-		return $temp;
3110
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3111
+			return $temp;
3112
+	}
2943 3113
 	$t = microtime();
2944 3114
 
2945 3115
 	// Get the host to pester...
@@ -2949,12 +3119,10 @@  discard block
 block discarded – undo
2949 3119
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2950 3120
 	{
2951 3121
 		return false;
2952
-	}
2953
-	elseif (!isset($match[1]))
3122
+	} elseif (!isset($match[1]))
2954 3123
 	{
2955 3124
 		$size = @getimagesize($url);
2956
-	}
2957
-	else
3125
+	} else
2958 3126
 	{
2959 3127
 		// Try to connect to the server... give it half a second.
2960 3128
 		$temp = 0;
@@ -2993,12 +3161,14 @@  discard block
 block discarded – undo
2993 3161
 	}
2994 3162
 
2995 3163
 	// If we didn't get it, we failed.
2996
-	if (!isset($size))
2997
-		$size = false;
3164
+	if (!isset($size)) {
3165
+			$size = false;
3166
+	}
2998 3167
 
2999 3168
 	// If this took a long time, we may never have to do it again, but then again we might...
3000
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3001
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3169
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3170
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3171
+	}
3002 3172
 
3003 3173
 	// Didn't work.
3004 3174
 	return $size;
@@ -3016,8 +3186,9 @@  discard block
 block discarded – undo
3016 3186
 
3017 3187
 	// Under SSI this function can be called more then once.  That can cause some problems.
3018 3188
 	//   So only run the function once unless we are forced to run it again.
3019
-	if ($loaded && !$forceload)
3020
-		return;
3189
+	if ($loaded && !$forceload) {
3190
+			return;
3191
+	}
3021 3192
 
3022 3193
 	$loaded = true;
3023 3194
 
@@ -3029,14 +3200,16 @@  discard block
 block discarded – undo
3029 3200
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3030 3201
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3031 3202
 	{
3032
-		if (trim($context['news_lines'][$i]) == '')
3033
-			continue;
3203
+		if (trim($context['news_lines'][$i]) == '') {
3204
+					continue;
3205
+		}
3034 3206
 
3035 3207
 		// Clean it up for presentation ;).
3036 3208
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3037 3209
 	}
3038
-	if (!empty($context['news_lines']))
3039
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3210
+	if (!empty($context['news_lines'])) {
3211
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3212
+	}
3040 3213
 
3041 3214
 	if (!$user_info['is_guest'])
3042 3215
 	{
@@ -3045,40 +3218,48 @@  discard block
 block discarded – undo
3045 3218
 		$context['user']['alerts'] = &$user_info['alerts'];
3046 3219
 
3047 3220
 		// Personal message popup...
3048
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3049
-			$context['user']['popup_messages'] = true;
3050
-		else
3051
-			$context['user']['popup_messages'] = false;
3221
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3222
+					$context['user']['popup_messages'] = true;
3223
+		} else {
3224
+					$context['user']['popup_messages'] = false;
3225
+		}
3052 3226
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3053 3227
 
3054
-		if (allowedTo('moderate_forum'))
3055
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3228
+		if (allowedTo('moderate_forum')) {
3229
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3230
+		}
3056 3231
 
3057 3232
 		$context['user']['avatar'] = array();
3058 3233
 
3059 3234
 		// Check for gravatar first since we might be forcing them...
3060 3235
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3061 3236
 		{
3062
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3063
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3064
-			else
3065
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3237
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3238
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3239
+			} else {
3240
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3241
+			}
3066 3242
 		}
3067 3243
 		// Uploaded?
3068
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3069
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3244
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3245
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3246
+		}
3070 3247
 		// Full URL?
3071
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3072
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3248
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3249
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3250
+		}
3073 3251
 		// Otherwise we assume it's server stored.
3074
-		elseif ($user_info['avatar']['url'] != '')
3075
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3252
+		elseif ($user_info['avatar']['url'] != '') {
3253
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3254
+		}
3076 3255
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3077
-		else
3078
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3256
+		else {
3257
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3258
+		}
3079 3259
 
3080
-		if (!empty($context['user']['avatar']))
3081
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3260
+		if (!empty($context['user']['avatar'])) {
3261
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3262
+		}
3082 3263
 
3083 3264
 		// Figure out how long they've been logged in.
3084 3265
 		$context['user']['total_time_logged_in'] = array(
@@ -3086,8 +3267,7 @@  discard block
 block discarded – undo
3086 3267
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3087 3268
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3088 3269
 		);
3089
-	}
3090
-	else
3270
+	} else
3091 3271
 	{
3092 3272
 		$context['user']['messages'] = 0;
3093 3273
 		$context['user']['unread_messages'] = 0;
@@ -3095,12 +3275,14 @@  discard block
 block discarded – undo
3095 3275
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3096 3276
 		$context['user']['popup_messages'] = false;
3097 3277
 
3098
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3099
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3278
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3279
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3280
+		}
3100 3281
 
3101 3282
 		// If we've upgraded recently, go easy on the passwords.
3102
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3103
-			$context['disable_login_hashing'] = true;
3283
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3284
+					$context['disable_login_hashing'] = true;
3285
+		}
3104 3286
 	}
3105 3287
 
3106 3288
 	// Setup the main menu items.
@@ -3113,8 +3295,8 @@  discard block
 block discarded – undo
3113 3295
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3114 3296
 
3115 3297
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3116
-	if ($context['show_pm_popup'])
3117
-		addInlineJavaScript('
3298
+	if ($context['show_pm_popup']) {
3299
+			addInlineJavaScript('
3118 3300
 		jQuery(document).ready(function($) {
3119 3301
 			new smc_Popup({
3120 3302
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3122,15 +3304,17 @@  discard block
 block discarded – undo
3122 3304
 				icon_class: \'generic_icons mail_new\'
3123 3305
 			});
3124 3306
 		});');
3307
+	}
3125 3308
 
3126 3309
 	// Add a generic "Are you sure?" confirmation message.
3127 3310
 	addInlineJavaScript('
3128 3311
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3129 3312
 
3130 3313
 	// Now add the capping code for avatars.
3131
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3132
-		addInlineCss('
3314
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3315
+			addInlineCss('
3133 3316
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3317
+	}
3134 3318
 
3135 3319
 	// This looks weird, but it's because BoardIndex.php references the variable.
3136 3320
 	$context['common_stats']['latest_member'] = array(
@@ -3147,11 +3331,13 @@  discard block
 block discarded – undo
3147 3331
 	);
3148 3332
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3149 3333
 
3150
-	if (empty($settings['theme_version']))
3151
-		addJavaScriptVar('smf_scripturl', $scripturl);
3334
+	if (empty($settings['theme_version'])) {
3335
+			addJavaScriptVar('smf_scripturl', $scripturl);
3336
+	}
3152 3337
 
3153
-	if (!isset($context['page_title']))
3154
-		$context['page_title'] = '';
3338
+	if (!isset($context['page_title'])) {
3339
+			$context['page_title'] = '';
3340
+	}
3155 3341
 
3156 3342
 	// Set some specific vars.
3157 3343
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3161,21 +3347,23 @@  discard block
 block discarded – undo
3161 3347
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3162 3348
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3163 3349
 
3164
-	if (!empty($context['meta_keywords']))
3165
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3350
+	if (!empty($context['meta_keywords'])) {
3351
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3352
+	}
3166 3353
 
3167
-	if (!empty($context['canonical_url']))
3168
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3354
+	if (!empty($context['canonical_url'])) {
3355
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3356
+	}
3169 3357
 
3170
-	if (!empty($settings['og_image']))
3171
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3358
+	if (!empty($settings['og_image'])) {
3359
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3360
+	}
3172 3361
 
3173 3362
 	if (!empty($context['meta_description']))
3174 3363
 	{
3175 3364
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3176 3365
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3177
-	}
3178
-	else
3366
+	} else
3179 3367
 	{
3180 3368
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3181 3369
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3200,8 +3388,9 @@  discard block
 block discarded – undo
3200 3388
 	$memory_needed = memoryReturnBytes($needed);
3201 3389
 
3202 3390
 	// should we account for how much is currently being used?
3203
-	if ($in_use)
3204
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3391
+	if ($in_use) {
3392
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3393
+	}
3205 3394
 
3206 3395
 	// if more is needed, request it
3207 3396
 	if ($memory_current < $memory_needed)
@@ -3224,8 +3413,9 @@  discard block
 block discarded – undo
3224 3413
  */
3225 3414
 function memoryReturnBytes($val)
3226 3415
 {
3227
-	if (is_integer($val))
3228
-		return $val;
3416
+	if (is_integer($val)) {
3417
+			return $val;
3418
+	}
3229 3419
 
3230 3420
 	// Separate the number from the designator
3231 3421
 	$val = trim($val);
@@ -3261,10 +3451,11 @@  discard block
 block discarded – undo
3261 3451
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3262 3452
 
3263 3453
 		// Are we debugging the template/html content?
3264
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3265
-			header('Content-Type: application/xhtml+xml');
3266
-		elseif (!isset($_REQUEST['xml']))
3267
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3454
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3455
+					header('Content-Type: application/xhtml+xml');
3456
+		} elseif (!isset($_REQUEST['xml'])) {
3457
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3458
+		}
3268 3459
 	}
3269 3460
 
3270 3461
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3273,8 +3464,9 @@  discard block
 block discarded – undo
3273 3464
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3274 3465
 	{
3275 3466
 		$position = array_search('body', $context['template_layers']);
3276
-		if ($position === false)
3277
-			$position = array_search('main', $context['template_layers']);
3467
+		if ($position === false) {
3468
+					$position = array_search('main', $context['template_layers']);
3469
+		}
3278 3470
 
3279 3471
 		if ($position !== false)
3280 3472
 		{
@@ -3302,23 +3494,25 @@  discard block
 block discarded – undo
3302 3494
 
3303 3495
 			foreach ($securityFiles as $i => $securityFile)
3304 3496
 			{
3305
-				if (!file_exists($boarddir . '/' . $securityFile))
3306
-					unset($securityFiles[$i]);
3497
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3498
+									unset($securityFiles[$i]);
3499
+				}
3307 3500
 			}
3308 3501
 
3309 3502
 			// We are already checking so many files...just few more doesn't make any difference! :P
3310
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3311
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3312
-
3313
-			else
3314
-				$path = $modSettings['attachmentUploadDir'];
3503
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3504
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3505
+			} else {
3506
+							$path = $modSettings['attachmentUploadDir'];
3507
+			}
3315 3508
 
3316 3509
 			secureDirectory($path, true);
3317 3510
 			secureDirectory($cachedir);
3318 3511
 
3319 3512
 			// If agreement is enabled, at least the english version shall exists
3320
-			if ($modSettings['requireAgreement'])
3321
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3513
+			if ($modSettings['requireAgreement']) {
3514
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3515
+			}
3322 3516
 
3323 3517
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3324 3518
 			{
@@ -3333,18 +3527,21 @@  discard block
 block discarded – undo
3333 3527
 					echo '
3334 3528
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3335 3529
 
3336
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3337
-						echo '
3530
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3531
+											echo '
3338 3532
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3533
+					}
3339 3534
 				}
3340 3535
 
3341
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3342
-					echo '
3536
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3537
+									echo '
3343 3538
 				<strong>', $txt['cache_writable'], '</strong><br>';
3539
+				}
3344 3540
 
3345
-				if (!empty($agreement))
3346
-					echo '
3541
+				if (!empty($agreement)) {
3542
+									echo '
3347 3543
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3544
+				}
3348 3545
 
3349 3546
 				echo '
3350 3547
 			</p>
@@ -3359,16 +3556,18 @@  discard block
 block discarded – undo
3359 3556
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3360 3557
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3361 3558
 
3362
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3363
-				echo '
3559
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3560
+							echo '
3364 3561
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3562
+			}
3365 3563
 
3366
-			if (!empty($_SESSION['ban']['expire_time']))
3367
-				echo '
3564
+			if (!empty($_SESSION['ban']['expire_time'])) {
3565
+							echo '
3368 3566
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3369
-			else
3370
-				echo '
3567
+			} else {
3568
+							echo '
3371 3569
 					<div>', $txt['your_ban_expires_never'], '</div>';
3570
+			}
3372 3571
 
3373 3572
 			echo '
3374 3573
 				</div>';
@@ -3384,8 +3583,9 @@  discard block
 block discarded – undo
3384 3583
 	global $forum_copyright, $software_year, $forum_version;
3385 3584
 
3386 3585
 	// Don't display copyright for things like SSI.
3387
-	if (!isset($forum_version) || !isset($software_year))
3388
-		return;
3586
+	if (!isset($forum_version) || !isset($software_year)) {
3587
+			return;
3588
+	}
3389 3589
 
3390 3590
 	// Put in the version...
3391 3591
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3403,9 +3603,10 @@  discard block
 block discarded – undo
3403 3603
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3404 3604
 	$context['load_queries'] = $db_count;
3405 3605
 
3406
-	foreach (array_reverse($context['template_layers']) as $layer)
3407
-		loadSubTemplate($layer . '_below', true);
3408
-}
3606
+	foreach (array_reverse($context['template_layers']) as $layer) {
3607
+			loadSubTemplate($layer . '_below', true);
3608
+	}
3609
+	}
3409 3610
 
3410 3611
 /**
3411 3612
  * Output the Javascript files
@@ -3436,8 +3637,7 @@  discard block
 block discarded – undo
3436 3637
 			{
3437 3638
 				echo '
3438 3639
 		var ', $key, ';';
3439
-			}
3440
-			else
3640
+			} else
3441 3641
 			{
3442 3642
 				echo '
3443 3643
 		var ', $key, ' = ', $value, ';';
@@ -3452,26 +3652,27 @@  discard block
 block discarded – undo
3452 3652
 	foreach ($context['javascript_files'] as $id => $js_file)
3453 3653
 	{
3454 3654
 		// Last minute call! allow theme authors to disable single files.
3455
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3456
-			continue;
3655
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3656
+					continue;
3657
+		}
3457 3658
 
3458 3659
 		// By default all files don't get minimized unless the file explicitly says so!
3459 3660
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3460 3661
 		{
3461
-			if ($do_deferred && !empty($js_file['options']['defer']))
3462
-				$toMinifyDefer[] = $js_file;
3463
-
3464
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3465
-				$toMinify[] = $js_file;
3662
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3663
+							$toMinifyDefer[] = $js_file;
3664
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3665
+							$toMinify[] = $js_file;
3666
+			}
3466 3667
 
3467 3668
 			// Grab a random seed.
3468
-			if (!isset($minSeed))
3469
-				$minSeed = $js_file['options']['seed'];
3470
-		}
3471
-
3472
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3473
-			echo '
3669
+			if (!isset($minSeed)) {
3670
+							$minSeed = $js_file['options']['seed'];
3671
+			}
3672
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3673
+					echo '
3474 3674
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3675
+		}
3475 3676
 	}
3476 3677
 
3477 3678
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3479,14 +3680,14 @@  discard block
 block discarded – undo
3479 3680
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3480 3681
 
3481 3682
 		// Minify process couldn't work, print each individual files.
3482
-		if (!empty($result) && is_array($result))
3483
-			foreach ($result as $minFailedFile)
3683
+		if (!empty($result) && is_array($result)) {
3684
+					foreach ($result as $minFailedFile)
3484 3685
 				echo '
3485 3686
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3486
-
3487
-		else
3488
-			echo '
3687
+		} else {
3688
+					echo '
3489 3689
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3690
+		}
3490 3691
 	}
3491 3692
 
3492 3693
 	// Inline JavaScript - Actually useful some times!
@@ -3497,8 +3698,9 @@  discard block
 block discarded – undo
3497 3698
 			echo '
3498 3699
 <script>';
3499 3700
 
3500
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3501
-				echo $js_code;
3701
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3702
+							echo $js_code;
3703
+			}
3502 3704
 
3503 3705
 			echo '
3504 3706
 </script>';
@@ -3509,8 +3711,9 @@  discard block
 block discarded – undo
3509 3711
 			echo '
3510 3712
 	<script>';
3511 3713
 
3512
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3513
-				echo $js_code;
3714
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3715
+							echo $js_code;
3716
+			}
3514 3717
 
3515 3718
 			echo '
3516 3719
 	</script>';
@@ -3535,8 +3738,9 @@  discard block
 block discarded – undo
3535 3738
 	foreach ($context['css_files'] as $id => $file)
3536 3739
 	{
3537 3740
 		// Last minute call! allow theme authors to disable single files.
3538
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3539
-			continue;
3741
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3742
+					continue;
3743
+		}
3540 3744
 
3541 3745
 		// By default all files don't get minimized unless the file explicitly says so!
3542 3746
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3544,12 +3748,12 @@  discard block
 block discarded – undo
3544 3748
 			$toMinify[] = $file;
3545 3749
 
3546 3750
 			// Grab a random seed.
3547
-			if (!isset($minSeed))
3548
-				$minSeed = $file['options']['seed'];
3751
+			if (!isset($minSeed)) {
3752
+							$minSeed = $file['options']['seed'];
3753
+			}
3754
+		} else {
3755
+					$normal[] = $file['fileUrl'];
3549 3756
 		}
3550
-
3551
-		else
3552
-			$normal[] = $file['fileUrl'];
3553 3757
 	}
3554 3758
 
3555 3759
 	if (!empty($toMinify))
@@ -3557,28 +3761,30 @@  discard block
 block discarded – undo
3557 3761
 		$result = custMinify($toMinify, 'css');
3558 3762
 
3559 3763
 		// Minify process couldn't work, print each individual files.
3560
-		if (!empty($result) && is_array($result))
3561
-			foreach ($result as $minFailedFile)
3764
+		if (!empty($result) && is_array($result)) {
3765
+					foreach ($result as $minFailedFile)
3562 3766
 				echo '
3563 3767
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3564
-
3565
-		else
3566
-			echo '
3768
+		} else {
3769
+					echo '
3567 3770
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3771
+		}
3568 3772
 	}
3569 3773
 
3570 3774
 	// Print the rest after the minified files.
3571
-	if (!empty($normal))
3572
-		foreach ($normal as $nf)
3775
+	if (!empty($normal)) {
3776
+			foreach ($normal as $nf)
3573 3777
 			echo '
3574 3778
 	<link rel="stylesheet" href="', $nf ,'">';
3779
+	}
3575 3780
 
3576 3781
 	if ($db_show_debug === true)
3577 3782
 	{
3578 3783
 		// Try to keep only what's useful.
3579 3784
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3580
-		foreach ($context['css_files'] as $file)
3581
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3785
+		foreach ($context['css_files'] as $file) {
3786
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3787
+		}
3582 3788
 	}
3583 3789
 
3584 3790
 	if (!empty($context['css_header']))
@@ -3586,9 +3792,10 @@  discard block
 block discarded – undo
3586 3792
 		echo '
3587 3793
 	<style>';
3588 3794
 
3589
-		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3795
+		foreach ($context['css_header'] as $css) {
3796
+					echo $css .'
3591 3797
 	';
3798
+		}
3592 3799
 
3593 3800
 		echo'
3594 3801
 	</style>';
@@ -3612,15 +3819,17 @@  discard block
 block discarded – undo
3612 3819
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3613 3820
 	$data = !empty($data) ? $data : false;
3614 3821
 
3615
-	if (empty($type) || empty($data))
3616
-		return false;
3822
+	if (empty($type) || empty($data)) {
3823
+			return false;
3824
+	}
3617 3825
 
3618 3826
 	// Did we already did this?
3619 3827
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3620 3828
 
3621 3829
 	// Already done?
3622
-	if (!empty($toCache))
3623
-		return true;
3830
+	if (!empty($toCache)) {
3831
+			return true;
3832
+	}
3624 3833
 
3625 3834
 	// No namespaces, sorry!
3626 3835
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3702,8 +3911,9 @@  discard block
 block discarded – undo
3702 3911
 	global $modSettings, $smcFunc;
3703 3912
 
3704 3913
 	// Just make up a nice hash...
3705
-	if ($new)
3706
-		return sha1(md5($filename . time()) . mt_rand());
3914
+	if ($new) {
3915
+			return sha1(md5($filename . time()) . mt_rand());
3916
+	}
3707 3917
 
3708 3918
 	// Just make sure that attachment id is only a int
3709 3919
 	$attachment_id = (int) $attachment_id;
@@ -3720,23 +3930,25 @@  discard block
 block discarded – undo
3720 3930
 				'id_attach' => $attachment_id,
3721 3931
 			));
3722 3932
 
3723
-		if ($smcFunc['db_num_rows']($request) === 0)
3724
-			return false;
3933
+		if ($smcFunc['db_num_rows']($request) === 0) {
3934
+					return false;
3935
+		}
3725 3936
 
3726 3937
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3727 3938
 		$smcFunc['db_free_result']($request);
3728 3939
 	}
3729 3940
 
3730 3941
 	// Still no hash? mmm...
3731
-	if (empty($file_hash))
3732
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3942
+	if (empty($file_hash)) {
3943
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3944
+	}
3733 3945
 
3734 3946
 	// Are we using multiple directories?
3735
-	if (is_array($modSettings['attachmentUploadDir']))
3736
-		$path = $modSettings['attachmentUploadDir'][$dir];
3737
-
3738
-	else
3739
-		$path = $modSettings['attachmentUploadDir'];
3947
+	if (is_array($modSettings['attachmentUploadDir'])) {
3948
+			$path = $modSettings['attachmentUploadDir'][$dir];
3949
+	} else {
3950
+			$path = $modSettings['attachmentUploadDir'];
3951
+	}
3740 3952
 
3741 3953
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3742 3954
 }
@@ -3751,8 +3963,9 @@  discard block
 block discarded – undo
3751 3963
 function ip2range($fullip)
3752 3964
 {
3753 3965
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3754
-	if ($fullip == 'unknown')
3755
-		$fullip = '255.255.255.255';
3966
+	if ($fullip == 'unknown') {
3967
+			$fullip = '255.255.255.255';
3968
+	}
3756 3969
 
3757 3970
 	$ip_parts = explode('-', $fullip);
3758 3971
 	$ip_array = array();
@@ -3776,10 +3989,11 @@  discard block
 block discarded – undo
3776 3989
 		$ip_array['low'] = $ip_parts[0];
3777 3990
 		$ip_array['high'] = $ip_parts[1];
3778 3991
 		return $ip_array;
3779
-	}
3780
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3992
+	} elseif (count($ip_parts) == 2) {
3993
+		// if ip 22.22.*-22.22.*
3781 3994
 	{
3782 3995
 		$valid_low = isValidIP($ip_parts[0]);
3996
+	}
3783 3997
 		$valid_high = isValidIP($ip_parts[1]);
3784 3998
 		$count = 0;
3785 3999
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3794,7 +4008,9 @@  discard block
 block discarded – undo
3794 4008
 				$ip_parts[0] .= $mode . $min;
3795 4009
 				$valid_low = isValidIP($ip_parts[0]);
3796 4010
 				$count++;
3797
-				if ($count > 9) break;
4011
+				if ($count > 9) {
4012
+					break;
4013
+				}
3798 4014
 			}
3799 4015
 		}
3800 4016
 
@@ -3808,7 +4024,9 @@  discard block
 block discarded – undo
3808 4024
 				$ip_parts[1] .= $mode . $max;
3809 4025
 				$valid_high = isValidIP($ip_parts[1]);
3810 4026
 				$count++;
3811
-				if ($count > 9) break;
4027
+				if ($count > 9) {
4028
+					break;
4029
+				}
3812 4030
 			}
3813 4031
 		}
3814 4032
 
@@ -3833,46 +4051,54 @@  discard block
 block discarded – undo
3833 4051
 {
3834 4052
 	global $modSettings;
3835 4053
 
3836
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3837
-		return $host;
4054
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4055
+			return $host;
4056
+	}
3838 4057
 	$t = microtime();
3839 4058
 
3840 4059
 	// Try the Linux host command, perhaps?
3841 4060
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3842 4061
 	{
3843
-		if (!isset($modSettings['host_to_dis']))
3844
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3845
-		else
3846
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4062
+		if (!isset($modSettings['host_to_dis'])) {
4063
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4064
+		} else {
4065
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4066
+		}
3847 4067
 
3848 4068
 		// Did host say it didn't find anything?
3849
-		if (strpos($test, 'not found') !== false)
3850
-			$host = '';
4069
+		if (strpos($test, 'not found') !== false) {
4070
+					$host = '';
4071
+		}
3851 4072
 		// Invalid server option?
3852
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3853
-			updateSettings(array('host_to_dis' => 1));
4073
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4074
+					updateSettings(array('host_to_dis' => 1));
4075
+		}
3854 4076
 		// Maybe it found something, after all?
3855
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3856
-			$host = $match[1];
4077
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4078
+					$host = $match[1];
4079
+		}
3857 4080
 	}
3858 4081
 
3859 4082
 	// This is nslookup; usually only Windows, but possibly some Unix?
3860 4083
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3861 4084
 	{
3862 4085
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3863
-		if (strpos($test, 'Non-existent domain') !== false)
3864
-			$host = '';
3865
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3866
-			$host = $match[1];
4086
+		if (strpos($test, 'Non-existent domain') !== false) {
4087
+					$host = '';
4088
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4089
+					$host = $match[1];
4090
+		}
3867 4091
 	}
3868 4092
 
3869 4093
 	// This is the last try :/.
3870
-	if (!isset($host) || $host === false)
3871
-		$host = @gethostbyaddr($ip);
4094
+	if (!isset($host) || $host === false) {
4095
+			$host = @gethostbyaddr($ip);
4096
+	}
3872 4097
 
3873 4098
 	// It took a long time, so let's cache it!
3874
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3875
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4099
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4100
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4101
+	}
3876 4102
 
3877 4103
 	return $host;
3878 4104
 }
@@ -3908,20 +4134,21 @@  discard block
 block discarded – undo
3908 4134
 			{
3909 4135
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3910 4136
 				$total = 0;
3911
-				for ($i = 0; $i < $max_chars; $i++)
3912
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4137
+				for ($i = 0; $i < $max_chars; $i++) {
4138
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4139
+				}
3913 4140
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3914 4141
 			}
3915 4142
 		}
3916 4143
 		return array_unique($returned_ints);
3917
-	}
3918
-	else
4144
+	} else
3919 4145
 	{
3920 4146
 		// Trim characters before and after and add slashes for database insertion.
3921 4147
 		$returned_words = array();
3922
-		foreach ($words as $word)
3923
-			if (($word = trim($word, '-_\'')) !== '')
4148
+		foreach ($words as $word) {
4149
+					if (($word = trim($word, '-_\'')) !== '')
3924 4150
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4151
+		}
3925 4152
 
3926 4153
 		// Filter out all words that occur more than once.
3927 4154
 		return array_unique($returned_words);
@@ -3943,16 +4170,18 @@  discard block
 block discarded – undo
3943 4170
 	global $settings, $txt;
3944 4171
 
3945 4172
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3946
-	if (function_exists('template_create_button') && !$force_use)
3947
-		return template_create_button($name, $alt, $label = '', $custom = '');
4173
+	if (function_exists('template_create_button') && !$force_use) {
4174
+			return template_create_button($name, $alt, $label = '', $custom = '');
4175
+	}
3948 4176
 
3949
-	if (!$settings['use_image_buttons'])
3950
-		return $txt[$alt];
3951
-	elseif (!empty($settings['use_buttons']))
3952
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3953
-	else
3954
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3955
-}
4177
+	if (!$settings['use_image_buttons']) {
4178
+			return $txt[$alt];
4179
+	} elseif (!empty($settings['use_buttons'])) {
4180
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4181
+	} else {
4182
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4183
+	}
4184
+	}
3956 4185
 
3957 4186
 /**
3958 4187
  * Sets up all of the top menu buttons
@@ -3995,9 +4224,10 @@  discard block
 block discarded – undo
3995 4224
 	var user_menus = new smc_PopupMenu();
3996 4225
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997 4226
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3998
-		if ($context['allow_pm'])
3999
-			addInlineJavaScript('
4227
+		if ($context['allow_pm']) {
4228
+					addInlineJavaScript('
4000 4229
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4230
+		}
4001 4231
 
4002 4232
 		if (!empty($modSettings['enable_ajax_alerts']))
4003 4233
 		{
@@ -4157,88 +4387,96 @@  discard block
 block discarded – undo
4157 4387
 
4158 4388
 		// Now we put the buttons in the context so the theme can use them.
4159 4389
 		$menu_buttons = array();
4160
-		foreach ($buttons as $act => $button)
4161
-			if (!empty($button['show']))
4390
+		foreach ($buttons as $act => $button) {
4391
+					if (!empty($button['show']))
4162 4392
 			{
4163 4393
 				$button['active_button'] = false;
4394
+		}
4164 4395
 
4165 4396
 				// This button needs some action.
4166
-				if (isset($button['action_hook']))
4167
-					$needs_action_hook = true;
4397
+				if (isset($button['action_hook'])) {
4398
+									$needs_action_hook = true;
4399
+				}
4168 4400
 
4169 4401
 				// Make sure the last button truly is the last button.
4170 4402
 				if (!empty($button['is_last']))
4171 4403
 				{
4172
-					if (isset($last_button))
4173
-						unset($menu_buttons[$last_button]['is_last']);
4404
+					if (isset($last_button)) {
4405
+											unset($menu_buttons[$last_button]['is_last']);
4406
+					}
4174 4407
 					$last_button = $act;
4175 4408
 				}
4176 4409
 
4177 4410
 				// Go through the sub buttons if there are any.
4178
-				if (!empty($button['sub_buttons']))
4179
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4411
+				if (!empty($button['sub_buttons'])) {
4412
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4180 4413
 					{
4181 4414
 						if (empty($subbutton['show']))
4182 4415
 							unset($button['sub_buttons'][$key]);
4416
+				}
4183 4417
 
4184 4418
 						// 2nd level sub buttons next...
4185 4419
 						if (!empty($subbutton['sub_buttons']))
4186 4420
 						{
4187 4421
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4188 4422
 							{
4189
-								if (empty($sub_button2['show']))
4190
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4423
+								if (empty($sub_button2['show'])) {
4424
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4425
+								}
4191 4426
 							}
4192 4427
 						}
4193 4428
 					}
4194 4429
 
4195 4430
 				// Does this button have its own icon?
4196
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4197
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4198
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4199
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4200
-				elseif (isset($button['icon']))
4201
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4202
-				else
4203
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4431
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4432
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4433
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4434
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4435
+				} elseif (isset($button['icon'])) {
4436
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4437
+				} else {
4438
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4439
+				}
4204 4440
 
4205 4441
 				$menu_buttons[$act] = $button;
4206 4442
 			}
4207 4443
 
4208
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4209
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4444
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4445
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4446
+		}
4210 4447
 	}
4211 4448
 
4212 4449
 	$context['menu_buttons'] = $menu_buttons;
4213 4450
 
4214 4451
 	// Logging out requires the session id in the url.
4215
-	if (isset($context['menu_buttons']['logout']))
4216
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4452
+	if (isset($context['menu_buttons']['logout'])) {
4453
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4454
+	}
4217 4455
 
4218 4456
 	// Figure out which action we are doing so we can set the active tab.
4219 4457
 	// Default to home.
4220 4458
 	$current_action = 'home';
4221 4459
 
4222
-	if (isset($context['menu_buttons'][$context['current_action']]))
4223
-		$current_action = $context['current_action'];
4224
-	elseif ($context['current_action'] == 'search2')
4225
-		$current_action = 'search';
4226
-	elseif ($context['current_action'] == 'theme')
4227
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4228
-	elseif ($context['current_action'] == 'register2')
4229
-		$current_action = 'register';
4230
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4231
-		$current_action = 'login';
4232
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4233
-		$current_action = 'moderate';
4460
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4461
+			$current_action = $context['current_action'];
4462
+	} elseif ($context['current_action'] == 'search2') {
4463
+			$current_action = 'search';
4464
+	} elseif ($context['current_action'] == 'theme') {
4465
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4466
+	} elseif ($context['current_action'] == 'register2') {
4467
+			$current_action = 'register';
4468
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4469
+			$current_action = 'login';
4470
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4471
+			$current_action = 'moderate';
4472
+	}
4234 4473
 
4235 4474
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4236 4475
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4237 4476
 	{
4238 4477
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4239 4478
 		$context[$current_action] = true;
4240
-	}
4241
-	elseif ($context['current_action'] == 'pm')
4479
+	} elseif ($context['current_action'] == 'pm')
4242 4480
 	{
4243 4481
 		$current_action = 'self_pm';
4244 4482
 		$context['self_pm'] = true;
@@ -4281,12 +4519,14 @@  discard block
 block discarded – undo
4281 4519
 	}
4282 4520
 
4283 4521
 	// Not all actions are simple.
4284
-	if (!empty($needs_action_hook))
4285
-		call_integration_hook('integrate_current_action', array(&$current_action));
4522
+	if (!empty($needs_action_hook)) {
4523
+			call_integration_hook('integrate_current_action', array(&$current_action));
4524
+	}
4286 4525
 
4287
-	if (isset($context['menu_buttons'][$current_action]))
4288
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4289
-}
4526
+	if (isset($context['menu_buttons'][$current_action])) {
4527
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4528
+	}
4529
+	}
4290 4530
 
4291 4531
 /**
4292 4532
  * Generate a random seed and ensure it's stored in settings.
@@ -4310,30 +4550,35 @@  discard block
 block discarded – undo
4310 4550
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4311 4551
 	global $context, $txt;
4312 4552
 
4313
-	if ($db_show_debug === true)
4314
-		$context['debug']['hooks'][] = $hook;
4553
+	if ($db_show_debug === true) {
4554
+			$context['debug']['hooks'][] = $hook;
4555
+	}
4315 4556
 
4316 4557
 	// Need to have some control.
4317
-	if (!isset($context['instances']))
4318
-		$context['instances'] = array();
4558
+	if (!isset($context['instances'])) {
4559
+			$context['instances'] = array();
4560
+	}
4319 4561
 
4320 4562
 	$results = array();
4321
-	if (empty($modSettings[$hook]))
4322
-		return $results;
4563
+	if (empty($modSettings[$hook])) {
4564
+			return $results;
4565
+	}
4323 4566
 
4324 4567
 	$functions = explode(',', $modSettings[$hook]);
4325 4568
 	// Loop through each function.
4326 4569
 	foreach ($functions as $function)
4327 4570
 	{
4328 4571
 		// Hook has been marked as "disabled". Skip it!
4329
-		if (strpos($function, '!') !== false)
4330
-			continue;
4572
+		if (strpos($function, '!') !== false) {
4573
+					continue;
4574
+		}
4331 4575
 
4332 4576
 		$call = call_helper($function, true);
4333 4577
 
4334 4578
 		// Is it valid?
4335
-		if (!empty($call))
4336
-			$results[$function] = call_user_func_array($call, $parameters);
4579
+		if (!empty($call)) {
4580
+					$results[$function] = call_user_func_array($call, $parameters);
4581
+		}
4337 4582
 
4338 4583
 		// Whatever it was suppose to call, it failed :(
4339 4584
 		elseif (!empty($function))
@@ -4349,8 +4594,9 @@  discard block
 block discarded – undo
4349 4594
 			}
4350 4595
 
4351 4596
 			// "Assume" the file resides on $boarddir somewhere...
4352
-			else
4353
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4597
+			else {
4598
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4599
+			}
4354 4600
 		}
4355 4601
 	}
4356 4602
 
@@ -4372,12 +4618,14 @@  discard block
 block discarded – undo
4372 4618
 	global $smcFunc, $modSettings;
4373 4619
 
4374 4620
 	// Any objects?
4375
-	if ($object)
4376
-		$function = $function . '#';
4621
+	if ($object) {
4622
+			$function = $function . '#';
4623
+	}
4377 4624
 
4378 4625
 	// Any files  to load?
4379
-	if (!empty($file) && is_string($file))
4380
-		$function = $file . (!empty($function) ? '|' . $function : '');
4626
+	if (!empty($file) && is_string($file)) {
4627
+			$function = $file . (!empty($function) ? '|' . $function : '');
4628
+	}
4381 4629
 
4382 4630
 	// Get the correct string.
4383 4631
 	$integration_call = $function;
@@ -4399,13 +4647,14 @@  discard block
 block discarded – undo
4399 4647
 		if (!empty($current_functions))
4400 4648
 		{
4401 4649
 			$current_functions = explode(',', $current_functions);
4402
-			if (in_array($integration_call, $current_functions))
4403
-				return;
4650
+			if (in_array($integration_call, $current_functions)) {
4651
+							return;
4652
+			}
4404 4653
 
4405 4654
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4655
+		} else {
4656
+					$permanent_functions = array($integration_call);
4406 4657
 		}
4407
-		else
4408
-			$permanent_functions = array($integration_call);
4409 4658
 
4410 4659
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4411 4660
 	}
@@ -4414,8 +4663,9 @@  discard block
 block discarded – undo
4414 4663
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4415 4664
 
4416 4665
 	// Do nothing, if it's already there.
4417
-	if (in_array($integration_call, $functions))
4418
-		return;
4666
+	if (in_array($integration_call, $functions)) {
4667
+			return;
4668
+	}
4419 4669
 
4420 4670
 	$functions[] = $integration_call;
4421 4671
 	$modSettings[$hook] = implode(',', $functions);
@@ -4438,12 +4688,14 @@  discard block
 block discarded – undo
4438 4688
 	global $smcFunc, $modSettings;
4439 4689
 
4440 4690
 	// Any objects?
4441
-	if ($object)
4442
-		$function = $function . '#';
4691
+	if ($object) {
4692
+			$function = $function . '#';
4693
+	}
4443 4694
 
4444 4695
 	// Any files  to load?
4445
-	if (!empty($file) && is_string($file))
4446
-		$function = $file . '|' . $function;
4696
+	if (!empty($file) && is_string($file)) {
4697
+			$function = $file . '|' . $function;
4698
+	}
4447 4699
 
4448 4700
 	// Get the correct string.
4449 4701
 	$integration_call = $function;
@@ -4464,16 +4716,18 @@  discard block
 block discarded – undo
4464 4716
 	{
4465 4717
 		$current_functions = explode(',', $current_functions);
4466 4718
 
4467
-		if (in_array($integration_call, $current_functions))
4468
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4719
+		if (in_array($integration_call, $current_functions)) {
4720
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4721
+		}
4469 4722
 	}
4470 4723
 
4471 4724
 	// Turn the function list into something usable.
4472 4725
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4473 4726
 
4474 4727
 	// You can only remove it if it's available.
4475
-	if (!in_array($integration_call, $functions))
4476
-		return;
4728
+	if (!in_array($integration_call, $functions)) {
4729
+			return;
4730
+	}
4477 4731
 
4478 4732
 	$functions = array_diff($functions, array($integration_call));
4479 4733
 	$modSettings[$hook] = implode(',', $functions);
@@ -4494,17 +4748,20 @@  discard block
 block discarded – undo
4494 4748
 	global $context, $smcFunc, $txt, $db_show_debug;
4495 4749
 
4496 4750
 	// Really?
4497
-	if (empty($string))
4498
-		return false;
4751
+	if (empty($string)) {
4752
+			return false;
4753
+	}
4499 4754
 
4500 4755
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4501 4756
 	// A closure? should be a callable one.
4502
-	if (is_array($string) || $string instanceof Closure)
4503
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4757
+	if (is_array($string) || $string instanceof Closure) {
4758
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4759
+	}
4504 4760
 
4505 4761
 	// No full objects, sorry! pass a method or a property instead!
4506
-	if (is_object($string))
4507
-		return false;
4762
+	if (is_object($string)) {
4763
+			return false;
4764
+	}
4508 4765
 
4509 4766
 	// Stay vitaminized my friends...
4510 4767
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4513,8 +4770,9 @@  discard block
 block discarded – undo
4513 4770
 	$string = load_file($string);
4514 4771
 
4515 4772
 	// Loaded file failed
4516
-	if (empty($string))
4517
-		return false;
4773
+	if (empty($string)) {
4774
+			return false;
4775
+	}
4518 4776
 
4519 4777
 	// Found a method.
4520 4778
 	if (strpos($string, '::') !== false)
@@ -4535,8 +4793,9 @@  discard block
 block discarded – undo
4535 4793
 				// Add another one to the list.
4536 4794
 				if ($db_show_debug === true)
4537 4795
 				{
4538
-					if (!isset($context['debug']['instances']))
4539
-						$context['debug']['instances'] = array();
4796
+					if (!isset($context['debug']['instances'])) {
4797
+											$context['debug']['instances'] = array();
4798
+					}
4540 4799
 
4541 4800
 					$context['debug']['instances'][$class] = $class;
4542 4801
 				}
@@ -4546,13 +4805,15 @@  discard block
 block discarded – undo
4546 4805
 		}
4547 4806
 
4548 4807
 		// Right then. This is a call to a static method.
4549
-		else
4550
-			$func = array($class, $method);
4808
+		else {
4809
+					$func = array($class, $method);
4810
+		}
4551 4811
 	}
4552 4812
 
4553 4813
 	// Nope! just a plain regular function.
4554
-	else
4555
-		$func = $string;
4814
+	else {
4815
+			$func = $string;
4816
+	}
4556 4817
 
4557 4818
 	// Right, we got what we need, time to do some checks.
4558 4819
 	if (!is_callable($func, false, $callable_name))
@@ -4568,17 +4829,18 @@  discard block
 block discarded – undo
4568 4829
 	else
4569 4830
 	{
4570 4831
 		// What are we gonna do about it?
4571
-		if ($return)
4572
-			return $func;
4832
+		if ($return) {
4833
+					return $func;
4834
+		}
4573 4835
 
4574 4836
 		// If this is a plain function, avoid the heat of calling call_user_func().
4575 4837
 		else
4576 4838
 		{
4577
-			if (is_array($func))
4578
-				call_user_func($func);
4579
-
4580
-			else
4581
-				$func();
4839
+			if (is_array($func)) {
4840
+							call_user_func($func);
4841
+			} else {
4842
+							$func();
4843
+			}
4582 4844
 		}
4583 4845
 	}
4584 4846
 }
@@ -4595,31 +4857,34 @@  discard block
 block discarded – undo
4595 4857
 {
4596 4858
 	global $sourcedir, $txt, $boarddir, $settings;
4597 4859
 
4598
-	if (empty($string))
4599
-		return false;
4860
+	if (empty($string)) {
4861
+			return false;
4862
+	}
4600 4863
 
4601 4864
 	if (strpos($string, '|') !== false)
4602 4865
 	{
4603 4866
 		list ($file, $string) = explode('|', $string);
4604 4867
 
4605 4868
 		// Match the wildcards to their regular vars.
4606
-		if (empty($settings['theme_dir']))
4607
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4608
-
4609
-		else
4610
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4869
+		if (empty($settings['theme_dir'])) {
4870
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4871
+		} else {
4872
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4873
+		}
4611 4874
 
4612 4875
 		// Load the file if it can be loaded.
4613
-		if (file_exists($absPath))
4614
-			require_once($absPath);
4876
+		if (file_exists($absPath)) {
4877
+					require_once($absPath);
4878
+		}
4615 4879
 
4616 4880
 		// No? try a fallback to $sourcedir
4617 4881
 		else
4618 4882
 		{
4619 4883
 			$absPath = $sourcedir .'/'. $file;
4620 4884
 
4621
-			if (file_exists($absPath))
4622
-				require_once($absPath);
4885
+			if (file_exists($absPath)) {
4886
+							require_once($absPath);
4887
+			}
4623 4888
 
4624 4889
 			// Sorry, can't do much for you at this point.
4625 4890
 			else
@@ -4646,8 +4911,9 @@  discard block
 block discarded – undo
4646 4911
 	global $user_info, $smcFunc;
4647 4912
 
4648 4913
 	// Make sure we have something to work with.
4649
-	if (empty($topic))
4650
-		return array();
4914
+	if (empty($topic)) {
4915
+			return array();
4916
+	}
4651 4917
 
4652 4918
 
4653 4919
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4670,8 +4936,9 @@  discard block
 block discarded – undo
4670 4936
 				'topic' => $topic,
4671 4937
 			)
4672 4938
 		);
4673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4674
-			$temp[] = (int) $row['content_id'];
4939
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4940
+					$temp[] = (int) $row['content_id'];
4941
+		}
4675 4942
 
4676 4943
 		cache_put_data($cache_key, $temp, $ttl);
4677 4944
 	}
@@ -4692,8 +4959,9 @@  discard block
 block discarded – undo
4692 4959
 {
4693 4960
 	global $context;
4694 4961
 
4695
-	if (empty($string))
4696
-		return $string;
4962
+	if (empty($string)) {
4963
+			return $string;
4964
+	}
4697 4965
 
4698 4966
 	// UTF-8 occurences of MS special characters
4699 4967
 	$findchars_utf8 = array(
@@ -4734,10 +5002,11 @@  discard block
 block discarded – undo
4734 5002
 		'--',	// &mdash;
4735 5003
 	);
4736 5004
 
4737
-	if ($context['utf8'])
4738
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4739
-	else
4740
-		$string = str_replace($findchars_iso, $replacechars, $string);
5005
+	if ($context['utf8']) {
5006
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5007
+	} else {
5008
+			$string = str_replace($findchars_iso, $replacechars, $string);
5009
+	}
4741 5010
 
4742 5011
 	return $string;
4743 5012
 }
@@ -4756,49 +5025,59 @@  discard block
 block discarded – undo
4756 5025
 {
4757 5026
 	global $context;
4758 5027
 
4759
-	if (!isset($matches[2]))
4760
-		return '';
5028
+	if (!isset($matches[2])) {
5029
+			return '';
5030
+	}
4761 5031
 
4762 5032
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4763 5033
 
4764 5034
 	// remove left to right / right to left overrides
4765
-	if ($num === 0x202D || $num === 0x202E)
4766
-		return '';
5035
+	if ($num === 0x202D || $num === 0x202E) {
5036
+			return '';
5037
+	}
4767 5038
 
4768 5039
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4769
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4770
-		return '&#' . $num . ';';
5040
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5041
+			return '&#' . $num . ';';
5042
+	}
4771 5043
 
4772 5044
 	if (empty($context['utf8']))
4773 5045
 	{
4774 5046
 		// no control characters
4775
-		if ($num < 0x20)
4776
-			return '';
5047
+		if ($num < 0x20) {
5048
+					return '';
5049
+		}
4777 5050
 		// text is text
4778
-		elseif ($num < 0x80)
4779
-			return chr($num);
5051
+		elseif ($num < 0x80) {
5052
+					return chr($num);
5053
+		}
4780 5054
 		// all others get html-ised
4781
-		else
4782
-			return '&#' . $matches[2] . ';';
4783
-	}
4784
-	else
5055
+		else {
5056
+					return '&#' . $matches[2] . ';';
5057
+		}
5058
+	} else
4785 5059
 	{
4786 5060
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4787 5061
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4788
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4789
-			return '';
5062
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5063
+					return '';
5064
+		}
4790 5065
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4791
-		elseif ($num < 0x80)
4792
-			return chr($num);
5066
+		elseif ($num < 0x80) {
5067
+					return chr($num);
5068
+		}
4793 5069
 		// <0x800 (2048)
4794
-		elseif ($num < 0x800)
4795
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5070
+		elseif ($num < 0x800) {
5071
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5072
+		}
4796 5073
 		// < 0x10000 (65536)
4797
-		elseif ($num < 0x10000)
4798
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5074
+		elseif ($num < 0x10000) {
5075
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5076
+		}
4799 5077
 		// <= 0x10FFFF (1114111)
4800
-		else
4801
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5078
+		else {
5079
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5080
+		}
4802 5081
 	}
4803 5082
 }
4804 5083
 
@@ -4814,28 +5093,34 @@  discard block
 block discarded – undo
4814 5093
  */
4815 5094
 function fixchar__callback($matches)
4816 5095
 {
4817
-	if (!isset($matches[1]))
4818
-		return '';
5096
+	if (!isset($matches[1])) {
5097
+			return '';
5098
+	}
4819 5099
 
4820 5100
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4821 5101
 
4822 5102
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4823 5103
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4824
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4825
-		return '';
5104
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5105
+			return '';
5106
+	}
4826 5107
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4827
-	elseif ($num < 0x80)
4828
-		return chr($num);
5108
+	elseif ($num < 0x80) {
5109
+			return chr($num);
5110
+	}
4829 5111
 	// <0x800 (2048)
4830
-	elseif ($num < 0x800)
4831
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5112
+	elseif ($num < 0x800) {
5113
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5114
+	}
4832 5115
 	// < 0x10000 (65536)
4833
-	elseif ($num < 0x10000)
4834
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5116
+	elseif ($num < 0x10000) {
5117
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5118
+	}
4835 5119
 	// <= 0x10FFFF (1114111)
4836
-	else
4837
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4838
-}
5120
+	else {
5121
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+	}
5123
+	}
4839 5124
 
4840 5125
 /**
4841 5126
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4848,17 +5133,19 @@  discard block
 block discarded – undo
4848 5133
  */
4849 5134
 function entity_fix__callback($matches)
4850 5135
 {
4851
-	if (!isset($matches[2]))
4852
-		return '';
5136
+	if (!isset($matches[2])) {
5137
+			return '';
5138
+	}
4853 5139
 
4854 5140
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4855 5141
 
4856 5142
 	// we don't allow control characters, characters out of range, byte markers, etc
4857
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4858
-		return '';
4859
-	else
4860
-		return '&#' . $num . ';';
4861
-}
5143
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5144
+			return '';
5145
+	} else {
5146
+			return '&#' . $num . ';';
5147
+	}
5148
+	}
4862 5149
 
4863 5150
 /**
4864 5151
  * Return a Gravatar URL based on
@@ -4882,18 +5169,23 @@  discard block
 block discarded – undo
4882 5169
 		$ratings = array('G', 'PG', 'R', 'X');
4883 5170
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4884 5171
 		$url_params = array();
4885
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4886
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4887
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4888
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4889
-		if (!empty($modSettings['avatar_max_width_external']))
4890
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4891
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4892
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5172
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5173
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5174
+		}
5175
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5176
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5177
+		}
5178
+		if (!empty($modSettings['avatar_max_width_external'])) {
5179
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5180
+		}
5181
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5182
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4893 5183
 				$size_string = $modSettings['avatar_max_height_external'];
5184
+		}
4894 5185
 
4895
-		if (!empty($size_string))
4896
-			$url_params[] = 's=' . $size_string;
5186
+		if (!empty($size_string)) {
5187
+					$url_params[] = 's=' . $size_string;
5188
+		}
4897 5189
 	}
4898 5190
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4899 5191
 
@@ -4912,22 +5204,26 @@  discard block
 block discarded – undo
4912 5204
 	static $timezones = null, $lastwhen = null;
4913 5205
 
4914 5206
 	// No point doing this over if we already did it once
4915
-	if (!empty($timezones) && $when == $lastwhen)
4916
-		return $timezones;
4917
-	else
4918
-		$lastwhen = $when;
5207
+	if (!empty($timezones) && $when == $lastwhen) {
5208
+			return $timezones;
5209
+	} else {
5210
+			$lastwhen = $when;
5211
+	}
4919 5212
 
4920 5213
 	// Parseable datetime string?
4921
-	if (is_int($timestamp = strtotime($when)))
4922
-		$when = $timestamp;
5214
+	if (is_int($timestamp = strtotime($when))) {
5215
+			$when = $timestamp;
5216
+	}
4923 5217
 
4924 5218
 	// A Unix timestamp?
4925
-	elseif (is_numeric($when))
4926
-		$when = intval($when);
5219
+	elseif (is_numeric($when)) {
5220
+			$when = intval($when);
5221
+	}
4927 5222
 
4928 5223
 	// Invalid value? Just get current Unix timestamp.
4929
-	else
4930
-		$when = time();
5224
+	else {
5225
+			$when = time();
5226
+	}
4931 5227
 
4932 5228
 	// We'll need these too
4933 5229
 	$date_when = date_create('@' . $when);
@@ -4991,8 +5287,9 @@  discard block
 block discarded – undo
4991 5287
 	foreach ($priority_countries as $country)
4992 5288
 	{
4993 5289
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4994
-		if (!empty($country_tzids))
4995
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5290
+		if (!empty($country_tzids)) {
5291
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5292
+		}
4996 5293
 	}
4997 5294
 
4998 5295
 	// Process the preferred timezones first, then the rest.
@@ -5002,8 +5299,9 @@  discard block
 block discarded – undo
5002 5299
 	foreach ($tzids as $tzid)
5003 5300
 	{
5004 5301
 		// We don't want UTC right now
5005
-		if ($tzid == 'UTC')
5006
-			continue;
5302
+		if ($tzid == 'UTC') {
5303
+					continue;
5304
+		}
5007 5305
 
5008 5306
 		$tz = timezone_open($tzid);
5009 5307
 
@@ -5018,12 +5316,14 @@  discard block
 block discarded – undo
5018 5316
 		$tzgeo = timezone_location_get($tz);
5019 5317
 
5020 5318
 		// Don't overwrite our preferred tzids
5021
-		if (empty($zones[$tzkey]['tzid']))
5022
-			$zones[$tzkey]['tzid'] = $tzid;
5319
+		if (empty($zones[$tzkey]['tzid'])) {
5320
+					$zones[$tzkey]['tzid'] = $tzid;
5321
+		}
5023 5322
 
5024 5323
 		// A time zone from a prioritized country?
5025
-		if (in_array($tzid, $priority_tzids))
5026
-			$priority_zones[$tzkey] = true;
5324
+		if (in_array($tzid, $priority_tzids)) {
5325
+					$priority_zones[$tzkey] = true;
5326
+		}
5027 5327
 
5028 5328
 		// Keep track of the location and offset for this tzid
5029 5329
 		$tzid_parts = explode('/', $tzid);
@@ -5044,15 +5344,17 @@  discard block
 block discarded – undo
5044 5344
 
5045 5345
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5046 5346
 
5047
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5048
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5049
-		else
5050
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5347
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5348
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5349
+		} else {
5350
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5351
+		}
5051 5352
 
5052
-		if (isset($priority_zones[$tzkey]))
5053
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5054
-		else
5055
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5353
+		if (isset($priority_zones[$tzkey])) {
5354
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5355
+		} else {
5356
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5357
+		}
5056 5358
 	}
5057 5359
 
5058 5360
 	$timezones = array_merge(
@@ -5106,9 +5408,9 @@  discard block
 block discarded – undo
5106 5408
 			'Indian/Kerguelen' => 'TFT',
5107 5409
 		);
5108 5410
 
5109
-		if (!empty($missing_tz_abbrs[$tzid]))
5110
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5111
-		else
5411
+		if (!empty($missing_tz_abbrs[$tzid])) {
5412
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5413
+		} else
5112 5414
 		{
5113 5415
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5114 5416
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5136,8 +5438,9 @@  discard block
 block discarded – undo
5136 5438
  */
5137 5439
 function inet_ptod($ip_address)
5138 5440
 {
5139
-	if (!isValidIP($ip_address))
5140
-		return $ip_address;
5441
+	if (!isValidIP($ip_address)) {
5442
+			return $ip_address;
5443
+	}
5141 5444
 
5142 5445
 	$bin = inet_pton($ip_address);
5143 5446
 	return $bin;
@@ -5149,13 +5452,15 @@  discard block
 block discarded – undo
5149 5452
  */
5150 5453
 function inet_dtop($bin)
5151 5454
 {
5152
-	if(empty($bin))
5153
-		return '';
5455
+	if(empty($bin)) {
5456
+			return '';
5457
+	}
5154 5458
 
5155 5459
 	global $db_type;
5156 5460
 
5157
-	if ($db_type == 'postgresql')
5158
-		return $bin;
5461
+	if ($db_type == 'postgresql') {
5462
+			return $bin;
5463
+	}
5159 5464
 
5160 5465
 	$ip_address = inet_ntop($bin);
5161 5466
 
@@ -5180,26 +5485,32 @@  discard block
 block discarded – undo
5180 5485
  */
5181 5486
 function _safe_serialize($value)
5182 5487
 {
5183
-	if(is_null($value))
5184
-		return 'N;';
5488
+	if(is_null($value)) {
5489
+			return 'N;';
5490
+	}
5185 5491
 
5186
-	if(is_bool($value))
5187
-		return 'b:'. (int) $value .';';
5492
+	if(is_bool($value)) {
5493
+			return 'b:'. (int) $value .';';
5494
+	}
5188 5495
 
5189
-	if(is_int($value))
5190
-		return 'i:'. $value .';';
5496
+	if(is_int($value)) {
5497
+			return 'i:'. $value .';';
5498
+	}
5191 5499
 
5192
-	if(is_float($value))
5193
-		return 'd:'. str_replace(',', '.', $value) .';';
5500
+	if(is_float($value)) {
5501
+			return 'd:'. str_replace(',', '.', $value) .';';
5502
+	}
5194 5503
 
5195
-	if(is_string($value))
5196
-		return 's:'. strlen($value) .':"'. $value .'";';
5504
+	if(is_string($value)) {
5505
+			return 's:'. strlen($value) .':"'. $value .'";';
5506
+	}
5197 5507
 
5198 5508
 	if(is_array($value))
5199 5509
 	{
5200 5510
 		$out = '';
5201
-		foreach($value as $k => $v)
5202
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5511
+		foreach($value as $k => $v) {
5512
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5513
+		}
5203 5514
 
5204 5515
 		return 'a:'. count($value) .':{'. $out .'}';
5205 5516
 	}
@@ -5225,8 +5536,9 @@  discard block
 block discarded – undo
5225 5536
 
5226 5537
 	$out = _safe_serialize($value);
5227 5538
 
5228
-	if (isset($mbIntEnc))
5229
-		mb_internal_encoding($mbIntEnc);
5539
+	if (isset($mbIntEnc)) {
5540
+			mb_internal_encoding($mbIntEnc);
5541
+	}
5230 5542
 
5231 5543
 	return $out;
5232 5544
 }
@@ -5243,8 +5555,9 @@  discard block
 block discarded – undo
5243 5555
 function _safe_unserialize($str)
5244 5556
 {
5245 5557
 	// Input  is not a string.
5246
-	if(empty($str) || !is_string($str))
5247
-		return false;
5558
+	if(empty($str) || !is_string($str)) {
5559
+			return false;
5560
+	}
5248 5561
 
5249 5562
 	$stack = array();
5250 5563
 	$expected = array();
@@ -5260,43 +5573,38 @@  discard block
 block discarded – undo
5260 5573
 	while($state != 1)
5261 5574
 	{
5262 5575
 		$type = isset($str[0]) ? $str[0] : '';
5263
-		if($type == '}')
5264
-			$str = substr($str, 1);
5265
-
5266
-		else if($type == 'N' && $str[1] == ';')
5576
+		if($type == '}') {
5577
+					$str = substr($str, 1);
5578
+		} else if($type == 'N' && $str[1] == ';')
5267 5579
 		{
5268 5580
 			$value = null;
5269 5581
 			$str = substr($str, 2);
5270
-		}
5271
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5582
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5272 5583
 		{
5273 5584
 			$value = $matches[1] == '1' ? true : false;
5274 5585
 			$str = substr($str, 4);
5275
-		}
5276
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5586
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5277 5587
 		{
5278 5588
 			$value = (int)$matches[1];
5279 5589
 			$str = $matches[2];
5280
-		}
5281
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5590
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5282 5591
 		{
5283 5592
 			$value = (float)$matches[1];
5284 5593
 			$str = $matches[3];
5285
-		}
5286
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5594
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5287 5595
 		{
5288 5596
 			$value = substr($matches[2], 0, (int)$matches[1]);
5289 5597
 			$str = substr($matches[2], (int)$matches[1] + 2);
5290
-		}
5291
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5598
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5292 5599
 		{
5293 5600
 			$expectedLength = (int)$matches[1];
5294 5601
 			$str = $matches[2];
5295 5602
 		}
5296 5603
 
5297 5604
 		// Object or unknown/malformed type.
5298
-		else
5299
-			return false;
5605
+		else {
5606
+					return false;
5607
+		}
5300 5608
 
5301 5609
 		switch($state)
5302 5610
 		{
@@ -5324,8 +5632,9 @@  discard block
 block discarded – undo
5324 5632
 				if($type == '}')
5325 5633
 				{
5326 5634
 					// Array size is less than expected.
5327
-					if(count($list) < end($expected))
5328
-						return false;
5635
+					if(count($list) < end($expected)) {
5636
+											return false;
5637
+					}
5329 5638
 
5330 5639
 					unset($list);
5331 5640
 					$list = &$stack[count($stack)-1];
@@ -5334,8 +5643,9 @@  discard block
 block discarded – undo
5334 5643
 					// Go to terminal state if we're at the end of the root array.
5335 5644
 					array_pop($expected);
5336 5645
 
5337
-					if(count($expected) == 0)
5338
-						$state = 1;
5646
+					if(count($expected) == 0) {
5647
+											$state = 1;
5648
+					}
5339 5649
 
5340 5650
 					break;
5341 5651
 				}
@@ -5343,8 +5653,9 @@  discard block
 block discarded – undo
5343 5653
 				if($type == 'i' || $type == 's')
5344 5654
 				{
5345 5655
 					// Array size exceeds expected length.
5346
-					if(count($list) >= end($expected))
5347
-						return false;
5656
+					if(count($list) >= end($expected)) {
5657
+											return false;
5658
+					}
5348 5659
 
5349 5660
 					$key = $value;
5350 5661
 					$state = 3;
@@ -5378,8 +5689,9 @@  discard block
 block discarded – undo
5378 5689
 	}
5379 5690
 
5380 5691
 	// Trailing data in input.
5381
-	if(!empty($str))
5382
-		return false;
5692
+	if(!empty($str)) {
5693
+			return false;
5694
+	}
5383 5695
 
5384 5696
 	return $data;
5385 5697
 }
@@ -5402,8 +5714,9 @@  discard block
 block discarded – undo
5402 5714
 
5403 5715
 	$out = _safe_unserialize($str);
5404 5716
 
5405
-	if (isset($mbIntEnc))
5406
-		mb_internal_encoding($mbIntEnc);
5717
+	if (isset($mbIntEnc)) {
5718
+			mb_internal_encoding($mbIntEnc);
5719
+	}
5407 5720
 
5408 5721
 	return $out;
5409 5722
 }
@@ -5418,12 +5731,14 @@  discard block
 block discarded – undo
5418 5731
 function smf_chmod($file, $value = 0)
5419 5732
 {
5420 5733
 	// No file? no checks!
5421
-	if (empty($file))
5422
-		return false;
5734
+	if (empty($file)) {
5735
+			return false;
5736
+	}
5423 5737
 
5424 5738
 	// Already writable?
5425
-	if (is_writable($file))
5426
-		return true;
5739
+	if (is_writable($file)) {
5740
+			return true;
5741
+	}
5427 5742
 
5428 5743
 	// Do we have a file or a dir?
5429 5744
 	$isDir = is_dir($file);
@@ -5439,10 +5754,9 @@  discard block
 block discarded – undo
5439 5754
 		{
5440 5755
 			$isWritable = true;
5441 5756
 			break;
5757
+		} else {
5758
+					@chmod($file, $val);
5442 5759
 		}
5443
-
5444
-		else
5445
-			@chmod($file, $val);
5446 5760
 	}
5447 5761
 
5448 5762
 	return $isWritable;
@@ -5461,8 +5775,9 @@  discard block
 block discarded – undo
5461 5775
 	global $txt;
5462 5776
 
5463 5777
 	// Come on...
5464
-	if (empty($json) || !is_string($json))
5465
-		return array();
5778
+	if (empty($json) || !is_string($json)) {
5779
+			return array();
5780
+	}
5466 5781
 
5467 5782
 	$returnArray = @json_decode($json, $returnAsArray);
5468 5783
 
@@ -5500,11 +5815,11 @@  discard block
 block discarded – undo
5500 5815
 		$jsonDebug = $jsonDebug[0];
5501 5816
 		loadLanguage('Errors');
5502 5817
 
5503
-		if (!empty($jsonDebug))
5504
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5505
-
5506
-		else
5507
-			log_error($txt['json_'. $jsonError], 'critical');
5818
+		if (!empty($jsonDebug)) {
5819
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5820
+		} else {
5821
+					log_error($txt['json_'. $jsonError], 'critical');
5822
+		}
5508 5823
 
5509 5824
 		// Everyone expects an array.
5510 5825
 		return array();
@@ -5534,8 +5849,9 @@  discard block
 block discarded – undo
5534 5849
 	global $db_show_debug, $modSettings;
5535 5850
 
5536 5851
 	// Defensive programming anyone?
5537
-	if (empty($data))
5538
-		return false;
5852
+	if (empty($data)) {
5853
+			return false;
5854
+	}
5539 5855
 
5540 5856
 	// Don't need extra stuff...
5541 5857
 	$db_show_debug = false;
@@ -5543,11 +5859,11 @@  discard block
 block discarded – undo
5543 5859
 	// Kill anything else.
5544 5860
 	ob_end_clean();
5545 5861
 
5546
-	if (!empty($modSettings['CompressedOutput']))
5547
-		@ob_start('ob_gzhandler');
5548
-
5549
-	else
5550
-		ob_start();
5862
+	if (!empty($modSettings['CompressedOutput'])) {
5863
+			@ob_start('ob_gzhandler');
5864
+	} else {
5865
+			ob_start();
5866
+	}
5551 5867
 
5552 5868
 	// Set the header.
5553 5869
 	header($type);
@@ -5579,8 +5895,9 @@  discard block
 block discarded – undo
5579 5895
 	static $done = false;
5580 5896
 
5581 5897
 	// If we don't need to do anything, don't
5582
-	if (!$update && $done)
5583
-		return;
5898
+	if (!$update && $done) {
5899
+			return;
5900
+	}
5584 5901
 
5585 5902
 	// Should we get a new copy of the official list of TLDs?
5586 5903
 	if ($update)
@@ -5601,10 +5918,11 @@  discard block
 block discarded – undo
5601 5918
 		// Clean $tlds and convert it to an array
5602 5919
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5603 5920
 			$line = trim($line);
5604
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5605
-				return false;
5606
-			else
5607
-				return true;
5921
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5922
+							return false;
5923
+			} else {
5924
+							return true;
5925
+			}
5608 5926
 		});
5609 5927
 
5610 5928
 		// Convert Punycode to Unicode
@@ -5658,8 +5976,9 @@  discard block
 block discarded – undo
5658 5976
 						$idx += $digit * $w;
5659 5977
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5660 5978
 
5661
-						if ($digit < $t)
5662
-							break;
5979
+						if ($digit < $t) {
5980
+													break;
5981
+						}
5663 5982
 
5664 5983
 						$w = (int) ($w * ($base - $t));
5665 5984
 					}
@@ -5668,8 +5987,9 @@  discard block
 block discarded – undo
5668 5987
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5669 5988
 					$delta += intval($delta / ($deco_len + 1));
5670 5989
 
5671
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5672
-						$delta = intval($delta / ($base - $tmin));
5990
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5991
+											$delta = intval($delta / ($base - $tmin));
5992
+					}
5673 5993
 
5674 5994
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5675 5995
 					$is_first = false;
@@ -5678,8 +5998,9 @@  discard block
 block discarded – undo
5678 5998
 
5679 5999
 					if ($deco_len > 0)
5680 6000
 					{
5681
-						for ($i = $deco_len; $i > $idx; $i--)
5682
-							$decoded[$i] = $decoded[($i - 1)];
6001
+						for ($i = $deco_len; $i > $idx; $i--) {
6002
+													$decoded[$i] = $decoded[($i - 1)];
6003
+						}
5683 6004
 					}
5684 6005
 					$decoded[$idx++] = $char;
5685 6006
 				}
@@ -5687,24 +6008,29 @@  discard block
 block discarded – undo
5687 6008
 				foreach ($decoded as $k => $v)
5688 6009
 				{
5689 6010
 					// 7bit are transferred literally
5690
-					if ($v < 128)
5691
-						$output .= chr($v);
6011
+					if ($v < 128) {
6012
+											$output .= chr($v);
6013
+					}
5692 6014
 
5693 6015
 					// 2 bytes
5694
-					elseif ($v < (1 << 11))
5695
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6016
+					elseif ($v < (1 << 11)) {
6017
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6018
+					}
5696 6019
 
5697 6020
 					// 3 bytes
5698
-					elseif ($v < (1 << 16))
5699
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6021
+					elseif ($v < (1 << 16)) {
6022
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6023
+					}
5700 6024
 
5701 6025
 					// 4 bytes
5702
-					elseif ($v < (1 << 21))
5703
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6026
+					elseif ($v < (1 << 21)) {
6027
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6028
+					}
5704 6029
 
5705 6030
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5706
-					else
5707
-						$output .= $safe_char;
6031
+					else {
6032
+											$output .= $safe_char;
6033
+					}
5708 6034
 				}
5709 6035
 
5710 6036
 				$output_parts[] = $output;
@@ -5799,8 +6125,7 @@  discard block
 block discarded – undo
5799 6125
 
5800 6126
 		$strlen = 'mb_strlen';
5801 6127
 		$substr = 'mb_substr';
5802
-	}
5803
-	else
6128
+	} else
5804 6129
 	{
5805 6130
 		$strlen = $smcFunc['strlen'];
5806 6131
 		$substr = $smcFunc['substr'];
@@ -5814,20 +6139,21 @@  discard block
 block discarded – undo
5814 6139
 
5815 6140
 		$first = $substr($string, 0, 1);
5816 6141
 
5817
-		if (empty($index[$first]))
5818
-			$index[$first] = array();
6142
+		if (empty($index[$first])) {
6143
+					$index[$first] = array();
6144
+		}
5819 6145
 
5820 6146
 		if ($strlen($string) > 1)
5821 6147
 		{
5822 6148
 			// Sanity check on recursion
5823
-			if ($depth > 99)
5824
-				$index[$first][$substr($string, 1)] = '';
5825
-
5826
-			else
5827
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6149
+			if ($depth > 99) {
6150
+							$index[$first][$substr($string, 1)] = '';
6151
+			} else {
6152
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6153
+			}
6154
+		} else {
6155
+					$index[$first][''] = '';
5828 6156
 		}
5829
-		else
5830
-			$index[$first][''] = '';
5831 6157
 
5832 6158
 		$depth--;
5833 6159
 		return $index;
@@ -5850,9 +6176,9 @@  discard block
 block discarded – undo
5850 6176
 			$key_regex = preg_quote($key, $delim);
5851 6177
 			$new_key = $key;
5852 6178
 
5853
-			if (empty($value))
5854
-				$sub_regex = '';
5855
-			else
6179
+			if (empty($value)) {
6180
+							$sub_regex = '';
6181
+			} else
5856 6182
 			{
5857 6183
 				$sub_regex = $index_to_regex($value, $delim);
5858 6184
 
@@ -5860,22 +6186,22 @@  discard block
 block discarded – undo
5860 6186
 				{
5861 6187
 					$new_key_array = explode('(?'.'>', $sub_regex);
5862 6188
 					$new_key .= $new_key_array[0];
6189
+				} else {
6190
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5863 6191
 				}
5864
-				else
5865
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5866 6192
 			}
5867 6193
 
5868
-			if ($depth > 1)
5869
-				$regex[$new_key] = $key_regex . $sub_regex;
5870
-			else
6194
+			if ($depth > 1) {
6195
+							$regex[$new_key] = $key_regex . $sub_regex;
6196
+			} else
5871 6197
 			{
5872 6198
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5873 6199
 				{
5874 6200
 					$regex[$new_key] = $key_regex . $sub_regex;
5875 6201
 					unset($index[$key]);
6202
+				} else {
6203
+									break;
5876 6204
 				}
5877
-				else
5878
-					break;
5879 6205
 			}
5880 6206
 		}
5881 6207
 
@@ -5884,10 +6210,11 @@  discard block
 block discarded – undo
5884 6210
 			$l1 = $strlen($k1);
5885 6211
 			$l2 = $strlen($k2);
5886 6212
 
5887
-			if ($l1 == $l2)
5888
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5889
-			else
5890
-				return $l1 > $l2 ? -1 : 1;
6213
+			if ($l1 == $l2) {
6214
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6215
+			} else {
6216
+							return $l1 > $l2 ? -1 : 1;
6217
+			}
5891 6218
 		});
5892 6219
 
5893 6220
 		$depth--;
@@ -5898,15 +6225,18 @@  discard block
 block discarded – undo
5898 6225
 	$index = array();
5899 6226
 	$regexes = array();
5900 6227
 
5901
-	foreach ($strings as $string)
5902
-		$index = $add_string_to_index($string, $index);
6228
+	foreach ($strings as $string) {
6229
+			$index = $add_string_to_index($string, $index);
6230
+	}
5903 6231
 
5904
-	while (!empty($index))
5905
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6232
+	while (!empty($index)) {
6233
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6234
+	}
5906 6235
 
5907 6236
 	// Restore PHP's internal character encoding to whatever it was originally
5908
-	if (!empty($current_encoding))
5909
-		mb_internal_encoding($current_encoding);
6237
+	if (!empty($current_encoding)) {
6238
+			mb_internal_encoding($current_encoding);
6239
+	}
5910 6240
 
5911 6241
 	return $regexes;
5912 6242
 }
Please login to merge, or discard this patch.
Sources/Stats.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -555,7 +555,7 @@
 block discarded – undo
555 555
 				'subject' => $row_liked_message['subject'],
556 556
 				'num' => $row_liked_message['likes'],
557 557
 				'href' => $scripturl . '?msg=' . $row_liked_message['id_msg'],
558
-				'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] .'">' . $row_liked_message['subject'] . '</a>'
558
+				'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] . '">' . $row_liked_message['subject'] . '</a>'
559 559
 			);
560 560
 
561 561
 			if ($max_liked_message < $row_liked_message['likes'])
Please login to merge, or discard this patch.
Braces   +112 added lines, -78 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
  * Display some useful/interesting board statistics.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 
31 32
 	isAllowedTo('view_stats');
32 33
 	// Page disabled - redirect them out
33
-	if (empty($modSettings['trackStats']))
34
-		fatal_lang_error('feature_disabled', true);
34
+	if (empty($modSettings['trackStats'])) {
35
+			fatal_lang_error('feature_disabled', true);
36
+	}
35 37
 
36 38
 	if (!empty($_REQUEST['expand']))
37 39
 	{
@@ -39,31 +41,34 @@  discard block
 block discarded – undo
39 41
 
40 42
 		$month = (int) substr($_REQUEST['expand'], 4);
41 43
 		$year = (int) substr($_REQUEST['expand'], 0, 4);
42
-		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12)
43
-			$_SESSION['expanded_stats'][$year][] = $month;
44
-	}
45
-	elseif (!empty($_REQUEST['collapse']))
44
+		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12) {
45
+					$_SESSION['expanded_stats'][$year][] = $month;
46
+		}
47
+	} elseif (!empty($_REQUEST['collapse']))
46 48
 	{
47 49
 		$context['robot_no_index'] = true;
48 50
 
49 51
 		$month = (int) substr($_REQUEST['collapse'], 4);
50 52
 		$year = (int) substr($_REQUEST['collapse'], 0, 4);
51
-		if (!empty($_SESSION['expanded_stats'][$year]))
52
-			$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
53
+		if (!empty($_SESSION['expanded_stats'][$year])) {
54
+					$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
55
+		}
53 56
 	}
54 57
 
55 58
 	// Handle the XMLHttpRequest.
56 59
 	if (isset($_REQUEST['xml']))
57 60
 	{
58 61
 		// Collapsing stats only needs adjustments of the session variables.
59
-		if (!empty($_REQUEST['collapse']))
60
-			obExit(false);
62
+		if (!empty($_REQUEST['collapse'])) {
63
+					obExit(false);
64
+		}
61 65
 
62 66
 		$context['sub_template'] = 'stats';
63 67
 		$context['yearly'] = array();
64 68
 
65
-		if (empty($month) || empty($year))
66
-			return;
69
+		if (empty($month) || empty($year)) {
70
+					return;
71
+		}
67 72
 
68 73
 		getDailyStats('YEAR(date) = {int:year} AND MONTH(date) = {int:month}', array('year' => $year, 'month' => $month));
69 74
 		$context['yearly'][$year]['months'][$month]['date'] = array(
@@ -220,8 +225,9 @@  discard block
 block discarded – undo
220 225
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
221 226
 		);
222 227
 
223
-		if ($max_num_posts < $row_members['posts'])
224
-			$max_num_posts = $row_members['posts'];
228
+		if ($max_num_posts < $row_members['posts']) {
229
+					$max_num_posts = $row_members['posts'];
230
+		}
225 231
 	}
226 232
 	$smcFunc['db_free_result']($members_result);
227 233
 
@@ -257,8 +263,9 @@  discard block
 block discarded – undo
257 263
 			'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['name'] . '</a>'
258 264
 		);
259 265
 
260
-		if ($max_num_posts < $row_board['num_posts'])
261
-			$max_num_posts = $row_board['num_posts'];
266
+		if ($max_num_posts < $row_board['num_posts']) {
267
+					$max_num_posts = $row_board['num_posts'];
268
+		}
262 269
 	}
263 270
 	$smcFunc['db_free_result']($boards_result);
264 271
 
@@ -284,12 +291,13 @@  discard block
 block discarded – undo
284 291
 			)
285 292
 		);
286 293
 		$topic_ids = array();
287
-		while ($row = $smcFunc['db_fetch_assoc']($request))
288
-			$topic_ids[] = $row['id_topic'];
294
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
295
+					$topic_ids[] = $row['id_topic'];
296
+		}
289 297
 		$smcFunc['db_free_result']($request);
298
+	} else {
299
+			$topic_ids = array();
290 300
 	}
291
-	else
292
-		$topic_ids = array();
293 301
 
294 302
 	// Topic replies top 10.
295 303
 	$topic_reply_result = $smcFunc['db_query']('', '
@@ -329,8 +337,9 @@  discard block
 block discarded – undo
329 337
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['id_topic'] . '.0">' . $row_topic_reply['subject'] . '</a>'
330 338
 		);
331 339
 
332
-		if ($max_num_replies < $row_topic_reply['num_replies'])
333
-			$max_num_replies = $row_topic_reply['num_replies'];
340
+		if ($max_num_replies < $row_topic_reply['num_replies']) {
341
+					$max_num_replies = $row_topic_reply['num_replies'];
342
+		}
334 343
 	}
335 344
 	$smcFunc['db_free_result']($topic_reply_result);
336 345
 
@@ -354,12 +363,13 @@  discard block
 block discarded – undo
354 363
 			)
355 364
 		);
356 365
 		$topic_ids = array();
357
-		while ($row = $smcFunc['db_fetch_assoc']($request))
358
-			$topic_ids[] = $row['id_topic'];
366
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
367
+					$topic_ids[] = $row['id_topic'];
368
+		}
359 369
 		$smcFunc['db_free_result']($request);
370
+	} else {
371
+			$topic_ids = array();
360 372
 	}
361
-	else
362
-		$topic_ids = array();
363 373
 
364 374
 	// Topic views top 10.
365 375
 	$topic_view_result = $smcFunc['db_query']('', '
@@ -399,8 +409,9 @@  discard block
 block discarded – undo
399 409
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0">' . $row_topic_views['subject'] . '</a>'
400 410
 		);
401 411
 
402
-		if ($max_num < $row_topic_views['num_views'])
403
-			$max_num = $row_topic_views['num_views'];
412
+		if ($max_num < $row_topic_views['num_views']) {
413
+					$max_num = $row_topic_views['num_views'];
414
+		}
404 415
 	}
405 416
 	$smcFunc['db_free_result']($topic_view_result);
406 417
 
@@ -425,15 +436,17 @@  discard block
 block discarded – undo
425 436
 			)
426 437
 		);
427 438
 		$members = array();
428
-		while ($row = $smcFunc['db_fetch_assoc']($request))
429
-			$members[$row['id_member_started']] = $row['hits'];
439
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
440
+					$members[$row['id_member_started']] = $row['hits'];
441
+		}
430 442
 		$smcFunc['db_free_result']($request);
431 443
 
432 444
 		cache_put_data('stats_top_starters', $members, 360);
433 445
 	}
434 446
 
435
-	if (empty($members))
436
-		$members = array(0 => 0);
447
+	if (empty($members)) {
448
+			$members = array(0 => 0);
449
+	}
437 450
 
438 451
 	// Topic poster top 10.
439 452
 	$members_result = $smcFunc['db_query']('', '
@@ -458,8 +471,9 @@  discard block
 block discarded – undo
458 471
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
459 472
 		);
460 473
 
461
-		if ($max_num < $members[$row_members['id_member']])
462
-			$max_num = $members[$row_members['id_member']];
474
+		if ($max_num < $members[$row_members['id_member']]) {
475
+					$max_num = $members[$row_members['id_member']];
476
+		}
463 477
 	}
464 478
 	ksort($context['stats_blocks']['starters']);
465 479
 	$smcFunc['db_free_result']($members_result);
@@ -488,8 +502,9 @@  discard block
 block discarded – undo
488 502
 	while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
489 503
 	{
490 504
 		$temp2[] = (int) $row_members['id_member'];
491
-		if (count($context['stats_blocks']['time_online']) >= 10)
492
-			continue;
505
+		if (count($context['stats_blocks']['time_online']) >= 10) {
506
+					continue;
507
+		}
493 508
 
494 509
 		// Figure out the days, hours and minutes.
495 510
 		$timeDays = floor($row_members['total_time_logged_in'] / 86400);
@@ -497,10 +512,12 @@  discard block
 block discarded – undo
497 512
 
498 513
 		// Figure out which things to show... (days, hours, minutes, etc.)
499 514
 		$timelogged = '';
500
-		if ($timeDays > 0)
501
-			$timelogged .= $timeDays . $txt['totalTimeLogged5'];
502
-		if ($timeHours > 0)
503
-			$timelogged .= $timeHours . $txt['totalTimeLogged6'];
515
+		if ($timeDays > 0) {
516
+					$timelogged .= $timeDays . $txt['totalTimeLogged5'];
517
+		}
518
+		if ($timeHours > 0) {
519
+					$timelogged .= $timeHours . $txt['totalTimeLogged6'];
520
+		}
504 521
 		$timelogged .= floor(($row_members['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged7'];
505 522
 
506 523
 		$context['stats_blocks']['time_online'][] = array(
@@ -512,17 +529,20 @@  discard block
 block discarded – undo
512 529
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
513 530
 		);
514 531
 
515
-		if ($max_time_online < $row_members['total_time_logged_in'])
516
-			$max_time_online = $row_members['total_time_logged_in'];
532
+		if ($max_time_online < $row_members['total_time_logged_in']) {
533
+					$max_time_online = $row_members['total_time_logged_in'];
534
+		}
517 535
 	}
518 536
 	$smcFunc['db_free_result']($members_result);
519 537
 
520
-	foreach ($context['stats_blocks']['time_online'] as $i => $member)
521
-		$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
538
+	foreach ($context['stats_blocks']['time_online'] as $i => $member) {
539
+			$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
540
+	}
522 541
 
523 542
 	// Cache the ones we found for a bit, just so we don't have to look again.
524
-	if ($temp !== $temp2)
525
-		cache_put_data('stats_total_time_members', $temp2, 480);
543
+	if ($temp !== $temp2) {
544
+			cache_put_data('stats_total_time_members', $temp2, 480);
545
+	}
526 546
 
527 547
 	// Likes.
528 548
 	if (!empty($modSettings['enable_likes']))
@@ -558,13 +578,15 @@  discard block
 block discarded – undo
558 578
 				'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] .'">' . $row_liked_message['subject'] . '</a>'
559 579
 			);
560 580
 
561
-			if ($max_liked_message < $row_liked_message['likes'])
562
-				$max_liked_message = $row_liked_message['likes'];
581
+			if ($max_liked_message < $row_liked_message['likes']) {
582
+							$max_liked_message = $row_liked_message['likes'];
583
+			}
563 584
 		}
564 585
 		$smcFunc['db_free_result']($liked_messages);
565 586
 
566
-		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages)
567
-			$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
587
+		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages) {
588
+					$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
589
+		}
568 590
 
569 591
 		// Liked users top 10.
570 592
 		$context['stats_blocks']['liked_users'] = array();
@@ -595,14 +617,16 @@  discard block
 block discarded – undo
595 617
 				'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_liked_users['liked_user'] . '">' . $row_liked_users['real_name'] . '</a>',
596 618
 			);
597 619
 
598
-			if ($max_liked_users < $row_liked_users['count'])
599
-				$max_liked_users = $row_liked_users['count'];
620
+			if ($max_liked_users < $row_liked_users['count']) {
621
+							$max_liked_users = $row_liked_users['count'];
622
+			}
600 623
 		}
601 624
 
602 625
 		$smcFunc['db_free_result']($liked_users);
603 626
 
604
-		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users)
605
-			$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
627
+		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users) {
628
+					$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
629
+		}
606 630
 	}
607 631
 
608 632
 	// Activity by month.
@@ -620,8 +644,8 @@  discard block
 block discarded – undo
620 644
 		$ID_MONTH = $row_months['stats_year'] . sprintf('%02d', $row_months['stats_month']);
621 645
 		$expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]);
622 646
 
623
-		if (!isset($context['yearly'][$row_months['stats_year']]))
624
-			$context['yearly'][$row_months['stats_year']] = array(
647
+		if (!isset($context['yearly'][$row_months['stats_year']])) {
648
+					$context['yearly'][$row_months['stats_year']] = array(
625 649
 				'year' => $row_months['stats_year'],
626 650
 				'new_topics' => 0,
627 651
 				'new_posts' => 0,
@@ -633,6 +657,7 @@  discard block
 block discarded – undo
633 657
 				'expanded' => false,
634 658
 				'current_year' => $row_months['stats_year'] == date('Y'),
635 659
 			);
660
+		}
636 661
 
637 662
 		$context['yearly'][$row_months['stats_year']]['months'][(int) $row_months['stats_month']] = array(
638 663
 			'id' => $ID_MONTH,
@@ -678,26 +703,30 @@  discard block
 block discarded – undo
678 703
 		$context['yearly'][$year]['hits'] = comma_format($data['hits']);
679 704
 
680 705
 		// Keep a list of collapsed years.
681
-		if (!$data['expanded'] && !$data['current_year'])
682
-			$context['collapsed_years'][] = $year;
706
+		if (!$data['expanded'] && !$data['current_year']) {
707
+					$context['collapsed_years'][] = $year;
708
+		}
683 709
 	}
684 710
 
685
-	if (empty($_SESSION['expanded_stats']))
686
-		return;
711
+	if (empty($_SESSION['expanded_stats'])) {
712
+			return;
713
+	}
687 714
 
688 715
 	$condition_text = array();
689 716
 	$condition_params = array();
690
-	foreach ($_SESSION['expanded_stats'] as $year => $months)
691
-		if (!empty($months))
717
+	foreach ($_SESSION['expanded_stats'] as $year => $months) {
718
+			if (!empty($months))
692 719
 		{
693 720
 			$condition_text[] = 'YEAR(date) = {int:year_' . $year . '} AND MONTH(date) IN ({array_int:months_' . $year . '})';
721
+	}
694 722
 			$condition_params['year_' . $year] = $year;
695 723
 			$condition_params['months_' . $year] = $months;
696 724
 		}
697 725
 
698 726
 	// No daily stats to even look at?
699
-	if (empty($condition_text))
700
-		return;
727
+	if (empty($condition_text)) {
728
+			return;
729
+	}
701 730
 
702 731
 	getDailyStats(implode(' OR ', $condition_text), $condition_params);
703 732
 
@@ -723,8 +752,8 @@  discard block
 block discarded – undo
723 752
 		ORDER BY stats_day ASC',
724 753
 		$condition_parameters
725 754
 	);
726
-	while ($row_days = $smcFunc['db_fetch_assoc']($days_result))
727
-		$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
755
+	while ($row_days = $smcFunc['db_fetch_assoc']($days_result)) {
756
+			$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
728 757
 			'day' => sprintf('%02d', $row_days['stats_day']),
729 758
 			'month' => sprintf('%02d', $row_days['stats_month']),
730 759
 			'year' => $row_days['stats_year'],
@@ -734,6 +763,7 @@  discard block
 block discarded – undo
734 763
 			'most_members_online' => comma_format($row_days['most_on']),
735 764
 			'hits' => comma_format($row_days['hits'])
736 765
 		);
766
+	}
737 767
 	$smcFunc['db_free_result']($days_result);
738 768
 }
739 769
 
@@ -751,16 +781,19 @@  discard block
 block discarded – undo
751 781
 	global $modSettings, $user_info, $forum_version, $sourcedir;
752 782
 
753 783
 	// First, is it disabled?
754
-	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key']))
755
-		die();
784
+	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key'])) {
785
+			die();
786
+	}
756 787
 
757 788
 	// Are we saying who we are, and are we right? (OR an admin)
758
-	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key']))
759
-		die();
789
+	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key'])) {
790
+			die();
791
+	}
760 792
 
761 793
 	// Verify the referer...
762
-	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085'))
763
-		die();
794
+	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085')) {
795
+			die();
796
+	}
764 797
 
765 798
 	// Get some server versions.
766 799
 	require_once($sourcedir . '/Subs-Admin.php');
@@ -786,16 +819,17 @@  discard block
 block discarded – undo
786 819
 	);
787 820
 
788 821
 	// Encode all the data, for security.
789
-	foreach ($stats_to_send as $k => $v)
790
-		$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
822
+	foreach ($stats_to_send as $k => $v) {
823
+			$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
824
+	}
791 825
 
792 826
 	// Turn this into the query string!
793 827
 	$stats_to_send = implode('&', $stats_to_send);
794 828
 
795 829
 	// If we're an admin, just plonk them out.
796
-	if ($user_info['is_admin'])
797
-		echo $stats_to_send;
798
-	else
830
+	if ($user_info['is_admin']) {
831
+			echo $stats_to_send;
832
+	} else
799 833
 	{
800 834
 		// Connect to the collection script.
801 835
 		$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
Please login to merge, or discard this patch.