Completed
Push — release-2.1 ( 64d581...84b0cc )
by Rick
06:44 queued 10s
created
Sources/Profile-Modify.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2183,7 +2183,7 @@  discard block
 block discarded – undo
2183 2183
  * Deletes a single or a group of alerts by ID
2184 2184
  *
2185 2185
  * @param int|array The ID of a single alert to delete or an array containing the IDs of multiple alerts. The function will convert integers into an array for better handling.
2186
- * @param bool|int $memID The user ID. Used to update the user unread alerts count.
2186
+ * @param integer $memID The user ID. Used to update the user unread alerts count.
2187 2187
  * @return void|int If the $memID param is set, returns the new amount of unread alerts.
2188 2188
  */
2189 2189
 function alert_delete($toDelete, $memID = false)
@@ -2839,7 +2839,7 @@  discard block
 block discarded – undo
2839 2839
 /**
2840 2840
  * Handles the "manage groups" section of the profile
2841 2841
  *
2842
- * @return true Always returns true
2842
+ * @return boolean Always returns true
2843 2843
  */
2844 2844
 function profileLoadGroups()
2845 2845
 {
@@ -2896,7 +2896,7 @@  discard block
 block discarded – undo
2896 2896
 /**
2897 2897
  * Load key signature context data.
2898 2898
  *
2899
- * @return true Always returns true
2899
+ * @return boolean Always returns true
2900 2900
  */
2901 2901
 function profileLoadSignatureData()
2902 2902
 {
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
 /**
2961 2961
  * Load avatar context data.
2962 2962
  *
2963
- * @return true Always returns true
2963
+ * @return boolean Always returns true
2964 2964
  */
2965 2965
 function profileLoadAvatarData()
2966 2966
 {
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
  * Save a members group.
3034 3034
  *
3035 3035
  * @param int &$value The ID of the (new) primary group
3036
- * @return true Always returns true
3036
+ * @return boolean Always returns true
3037 3037
  */
3038 3038
 function profileSaveGroups(&$value)
3039 3039
 {
@@ -3138,7 +3138,7 @@  discard block
 block discarded – undo
3138 3138
  * @todo argh, the avatar here. Take this out of here!
3139 3139
  *
3140 3140
  * @param string &$value What kind of avatar we're expecting. Can be 'none', 'server_stored', 'gravatar', 'external' or 'upload'
3141
- * @return bool|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3141
+ * @return false|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3142 3142
  */
3143 3143
 function profileSaveAvatarData(&$value)
3144 3144
 {
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			'type' => 'callback',
87 87
 			'callback_func' => 'birthdate',
88 88
 			'permission' => 'profile_extra',
89
-			'preload' => function () use ($cur_profile, &$context)
89
+			'preload' => function() use ($cur_profile, &$context)
90 90
 			{
91 91
 				// Split up the birthdate....
92 92
 				list ($uyear, $umonth, $uday) = explode('-', empty($cur_profile['birthdate']) || $cur_profile['birthdate'] == '0001-01-01' ? '0000-00-00' : $cur_profile['birthdate']);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
 				return true;
100 100
 			},
101
-			'input_validate' => function (&$value) use (&$cur_profile, &$profile_vars)
101
+			'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
102 102
 			{
103 103
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 104
 				{
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		'birthdate' => array(
121 121
 			'type' => 'hidden',
122 122
 			'permission' => 'profile_extra',
123
-			'input_validate' => function (&$value) use ($cur_profile)
123
+			'input_validate' => function(&$value) use ($cur_profile)
124 124
 			{
125 125
 				// @todo Should we check for this year and tell them they made a mistake :P? (based on coppa at least?)
126 126
 				if (preg_match('/(\d{4})[\-\., ](\d{2})[\-\., ](\d{2})/', $value, $dates) === 1)
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 			'label' => $txt['date_registered'],
142 142
 			'log_change' => true,
143 143
 			'permission' => 'moderate_forum',
144
-			'input_validate' => function (&$value) use ($txt, $user_info, $modSettings, $cur_profile, $context)
144
+			'input_validate' => function(&$value) use ($txt, $user_info, $modSettings, $cur_profile, $context)
145 145
 			{
146 146
 				// Bad date!  Go try again - please?
147 147
 				if (($value = strtotime($value)) === -1)
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
 			'js_submit' => !empty($modSettings['send_validation_onChange']) ? '
168 168
 	form_handle.addEventListener(\'submit\', function(event)
169 169
 	{
170
-		if (this.email_address.value != "'. $cur_profile['email_address'] .'")
170
+		if (this.email_address.value != "'. $cur_profile['email_address'] . '")
171 171
 		{
172
-			alert('. JavaScriptEscape($txt['email_change_logout']) .');
172
+			alert('. JavaScriptEscape($txt['email_change_logout']) . ');
173 173
 			return true;
174 174
 		}
175 175
 	}, false);' : '',
176
-			'input_validate' => function (&$value)
176
+			'input_validate' => function(&$value)
177 177
 			{
178 178
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 179
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			'callback_func' => 'theme_pick',
210 210
 			'permission' => 'profile_extra',
211 211
 			'enabled' => $modSettings['theme_allow'] || allowedTo('admin_forum'),
212
-			'preload' => function () use ($smcFunc, &$context, $cur_profile, $txt)
212
+			'preload' => function() use ($smcFunc, &$context, $cur_profile, $txt)
213 213
 			{
214 214
 				$request = $smcFunc['db_query']('', '
215 215
 					SELECT value
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 				);
231 231
 				return true;
232 232
 			},
233
-			'input_validate' => function (&$value)
233
+			'input_validate' => function(&$value)
234 234
 			{
235 235
 				$value = (int) $value;
236 236
 				return true;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		),
239 239
 		'lngfile' => array(
240 240
 			'type' => 'select',
241
-			'options' => function () use (&$context)
241
+			'options' => function() use (&$context)
242 242
 			{
243 243
 				return $context['profile_languages'];
244 244
 			},
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			'preload' => 'profileLoadLanguages',
248 248
 			'enabled' => !empty($modSettings['userLanguage']),
249 249
 			'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'],
250
-			'input_validate' => function (&$value) use (&$context, $cur_profile)
250
+			'input_validate' => function(&$value) use (&$context, $cur_profile)
251 251
 			{
252 252
 				// Load the languages.
253 253
 				profileLoadLanguages();
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 			'log_change' => true,
274 274
 			'permission' => 'profile_identity',
275 275
 			'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="alert">' . $txt['username_warning'] . '</div>' : '',
276
-			'input_validate' => function (&$value) use ($sourcedir, $context, $user_info, $cur_profile)
276
+			'input_validate' => function(&$value) use ($sourcedir, $context, $user_info, $cur_profile)
277 277
 			{
278 278
 				if (allowedTo('admin_forum'))
279 279
 				{
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 			'permission' => 'profile_password',
310 310
 			'save_key' => 'passwd',
311 311
 			// Note this will only work if passwrd2 also exists!
312
-			'input_validate' => function (&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
312
+			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 313
 			{
314 314
 				// If we didn't try it then ignore it!
315 315
 				if ($value == '')
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			'input_attr' => array('maxlength="50"'),
349 349
 			'size' => 50,
350 350
 			'permission' => 'profile_blurb',
351
-			'input_validate' => function (&$value) use ($smcFunc)
351
+			'input_validate' => function(&$value) use ($smcFunc)
352 352
 			{
353 353
 				if ($smcFunc['strlen']($value) > 50)
354 354
 					return 'personal_text_too_long';
@@ -361,14 +361,14 @@  discard block
 block discarded – undo
361 361
 			'type' => 'callback',
362 362
 			'callback_func' => 'pm_settings',
363 363
 			'permission' => 'pm_read',
364
-			'preload' => function () use (&$context, $cur_profile)
364
+			'preload' => function() use (&$context, $cur_profile)
365 365
 			{
366 366
 				$context['display_mode'] = $cur_profile['pm_prefs'] & 3;
367 367
 				$context['receive_from'] = !empty($cur_profile['pm_receive_from']) ? $cur_profile['pm_receive_from'] : 0;
368 368
 
369 369
 				return true;
370 370
 			},
371
-			'input_validate' => function (&$value) use (&$cur_profile, &$profile_vars)
371
+			'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
372 372
 			{
373 373
 				// Simple validate and apply the two "sub settings"
374 374
 				$value = max(min($value, 2), 0);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 			'log_change' => true,
385 385
 			'size' => 7,
386 386
 			'permission' => 'moderate_forum',
387
-			'input_validate' => function (&$value)
387
+			'input_validate' => function(&$value)
388 388
 			{
389 389
 				if (!is_numeric($value))
390 390
 					return 'digits_only';
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 			'input_attr' => array('maxlength="60"'),
402 402
 			'permission' => 'profile_displayed_name',
403 403
 			'enabled' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum'),
404
-			'input_validate' => function (&$value) use ($context, $smcFunc, $sourcedir, $cur_profile)
404
+			'input_validate' => function(&$value) use ($context, $smcFunc, $sourcedir, $cur_profile)
405 405
 			{
406 406
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 407
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 			'postinput' => '<span class="smalltext" style="margin-left: 4ex;">[<a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);">' . $txt['secret_why_blank'] . '</a>]</span>',
434 434
 			'value' => '',
435 435
 			'permission' => 'profile_password',
436
-			'input_validate' => function (&$value)
436
+			'input_validate' => function(&$value)
437 437
 			{
438 438
 				$value = $value != '' ? md5($value) : '';
439 439
 				return true;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 			'callback_func' => 'smiley_pick',
459 459
 			'enabled' => !empty($modSettings['smiley_sets_enable']),
460 460
 			'permission' => 'profile_extra',
461
-			'preload' => function () use ($modSettings, &$context, $txt, $cur_profile, $smcFunc)
461
+			'preload' => function() use ($modSettings, &$context, $txt, $cur_profile, $smcFunc)
462 462
 			{
463 463
 				$context['member']['smiley_set']['id'] = empty($cur_profile['smiley_set']) ? '' : $cur_profile['smiley_set'];
464 464
 				$context['smiley_sets'] = explode(',', 'none,,' . $modSettings['smiley_sets_known']);
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 				}
477 477
 				return true;
478 478
 			},
479
-			'input_validate' => function (&$value)
479
+			'input_validate' => function(&$value)
480 480
 			{
481 481
 				global $modSettings;
482 482
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 			'callback_func' => 'theme_settings',
493 493
 			'permission' => 'profile_extra',
494 494
 			'is_dummy' => true,
495
-			'preload' => function () use (&$context, $user_info, $modSettings)
495
+			'preload' => function() use (&$context, $user_info, $modSettings)
496 496
 			{
497 497
 				loadLanguage('Settings');
498 498
 
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
 			'type' => 'callback',
520 520
 			'callback_func' => 'timeformat_modify',
521 521
 			'permission' => 'profile_extra',
522
-			'preload' => function () use (&$context, $user_info, $txt, $cur_profile, $modSettings)
522
+			'preload' => function() use (&$context, $user_info, $txt, $cur_profile, $modSettings)
523 523
 			{
524 524
 				$context['easy_timeformats'] = array(
525 525
 					array('format' => '', 'title' => $txt['timeformat_default']),
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 			'options' => smf_list_timezones(),
543 543
 			'permission' => 'profile_extra',
544 544
 			'label' => $txt['timezone'],
545
-			'input_validate' => function ($value)
545
+			'input_validate' => function($value)
546 546
 			{
547 547
 				$tz = smf_list_timezones();
548 548
 				if (!isset($tz[$value]))
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 			'size' => 50,
560 560
 			'permission' => 'profile_other',
561 561
 			'enabled' => !empty($modSettings['titlesEnable']),
562
-			'input_validate' => function (&$value) use ($smcFunc)
562
+			'input_validate' => function(&$value) use ($smcFunc)
563 563
 			{
564 564
 				if ($smcFunc['strlen']($value) > 50)
565 565
 					return 'user_title_too_long';
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			'size' => 50,
583 583
 			'permission' => 'profile_other',
584 584
 			// Fix the URL...
585
-			'input_validate' => function (&$value)
585
+			'input_validate' => function(&$value)
586 586
 			{
587 587
 				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588 588
 					$value = 'http://' . $value;
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 		if (this.oldpasswrd.value == "")
708 708
 		{
709 709
 			event.preventDefault();
710
-			alert('. (JavaScriptEscape($txt['required_security_reasons'])) .');
710
+			alert('. (JavaScriptEscape($txt['required_security_reasons'])) . ');
711 711
 			return false;
712 712
 		}
713 713
 	}, false);' : ''), true);
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 	if (isset($_POST['ignore_brd']))
907 907
 	{
908 908
 		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
909
+			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
910 910
 
911 911
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 912
 		{
@@ -1872,7 +1872,7 @@  discard block
 block discarded – undo
1872 1872
 
1873 1873
 	// Now load all the values for this user.
1874 1874
 	require_once($sourcedir . '/Subs-Notify.php');
1875
-	$prefs = getNotifyPrefs($memID,  '', $memID != 0);
1875
+	$prefs = getNotifyPrefs($memID, '', $memID != 0);
1876 1876
 
1877 1877
 	$context['alert_prefs'] = !empty($prefs[$memID]) ? $prefs[$memID] : array();
1878 1878
 
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
 	);
2172 2172
 
2173 2173
 	// Gotta know how many unread alerts are left.
2174
-	$count =  alert_count($memID, true);
2174
+	$count = alert_count($memID, true);
2175 2175
 
2176 2176
 	updateMemberData($memID, array('alerts' => $count));
2177 2177
 
@@ -2206,7 +2206,7 @@  discard block
 block discarded – undo
2206 2206
 	// Gotta know how many unread alerts are left.
2207 2207
 	if ($memID)
2208 2208
 	{
2209
-		$count =  alert_count($memID, true);
2209
+		$count = alert_count($memID, true);
2210 2210
 
2211 2211
 		updateMemberData($memID, array('alerts' => $count));
2212 2212
 
@@ -2242,7 +2242,7 @@  discard block
 block discarded – undo
2242 2242
 		)
2243 2243
 	);
2244 2244
 
2245
-	$count =  $smcFunc['db_num_rows']($request);
2245
+	$count = $smcFunc['db_num_rows']($request);
2246 2246
 	$smcFunc['db_free_result']($request);
2247 2247
 
2248 2248
 	return $count;
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
 					'class' => 'lefttext',
2303 2303
 				),
2304 2304
 				'data' => array(
2305
-					'function' => function ($topic) use ($txt)
2305
+					'function' => function($topic) use ($txt)
2306 2306
 					{
2307 2307
 						$link = $topic['link'];
2308 2308
 
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
 					'class' => 'lefttext',
2358 2358
 				),
2359 2359
 				'data' => array(
2360
-					'function' => function ($topic) use ($txt)
2360
+					'function' => function($topic) use ($txt)
2361 2361
 					{
2362 2362
 						$pref = $topic['notify_pref'];
2363 2363
 						$mode = !empty($topic['unwatched']) ? 0 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 					'class' => 'lefttext',
2455 2455
 				),
2456 2456
 				'data' => array(
2457
-					'function' => function ($board) use ($txt)
2457
+					'function' => function($board) use ($txt)
2458 2458
 					{
2459 2459
 						$link = $board['link'];
2460 2460
 
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
 					'class' => 'lefttext',
2476 2476
 				),
2477 2477
 				'data' => array(
2478
-					'function' => function ($board) use ($txt)
2478
+					'function' => function($board) use ($txt)
2479 2479
 					{
2480 2480
 						$pref = $board['notify_pref'];
2481 2481
 						$mode = $pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1);
Please login to merge, or discard this patch.
Braces   +693 added lines, -519 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function (&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function (&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function (&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function ($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function (&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function (&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -883,8 +922,7 @@  discard block
 block discarded – undo
883 922
 	{
884 923
 		$changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own'));
885 924
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
886
-	}
887
-	else
925
+	} else
888 926
 	{
889 927
 		$changeIdentity = allowedTo('profile_identity_any', 'profile_signature_any');
890 928
 		$changeOther = allowedTo('profile_extra_any', 'profile_website_any', 'profile_signature_any');
@@ -899,22 +937,25 @@  discard block
 block discarded – undo
899 937
 		'ignore_boards',
900 938
 	);
901 939
 
902
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
903
-		$_POST['ignore_brd'] = array();
940
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
941
+			$_POST['ignore_brd'] = array();
942
+	}
904 943
 
905 944
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
906 945
 	if (isset($_POST['ignore_brd']))
907 946
 	{
908
-		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
947
+		if (!is_array($_POST['ignore_brd'])) {
948
+					$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
949
+		}
910 950
 
911 951
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 952
 		{
913 953
 			$d = (int) $d;
914
-			if ($d != 0)
915
-				$_POST['ignore_brd'][$k] = $d;
916
-			else
917
-				unset($_POST['ignore_brd'][$k]);
954
+			if ($d != 0) {
955
+							$_POST['ignore_brd'][$k] = $d;
956
+			} else {
957
+							unset($_POST['ignore_brd'][$k]);
958
+			}
918 959
 		}
919 960
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
920 961
 		unset($_POST['ignore_brd']);
@@ -927,21 +968,26 @@  discard block
 block discarded – undo
927 968
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
928 969
 		//makeAvatarChanges($memID, $post_errors);
929 970
 
930
-		if (!empty($_REQUEST['sa']))
931
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
971
+		if (!empty($_REQUEST['sa'])) {
972
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
973
+		}
932 974
 
933
-		foreach ($profile_bools as $var)
934
-			if (isset($_POST[$var]))
975
+		foreach ($profile_bools as $var) {
976
+					if (isset($_POST[$var]))
935 977
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
936
-		foreach ($profile_ints as $var)
937
-			if (isset($_POST[$var]))
978
+		}
979
+		foreach ($profile_ints as $var) {
980
+					if (isset($_POST[$var]))
938 981
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
939
-		foreach ($profile_floats as $var)
940
-			if (isset($_POST[$var]))
982
+		}
983
+		foreach ($profile_floats as $var) {
984
+					if (isset($_POST[$var]))
941 985
 				$profile_vars[$var] = (float) $_POST[$var];
942
-		foreach ($profile_strings as $var)
943
-			if (isset($_POST[$var]))
986
+		}
987
+		foreach ($profile_strings as $var) {
988
+					if (isset($_POST[$var]))
944 989
 				$profile_vars[$var] = $_POST[$var];
990
+		}
945 991
 	}
946 992
 }
947 993
 
@@ -975,8 +1021,9 @@  discard block
 block discarded – undo
975 1021
 	);
976 1022
 
977 1023
 	// Can't change reserved vars.
978
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
979
-		fatal_lang_error('no_access', false);
1024
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1025
+			fatal_lang_error('no_access', false);
1026
+	}
980 1027
 
981 1028
 	// Don't allow any overriding of custom fields with default or non-default options.
982 1029
 	$request = $smcFunc['db_query']('', '
@@ -988,8 +1035,9 @@  discard block
 block discarded – undo
988 1035
 		)
989 1036
 	);
990 1037
 	$custom_fields = array();
991
-	while ($row = $smcFunc['db_fetch_assoc']($request))
992
-		$custom_fields[] = $row['col_name'];
1038
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1039
+			$custom_fields[] = $row['col_name'];
1040
+	}
993 1041
 	$smcFunc['db_free_result']($request);
994 1042
 
995 1043
 	// These are the theme changes...
@@ -998,33 +1046,39 @@  discard block
 block discarded – undo
998 1046
 	{
999 1047
 		foreach ($_POST['options'] as $opt => $val)
1000 1048
 		{
1001
-			if (in_array($opt, $custom_fields))
1002
-				continue;
1049
+			if (in_array($opt, $custom_fields)) {
1050
+							continue;
1051
+			}
1003 1052
 
1004 1053
 			// These need to be controlled.
1005
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1006
-				$val = max(0, min($val, 50));
1054
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1055
+							$val = max(0, min($val, 50));
1056
+			}
1007 1057
 			// We don't set this per theme anymore.
1008
-			elseif ($opt == 'allow_no_censored')
1009
-				continue;
1058
+			elseif ($opt == 'allow_no_censored') {
1059
+							continue;
1060
+			}
1010 1061
 
1011 1062
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1012 1063
 		}
1013 1064
 	}
1014 1065
 
1015 1066
 	$erase_options = array();
1016
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1017
-		foreach ($_POST['default_options'] as $opt => $val)
1067
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1068
+			foreach ($_POST['default_options'] as $opt => $val)
1018 1069
 		{
1019 1070
 			if (in_array($opt, $custom_fields))
1020 1071
 				continue;
1072
+	}
1021 1073
 
1022 1074
 			// These need to be controlled.
1023
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1024
-				$val = max(0, min($val, 50));
1075
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1076
+							$val = max(0, min($val, 50));
1077
+			}
1025 1078
 			// Only let admins and owners change the censor.
1026
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1027
-					continue;
1079
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1080
+								continue;
1081
+			}
1028 1082
 
1029 1083
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1030 1084
 			$erase_options[] = $opt;
@@ -1060,8 +1114,9 @@  discard block
 block discarded – undo
1060 1114
 
1061 1115
 		// Admins can choose any theme, even if it's not enabled...
1062 1116
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1063
-		foreach ($themes as $t)
1064
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1117
+		foreach ($themes as $t) {
1118
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1119
+		}
1065 1120
 	}
1066 1121
 }
1067 1122
 
@@ -1080,8 +1135,9 @@  discard block
 block discarded – undo
1080 1135
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1081 1136
 	{
1082 1137
 		// Make sure only integers are deleted.
1083
-		foreach ($_POST['notify_boards'] as $index => $id)
1084
-			$_POST['notify_boards'][$index] = (int) $id;
1138
+		foreach ($_POST['notify_boards'] as $index => $id) {
1139
+					$_POST['notify_boards'][$index] = (int) $id;
1140
+		}
1085 1141
 
1086 1142
 		// id_board = 0 is reserved for topic notifications.
1087 1143
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1100,8 +1156,9 @@  discard block
 block discarded – undo
1100 1156
 	// We are editing topic notifications......
1101 1157
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1102 1158
 	{
1103
-		foreach ($_POST['notify_topics'] as $index => $id)
1104
-			$_POST['notify_topics'][$index] = (int) $id;
1159
+		foreach ($_POST['notify_topics'] as $index => $id) {
1160
+					$_POST['notify_topics'][$index] = (int) $id;
1161
+		}
1105 1162
 
1106 1163
 		// Make sure there are no zeros left.
1107 1164
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1115,16 +1172,18 @@  discard block
 block discarded – undo
1115 1172
 				'selected_member' => $memID,
1116 1173
 			)
1117 1174
 		);
1118
-		foreach ($_POST['notify_topics'] as $topic)
1119
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1175
+		foreach ($_POST['notify_topics'] as $topic) {
1176
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1177
+		}
1120 1178
 	}
1121 1179
 
1122 1180
 	// We are removing topic preferences
1123 1181
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1124 1182
 	{
1125 1183
 		$prefs = array();
1126
-		foreach ($_POST['notify_topics'] as $topic)
1127
-			$prefs[] = 'topic_notify_' . $topic;
1184
+		foreach ($_POST['notify_topics'] as $topic) {
1185
+					$prefs[] = 'topic_notify_' . $topic;
1186
+		}
1128 1187
 		deleteNotifyPrefs($memID, $prefs);
1129 1188
 	}
1130 1189
 
@@ -1132,8 +1191,9 @@  discard block
 block discarded – undo
1132 1191
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1133 1192
 	{
1134 1193
 		$prefs = array();
1135
-		foreach ($_POST['notify_boards'] as $board)
1136
-			$prefs[] = 'board_notify_' . $board;
1194
+		foreach ($_POST['notify_boards'] as $board) {
1195
+					$prefs[] = 'board_notify_' . $board;
1196
+		}
1137 1197
 		deleteNotifyPrefs($memID, $prefs);
1138 1198
 	}
1139 1199
 }
@@ -1154,8 +1214,9 @@  discard block
 block discarded – undo
1154 1214
 
1155 1215
 	$errors = array();
1156 1216
 
1157
-	if ($sanitize && isset($_POST['customfield']))
1158
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1217
+	if ($sanitize && isset($_POST['customfield'])) {
1218
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1219
+	}
1159 1220
 
1160 1221
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1161 1222
 
@@ -1180,48 +1241,49 @@  discard block
 block discarded – undo
1180 1241
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1181 1242
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1182 1243
 		*/
1183
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1184
-			continue;
1244
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1245
+					continue;
1246
+		}
1185 1247
 
1186 1248
 		// Validate the user data.
1187
-		if ($row['field_type'] == 'check')
1188
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1189
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1249
+		if ($row['field_type'] == 'check') {
1250
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1251
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1190 1252
 		{
1191 1253
 			$value = $row['default_value'];
1192
-			foreach (explode(',', $row['field_options']) as $k => $v)
1193
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1254
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1255
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1194 1256
 					$value = $v;
1257
+			}
1195 1258
 		}
1196 1259
 		// Otherwise some form of text!
1197 1260
 		else
1198 1261
 		{
1199 1262
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1200
-			if ($row['field_length'])
1201
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			if ($row['field_length']) {
1264
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1265
+			}
1202 1266
 
1203 1267
 			// Any masks?
1204 1268
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1205 1269
 			{
1206 1270
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1207 1271
 				{
1208
-					if ($returnErrors)
1209
-						$errors[] = 'custom_field_mail_fail';
1210
-
1211
-					else
1212
-						$value = '';
1213
-				}
1214
-				elseif ($row['mask'] == 'number')
1272
+					if ($returnErrors) {
1273
+											$errors[] = 'custom_field_mail_fail';
1274
+					} else {
1275
+											$value = '';
1276
+					}
1277
+				} elseif ($row['mask'] == 'number')
1215 1278
 				{
1216 1279
 					$value = (int) $value;
1217
-				}
1218
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1280
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1219 1281
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_regex_fail';
1222
-
1223
-					else
1224
-						$value = '';
1282
+					if ($returnErrors) {
1283
+											$errors[] = 'custom_field_regex_fail';
1284
+					} else {
1285
+											$value = '';
1286
+					}
1225 1287
 				}
1226 1288
 			}
1227 1289
 		}
@@ -1248,8 +1310,9 @@  discard block
 block discarded – undo
1248 1310
 	$hook_errors = array();
1249 1311
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1250 1312
 
1251
-	if (!empty($hook_errors) && is_array($hook_errors))
1252
-		$errors = array_merge($errors, $hook_errors);
1313
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1314
+			$errors = array_merge($errors, $hook_errors);
1315
+	}
1253 1316
 
1254 1317
 	// Make those changes!
1255 1318
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1267,9 +1330,10 @@  discard block
 block discarded – undo
1267 1330
 		}
1268 1331
 	}
1269 1332
 
1270
-	if ($returnErrors)
1271
-		return $errors;
1272
-}
1333
+	if ($returnErrors) {
1334
+			return $errors;
1335
+	}
1336
+	}
1273 1337
 
1274 1338
 /**
1275 1339
  * Show all the users buddies, as well as a add/delete interface.
@@ -1281,8 +1345,9 @@  discard block
 block discarded – undo
1281 1345
 	global $context, $txt, $modSettings;
1282 1346
 
1283 1347
 	// Do a quick check to ensure people aren't getting here illegally!
1284
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1285
-		fatal_lang_error('no_access', false);
1348
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1349
+			fatal_lang_error('no_access', false);
1350
+	}
1286 1351
 
1287 1352
 	// Can we email the user direct?
1288 1353
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1312,9 +1377,10 @@  discard block
 block discarded – undo
1312 1377
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1313 1378
 	$call = call_helper($subActions[$context['list_area']][0], true);
1314 1379
 
1315
-	if (!empty($call))
1316
-		call_user_func($call, $memID);
1317
-}
1380
+	if (!empty($call)) {
1381
+			call_user_func($call, $memID);
1382
+	}
1383
+	}
1318 1384
 
1319 1385
 /**
1320 1386
  * Show all the users buddies, as well as a add/delete interface.
@@ -1328,9 +1394,10 @@  discard block
 block discarded – undo
1328 1394
 
1329 1395
 	// For making changes!
1330 1396
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1331
-	foreach ($buddiesArray as $k => $dummy)
1332
-		if ($dummy == '')
1397
+	foreach ($buddiesArray as $k => $dummy) {
1398
+			if ($dummy == '')
1333 1399
 			unset($buddiesArray[$k]);
1400
+	}
1334 1401
 
1335 1402
 	// Removing a buddy?
1336 1403
 	if (isset($_GET['remove']))
@@ -1342,10 +1409,11 @@  discard block
 block discarded – undo
1342 1409
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1343 1410
 
1344 1411
 		// Heh, I'm lazy, do it the easy way...
1345
-		foreach ($buddiesArray as $key => $buddy)
1346
-			if ($buddy == (int) $_GET['remove'])
1412
+		foreach ($buddiesArray as $key => $buddy) {
1413
+					if ($buddy == (int) $_GET['remove'])
1347 1414
 			{
1348 1415
 				unset($buddiesArray[$key]);
1416
+		}
1349 1417
 				$_SESSION['prf-save'] = true;
1350 1418
 			}
1351 1419
 
@@ -1355,8 +1423,7 @@  discard block
 block discarded – undo
1355 1423
 
1356 1424
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1357 1425
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1358
-	}
1359
-	elseif (isset($_POST['new_buddy']))
1426
+	} elseif (isset($_POST['new_buddy']))
1360 1427
 	{
1361 1428
 		checkSession();
1362 1429
 
@@ -1369,8 +1436,9 @@  discard block
 block discarded – undo
1369 1436
 		{
1370 1437
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1371 1438
 
1372
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1373
-				unset($new_buddies[$k]);
1439
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1440
+							unset($new_buddies[$k]);
1441
+			}
1374 1442
 		}
1375 1443
 
1376 1444
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1390,16 +1458,18 @@  discard block
 block discarded – undo
1390 1458
 				)
1391 1459
 			);
1392 1460
 
1393
-			if ($smcFunc['db_num_rows']($request) != 0)
1394
-				$_SESSION['prf-save'] = true;
1461
+			if ($smcFunc['db_num_rows']($request) != 0) {
1462
+							$_SESSION['prf-save'] = true;
1463
+			}
1395 1464
 
1396 1465
 			// Add the new member to the buddies array.
1397 1466
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1467
 			{
1399
-				if (in_array($row['id_member'], $buddiesArray))
1400
-					continue;
1401
-				else
1402
-					$buddiesArray[] = (int) $row['id_member'];
1468
+				if (in_array($row['id_member'], $buddiesArray)) {
1469
+									continue;
1470
+				} else {
1471
+									$buddiesArray[] = (int) $row['id_member'];
1472
+				}
1403 1473
 			}
1404 1474
 			$smcFunc['db_free_result']($request);
1405 1475
 
@@ -1429,18 +1499,20 @@  discard block
 block discarded – undo
1429 1499
 
1430 1500
 	$context['custom_pf'] = array();
1431 1501
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1432
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1433
-		if (!isset($disabled_fields[$row['col_name']]))
1502
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1503
+			if (!isset($disabled_fields[$row['col_name']]))
1434 1504
 			$context['custom_pf'][$row['col_name']] = array(
1435 1505
 				'label' => $row['field_name'],
1436 1506
 				'type' => $row['field_type'],
1437 1507
 				'bbc' => !empty($row['bbc']),
1438 1508
 				'enclose' => $row['enclose'],
1439 1509
 			);
1510
+	}
1440 1511
 
1441 1512
 	// Gotta disable the gender option.
1442
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1443
-		unset($context['custom_pf']['cust_gender']);
1513
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1514
+			unset($context['custom_pf']['cust_gender']);
1515
+	}
1444 1516
 
1445 1517
 	$smcFunc['db_free_result']($request);
1446 1518
 
@@ -1457,8 +1529,9 @@  discard block
 block discarded – undo
1457 1529
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1458 1530
 			)
1459 1531
 		);
1460
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1461
-			$buddies[] = $row['id_member'];
1532
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1533
+					$buddies[] = $row['id_member'];
1534
+		}
1462 1535
 		$smcFunc['db_free_result']($result);
1463 1536
 	}
1464 1537
 
@@ -1486,30 +1559,32 @@  discard block
 block discarded – undo
1486 1559
 					continue;
1487 1560
 				}
1488 1561
 
1489
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1490
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1491
-
1492
-				elseif ($column['type'] == 'check')
1493
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1563
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1564
+				} elseif ($column['type'] == 'check') {
1565
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1566
+				}
1494 1567
 
1495 1568
 				// Enclosing the user input within some other text?
1496
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1497
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1569
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1570
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1498 1571
 						'{SCRIPTURL}' => $scripturl,
1499 1572
 						'{IMAGES_URL}' => $settings['images_url'],
1500 1573
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1501 1574
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1502 1575
 					));
1576
+				}
1503 1577
 			}
1504 1578
 		}
1505 1579
 	}
1506 1580
 
1507 1581
 	if (isset($_SESSION['prf-save']))
1508 1582
 	{
1509
-		if ($_SESSION['prf-save'] === true)
1510
-			$context['saved_successful'] = true;
1511
-		else
1512
-			$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		if ($_SESSION['prf-save'] === true) {
1584
+					$context['saved_successful'] = true;
1585
+		} else {
1586
+					$context['saved_failed'] = $_SESSION['prf-save'];
1587
+		}
1513 1588
 
1514 1589
 		unset($_SESSION['prf-save']);
1515 1590
 	}
@@ -1529,9 +1604,10 @@  discard block
 block discarded – undo
1529 1604
 
1530 1605
 	// For making changes!
1531 1606
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1532
-	foreach ($ignoreArray as $k => $dummy)
1533
-		if ($dummy == '')
1607
+	foreach ($ignoreArray as $k => $dummy) {
1608
+			if ($dummy == '')
1534 1609
 			unset($ignoreArray[$k]);
1610
+	}
1535 1611
 
1536 1612
 	// Removing a member from the ignore list?
1537 1613
 	if (isset($_GET['remove']))
@@ -1541,10 +1617,11 @@  discard block
 block discarded – undo
1541 1617
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1542 1618
 
1543 1619
 		// Heh, I'm lazy, do it the easy way...
1544
-		foreach ($ignoreArray as $key => $id_remove)
1545
-			if ($id_remove == (int) $_GET['remove'])
1620
+		foreach ($ignoreArray as $key => $id_remove) {
1621
+					if ($id_remove == (int) $_GET['remove'])
1546 1622
 			{
1547 1623
 				unset($ignoreArray[$key]);
1624
+		}
1548 1625
 				$_SESSION['prf-save'] = true;
1549 1626
 			}
1550 1627
 
@@ -1554,8 +1631,7 @@  discard block
 block discarded – undo
1554 1631
 
1555 1632
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1556 1633
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1557
-	}
1558
-	elseif (isset($_POST['new_ignore']))
1634
+	} elseif (isset($_POST['new_ignore']))
1559 1635
 	{
1560 1636
 		checkSession();
1561 1637
 		// Prepare the string for extraction...
@@ -1567,8 +1643,9 @@  discard block
 block discarded – undo
1567 1643
 		{
1568 1644
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1569 1645
 
1570
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1571
-				unset($new_entries[$k]);
1646
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1647
+							unset($new_entries[$k]);
1648
+			}
1572 1649
 		}
1573 1650
 
1574 1651
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1586,16 +1663,18 @@  discard block
 block discarded – undo
1586 1663
 				)
1587 1664
 			);
1588 1665
 
1589
-			if ($smcFunc['db_num_rows']($request) != 0)
1590
-				$_SESSION['prf-save'] = true;
1666
+			if ($smcFunc['db_num_rows']($request) != 0) {
1667
+							$_SESSION['prf-save'] = true;
1668
+			}
1591 1669
 
1592 1670
 			// Add the new member to the buddies array.
1593 1671
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1672
 			{
1595
-				if (in_array($row['id_member'], $ignoreArray))
1596
-					continue;
1597
-				else
1598
-					$ignoreArray[] = (int) $row['id_member'];
1673
+				if (in_array($row['id_member'], $ignoreArray)) {
1674
+									continue;
1675
+				} else {
1676
+									$ignoreArray[] = (int) $row['id_member'];
1677
+				}
1599 1678
 			}
1600 1679
 			$smcFunc['db_free_result']($request);
1601 1680
 
@@ -1624,8 +1703,9 @@  discard block
 block discarded – undo
1624 1703
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1625 1704
 			)
1626 1705
 		);
1627
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1628
-			$ignored[] = $row['id_member'];
1706
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1707
+					$ignored[] = $row['id_member'];
1708
+		}
1629 1709
 		$smcFunc['db_free_result']($result);
1630 1710
 	}
1631 1711
 
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 
1645 1725
 	if (isset($_SESSION['prf-save']))
1646 1726
 	{
1647
-		if ($_SESSION['prf-save'] === true)
1648
-			$context['saved_successful'] = true;
1649
-		else
1650
-			$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		if ($_SESSION['prf-save'] === true) {
1728
+					$context['saved_successful'] = true;
1729
+		} else {
1730
+					$context['saved_failed'] = $_SESSION['prf-save'];
1731
+		}
1651 1732
 
1652 1733
 		unset($_SESSION['prf-save']);
1653 1734
 	}
@@ -1663,8 +1744,9 @@  discard block
 block discarded – undo
1663 1744
 	global $context, $txt;
1664 1745
 
1665 1746
 	loadThemeOptions($memID);
1666
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1667
-		loadCustomFields($memID, 'account');
1747
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1748
+			loadCustomFields($memID, 'account');
1749
+	}
1668 1750
 
1669 1751
 	$context['sub_template'] = 'edit_options';
1670 1752
 	$context['page_desc'] = $txt['account_info'];
@@ -1691,8 +1773,9 @@  discard block
 block discarded – undo
1691 1773
 	global $context, $txt;
1692 1774
 
1693 1775
 	loadThemeOptions($memID);
1694
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1695
-		loadCustomFields($memID, 'forumprofile');
1776
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1777
+			loadCustomFields($memID, 'forumprofile');
1778
+	}
1696 1779
 
1697 1780
 	$context['sub_template'] = 'edit_options';
1698 1781
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1725,18 +1808,21 @@  discard block
 block discarded – undo
1725 1808
 	$dirs = array();
1726 1809
 	$files = array();
1727 1810
 
1728
-	if (!$dir)
1729
-		return array();
1811
+	if (!$dir) {
1812
+			return array();
1813
+	}
1730 1814
 
1731 1815
 	while ($line = $dir->read())
1732 1816
 	{
1733
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1734
-			continue;
1817
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1818
+					continue;
1819
+		}
1735 1820
 
1736
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1737
-			$dirs[] = $line;
1738
-		else
1739
-			$files[] = $line;
1821
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1822
+					$dirs[] = $line;
1823
+		} else {
1824
+					$files[] = $line;
1825
+		}
1740 1826
 	}
1741 1827
 	$dir->close();
1742 1828
 
@@ -1757,14 +1843,15 @@  discard block
 block discarded – undo
1757 1843
 	foreach ($dirs as $line)
1758 1844
 	{
1759 1845
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1760
-		if (!empty($tmp))
1761
-			$result[] = array(
1846
+		if (!empty($tmp)) {
1847
+					$result[] = array(
1762 1848
 				'filename' => $smcFunc['htmlspecialchars']($line),
1763 1849
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1764 1850
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1765 1851
 				'is_dir' => true,
1766 1852
 				'files' => $tmp
1767 1853
 		);
1854
+		}
1768 1855
 		unset($tmp);
1769 1856
 	}
1770 1857
 
@@ -1774,8 +1861,9 @@  discard block
 block discarded – undo
1774 1861
 		$extension = substr(strrchr($line, '.'), 1);
1775 1862
 
1776 1863
 		// Make sure it is an image.
1777
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1778
-			continue;
1864
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1865
+					continue;
1866
+		}
1779 1867
 
1780 1868
 		$result[] = array(
1781 1869
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1783,8 +1871,9 @@  discard block
 block discarded – undo
1783 1871
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1784 1872
 			'is_dir' => false
1785 1873
 		);
1786
-		if ($level == 1)
1787
-			$context['avatar_list'][] = $directory . '/' . $line;
1874
+		if ($level == 1) {
1875
+					$context['avatar_list'][] = $directory . '/' . $line;
1876
+		}
1788 1877
 	}
1789 1878
 
1790 1879
 	return $result;
@@ -1800,8 +1889,9 @@  discard block
 block discarded – undo
1800 1889
 	global $txt, $context;
1801 1890
 
1802 1891
 	loadThemeOptions($memID);
1803
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1804
-		loadCustomFields($memID, 'theme');
1892
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1893
+			loadCustomFields($memID, 'theme');
1894
+	}
1805 1895
 
1806 1896
 	$context['sub_template'] = 'edit_options';
1807 1897
 	$context['page_desc'] = $txt['theme_info'];
@@ -1855,16 +1945,19 @@  discard block
 block discarded – undo
1855 1945
 {
1856 1946
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1857 1947
 
1858
-	if (!isset($context['token_check']))
1859
-		$context['token_check'] = 'profile-nt' . $memID;
1948
+	if (!isset($context['token_check'])) {
1949
+			$context['token_check'] = 'profile-nt' . $memID;
1950
+	}
1860 1951
 
1861 1952
 	is_not_guest();
1862
-	if (!$context['user']['is_owner'])
1863
-		isAllowedTo('profile_extra_any');
1953
+	if (!$context['user']['is_owner']) {
1954
+			isAllowedTo('profile_extra_any');
1955
+	}
1864 1956
 
1865 1957
 	// Set the post action if we're coming from the profile...
1866
-	if (!isset($context['action']))
1867
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1958
+	if (!isset($context['action'])) {
1959
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1960
+	}
1868 1961
 
1869 1962
 	// What options are set
1870 1963
 	loadThemeOptions($memID);
@@ -1951,28 +2044,34 @@  discard block
 block discarded – undo
1951 2044
 	);
1952 2045
 
1953 2046
 	// There are certain things that are disabled at the group level.
1954
-	if (empty($modSettings['cal_enabled']))
1955
-		unset($alert_types['calendar']);
2047
+	if (empty($modSettings['cal_enabled'])) {
2048
+			unset($alert_types['calendar']);
2049
+	}
1956 2050
 
1957 2051
 	// Disable paid subscriptions at group level if they're disabled
1958
-	if (empty($modSettings['paid_enabled']))
1959
-		unset($alert_types['paidsubs']);
2052
+	if (empty($modSettings['paid_enabled'])) {
2053
+			unset($alert_types['paidsubs']);
2054
+	}
1960 2055
 
1961 2056
 	// Disable membergroup requests at group level if they're disabled
1962
-	if (empty($modSettings['show_group_membership']))
1963
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2057
+	if (empty($modSettings['show_group_membership'])) {
2058
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2059
+	}
1964 2060
 
1965 2061
 	// Disable mentions if they're disabled
1966
-	if (empty($modSettings['enable_mentions']))
1967
-		unset($alert_types['msg']['msg_mention']);
2062
+	if (empty($modSettings['enable_mentions'])) {
2063
+			unset($alert_types['msg']['msg_mention']);
2064
+	}
1968 2065
 
1969 2066
 	// Disable likes if they're disabled
1970
-	if (empty($modSettings['enable_likes']))
1971
-		unset($alert_types['msg']['msg_like']);
2067
+	if (empty($modSettings['enable_likes'])) {
2068
+			unset($alert_types['msg']['msg_like']);
2069
+	}
1972 2070
 
1973 2071
 	// Disable buddy requests if they're disabled
1974
-	if (empty($modSettings['enable_buddylist']))
1975
-		unset($alert_types['members']['buddy_request']);
2072
+	if (empty($modSettings['enable_buddylist'])) {
2073
+			unset($alert_types['members']['buddy_request']);
2074
+	}
1976 2075
 
1977 2076
 	// Now, now, we could pass this through global but we should really get into the habit of
1978 2077
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2000,15 +2099,17 @@  discard block
 block discarded – undo
2000 2099
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2001 2100
 		}
2002 2101
 
2003
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2004
-			unset($alert_types['members']['request_group']);
2102
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2103
+					unset($alert_types['members']['request_group']);
2104
+		}
2005 2105
 
2006 2106
 		foreach ($alert_types as $group => $items)
2007 2107
 		{
2008 2108
 			foreach ($items as $alert_key => $alert_value)
2009 2109
 			{
2010
-				if (!isset($alert_value['permission']))
2011
-					continue;
2110
+				if (!isset($alert_value['permission'])) {
2111
+									continue;
2112
+				}
2012 2113
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2013 2114
 				{
2014 2115
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2016,12 +2117,14 @@  discard block
 block discarded – undo
2016 2117
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2017 2118
 				}
2018 2119
 
2019
-				if (!$perms_cache[$alert_value['permission']['name']])
2020
-					unset ($alert_types[$group][$alert_key]);
2120
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2121
+									unset ($alert_types[$group][$alert_key]);
2122
+				}
2021 2123
 			}
2022 2124
 
2023
-			if (empty($alert_types[$group]))
2024
-				unset ($alert_types[$group]);
2125
+			if (empty($alert_types[$group])) {
2126
+							unset ($alert_types[$group]);
2127
+			}
2025 2128
 		}
2026 2129
 	}
2027 2130
 
@@ -2053,9 +2156,9 @@  discard block
 block discarded – undo
2053 2156
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2054 2157
 						break;
2055 2158
 					case 'select':
2056
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2057
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2058
-						else
2159
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2160
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2161
+						} else
2059 2162
 						{
2060 2163
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2061 2164
 							$keys = array_keys($this_option['opts']);
@@ -2075,23 +2178,28 @@  discard block
 block discarded – undo
2075 2178
 				$this_value = 0;
2076 2179
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2077 2180
 				{
2078
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2079
-						$this_value |= $bitvalue;
2181
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2182
+											$this_value |= $bitvalue;
2183
+					}
2184
+				}
2185
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2186
+									$update_prefs[$item_key] = $this_value;
2080 2187
 				}
2081
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2082
-					$update_prefs[$item_key] = $this_value;
2083 2188
 			}
2084 2189
 		}
2085 2190
 
2086
-		if (!empty($_POST['opt_alert_timeout']))
2087
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2191
+		if (!empty($_POST['opt_alert_timeout'])) {
2192
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2193
+		}
2088 2194
 
2089
-		if (!empty($_POST['notify_announcements']))
2090
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2195
+		if (!empty($_POST['notify_announcements'])) {
2196
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2197
+		}
2091 2198
 
2092 2199
 		setNotifyPrefs((int) $memID, $update_prefs);
2093
-		foreach ($update_prefs as $pref => $value)
2094
-			$context['alert_prefs'][$pref] = $value;
2200
+		foreach ($update_prefs as $pref => $value) {
2201
+					$context['alert_prefs'][$pref] = $value;
2202
+		}
2095 2203
 
2096 2204
 		makeNotificationChanges($memID);
2097 2205
 
@@ -2121,8 +2229,9 @@  discard block
 block discarded – undo
2121 2229
 
2122 2230
 	// Now we're all set up.
2123 2231
 	is_not_guest();
2124
-	if (!$context['user']['is_owner'])
2125
-		fatal_error('no_access');
2232
+	if (!$context['user']['is_owner']) {
2233
+			fatal_error('no_access');
2234
+	}
2126 2235
 
2127 2236
 	checkSession('get');
2128 2237
 
@@ -2154,8 +2263,9 @@  discard block
 block discarded – undo
2154 2263
 {
2155 2264
 	global $smcFunc;
2156 2265
 
2157
-	if (empty($toMark) || empty($memID))
2158
-		return false;
2266
+	if (empty($toMark) || empty($memID)) {
2267
+			return false;
2268
+	}
2159 2269
 
2160 2270
 	$toMark = (array) $toMark;
2161 2271
 	$count = 0;
@@ -2190,8 +2300,9 @@  discard block
 block discarded – undo
2190 2300
 {
2191 2301
 	global $smcFunc;
2192 2302
 
2193
-	if (empty($toDelete))
2194
-		return false;
2303
+	if (empty($toDelete)) {
2304
+			return false;
2305
+	}
2195 2306
 
2196 2307
 	$toDelete = (array) $toDelete;
2197 2308
 
@@ -2226,8 +2337,9 @@  discard block
 block discarded – undo
2226 2337
 {
2227 2338
 	global $smcFunc;
2228 2339
 
2229
-	if (empty($memID))
2230
-		return false;
2340
+	if (empty($memID)) {
2341
+			return false;
2342
+	}
2231 2343
 
2232 2344
 	$count = 0;
2233 2345
 
@@ -2306,8 +2418,9 @@  discard block
 block discarded – undo
2306 2418
 					{
2307 2419
 						$link = $topic['link'];
2308 2420
 
2309
-						if ($topic['new'])
2310
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2421
+						if ($topic['new']) {
2422
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2423
+						}
2311 2424
 
2312 2425
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2313 2426
 
@@ -2458,8 +2571,9 @@  discard block
 block discarded – undo
2458 2571
 					{
2459 2572
 						$link = $board['link'];
2460 2573
 
2461
-						if ($board['new'])
2462
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2574
+						if ($board['new']) {
2575
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2576
+						}
2463 2577
 
2464 2578
 						return $link;
2465 2579
 					},
@@ -2659,8 +2773,8 @@  discard block
 block discarded – undo
2659 2773
 		)
2660 2774
 	);
2661 2775
 	$notification_boards = array();
2662
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2663
-		$notification_boards[] = array(
2776
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2777
+			$notification_boards[] = array(
2664 2778
 			'id' => $row['id_board'],
2665 2779
 			'name' => $row['name'],
2666 2780
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2668,6 +2782,7 @@  discard block
 block discarded – undo
2668 2782
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2669 2783
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2670 2784
 		);
2785
+	}
2671 2786
 	$smcFunc['db_free_result']($request);
2672 2787
 
2673 2788
 	return $notification_boards;
@@ -2682,17 +2797,18 @@  discard block
 block discarded – undo
2682 2797
 {
2683 2798
 	global $context, $options, $cur_profile, $smcFunc;
2684 2799
 
2685
-	if (isset($_POST['default_options']))
2686
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2800
+	if (isset($_POST['default_options'])) {
2801
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2802
+	}
2687 2803
 
2688 2804
 	if ($context['user']['is_owner'])
2689 2805
 	{
2690 2806
 		$context['member']['options'] = $options;
2691
-		if (isset($_POST['options']) && is_array($_POST['options']))
2692
-			foreach ($_POST['options'] as $k => $v)
2807
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2808
+					foreach ($_POST['options'] as $k => $v)
2693 2809
 				$context['member']['options'][$k] = $v;
2694
-	}
2695
-	else
2810
+		}
2811
+	} else
2696 2812
 	{
2697 2813
 		$request = $smcFunc['db_query']('', '
2698 2814
 			SELECT id_member, variable, value
@@ -2713,8 +2829,9 @@  discard block
 block discarded – undo
2713 2829
 				continue;
2714 2830
 			}
2715 2831
 
2716
-			if (isset($_POST['options'][$row['variable']]))
2717
-				$row['value'] = $_POST['options'][$row['variable']];
2832
+			if (isset($_POST['options'][$row['variable']])) {
2833
+							$row['value'] = $_POST['options'][$row['variable']];
2834
+			}
2718 2835
 			$context['member']['options'][$row['variable']] = $row['value'];
2719 2836
 		}
2720 2837
 		$smcFunc['db_free_result']($request);
@@ -2722,8 +2839,9 @@  discard block
 block discarded – undo
2722 2839
 		// Load up the default theme options for any missing.
2723 2840
 		foreach ($temp as $k => $v)
2724 2841
 		{
2725
-			if (!isset($context['member']['options'][$k]))
2726
-				$context['member']['options'][$k] = $v;
2842
+			if (!isset($context['member']['options'][$k])) {
2843
+							$context['member']['options'][$k] = $v;
2844
+			}
2727 2845
 		}
2728 2846
 	}
2729 2847
 }
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2739 2857
 
2740 2858
 	// Have the admins enabled this option?
2741
-	if (empty($modSettings['allow_ignore_boards']))
2742
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2859
+	if (empty($modSettings['allow_ignore_boards'])) {
2860
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2861
+	}
2743 2862
 
2744 2863
 	// Find all the boards this user is allowed to see.
2745 2864
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2759,12 +2878,13 @@  discard block
 block discarded – undo
2759 2878
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2760 2879
 	{
2761 2880
 		// This category hasn't been set up yet..
2762
-		if (!isset($context['categories'][$row['id_cat']]))
2763
-			$context['categories'][$row['id_cat']] = array(
2881
+		if (!isset($context['categories'][$row['id_cat']])) {
2882
+					$context['categories'][$row['id_cat']] = array(
2764 2883
 				'id' => $row['id_cat'],
2765 2884
 				'name' => $row['cat_name'],
2766 2885
 				'boards' => array()
2767 2886
 			);
2887
+		}
2768 2888
 
2769 2889
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2770 2890
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2794,18 +2914,20 @@  discard block
 block discarded – undo
2794 2914
 	}
2795 2915
 
2796 2916
 	$max_boards = ceil(count($temp_boards) / 2);
2797
-	if ($max_boards == 1)
2798
-		$max_boards = 2;
2917
+	if ($max_boards == 1) {
2918
+			$max_boards = 2;
2919
+	}
2799 2920
 
2800 2921
 	// Now, alternate them so they can be shown left and right ;).
2801 2922
 	$context['board_columns'] = array();
2802 2923
 	for ($i = 0; $i < $max_boards; $i++)
2803 2924
 	{
2804 2925
 		$context['board_columns'][] = $temp_boards[$i];
2805
-		if (isset($temp_boards[$i + $max_boards]))
2806
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2807
-		else
2808
-			$context['board_columns'][] = array();
2926
+		if (isset($temp_boards[$i + $max_boards])) {
2927
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2928
+		} else {
2929
+					$context['board_columns'][] = array();
2930
+		}
2809 2931
 	}
2810 2932
 
2811 2933
 	loadThemeOptions($memID);
@@ -2874,8 +2996,9 @@  discard block
 block discarded – undo
2874 2996
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2875 2997
 	{
2876 2998
 		// We should skip the administrator group if they don't have the admin_forum permission!
2877
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2878
-			continue;
2999
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3000
+					continue;
3001
+		}
2879 3002
 
2880 3003
 		$context['member_groups'][$row['id_group']] = array(
2881 3004
 			'id' => $row['id_group'],
@@ -2921,16 +3044,17 @@  discard block
 block discarded – undo
2921 3044
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2922 3045
 	// Warning message for signature image limits?
2923 3046
 	$context['signature_warning'] = '';
2924
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2925
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2926
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2927
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3048
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3049
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3050
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3051
+	}
2928 3052
 
2929 3053
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2930 3054
 
2931
-	if (empty($context['do_preview']))
2932
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2933
-	else
3055
+	if (empty($context['do_preview'])) {
3056
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3057
+	} else
2934 3058
 	{
2935 3059
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2936 3060
 		$validation = profileValidateSignature($signature);
@@ -2940,8 +3064,9 @@  discard block
 block discarded – undo
2940 3064
 			$context['post_errors'] = array();
2941 3065
 		}
2942 3066
 		$context['post_errors'][] = 'signature_not_yet_saved';
2943
-		if ($validation !== true && $validation !== false)
2944
-			$context['post_errors'][] = $validation;
3067
+		if ($validation !== true && $validation !== false) {
3068
+					$context['post_errors'][] = $validation;
3069
+		}
2945 3070
 
2946 3071
 		censorText($context['member']['signature']);
2947 3072
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2951,8 +3076,9 @@  discard block
 block discarded – undo
2951 3076
 	}
2952 3077
 
2953 3078
 	// Load the spell checker?
2954
-	if ($context['show_spellchecking'])
2955
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3079
+	if ($context['show_spellchecking']) {
3080
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3081
+	}
2956 3082
 
2957 3083
 	return true;
2958 3084
 }
@@ -2986,8 +3112,7 @@  discard block
 block discarded – undo
2986 3112
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2987 3113
 		);
2988 3114
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2989
-	}
2990
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3115
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2991 3116
 	{
2992 3117
 		$context['member']['avatar'] += array(
2993 3118
 			'choice' => 'upload',
@@ -2995,34 +3120,34 @@  discard block
 block discarded – undo
2995 3120
 			'external' => 'http://'
2996 3121
 		);
2997 3122
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2998
-	}
2999
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3000
-		$context['member']['avatar'] += array(
3123
+	} elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3124
+			$context['member']['avatar'] += array(
3001 3125
 			'choice' => 'external',
3002 3126
 			'server_pic' => 'blank.png',
3003 3127
 			'external' => $cur_profile['avatar']
3004 3128
 		);
3005
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3006
-		$context['member']['avatar'] += array(
3129
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3130
+			$context['member']['avatar'] += array(
3007 3131
 			'choice' => 'server_stored',
3008 3132
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3009 3133
 			'external' => 'http://'
3010 3134
 		);
3011
-	else
3012
-		$context['member']['avatar'] += array(
3135
+	} else {
3136
+			$context['member']['avatar'] += array(
3013 3137
 			'choice' => 'none',
3014 3138
 			'server_pic' => 'blank.png',
3015 3139
 			'external' => 'http://'
3016 3140
 		);
3141
+	}
3017 3142
 
3018 3143
 	// Get a list of all the avatars.
3019 3144
 	if ($context['member']['avatar']['allow_server_stored'])
3020 3145
 	{
3021 3146
 		$context['avatar_list'] = array();
3022 3147
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3148
+	} else {
3149
+			$context['avatars'] = array();
3023 3150
 	}
3024
-	else
3025
-		$context['avatars'] = array();
3026 3151
 
3027 3152
 	// Second level selected avatar...
3028 3153
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3051,19 +3176,22 @@  discard block
 block discarded – undo
3051 3176
 			)
3052 3177
 		);
3053 3178
 		$protected_groups = array(1);
3054
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3055
-			$protected_groups[] = $row['id_group'];
3179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3180
+					$protected_groups[] = $row['id_group'];
3181
+		}
3056 3182
 		$smcFunc['db_free_result']($request);
3057 3183
 
3058 3184
 		$protected_groups = array_unique($protected_groups);
3059 3185
 	}
3060 3186
 
3061 3187
 	// The account page allows the change of your id_group - but not to a protected group!
3062
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3063
-		$value = (int) $value;
3188
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3189
+			$value = (int) $value;
3190
+	}
3064 3191
 	// ... otherwise it's the old group sir.
3065
-	else
3066
-		$value = $old_profile['id_group'];
3192
+	else {
3193
+			$value = $old_profile['id_group'];
3194
+	}
3067 3195
 
3068 3196
 	// Find the additional membergroups (if any)
3069 3197
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3072,16 +3200,18 @@  discard block
 block discarded – undo
3072 3200
 		foreach ($_POST['additional_groups'] as $group_id)
3073 3201
 		{
3074 3202
 			$group_id = (int) $group_id;
3075
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3076
-				$additional_groups[] = $group_id;
3203
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3204
+							$additional_groups[] = $group_id;
3205
+			}
3077 3206
 		}
3078 3207
 
3079 3208
 		// Put the protected groups back in there if you don't have permission to take them away.
3080 3209
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3081 3210
 		foreach ($old_additional_groups as $group_id)
3082 3211
 		{
3083
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3084
-				$additional_groups[] = $group_id;
3212
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3213
+							$additional_groups[] = $group_id;
3214
+			}
3085 3215
 		}
3086 3216
 
3087 3217
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3113,18 +3243,20 @@  discard block
 block discarded – undo
3113 3243
 			list ($another) = $smcFunc['db_fetch_row']($request);
3114 3244
 			$smcFunc['db_free_result']($request);
3115 3245
 
3116
-			if (empty($another))
3117
-				fatal_lang_error('at_least_one_admin', 'critical');
3246
+			if (empty($another)) {
3247
+							fatal_lang_error('at_least_one_admin', 'critical');
3248
+			}
3118 3249
 		}
3119 3250
 	}
3120 3251
 
3121 3252
 	// If we are changing group status, update permission cache as necessary.
3122 3253
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3123 3254
 	{
3124
-		if ($context['user']['is_owner'])
3125
-			$_SESSION['mc']['time'] = 0;
3126
-		else
3127
-			updateSettings(array('settings_updated' => time()));
3255
+		if ($context['user']['is_owner']) {
3256
+					$_SESSION['mc']['time'] = 0;
3257
+		} else {
3258
+					updateSettings(array('settings_updated' => time()));
3259
+		}
3128 3260
 	}
3129 3261
 
3130 3262
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3145,8 +3277,9 @@  discard block
 block discarded – undo
3145 3277
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3146 3278
 
3147 3279
 	$memID = $context['id_member'];
3148
-	if (empty($memID) && !empty($context['password_auth_failed']))
3149
-		return false;
3280
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3281
+			return false;
3282
+	}
3150 3283
 
3151 3284
 	require_once($sourcedir . '/ManageAttachments.php');
3152 3285
 
@@ -3157,8 +3290,9 @@  discard block
 block discarded – undo
3157 3290
 	$downloadedExternalAvatar = false;
3158 3291
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3159 3292
 	{
3160
-		if (!is_writable($uploadDir))
3161
-			fatal_lang_error('attachments_no_write', 'critical');
3293
+		if (!is_writable($uploadDir)) {
3294
+					fatal_lang_error('attachments_no_write', 'critical');
3295
+		}
3162 3296
 
3163 3297
 		require_once($sourcedir . '/Subs-Package.php');
3164 3298
 
@@ -3202,19 +3336,18 @@  discard block
 block discarded – undo
3202 3336
 
3203 3337
 		// Get rid of their old avatar. (if uploaded.)
3204 3338
 		removeAttachments(array('id_member' => $memID));
3205
-	}
3206
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3339
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3207 3340
 	{
3208 3341
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3209
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3210
-			$profile_vars['avatar'] = 'gravatar://';
3211
-		else
3212
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3342
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3343
+					$profile_vars['avatar'] = 'gravatar://';
3344
+		} else {
3345
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3346
+		}
3213 3347
 
3214 3348
 		// Get rid of their old avatar. (if uploaded.)
3215 3349
 		removeAttachments(array('id_member' => $memID));
3216
-	}
3217
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3350
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3218 3351
 	{
3219 3352
 		// We need these clean...
3220 3353
 		$cur_profile['id_attach'] = 0;
@@ -3226,11 +3359,13 @@  discard block
 block discarded – undo
3226 3359
 
3227 3360
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3228 3361
 
3229
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3230
-			$profile_vars['avatar'] = '';
3362
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3363
+					$profile_vars['avatar'] = '';
3364
+		}
3231 3365
 		// Trying to make us do something we'll regret?
3232
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3233
-			return 'bad_avatar_invalid_url';
3366
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3367
+					return 'bad_avatar_invalid_url';
3368
+		}
3234 3369
 		// Should we check dimensions?
3235 3370
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3236 3371
 		{
@@ -3240,9 +3375,9 @@  discard block
 block discarded – undo
3240 3375
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3241 3376
 			{
3242 3377
 				// Houston, we have a problem. The avatar is too large!!
3243
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3244
-					return 'bad_avatar_too_large';
3245
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3378
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3379
+									return 'bad_avatar_too_large';
3380
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3246 3381
 				{
3247 3382
 					// @todo remove this if appropriate
3248 3383
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3252,26 +3387,27 @@  discard block
 block discarded – undo
3252 3387
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3253 3388
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3254 3389
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3390
+					} else {
3391
+											return 'bad_avatar';
3255 3392
 					}
3256
-					else
3257
-						return 'bad_avatar';
3258 3393
 				}
3259 3394
 			}
3260 3395
 		}
3261
-	}
3262
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3396
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3263 3397
 	{
3264 3398
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3265 3399
 		{
3266 3400
 			// Get the dimensions of the image.
3267 3401
 			if (!$downloadedExternalAvatar)
3268 3402
 			{
3269
-				if (!is_writable($uploadDir))
3270
-					fatal_lang_error('attachments_no_write', 'critical');
3403
+				if (!is_writable($uploadDir)) {
3404
+									fatal_lang_error('attachments_no_write', 'critical');
3405
+				}
3271 3406
 
3272 3407
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3273
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3274
-					fatal_lang_error('attach_timeout', 'critical');
3408
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3409
+									fatal_lang_error('attach_timeout', 'critical');
3410
+				}
3275 3411
 
3276 3412
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3277 3413
 			}
@@ -3384,17 +3520,19 @@  discard block
 block discarded – undo
3384 3520
 			$profile_vars['avatar'] = '';
3385 3521
 
3386 3522
 			// Delete any temporary file.
3387
-			if (file_exists($_FILES['attachment']['tmp_name']))
3388
-				@unlink($_FILES['attachment']['tmp_name']);
3523
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3524
+							@unlink($_FILES['attachment']['tmp_name']);
3525
+			}
3389 3526
 		}
3390 3527
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3391
-		else
3528
+		else {
3529
+					$profile_vars['avatar'] = '';
3530
+		}
3531
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3532
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3533
+	} else {
3392 3534
 			$profile_vars['avatar'] = '';
3393 3535
 	}
3394
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3395
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3396
-	else
3397
-		$profile_vars['avatar'] = '';
3398 3536
 
3399 3537
 	// Setup the profile variables so it shows things right on display!
3400 3538
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3442,9 +3580,9 @@  discard block
 block discarded – undo
3442 3580
 		$smiley_parsed = $unparsed_signature;
3443 3581
 		parsesmileys($smiley_parsed);
3444 3582
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3445
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3446
-			return 'signature_allow_smileys';
3447
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3583
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3584
+					return 'signature_allow_smileys';
3585
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3448 3586
 		{
3449 3587
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3450 3588
 			return 'signature_max_smileys';
@@ -3457,14 +3595,15 @@  discard block
 block discarded – undo
3457 3595
 			{
3458 3596
 				$limit_broke = 0;
3459 3597
 				// Attempt to allow all sizes of abuse, so to speak.
3460
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3461
-					$limit_broke = $sig_limits[7] . 'px';
3462
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3463
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3464
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3465
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3466
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3467
-					$limit_broke = 'large';
3598
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3599
+									$limit_broke = $sig_limits[7] . 'px';
3600
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3601
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3602
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3603
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3604
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3605
+									$limit_broke = 'large';
3606
+				}
3468 3607
 
3469 3608
 				if ($limit_broke)
3470 3609
 				{
@@ -3506,24 +3645,26 @@  discard block
 block discarded – undo
3506 3645
 					$width = -1; $height = -1;
3507 3646
 
3508 3647
 					// Does it have predefined restraints? Width first.
3509
-					if ($matches[6][$key])
3510
-						$matches[2][$key] = $matches[6][$key];
3648
+					if ($matches[6][$key]) {
3649
+											$matches[2][$key] = $matches[6][$key];
3650
+					}
3511 3651
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3512 3652
 					{
3513 3653
 						$width = $sig_limits[5];
3514 3654
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3655
+					} elseif ($matches[2][$key]) {
3656
+											$width = $matches[2][$key];
3515 3657
 					}
3516
-					elseif ($matches[2][$key])
3517
-						$width = $matches[2][$key];
3518 3658
 					// ... and height.
3519 3659
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3520 3660
 					{
3521 3661
 						$height = $sig_limits[6];
3522
-						if ($width != -1)
3523
-							$width = $width * ($height / $matches[4][$key]);
3662
+						if ($width != -1) {
3663
+													$width = $width * ($height / $matches[4][$key]);
3664
+						}
3665
+					} elseif ($matches[4][$key]) {
3666
+											$height = $matches[4][$key];
3524 3667
 					}
3525
-					elseif ($matches[4][$key])
3526
-						$height = $matches[4][$key];
3527 3668
 
3528 3669
 					// If the dimensions are still not fixed - we need to check the actual image.
3529 3670
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3541,21 +3682,24 @@  discard block
 block discarded – undo
3541 3682
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3542 3683
 							{
3543 3684
 								$height = $sig_limits[6];
3544
-								if ($width == -1)
3545
-									$width = $sizes[0];
3685
+								if ($width == -1) {
3686
+																	$width = $sizes[0];
3687
+								}
3546 3688
 								$width = $width * ($height / $sizes[1]);
3689
+							} elseif ($width != -1) {
3690
+															$height = $sizes[1];
3547 3691
 							}
3548
-							elseif ($width != -1)
3549
-								$height = $sizes[1];
3550 3692
 						}
3551 3693
 					}
3552 3694
 
3553 3695
 					// Did we come up with some changes? If so remake the string.
3554
-					if ($width != -1 || $height != -1)
3555
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					if ($width != -1 || $height != -1) {
3697
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3698
+					}
3699
+				}
3700
+				if (!empty($replaces)) {
3701
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3556 3702
 				}
3557
-				if (!empty($replaces))
3558
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3559 3703
 			}
3560 3704
 		}
3561 3705
 
@@ -3599,10 +3743,12 @@  discard block
 block discarded – undo
3599 3743
 	$email = strtr($email, array('&#039;' => '\''));
3600 3744
 
3601 3745
 	// Check the name and email for validity.
3602
-	if (trim($email) == '')
3603
-		return 'no_email';
3604
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3605
-		return 'bad_email';
3746
+	if (trim($email) == '') {
3747
+			return 'no_email';
3748
+	}
3749
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3750
+			return 'bad_email';
3751
+	}
3606 3752
 
3607 3753
 	// Email addresses should be and stay unique.
3608 3754
 	$request = $smcFunc['db_query']('', '
@@ -3617,8 +3763,9 @@  discard block
 block discarded – undo
3617 3763
 		)
3618 3764
 	);
3619 3765
 
3620
-	if ($smcFunc['db_num_rows']($request) > 0)
3621
-		return 'email_taken';
3766
+	if ($smcFunc['db_num_rows']($request) > 0) {
3767
+			return 'email_taken';
3768
+	}
3622 3769
 	$smcFunc['db_free_result']($request);
3623 3770
 
3624 3771
 	return true;
@@ -3631,8 +3778,9 @@  discard block
 block discarded – undo
3631 3778
 {
3632 3779
 	global $modSettings, $context, $cur_profile;
3633 3780
 
3634
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3635
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3782
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3783
+	}
3636 3784
 
3637 3785
 	loadUserSettings();
3638 3786
 	writeLog();
@@ -3648,8 +3796,9 @@  discard block
 block discarded – undo
3648 3796
 	require_once($sourcedir . '/Subs-Post.php');
3649 3797
 
3650 3798
 	// Shouldn't happen but just in case.
3651
-	if (empty($profile_vars['email_address']))
3652
-		return;
3799
+	if (empty($profile_vars['email_address'])) {
3800
+			return;
3801
+	}
3653 3802
 
3654 3803
 	$replacements = array(
3655 3804
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3672,8 +3821,9 @@  discard block
 block discarded – undo
3672 3821
 	$_SESSION['log_time'] = 0;
3673 3822
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3674 3823
 
3675
-	if (isset($_COOKIE[$cookiename]))
3676
-		$_COOKIE[$cookiename] = '';
3824
+	if (isset($_COOKIE[$cookiename])) {
3825
+			$_COOKIE[$cookiename] = '';
3826
+	}
3677 3827
 
3678 3828
 	loadUserSettings();
3679 3829
 
@@ -3706,11 +3856,13 @@  discard block
 block discarded – undo
3706 3856
 	$groups[] = $curMember['id_group'];
3707 3857
 
3708 3858
 	// Ensure the query doesn't croak!
3709
-	if (empty($groups))
3710
-		$groups = array(0);
3859
+	if (empty($groups)) {
3860
+			$groups = array(0);
3861
+	}
3711 3862
 	// Just to be sure...
3712
-	foreach ($groups as $k => $v)
3713
-		$groups[$k] = (int) $v;
3863
+	foreach ($groups as $k => $v) {
3864
+			$groups[$k] = (int) $v;
3865
+	}
3714 3866
 
3715 3867
 	// Get all the membergroups they can join.
3716 3868
 	$request = $smcFunc['db_query']('', '
@@ -3740,12 +3892,14 @@  discard block
 block discarded – undo
3740 3892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3741 3893
 	{
3742 3894
 		// Can they edit their primary group?
3743
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3744
-			$context['can_edit_primary'] = true;
3895
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3896
+					$context['can_edit_primary'] = true;
3897
+		}
3745 3898
 
3746 3899
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3747
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3748
-			continue;
3900
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3901
+					continue;
3902
+		}
3749 3903
 
3750 3904
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3751 3905
 			'id' => $row['id_group'],
@@ -3774,13 +3928,15 @@  discard block
 block discarded – undo
3774 3928
 	);
3775 3929
 
3776 3930
 	// No changing primary one unless you have enough groups!
3777
-	if (count($context['groups']['member']) < 2)
3778
-		$context['can_edit_primary'] = false;
3931
+	if (count($context['groups']['member']) < 2) {
3932
+			$context['can_edit_primary'] = false;
3933
+	}
3779 3934
 
3780 3935
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3781
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3782
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3783
-}
3936
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3937
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3938
+	}
3939
+	}
3784 3940
 
3785 3941
 /**
3786 3942
  * This function actually makes all the group changes
@@ -3795,10 +3951,12 @@  discard block
 block discarded – undo
3795 3951
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3796 3952
 
3797 3953
 	// Let's be extra cautious...
3798
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3799
-		isAllowedTo('manage_membergroups');
3800
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3801
-		fatal_lang_error('no_access', false);
3954
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3955
+			isAllowedTo('manage_membergroups');
3956
+	}
3957
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3958
+			fatal_lang_error('no_access', false);
3959
+	}
3802 3960
 
3803 3961
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3804 3962
 
@@ -3817,8 +3975,9 @@  discard block
 block discarded – undo
3817 3975
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3818 3976
 
3819 3977
 	// Sanity check!!
3820
-	if ($group_id == 1)
3821
-		isAllowedTo('admin_forum');
3978
+	if ($group_id == 1) {
3979
+			isAllowedTo('admin_forum');
3980
+	}
3822 3981
 	// Protected groups too!
3823 3982
 	else
3824 3983
 	{
@@ -3835,8 +3994,9 @@  discard block
 block discarded – undo
3835 3994
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3836 3995
 		$smcFunc['db_free_result']($request);
3837 3996
 
3838
-		if ($is_protected == 1)
3839
-			isAllowedTo('admin_forum');
3997
+		if ($is_protected == 1) {
3998
+					isAllowedTo('admin_forum');
3999
+		}
3840 4000
 	}
3841 4001
 
3842 4002
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3858,36 +4018,43 @@  discard block
 block discarded – undo
3858 4018
 			$group_name = $row['group_name'];
3859 4019
 
3860 4020
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3861
-			if ($changeType == 'request' && $row['group_type'] != 2)
3862
-				fatal_lang_error('no_access', false);
4021
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4022
+							fatal_lang_error('no_access', false);
4023
+			}
3863 4024
 			// What about leaving a requestable group we are not a member of?
3864
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3865
-				fatal_lang_error('no_access', false);
3866
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3867
-				fatal_lang_error('no_access', false);
4025
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4026
+							fatal_lang_error('no_access', false);
4027
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4028
+							fatal_lang_error('no_access', false);
4029
+			}
3868 4030
 
3869 4031
 			// We can't change the primary group if this is hidden!
3870
-			if ($row['hidden'] == 2)
3871
-				$canChangePrimary = false;
4032
+			if ($row['hidden'] == 2) {
4033
+							$canChangePrimary = false;
4034
+			}
3872 4035
 		}
3873 4036
 
3874 4037
 		// If this is their old primary, can we change it?
3875
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3876
-			$canChangePrimary = 1;
4038
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4039
+					$canChangePrimary = 1;
4040
+		}
3877 4041
 
3878 4042
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3879
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3880
-			$canChangePrimary = false;
4043
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4044
+					$canChangePrimary = false;
4045
+		}
3881 4046
 
3882 4047
 		// If this is the one we are acting on, can we even act?
3883
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3884
-			$canChangePrimary = false;
4048
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4049
+					$canChangePrimary = false;
4050
+		}
3885 4051
 	}
3886 4052
 	$smcFunc['db_free_result']($request);
3887 4053
 
3888 4054
 	// Didn't find the target?
3889
-	if (!$foundTarget)
3890
-		fatal_lang_error('no_access', false);
4055
+	if (!$foundTarget) {
4056
+			fatal_lang_error('no_access', false);
4057
+	}
3891 4058
 
3892 4059
 	// Final security check, don't allow users to promote themselves to admin.
3893 4060
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3907,8 +4074,9 @@  discard block
 block discarded – undo
3907 4074
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3908 4075
 		$smcFunc['db_free_result']($request);
3909 4076
 
3910
-		if ($disallow)
3911
-			isAllowedTo('admin_forum');
4077
+		if ($disallow) {
4078
+					isAllowedTo('admin_forum');
4079
+		}
3912 4080
 	}
3913 4081
 
3914 4082
 	// If we're requesting, add the note then return.
@@ -3926,8 +4094,9 @@  discard block
 block discarded – undo
3926 4094
 				'status_open' => 0,
3927 4095
 			)
3928 4096
 		);
3929
-		if ($smcFunc['db_num_rows']($request) != 0)
3930
-			fatal_lang_error('profile_error_already_requested_group');
4097
+		if ($smcFunc['db_num_rows']($request) != 0) {
4098
+					fatal_lang_error('profile_error_already_requested_group');
4099
+		}
3931 4100
 		$smcFunc['db_free_result']($request);
3932 4101
 
3933 4102
 		// Log the request.
@@ -3961,10 +4130,11 @@  discard block
 block discarded – undo
3961 4130
 		// Are we leaving?
3962 4131
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3963 4132
 		{
3964
-			if ($old_profile['id_group'] == $group_id)
3965
-				$newPrimary = 0;
3966
-			else
3967
-				unset($addGroups[$group_id]);
4133
+			if ($old_profile['id_group'] == $group_id) {
4134
+							$newPrimary = 0;
4135
+			} else {
4136
+							unset($addGroups[$group_id]);
4137
+			}
3968 4138
 		}
3969 4139
 		// ... if not, must be joining.
3970 4140
 		else
@@ -3972,36 +4142,42 @@  discard block
 block discarded – undo
3972 4142
 			// Can we change the primary, and do we want to?
3973 4143
 			if ($canChangePrimary)
3974 4144
 			{
3975
-				if ($old_profile['id_group'] != 0)
3976
-					$addGroups[$old_profile['id_group']] = -1;
4145
+				if ($old_profile['id_group'] != 0) {
4146
+									$addGroups[$old_profile['id_group']] = -1;
4147
+				}
3977 4148
 				$newPrimary = $group_id;
3978 4149
 			}
3979 4150
 			// Otherwise it's an additional group...
3980
-			else
3981
-				$addGroups[$group_id] = -1;
4151
+			else {
4152
+							$addGroups[$group_id] = -1;
4153
+			}
3982 4154
 		}
3983 4155
 	}
3984 4156
 	// Finally, we must be setting the primary.
3985 4157
 	elseif ($canChangePrimary)
3986 4158
 	{
3987
-		if ($old_profile['id_group'] != 0)
3988
-			$addGroups[$old_profile['id_group']] = -1;
3989
-		if (isset($addGroups[$group_id]))
3990
-			unset($addGroups[$group_id]);
4159
+		if ($old_profile['id_group'] != 0) {
4160
+					$addGroups[$old_profile['id_group']] = -1;
4161
+		}
4162
+		if (isset($addGroups[$group_id])) {
4163
+					unset($addGroups[$group_id]);
4164
+		}
3991 4165
 		$newPrimary = $group_id;
3992 4166
 	}
3993 4167
 
3994 4168
 	// Finally, we can make the changes!
3995
-	foreach ($addGroups as $id => $dummy)
3996
-		if (empty($id))
4169
+	foreach ($addGroups as $id => $dummy) {
4170
+			if (empty($id))
3997 4171
 			unset($addGroups[$id]);
4172
+	}
3998 4173
 	$addGroups = implode(',', array_flip($addGroups));
3999 4174
 
4000 4175
 	// Ensure that we don't cache permissions if the group is changing.
4001
-	if ($context['user']['is_owner'])
4002
-		$_SESSION['mc']['time'] = 0;
4003
-	else
4004
-		updateSettings(array('settings_updated' => time()));
4176
+	if ($context['user']['is_owner']) {
4177
+			$_SESSION['mc']['time'] = 0;
4178
+	} else {
4179
+			updateSettings(array('settings_updated' => time()));
4180
+	}
4005 4181
 
4006 4182
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4007 4183
 
@@ -4024,8 +4200,9 @@  discard block
 block discarded – undo
4024 4200
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4025 4201
 	{
4026 4202
 		// Check to ensure we're forcing SSL for authentication
4027
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4028
-			fatal_lang_error('login_ssl_required');
4203
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4204
+					fatal_lang_error('login_ssl_required');
4205
+		}
4029 4206
 
4030 4207
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4031 4208
 		// we do not want too much AJAX to confuse them.
@@ -4062,8 +4239,7 @@  discard block
 block discarded – undo
4062 4239
 				$context['sub_template'] = 'tfasetup_backup';
4063 4240
 
4064 4241
 				return;
4065
-			}
4066
-			else
4242
+			} else
4067 4243
 			{
4068 4244
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4069 4245
 				$context['tfa_error'] = !$valid_code;
@@ -4071,8 +4247,7 @@  discard block
 block discarded – undo
4071 4247
 				$context['tfa_pass_value'] = $_POST['passwd'];
4072 4248
 				$context['tfa_value'] = $_POST['tfa_code'];
4073 4249
 			}
4074
-		}
4075
-		else
4250
+		} else
4076 4251
 		{
4077 4252
 			$totp = new \TOTP\Auth();
4078 4253
 			$secret = $totp->generateCode();
@@ -4082,17 +4257,16 @@  discard block
 block discarded – undo
4082 4257
 		}
4083 4258
 
4084 4259
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4085
-	}
4086
-	elseif (isset($_REQUEST['disable']))
4260
+	} elseif (isset($_REQUEST['disable']))
4087 4261
 	{
4088 4262
 		updateMemberData($memID, array(
4089 4263
 			'tfa_secret' => '',
4090 4264
 			'tfa_backup' => '',
4091 4265
 		));
4092 4266
 		redirectexit('action=profile;area=account;u=' . $memID);
4267
+	} else {
4268
+			redirectexit('action=profile;area=account;u=' . $memID);
4269
+	}
4093 4270
 	}
4094
-	else
4095
-		redirectexit('action=profile;area=account;u=' . $memID);
4096
-}
4097 4271
 
4098 4272
 ?>
4099 4273
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-View.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2610,7 +2610,7 @@
 block discarded – undo
2610 2610
  * @param int $start Which item to start with (for pagination purposes)
2611 2611
  * @param int $items_per_page How many items to show on each page
2612 2612
  * @param string $sort A string indicating how to sort the results
2613
- * @param int $memID The ID of the member
2613
+ * @param string $memID The ID of the member
2614 2614
  * @return array An array of information about the user's group requests
2615 2615
  */
2616 2616
 function list_getGroupRequests($start, $items_per_page, $sort, $memID)
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	// Prepare the pagination vars.
369 369
 	$maxIndex = 10;
370 370
 	$start = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
371
-	$count =  alert_count($memID);
371
+	$count = alert_count($memID);
372 372
 
373 373
 	// Get the alerts.
374 374
 	$context['alerts'] = fetch_alerts($memID, true, false, array('start' => $start, 'maxIndex' => $maxIndex));
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			),
834 834
 		),
835 835
 		'data_check' => array(
836
-			'class' => function ($data)
836
+			'class' => function($data)
837 837
 			{
838 838
 				return $data['approved'] ? '' : 'approvebg';
839 839
 			}
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 				),
1537 1537
 				'data' => array(
1538 1538
 					'sprintf' => array(
1539
-						'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
1539
+						'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>',
1540 1540
 						'params' => array(
1541 1541
 							'ip' => false,
1542 1542
 						),
Please login to merge, or discard this patch.
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']))
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -583,10 +613,11 @@  discard block
 block discarded – undo
583 613
 	$reverse = false;
584 614
 	$range_limit = '';
585 615
 
586
-	if ($context['is_topics'])
587
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
588
-	else
589
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
616
+	if ($context['is_topics']) {
617
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
618
+	} else {
619
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
620
+	}
590 621
 
591 622
 	$maxIndex = $maxPerPage;
592 623
 
@@ -612,9 +643,9 @@  discard block
 block discarded – undo
612 643
 		{
613 644
 			$margin *= 5;
614 645
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
646
+		} else {
647
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
615 648
 		}
616
-		else
617
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
618 649
 	}
619 650
 
620 651
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -646,8 +677,7 @@  discard block
 block discarded – undo
646 677
 					'max' => $maxIndex,
647 678
 				)
648 679
 			);
649
-		}
650
-		else
680
+		} else
651 681
 		{
652 682
 			$request = $smcFunc['db_query']('', '
653 683
 				SELECT
@@ -676,8 +706,9 @@  discard block
 block discarded – undo
676 706
 		}
677 707
 
678 708
 		// Make sure we quit this loop.
679
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
680
-			break;
709
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
710
+					break;
711
+		}
681 712
 		$looped = true;
682 713
 		$range_limit = '';
683 714
 	}
@@ -721,19 +752,21 @@  discard block
 block discarded – undo
721 752
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
722 753
 		);
723 754
 
724
-		if ($user_info['id'] == $row['id_member_started'])
725
-			$board_ids['own'][$row['id_board']][] = $counter;
755
+		if ($user_info['id'] == $row['id_member_started']) {
756
+					$board_ids['own'][$row['id_board']][] = $counter;
757
+		}
726 758
 		$board_ids['any'][$row['id_board']][] = $counter;
727 759
 	}
728 760
 	$smcFunc['db_free_result']($request);
729 761
 
730 762
 	// All posts were retrieved in reverse order, get them right again.
731
-	if ($reverse)
732
-		$context['posts'] = array_reverse($context['posts'], true);
763
+	if ($reverse) {
764
+			$context['posts'] = array_reverse($context['posts'], true);
765
+	}
733 766
 
734 767
 	// These are all the permissions that are different from board to board..
735
-	if ($context['is_topics'])
736
-		$permissions = array(
768
+	if ($context['is_topics']) {
769
+			$permissions = array(
737 770
 			'own' => array(
738 771
 				'post_reply_own' => 'can_reply',
739 772
 			),
@@ -741,8 +774,8 @@  discard block
 block discarded – undo
741 774
 				'post_reply_any' => 'can_reply',
742 775
 			)
743 776
 		);
744
-	else
745
-		$permissions = array(
777
+	} else {
778
+			$permissions = array(
746 779
 			'own' => array(
747 780
 				'post_reply_own' => 'can_reply',
748 781
 				'delete_own' => 'can_delete',
@@ -752,6 +785,7 @@  discard block
 block discarded – undo
752 785
 				'delete_any' => 'can_delete',
753 786
 			)
754 787
 		);
788
+	}
755 789
 
756 790
 	// For every permission in the own/any lists...
757 791
 	foreach ($permissions as $type => $list)
@@ -762,19 +796,22 @@  discard block
 block discarded – undo
762 796
 			$boards = boardsAllowedTo($permission);
763 797
 
764 798
 			// Hmm, they can do it on all boards, can they?
765
-			if (!empty($boards) && $boards[0] == 0)
766
-				$boards = array_keys($board_ids[$type]);
799
+			if (!empty($boards) && $boards[0] == 0) {
800
+							$boards = array_keys($board_ids[$type]);
801
+			}
767 802
 
768 803
 			// Now go through each board they can do the permission on.
769 804
 			foreach ($boards as $board_id)
770 805
 			{
771 806
 				// There aren't any posts displayed from this board.
772
-				if (!isset($board_ids[$type][$board_id]))
773
-					continue;
807
+				if (!isset($board_ids[$type][$board_id])) {
808
+									continue;
809
+				}
774 810
 
775 811
 				// Set the permission to true ;).
776
-				foreach ($board_ids[$type][$board_id] as $counter)
777
-					$context['posts'][$counter][$allowed] = true;
812
+				foreach ($board_ids[$type][$board_id] as $counter) {
813
+									$context['posts'][$counter][$allowed] = true;
814
+				}
778 815
 			}
779 816
 		}
780 817
 	}
@@ -805,8 +842,9 @@  discard block
 block discarded – undo
805 842
 	$boardsAllowed = boardsAllowedTo('view_attachments');
806 843
 
807 844
 	// Make sure we can't actually see anything...
808
-	if (empty($boardsAllowed))
809
-		$boardsAllowed = array(-1);
845
+	if (empty($boardsAllowed)) {
846
+			$boardsAllowed = array(-1);
847
+	}
810 848
 
811 849
 	require_once($sourcedir . '/Subs-List.php');
812 850
 
@@ -957,8 +995,8 @@  discard block
 block discarded – undo
957 995
 		)
958 996
 	);
959 997
 	$attachments = array();
960
-	while ($row = $smcFunc['db_fetch_assoc']($request))
961
-		$attachments[] = array(
998
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
999
+			$attachments[] = array(
962 1000
 			'id' => $row['id_attach'],
963 1001
 			'filename' => $row['filename'],
964 1002
 			'downloads' => $row['downloads'],
@@ -970,6 +1008,7 @@  discard block
 block discarded – undo
970 1008
 			'board_name' => $row['name'],
971 1009
 			'approved' => $row['approved'],
972 1010
 		);
1011
+	}
973 1012
 
974 1013
 	$smcFunc['db_free_result']($request);
975 1014
 
@@ -1024,8 +1063,9 @@  discard block
 block discarded – undo
1024 1063
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1025 1064
 
1026 1065
 	// Only the owner can see the list (if the function is enabled of course)
1027
-	if ($user_info['id'] != $memID)
1028
-		return;
1066
+	if ($user_info['id'] != $memID) {
1067
+			return;
1068
+	}
1029 1069
 
1030 1070
 	require_once($sourcedir . '/Subs-List.php');
1031 1071
 
@@ -1171,8 +1211,9 @@  discard block
 block discarded – undo
1171 1211
 	);
1172 1212
 
1173 1213
 	$topics = array();
1174
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1175
-		$topics[] = $row['id_topic'];
1214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1215
+			$topics[] = $row['id_topic'];
1216
+	}
1176 1217
 
1177 1218
 	$smcFunc['db_free_result']($request);
1178 1219
 
@@ -1192,8 +1233,9 @@  discard block
 block discarded – undo
1192 1233
 				'topics' => $topics,
1193 1234
 			)
1194 1235
 		);
1195
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1196
-			$topicsInfo[] = $row;
1236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1237
+					$topicsInfo[] = $row;
1238
+		}
1197 1239
 		$smcFunc['db_free_result']($request);
1198 1240
 	}
1199 1241
 
@@ -1241,8 +1283,9 @@  discard block
 block discarded – undo
1241 1283
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1242 1284
 
1243 1285
 	// Is the load average too high to allow searching just now?
1244
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1245
-		fatal_lang_error('loadavg_userstats_disabled', false);
1286
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1287
+			fatal_lang_error('loadavg_userstats_disabled', false);
1288
+	}
1246 1289
 
1247 1290
 	// General user statistics.
1248 1291
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1400,11 +1443,13 @@  discard block
 block discarded – undo
1400 1443
 	}
1401 1444
 	$smcFunc['db_free_result']($result);
1402 1445
 
1403
-	if ($maxPosts > 0)
1404
-		for ($hour = 0; $hour < 24; $hour++)
1446
+	if ($maxPosts > 0) {
1447
+			for ($hour = 0;
1448
+	}
1449
+	$hour < 24; $hour++)
1405 1450
 		{
1406
-			if (!isset($context['posts_by_time'][$hour]))
1407
-				$context['posts_by_time'][$hour] = array(
1451
+			if (!isset($context['posts_by_time'][$hour])) {
1452
+							$context['posts_by_time'][$hour] = array(
1408 1453
 					'hour' => $hour,
1409 1454
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1410 1455
 					'posts' => 0,
@@ -1412,7 +1457,7 @@  discard block
 block discarded – undo
1412 1457
 					'relative_percent' => 0,
1413 1458
 					'is_last' => $hour == 23,
1414 1459
 				);
1415
-			else
1460
+			} else
1416 1461
 			{
1417 1462
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1418 1463
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1445,8 +1490,9 @@  discard block
 block discarded – undo
1445 1490
 
1446 1491
 	foreach ($subActions as $sa => $action)
1447 1492
 	{
1448
-		if (!allowedTo($action[2]))
1449
-			unset($subActions[$sa]);
1493
+		if (!allowedTo($action[2])) {
1494
+					unset($subActions[$sa]);
1495
+		}
1450 1496
 	}
1451 1497
 
1452 1498
 	// Create the tabs for the template.
@@ -1464,15 +1510,18 @@  discard block
 block discarded – undo
1464 1510
 	);
1465 1511
 
1466 1512
 	// Moderation must be on to track edits.
1467
-	if (empty($modSettings['userlog_enabled']))
1468
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1513
+	if (empty($modSettings['userlog_enabled'])) {
1514
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1515
+	}
1469 1516
 
1470 1517
 	// Group requests must be active to show it...
1471
-	if (empty($modSettings['show_group_membership']))
1472
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1518
+	if (empty($modSettings['show_group_membership'])) {
1519
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1520
+	}
1473 1521
 
1474
-	if (empty($subActions))
1475
-		fatal_lang_error('no_access', false);
1522
+	if (empty($subActions)) {
1523
+			fatal_lang_error('no_access', false);
1524
+	}
1476 1525
 
1477 1526
 	$keys = array_keys($subActions);
1478 1527
 	$default = array_shift($keys);
@@ -1485,9 +1534,10 @@  discard block
 block discarded – undo
1485 1534
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1486 1535
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1487 1536
 
1488
-	if (!empty($call))
1489
-		call_user_func($call, $memID);
1490
-}
1537
+	if (!empty($call)) {
1538
+			call_user_func($call, $memID);
1539
+	}
1540
+	}
1491 1541
 
1492 1542
 /**
1493 1543
  * Handles tracking a user's activity
@@ -1503,8 +1553,9 @@  discard block
 block discarded – undo
1503 1553
 	isAllowedTo('moderate_forum');
1504 1554
 
1505 1555
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1506
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1507
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1556
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1557
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1558
+	}
1508 1559
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1509 1560
 
1510 1561
 	// Set the options for the list component.
@@ -1670,8 +1721,9 @@  discard block
 block discarded – undo
1670 1721
 			)
1671 1722
 		);
1672 1723
 		$message_members = array();
1673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-			$message_members[] = $row['id_member'];
1724
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1725
+					$message_members[] = $row['id_member'];
1726
+		}
1675 1727
 		$smcFunc['db_free_result']($request);
1676 1728
 
1677 1729
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1686,8 +1738,9 @@  discard block
 block discarded – undo
1686 1738
 					'ip_list' => $ips,
1687 1739
 				)
1688 1740
 			);
1689
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1690
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1741
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1742
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1743
+			}
1691 1744
 			$smcFunc['db_free_result']($request);
1692 1745
 		}
1693 1746
 
@@ -1701,8 +1754,9 @@  discard block
 block discarded – undo
1701 1754
 				'ip_list' => $ips,
1702 1755
 			)
1703 1756
 		);
1704
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1705
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1757
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1758
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1759
+		}
1706 1760
 		$smcFunc['db_free_result']($request);
1707 1761
 	}
1708 1762
 }
@@ -1762,8 +1816,8 @@  discard block
 block discarded – undo
1762 1816
 		))
1763 1817
 	);
1764 1818
 	$error_messages = array();
1765
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1766
-		$error_messages[] = array(
1819
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1820
+			$error_messages[] = array(
1767 1821
 			'ip' => inet_dtop($row['ip']),
1768 1822
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1769 1823
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1771,6 +1825,7 @@  discard block
 block discarded – undo
1771 1825
 			'time' => timeformat($row['log_time']),
1772 1826
 			'timestamp' => forum_time(true, $row['log_time']),
1773 1827
 		);
1828
+	}
1774 1829
 	$smcFunc['db_free_result']($request);
1775 1830
 
1776 1831
 	return $error_messages;
@@ -1833,8 +1888,8 @@  discard block
 block discarded – undo
1833 1888
 		))
1834 1889
 	);
1835 1890
 	$messages = array();
1836
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1837
-		$messages[] = array(
1891
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1892
+			$messages[] = array(
1838 1893
 			'ip' => inet_dtop($row['poster_ip']),
1839 1894
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1840 1895
 			'board' => array(
@@ -1847,6 +1902,7 @@  discard block
 block discarded – undo
1847 1902
 			'time' => timeformat($row['poster_time']),
1848 1903
 			'timestamp' => forum_time(true, $row['poster_time'])
1849 1904
 		);
1905
+	}
1850 1906
 	$smcFunc['db_free_result']($request);
1851 1907
 
1852 1908
 	return $messages;
@@ -1873,19 +1929,20 @@  discard block
 block discarded – undo
1873 1929
 		$context['sub_template'] = 'trackIP';
1874 1930
 		$context['page_title'] = $txt['profile'];
1875 1931
 		$context['base_url'] = $scripturl . '?action=trackip';
1876
-	}
1877
-	else
1932
+	} else
1878 1933
 	{
1879 1934
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1880 1935
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1881 1936
 	}
1882 1937
 
1883 1938
 	// Searching?
1884
-	if (isset($_REQUEST['searchip']))
1885
-		$context['ip'] = trim($_REQUEST['searchip']);
1939
+	if (isset($_REQUEST['searchip'])) {
1940
+			$context['ip'] = trim($_REQUEST['searchip']);
1941
+	}
1886 1942
 
1887
-	if (isValidIP($context['ip']) === false)
1888
-		fatal_lang_error('invalid_tracking_ip', false);
1943
+	if (isValidIP($context['ip']) === false) {
1944
+			fatal_lang_error('invalid_tracking_ip', false);
1945
+	}
1889 1946
 
1890 1947
 	//mysql didn't support like search with varbinary
1891 1948
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1893,8 +1950,9 @@  discard block
 block discarded – undo
1893 1950
 	$ip_var = $context['ip'];
1894 1951
 	$ip_string = '= {inet:ip_address}';
1895 1952
 
1896
-	if (empty($context['tracking_area']))
1897
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1953
+	if (empty($context['tracking_area'])) {
1954
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1955
+	}
1898 1956
 
1899 1957
 	$request = $smcFunc['db_query']('', '
1900 1958
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1905,8 +1963,9 @@  discard block
 block discarded – undo
1905 1963
 		)
1906 1964
 	);
1907 1965
 	$context['ips'] = array();
1908
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1968
+	}
1910 1969
 	$smcFunc['db_free_result']($request);
1911 1970
 
1912 1971
 	ksort($context['ips']);
@@ -2135,8 +2194,9 @@  discard block
 block discarded – undo
2135 2194
 		foreach ($context['whois_servers'] as $whois)
2136 2195
 		{
2137 2196
 			// Strip off the "decimal point" and anything following...
2138
-			if (in_array((int) $context['ip'], $whois['range']))
2139
-				$context['auto_whois_server'] = $whois;
2197
+			if (in_array((int) $context['ip'], $whois['range'])) {
2198
+							$context['auto_whois_server'] = $whois;
2199
+			}
2140 2200
 		}
2141 2201
 	}
2142 2202
 }
@@ -2153,10 +2213,11 @@  discard block
 block discarded – undo
2153 2213
 	// Gonna want this for the list.
2154 2214
 	require_once($sourcedir . '/Subs-List.php');
2155 2215
 
2156
-	if ($memID == 0)
2157
-		$context['base_url'] = $scripturl . '?action=trackip';
2158
-	else
2159
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2216
+	if ($memID == 0) {
2217
+			$context['base_url'] = $scripturl . '?action=trackip';
2218
+	} else {
2219
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2220
+	}
2160 2221
 
2161 2222
 	// Start with the user messages.
2162 2223
 	$listOptions = array(
@@ -2266,12 +2327,13 @@  discard block
 block discarded – undo
2266 2327
 		)
2267 2328
 	);
2268 2329
 	$logins = array();
2269
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2270
-		$logins[] = array(
2330
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2331
+			$logins[] = array(
2271 2332
 			'time' => timeformat($row['time']),
2272 2333
 			'ip' => inet_dtop($row['ip']),
2273 2334
 			'ip2' => inet_dtop($row['ip2']),
2274 2335
 		);
2336
+	}
2275 2337
 	$smcFunc['db_free_result']($request);
2276 2338
 
2277 2339
 	return $logins;
@@ -2296,11 +2358,12 @@  discard block
 block discarded – undo
2296 2358
 		)
2297 2359
 	);
2298 2360
 	$context['custom_field_titles'] = array();
2299
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2300
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2361
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2362
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2301 2363
 			'title' => $row['field_name'],
2302 2364
 			'parse_bbc' => $row['bbc'],
2303 2365
 		);
2366
+	}
2304 2367
 	$smcFunc['db_free_result']($request);
2305 2368
 
2306 2369
 	// Set the options for the error lists.
@@ -2439,19 +2502,22 @@  discard block
 block discarded – undo
2439 2502
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2440 2503
 	{
2441 2504
 		$extra = smf_json_decode($row['extra'], true);
2442
-		if (!empty($extra['applicator']))
2443
-			$members[] = $extra['applicator'];
2505
+		if (!empty($extra['applicator'])) {
2506
+					$members[] = $extra['applicator'];
2507
+		}
2444 2508
 
2445 2509
 		// Work out what the name of the action is.
2446
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2447
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2448
-		elseif (isset($txt[$row['action']]))
2449
-			$action_text = $txt[$row['action']];
2510
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2511
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2512
+		} elseif (isset($txt[$row['action']])) {
2513
+					$action_text = $txt[$row['action']];
2514
+		}
2450 2515
 		// Custom field?
2451
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2452
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2453
-		else
2454
-			$action_text = $row['action'];
2516
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2517
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2518
+		} else {
2519
+					$action_text = $row['action'];
2520
+		}
2455 2521
 
2456 2522
 		// Parse BBC?
2457 2523
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2483,13 +2549,15 @@  discard block
 block discarded – undo
2483 2549
 			)
2484 2550
 		);
2485 2551
 		$members = array();
2486
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2487
-			$members[$row['id_member']] = $row['real_name'];
2552
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2553
+					$members[$row['id_member']] = $row['real_name'];
2554
+		}
2488 2555
 		$smcFunc['db_free_result']($request);
2489 2556
 
2490
-		foreach ($edits as $key => $value)
2491
-			if (isset($members[$value['id_member']]))
2557
+		foreach ($edits as $key => $value) {
2558
+					if (isset($members[$value['id_member']]))
2492 2559
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2560
+		}
2493 2561
 	}
2494 2562
 
2495 2563
 	return $edits;
@@ -2690,10 +2758,11 @@  discard block
 block discarded – undo
2690 2758
 	$context['board'] = $board;
2691 2759
 
2692 2760
 	// Determine which groups this user is in.
2693
-	if (empty($user_profile[$memID]['additional_groups']))
2694
-		$curGroups = array();
2695
-	else
2696
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2761
+	if (empty($user_profile[$memID]['additional_groups'])) {
2762
+			$curGroups = array();
2763
+	} else {
2764
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2765
+	}
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_group'];
2698 2767
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2699 2768
 
@@ -2713,28 +2782,30 @@  discard block
 block discarded – undo
2713 2782
 	$context['no_access_boards'] = array();
2714 2783
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2715 2784
 	{
2716
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2717
-			$context['no_access_boards'][] = array(
2785
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2786
+					$context['no_access_boards'][] = array(
2718 2787
 				'id' => $row['id_board'],
2719 2788
 				'name' => $row['name'],
2720 2789
 				'is_last' => false,
2721 2790
 			);
2722
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2723
-			$context['boards'][$row['id_board']] = array(
2791
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2792
+					$context['boards'][$row['id_board']] = array(
2724 2793
 				'id' => $row['id_board'],
2725 2794
 				'name' => $row['name'],
2726 2795
 				'selected' => $board == $row['id_board'],
2727 2796
 				'profile' => $row['id_profile'],
2728 2797
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2729 2798
 			);
2799
+		}
2730 2800
 	}
2731 2801
 	$smcFunc['db_free_result']($request);
2732 2802
 
2733 2803
 	require_once($sourcedir . '/Subs-Boards.php');
2734 2804
 	sortBoards($context['boards']);
2735 2805
 
2736
-	if (!empty($context['no_access_boards']))
2737
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2806
+	if (!empty($context['no_access_boards'])) {
2807
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2808
+	}
2738 2809
 
2739 2810
 	$context['member']['permissions'] = array(
2740 2811
 		'general' => array(),
@@ -2743,8 +2814,9 @@  discard block
 block discarded – undo
2743 2814
 
2744 2815
 	// If you're an admin we know you can do everything, we might as well leave.
2745 2816
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2746
-	if ($context['member']['has_all_permissions'])
2747
-		return;
2817
+	if ($context['member']['has_all_permissions']) {
2818
+			return;
2819
+	}
2748 2820
 
2749 2821
 	$denied = array();
2750 2822
 
@@ -2763,21 +2835,24 @@  discard block
 block discarded – undo
2763 2835
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2764 2836
 	{
2765 2837
 		// We don't know about this permission, it doesn't exist :P.
2766
-		if (!isset($txt['permissionname_' . $row['permission']]))
2767
-			continue;
2838
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2839
+					continue;
2840
+		}
2768 2841
 
2769
-		if (empty($row['add_deny']))
2770
-			$denied[] = $row['permission'];
2842
+		if (empty($row['add_deny'])) {
2843
+					$denied[] = $row['permission'];
2844
+		}
2771 2845
 
2772 2846
 		// Permissions that end with _own or _any consist of two parts.
2773
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2774
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2775
-		else
2776
-			$name = $txt['permissionname_' . $row['permission']];
2847
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2848
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2849
+		} else {
2850
+					$name = $txt['permissionname_' . $row['permission']];
2851
+		}
2777 2852
 
2778 2853
 		// Add this permission if it doesn't exist yet.
2779
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2780
-			$context['member']['permissions']['general'][$row['permission']] = array(
2854
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2855
+					$context['member']['permissions']['general'][$row['permission']] = array(
2781 2856
 				'id' => $row['permission'],
2782 2857
 				'groups' => array(
2783 2858
 					'allowed' => array(),
@@ -2787,6 +2862,7 @@  discard block
 block discarded – undo
2787 2862
 				'is_denied' => false,
2788 2863
 				'is_global' => true,
2789 2864
 			);
2865
+		}
2790 2866
 
2791 2867
 		// Add the membergroup to either the denied or the allowed groups.
2792 2868
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2820,18 +2896,20 @@  discard block
 block discarded – undo
2820 2896
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2821 2897
 	{
2822 2898
 		// We don't know about this permission, it doesn't exist :P.
2823
-		if (!isset($txt['permissionname_' . $row['permission']]))
2824
-			continue;
2899
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2900
+					continue;
2901
+		}
2825 2902
 
2826 2903
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2827
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2828
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2829
-		else
2830
-			$name = $txt['permissionname_' . $row['permission']];
2904
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2905
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2906
+		} else {
2907
+					$name = $txt['permissionname_' . $row['permission']];
2908
+		}
2831 2909
 
2832 2910
 		// Create the structure for this permission.
2833
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2834
-			$context['member']['permissions']['board'][$row['permission']] = array(
2911
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2912
+					$context['member']['permissions']['board'][$row['permission']] = array(
2835 2913
 				'id' => $row['permission'],
2836 2914
 				'groups' => array(
2837 2915
 					'allowed' => array(),
@@ -2841,6 +2919,7 @@  discard block
 block discarded – undo
2841 2919
 				'is_denied' => false,
2842 2920
 				'is_global' => empty($board),
2843 2921
 			);
2922
+		}
2844 2923
 
2845 2924
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2846 2925
 
@@ -2859,8 +2938,9 @@  discard block
 block discarded – undo
2859 2938
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2860 2939
 
2861 2940
 	// Firstly, can we actually even be here?
2862
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2863
-		fatal_lang_error('no_access', false);
2941
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2942
+			fatal_lang_error('no_access', false);
2943
+	}
2864 2944
 
2865 2945
 	// Make sure things which are disabled stay disabled.
2866 2946
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2947,9 +3027,10 @@  discard block
 block discarded – undo
2947 3027
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2948 3028
 	);
2949 3029
 	$context['current_level'] = 0;
2950
-	foreach ($context['level_effects'] as $limit => $dummy)
2951
-		if ($context['member']['warning'] >= $limit)
3030
+	foreach ($context['level_effects'] as $limit => $dummy) {
3031
+			if ($context['member']['warning'] >= $limit)
2952 3032
 			$context['current_level'] = $limit;
2953
-}
3033
+	}
3034
+	}
2954 3035
 
2955 3036
 ?>
2956 3037
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/QueryString.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -321,7 +321,7 @@
 block discarded – undo
321 321
  * Validates a IPv6 address. returns true if it is ipv6.
322 322
  *
323 323
  * @param string $ip The ip address to be validated
324
- * @return boolean Whether the specified IP is a valid IPv6 address
324
+ * @return false|string Whether the specified IP is a valid IPv6 address
325 325
  */
326 326
 function isValidIPv6($ip)
327 327
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -422,8 +422,8 @@
 block discarded – undo
422 422
 */
423 423
 function matchIPtoCIDR($ip_address, $cidr_address)
424 424
 {
425
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
426
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
425
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
426
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
427 427
 }
428 428
 
429 429
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 function isValidIPv6($ip)
327 327
 {
328 328
 	//looking for :
329
-	if (strpos($ip , ':') === false )
329
+	if (strpos($ip, ':') === false)
330 330
 		return false;
331 331
 	
332 332
 	//check valid address
@@ -658,15 +658,15 @@  discard block
 block discarded – undo
658 658
 	{
659 659
 		// Let's do something special for session ids!
660 660
 		if (defined('SID') && SID != '')
661
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
661
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
662 662
 			{
663 663
 				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
664 664
 			}, $buffer);
665 665
 		else
666
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
666
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
667 667
 			{
668 668
 				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
669
-			}, $buffer );
669
+			}, $buffer);
670 670
 	}
671 671
 
672 672
 	// Return the changed buffer.
Please login to merge, or discard this patch.
Braces   +184 added lines, -130 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
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,29 +201,34 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193
-		elseif (strpos($_REQUEST['topic'], '.') !== false)
194
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		$topic = (int) $_REQUEST['topic'];
197 213
 
198 214
 		// Now make sure the online log gets the right number.
199 215
 		$_GET['topic'] = $topic;
216
+	} else {
217
+			$topic = 0;
200 218
 	}
201
-	else
202
-		$topic = 0;
203 219
 
204 220
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
205
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
206
-		$_REQUEST['start'] = 0;
221
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
222
+			$_REQUEST['start'] = 0;
223
+	}
207 224
 
208 225
 	// The action needs to be a string and not an array or anything else
209
-	if (isset($_REQUEST['action']))
210
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
211
-	if (isset($_GET['action']))
212
-		$_GET['action'] = (string) $_GET['action'];
226
+	if (isset($_REQUEST['action'])) {
227
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
228
+	}
229
+	if (isset($_GET['action'])) {
230
+			$_GET['action'] = (string) $_GET['action'];
231
+	}
213 232
 
214 233
 	// Some mail providers like to encode semicolons in activation URLs...
215 234
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -235,29 +254,33 @@  discard block
 block discarded – undo
235 254
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
236 255
 
237 256
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
238
-	if (!isset($modSettings['proxy_ip_header']))
239
-		$modSettings['proxy_ip_header'] = 'autodetect';
257
+	if (!isset($modSettings['proxy_ip_header'])) {
258
+			$modSettings['proxy_ip_header'] = 'autodetect';
259
+	}
240 260
 
241 261
 	// Which headers are we going to check for Reverse Proxy IP headers?
242
-	if ($modSettings['proxy_ip_header'] == 'disabled')
243
-		$reverseIPheaders = array();
244
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
245
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
246
-	else
247
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
262
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
263
+			$reverseIPheaders = array();
264
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
265
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
266
+	} else {
267
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
268
+	}
248 269
 
249 270
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
250 271
 	foreach ($reverseIPheaders as $proxyIPheader)
251 272
 	{
252 273
 		// Ignore if this is not set.
253
-		if (!isset($_SERVER[$proxyIPheader]))
254
-			continue;
274
+		if (!isset($_SERVER[$proxyIPheader])) {
275
+					continue;
276
+		}
255 277
 
256 278
 		if (!empty($modSettings['proxy_ip_servers']))
257 279
 		{
258
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
259
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
280
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
281
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
260 282
 					continue;
283
+			}
261 284
 		}
262 285
 
263 286
 		// If there are commas, get the last one.. probably.
@@ -277,8 +300,9 @@  discard block
 block discarded – undo
277 300
 
278 301
 						// Just incase we have a legacy IPv4 address.
279 302
 						// @ TODO: Convert to IPv6.
280
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
281
-							continue;
303
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
304
+													continue;
305
+						}
282 306
 					}
283 307
 
284 308
 					continue;
@@ -290,36 +314,40 @@  discard block
 block discarded – undo
290 314
 			}
291 315
 		}
292 316
 		// Otherwise just use the only one.
293
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
294
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
295
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
317
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
318
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
319
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
296 320
 		{
297 321
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
298 322
 
299 323
 			// Just incase we have a legacy IPv4 address.
300 324
 			// @ TODO: Convert to IPv6.
301
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
302
-				continue;
325
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
326
+							continue;
327
+			}
303 328
 		}
304 329
 	}
305 330
 
306 331
 	// Make sure we know the URL of the current request.
307
-	if (empty($_SERVER['REQUEST_URI']))
308
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
309
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
310
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
311
-	else
312
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
332
+	if (empty($_SERVER['REQUEST_URI'])) {
333
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
335
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
+	} else {
337
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
338
+	}
313 339
 
314 340
 	// And make sure HTTP_USER_AGENT is set.
315 341
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
316 342
 
317 343
 	// Some final checking.
318
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
319
-		$_SERVER['BAN_CHECK_IP'] = '';
320
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
321
-		$_SERVER['REMOTE_ADDR'] = '';
322
-}
344
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
345
+			$_SERVER['BAN_CHECK_IP'] = '';
346
+	}
347
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
348
+			$_SERVER['REMOTE_ADDR'] = '';
349
+	}
350
+	}
323 351
 
324 352
 /**
325 353
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -330,8 +358,9 @@  discard block
 block discarded – undo
330 358
 function isValidIPv6($ip)
331 359
 {
332 360
 	//looking for :
333
-	if (strpos($ip , ':') === false )
334
-		return false;
361
+	if (strpos($ip , ':') === false ) {
362
+			return false;
363
+	}
335 364
 
336 365
 	//check valid address
337 366
 	return inet_pton($ip);
@@ -348,15 +377,17 @@  discard block
 block discarded – undo
348 377
 	static $expanded = array();
349 378
 
350 379
 	// Check if we have done this already.
351
-	if (isset($expanded[$ip]))
352
-		return $expanded[$ip];
380
+	if (isset($expanded[$ip])) {
381
+			return $expanded[$ip];
382
+	}
353 383
 
354 384
 	// Expand the IP out.
355 385
 	$expanded_ip = explode(':', expandIPv6($ip));
356 386
 
357 387
 	$new_ip = array();
358
-	foreach ($expanded_ip as $int)
359
-		$new_ip[] = hexdec($int);
388
+	foreach ($expanded_ip as $int) {
389
+			$new_ip[] = hexdec($int);
390
+	}
360 391
 
361 392
 	// Save this incase of repeated use.
362 393
 	$expanded[$ip] = $new_ip;
@@ -376,8 +407,9 @@  discard block
 block discarded – undo
376 407
 	static $converted = array();
377 408
 
378 409
 	// Check if we have done this already.
379
-	if (isset($converted[$addr]))
380
-		return $converted[$addr];
410
+	if (isset($converted[$addr])) {
411
+			return $converted[$addr];
412
+	}
381 413
 
382 414
 	// Check if there are segments missing, insert if necessary.
383 415
 	if (strpos($addr, '::') !== false)
@@ -387,18 +419,20 @@  discard block
 block discarded – undo
387 419
 		$part[1] = explode(':', $part[1]);
388 420
 		$missing = array();
389 421
 
390
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
391
-			array_push($missing, '0000');
422
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
423
+					array_push($missing, '0000');
424
+		}
392 425
 
393 426
 		$part = array_merge($part[0], $missing, $part[1]);
427
+	} else {
428
+			$part = explode(':', $addr);
394 429
 	}
395
-	else
396
-		$part = explode(':', $addr);
397 430
 
398 431
 	// Pad each segment until it has 4 digits.
399
-	foreach ($part as &$p)
400
-		while (strlen($p) < 4)
432
+	foreach ($part as &$p) {
433
+			while (strlen($p) < 4)
401 434
 			$p = '0' . $p;
435
+	}
402 436
 
403 437
 	unset($p);
404 438
 
@@ -409,11 +443,12 @@  discard block
 block discarded – undo
409 443
 	$converted[$addr] = $result;
410 444
 
411 445
 	// Quick check to make sure the length is as expected.
412
-	if (!$strict_check || strlen($result) == 39)
413
-		return $result;
414
-	else
415
-		return false;
416
-}
446
+	if (!$strict_check || strlen($result) == 39) {
447
+			return $result;
448
+	} else {
449
+			return false;
450
+	}
451
+	}
417 452
 
418 453
 
419 454
 /**
@@ -444,15 +479,17 @@  discard block
 block discarded – undo
444 479
 {
445 480
 	global $smcFunc;
446 481
 
447
-	if (!is_array($var))
448
-		return $smcFunc['db_escape_string']($var);
482
+	if (!is_array($var)) {
483
+			return $smcFunc['db_escape_string']($var);
484
+	}
449 485
 
450 486
 	// Reindex the array with slashes.
451 487
 	$new_var = array();
452 488
 
453 489
 	// Add slashes to every element, even the indexes!
454
-	foreach ($var as $k => $v)
455
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
490
+	foreach ($var as $k => $v) {
491
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
492
+	}
456 493
 
457 494
 	return $new_var;
458 495
 }
@@ -472,12 +509,14 @@  discard block
 block discarded – undo
472 509
 {
473 510
 	global $smcFunc;
474 511
 
475
-	if (!is_array($var))
476
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
512
+	if (!is_array($var)) {
513
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
514
+	}
477 515
 
478 516
 	// Add the htmlspecialchars to every element.
479
-	foreach ($var as $k => $v)
480
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
517
+	foreach ($var as $k => $v) {
518
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
519
+	}
481 520
 
482 521
 	return $var;
483 522
 }
@@ -495,15 +534,17 @@  discard block
 block discarded – undo
495 534
  */
496 535
 function urldecode__recursive($var, $level = 0)
497 536
 {
498
-	if (!is_array($var))
499
-		return urldecode($var);
537
+	if (!is_array($var)) {
538
+			return urldecode($var);
539
+	}
500 540
 
501 541
 	// Reindex the array...
502 542
 	$new_var = array();
503 543
 
504 544
 	// Add the htmlspecialchars to every element.
505
-	foreach ($var as $k => $v)
506
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
545
+	foreach ($var as $k => $v) {
546
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
547
+	}
507 548
 
508 549
 	return $new_var;
509 550
 }
@@ -521,15 +562,17 @@  discard block
 block discarded – undo
521 562
 {
522 563
 	global $smcFunc;
523 564
 
524
-	if (!is_array($var))
525
-		return $smcFunc['db_unescape_string']($var);
565
+	if (!is_array($var)) {
566
+			return $smcFunc['db_unescape_string']($var);
567
+	}
526 568
 
527 569
 	// Reindex the array without slashes, this time.
528 570
 	$new_var = array();
529 571
 
530 572
 	// Strip the slashes from every element.
531
-	foreach ($var as $k => $v)
532
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
573
+	foreach ($var as $k => $v) {
574
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
575
+	}
533 576
 
534 577
 	return $new_var;
535 578
 }
@@ -547,15 +590,17 @@  discard block
 block discarded – undo
547 590
  */
548 591
 function stripslashes__recursive($var, $level = 0)
549 592
 {
550
-	if (!is_array($var))
551
-		return stripslashes($var);
593
+	if (!is_array($var)) {
594
+			return stripslashes($var);
595
+	}
552 596
 
553 597
 	// Reindex the array without slashes, this time.
554 598
 	$new_var = array();
555 599
 
556 600
 	// Strip the slashes from every element.
557
-	foreach ($var as $k => $v)
558
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
601
+	foreach ($var as $k => $v) {
602
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
603
+	}
559 604
 
560 605
 	return $new_var;
561 606
 }
@@ -576,12 +621,14 @@  discard block
 block discarded – undo
576 621
 	global $smcFunc;
577 622
 
578 623
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
579
-	if (!is_array($var))
580
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
624
+	if (!is_array($var)) {
625
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
626
+	}
581 627
 
582 628
 	// Go through all the elements and remove the whitespace.
583
-	foreach ($var as $k => $v)
584
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
629
+	foreach ($var as $k => $v) {
630
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
631
+	}
585 632
 
586 633
 	return $var;
587 634
 }
@@ -646,30 +693,37 @@  discard block
 block discarded – undo
646 693
 	global $scripturl, $modSettings, $context;
647 694
 
648 695
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
649
-	if ($scripturl == '' || !defined('SID'))
650
-		return $buffer;
696
+	if ($scripturl == '' || !defined('SID')) {
697
+			return $buffer;
698
+	}
651 699
 
652 700
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
653 701
 	// @todo smflib
654
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
655
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
702
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
703
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
704
+	}
656 705
 	// Debugging templates, are we?
657
-	elseif (isset($_GET['debug']))
658
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
706
+	elseif (isset($_GET['debug'])) {
707
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
708
+	}
659 709
 
660 710
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
661 711
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
662 712
 	{
663 713
 		// Let's do something special for session ids!
664
-		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
714
+		if (defined('SID') && SID != '') {
715
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
666 716
 			{
667
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
717
+				global $scripturl;
718
+		}
719
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 720
 			}, $buffer);
669
-		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
721
+		else {
722
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
671 723
 			{
672
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
724
+				global $scripturl;
725
+		}
726
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673 727
 			}, $buffer );
674 728
 	}
675 729
 
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1491,7 +1491,7 @@
 block discarded – undo
1491 1491
 
1492 1492
 /**
1493 1493
  * Try to determine if the topic has already been deleted by another user.
1494
- * @return bool False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1494
+ * @return boolean|null False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1495 1495
  */
1496 1496
 function removeDeleteConcurrence()
1497 1497
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -398,7 +398,7 @@
 block discarded – undo
398 398
 	}
399 399
 	$smcFunc['db_free_result']($request);
400 400
 
401
-	if($updateBoardCount)
401
+	if ($updateBoardCount)
402 402
 	{
403 403
 		// Decrease the posts/topics...
404 404
 		foreach ($adjustBoards as $stats)
Please login to merge, or discard this patch.
Braces   +267 added lines, -200 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
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -820,6 +855,7 @@  discard block
 block discarded – undo
820 855
 				),
821 856
 				array('id_topic')
822 857
 			);
858
+		}
823 859
 
824 860
 		// Capture the ID of the new topic...
825 861
 		$topicID = empty($id_recycle_topic) ? $smcFunc['db_insert_id']('{db_prefix}topics', 'id_topic') : $id_recycle_topic;
@@ -857,22 +893,24 @@  discard block
 block discarded – undo
857 893
 			);
858 894
 
859 895
 			// Mark recycled topic as read.
860
-			if (!$user_info['is_guest'])
861
-				$smcFunc['db_insert']('replace',
896
+			if (!$user_info['is_guest']) {
897
+							$smcFunc['db_insert']('replace',
862 898
 					'{db_prefix}log_topics',
863 899
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
864 900
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
865 901
 					array('id_topic', 'id_member')
866 902
 				);
903
+			}
867 904
 
868 905
 			// Mark recycle board as seen, if it was marked as seen before.
869
-			if (!empty($isRead) && !$user_info['is_guest'])
870
-				$smcFunc['db_insert']('replace',
906
+			if (!empty($isRead) && !$user_info['is_guest']) {
907
+							$smcFunc['db_insert']('replace',
871 908
 					'{db_prefix}log_boards',
872 909
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
873 910
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
874 911
 					array('id_board', 'id_member')
875 912
 				);
913
+			}
876 914
 
877 915
 			// Add one topic and post to the recycle bin board.
878 916
 			$smcFunc['db_query']('', '
@@ -890,8 +928,8 @@  discard block
 block discarded – undo
890 928
 			);
891 929
 
892 930
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
893
-			if (!empty($id_recycle_topic))
894
-				$smcFunc['db_query']('', '
931
+			if (!empty($id_recycle_topic)) {
932
+							$smcFunc['db_query']('', '
895 933
 					UPDATE {db_prefix}topics
896 934
 					SET num_replies = num_replies + 1' .
897 935
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -902,6 +940,7 @@  discard block
 block discarded – undo
902 940
 						'id_merged_msg' => $message,
903 941
 					)
904 942
 				);
943
+			}
905 944
 
906 945
 			// Make sure this message isn't getting deleted later on.
907 946
 			$recycle = true;
@@ -911,8 +950,8 @@  discard block
 block discarded – undo
911 950
 		}
912 951
 
913 952
 		// If it wasn't approved don't keep it in the queue.
914
-		if (!$row['approved'])
915
-			$smcFunc['db_query']('', '
953
+		if (!$row['approved']) {
954
+					$smcFunc['db_query']('', '
916 955
 				DELETE FROM {db_prefix}approval_queue
917 956
 				WHERE id_msg = {int:id_msg}
918 957
 					AND id_attach = {int:id_attach}',
@@ -921,6 +960,7 @@  discard block
 block discarded – undo
921 960
 					'id_attach' => 0,
922 961
 				)
923 962
 			);
963
+		}
924 964
 	}
925 965
 
926 966
 	$smcFunc['db_query']('', '
@@ -938,8 +978,9 @@  discard block
 block discarded – undo
938 978
 
939 979
 	// If the poster was registered and the board this message was on incremented
940 980
 	// the member's posts when it was posted, decrease his or her post count.
941
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
942
-		updateMemberData($row['id_member'], array('posts' => '-'));
981
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
982
+			updateMemberData($row['id_member'], array('posts' => '-'));
983
+	}
943 984
 
944 985
 	// Only remove posts if they're not recycled.
945 986
 	if (!$recycle)
@@ -947,8 +988,9 @@  discard block
 block discarded – undo
947 988
 		// Callback for search APIs to do their thing
948 989
 		require_once($sourcedir . '/Search.php');
949 990
 		$searchAPI = findSearchAPI();
950
-		if ($searchAPI->supportsMethod('postRemoved'))
951
-			$searchAPI->postRemoved($message);
991
+		if ($searchAPI->supportsMethod('postRemoved')) {
992
+					$searchAPI->postRemoved($message);
993
+		}
952 994
 
953 995
 		// Remove the message!
954 996
 		$smcFunc['db_query']('', '
@@ -963,8 +1005,8 @@  discard block
 block discarded – undo
963 1005
 		{
964 1006
 			$customIndexSettings = json_decode($modSettings['search_custom_index_config'], true);
965 1007
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
966
-			if (!empty($words))
967
-				$smcFunc['db_query']('', '
1008
+			if (!empty($words)) {
1009
+							$smcFunc['db_query']('', '
968 1010
 					DELETE FROM {db_prefix}log_search_words
969 1011
 					WHERE id_word IN ({array_int:word_list})
970 1012
 						AND id_msg = {int:id_msg}',
@@ -973,6 +1015,7 @@  discard block
 block discarded – undo
973 1015
 						'id_msg' => $message,
974 1016
 					)
975 1017
 				);
1018
+			}
976 1019
 		}
977 1020
 
978 1021
 		// Delete attachment(s) if they exist.
@@ -996,10 +1039,11 @@  discard block
 block discarded – undo
996 1039
 
997 1040
 	// And now to update the last message of each board we messed with.
998 1041
 	require_once($sourcedir . '/Subs-Post.php');
999
-	if ($recycle)
1000
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1001
-	else
1002
-		updateLastMessages($row['id_board']);
1042
+	if ($recycle) {
1043
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1044
+	} else {
1045
+			updateLastMessages($row['id_board']);
1046
+	}
1003 1047
 
1004 1048
 	// Close any moderation reports for this message.
1005 1049
 	$smcFunc['db_query']('', '
@@ -1032,8 +1076,9 @@  discard block
 block discarded – undo
1032 1076
 	checkSession('get');
1033 1077
 
1034 1078
 	// Is recycled board enabled?
1035
-	if (empty($modSettings['recycle_enable']))
1036
-		fatal_lang_error('restored_disabled', 'critical');
1079
+	if (empty($modSettings['recycle_enable'])) {
1080
+			fatal_lang_error('restored_disabled', 'critical');
1081
+	}
1037 1082
 
1038 1083
 	// Can we be in here?
1039 1084
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1048,8 +1093,9 @@  discard block
 block discarded – undo
1048 1093
 	if (!empty($_REQUEST['msgs']))
1049 1094
 	{
1050 1095
 		$msgs = explode(',', $_REQUEST['msgs']);
1051
-		foreach ($msgs as $k => $msg)
1052
-			$msgs[$k] = (int) $msg;
1096
+		foreach ($msgs as $k => $msg) {
1097
+					$msgs[$k] = (int) $msg;
1098
+		}
1053 1099
 
1054 1100
 		// Get the id_previous_board and id_previous_topic.
1055 1101
 		$request = $smcFunc['db_query']('', '
@@ -1083,8 +1129,8 @@  discard block
 block discarded – undo
1083 1129
 			}
1084 1130
 
1085 1131
 			$previous_topics[] = $row['id_previous_topic'];
1086
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1087
-				$actioned_messages[$row['id_previous_topic']] = array(
1132
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1133
+							$actioned_messages[$row['id_previous_topic']] = array(
1088 1134
 					'msgs' => array(),
1089 1135
 					'count_posts' => $row['count_posts'],
1090 1136
 					'subject' => $row['subject'],
@@ -1094,17 +1140,20 @@  discard block
 block discarded – undo
1094 1140
 					'current_board' => $row['id_board'],
1095 1141
 					'members' => array(),
1096 1142
 				);
1143
+			}
1097 1144
 
1098 1145
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1099
-			if ($row['id_member'])
1100
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1146
+			if ($row['id_member']) {
1147
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1148
+			}
1101 1149
 		}
1102 1150
 		$smcFunc['db_free_result']($request);
1103 1151
 
1104 1152
 		// Check for topics we are going to fully restore.
1105
-		foreach ($actioned_messages as $topic => $data)
1106
-			if (in_array($topic, $topics_to_restore))
1153
+		foreach ($actioned_messages as $topic => $data) {
1154
+					if (in_array($topic, $topics_to_restore))
1107 1155
 				unset($actioned_messages[$topic]);
1156
+		}
1108 1157
 
1109 1158
 		// Load any previous topics to check they exist.
1110 1159
 		if (!empty($previous_topics))
@@ -1119,11 +1168,12 @@  discard block
 block discarded – undo
1119 1168
 				)
1120 1169
 			);
1121 1170
 			$previous_topics = array();
1122
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1123
-				$previous_topics[$row['id_topic']] = array(
1171
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1172
+							$previous_topics[$row['id_topic']] = array(
1124 1173
 					'board' => $row['id_board'],
1125 1174
 					'subject' => $row['subject'],
1126 1175
 				);
1176
+			}
1127 1177
 			$smcFunc['db_free_result']($request);
1128 1178
 		}
1129 1179
 
@@ -1145,11 +1195,11 @@  discard block
 block discarded – undo
1145 1195
 				// Log em.
1146 1196
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1147 1197
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1148
-			}
1149
-			else
1198
+			} else
1150 1199
 			{
1151
-				foreach ($data['msgs'] as $msg)
1152
-					$unfound_messages[$msg['id']] = $msg['subject'];
1200
+				foreach ($data['msgs'] as $msg) {
1201
+									$unfound_messages[$msg['id']] = $msg['subject'];
1202
+				}
1153 1203
 			}
1154 1204
 		}
1155 1205
 	}
@@ -1158,8 +1208,9 @@  discard block
 block discarded – undo
1158 1208
 	if (!empty($_REQUEST['topics']))
1159 1209
 	{
1160 1210
 		$topics = explode(',', $_REQUEST['topics']);
1161
-		foreach ($topics as $id)
1162
-			$topics_to_restore[] = (int) $id;
1211
+		foreach ($topics as $id) {
1212
+					$topics_to_restore[] = (int) $id;
1213
+		}
1163 1214
 	}
1164 1215
 
1165 1216
 	if (!empty($topics_to_restore))
@@ -1213,8 +1264,9 @@  discard block
 block discarded – undo
1213 1264
 					)
1214 1265
 				);
1215 1266
 
1216
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1217
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1267
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1268
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1269
+				}
1218 1270
 				$smcFunc['db_free_result']($request2);
1219 1271
 			}
1220 1272
 
@@ -1225,8 +1277,9 @@  discard block
 block discarded – undo
1225 1277
 	}
1226 1278
 
1227 1279
 	// Didn't find some things?
1228
-	if (!empty($unfound_messages))
1229
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1280
+	if (!empty($unfound_messages)) {
1281
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1282
+	}
1230 1283
 
1231 1284
 	// Just send them to the index if they get here.
1232 1285
 	redirectexit();
@@ -1246,12 +1299,14 @@  discard block
 block discarded – undo
1246 1299
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1247 1300
 
1248 1301
 	// Is it an array?
1249
-	if (!is_array($msgs))
1250
-		$msgs = array($msgs);
1302
+	if (!is_array($msgs)) {
1303
+			$msgs = array($msgs);
1304
+	}
1251 1305
 
1252 1306
 	// Lets make sure they are int.
1253
-	foreach ($msgs as $key => $msg)
1254
-		$msgs[$key] = (int) $msg;
1307
+	foreach ($msgs as $key => $msg) {
1308
+			$msgs[$key] = (int) $msg;
1309
+	}
1255 1310
 
1256 1311
 	// Get the source information.
1257 1312
 	$request = $smcFunc['db_query']('', '
@@ -1294,8 +1349,9 @@  discard block
 block discarded – undo
1294 1349
 			)
1295 1350
 		);
1296 1351
 
1297
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1298
-			updateMemberData($row['id_member'], array('posts' => '+'));
1352
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1353
+					updateMemberData($row['id_member'], array('posts' => '+'));
1354
+		}
1299 1355
 	}
1300 1356
 
1301 1357
 	// Time to move the messages.
@@ -1331,13 +1387,15 @@  discard block
 block discarded – undo
1331 1387
 	);
1332 1388
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1333 1389
 	{
1334
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1335
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1390
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1391
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1392
+		}
1336 1393
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1337
-		if (!$row['approved'])
1338
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1339
-		else
1340
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1394
+		if (!$row['approved']) {
1395
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1396
+		} else {
1397
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1398
+		}
1341 1399
 	}
1342 1400
 	$smcFunc['db_free_result']($request);
1343 1401
 
@@ -1396,13 +1454,15 @@  discard block
 block discarded – undo
1396 1454
 		);
1397 1455
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1456
 		{
1399
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1400
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1457
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1458
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1459
+			}
1401 1460
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1402
-			if (!$row['approved'])
1403
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1404
-			else
1405
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1461
+			if (!$row['approved']) {
1462
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1463
+			} else {
1464
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1465
+			}
1406 1466
 		}
1407 1467
 		$smcFunc['db_free_result']($request);
1408 1468
 
@@ -1466,10 +1526,12 @@  discard block
 block discarded – undo
1466 1526
 
1467 1527
 	// Subject cache?
1468 1528
 	$cache_updates = array();
1469
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1470
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1471
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1472
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1529
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1530
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1531
+	}
1532
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1533
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1534
+	}
1473 1535
 
1474 1536
 	if (!empty($cache_updates))
1475 1537
 	{
@@ -1481,8 +1543,9 @@  discard block
 block discarded – undo
1481 1543
 				'first_messages' => $cache_updates,
1482 1544
 			)
1483 1545
 		);
1484
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1485
-			updateStats('subject', $row['id_topic'], $row['subject']);
1546
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1547
+					updateStats('subject', $row['id_topic'], $row['subject']);
1548
+		}
1486 1549
 		$smcFunc['db_free_result']($request);
1487 1550
 	}
1488 1551
 
@@ -1498,22 +1561,26 @@  discard block
 block discarded – undo
1498 1561
 	global $modSettings, $board, $scripturl, $context;
1499 1562
 
1500 1563
 	// No recycle no need to go further
1501
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1502
-		return false;
1564
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1565
+			return false;
1566
+	}
1503 1567
 
1504 1568
 	// If it's confirmed go on and delete (from recycle)
1505
-	if (isset($_GET['confirm_delete']))
1506
-		return true;
1569
+	if (isset($_GET['confirm_delete'])) {
1570
+			return true;
1571
+	}
1507 1572
 
1508
-	if (empty($board))
1509
-		return false;
1573
+	if (empty($board)) {
1574
+			return false;
1575
+	}
1510 1576
 
1511
-	if ($modSettings['recycle_board'] != $board)
1512
-		return true;
1513
-	elseif (isset($_REQUEST['msg']))
1514
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1515
-	else
1516
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1577
+	if ($modSettings['recycle_board'] != $board) {
1578
+			return true;
1579
+	} elseif (isset($_REQUEST['msg'])) {
1580
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1581
+	} else {
1582
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1583
+	}
1517 1584
 
1518 1585
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1519 1586
 }
Please login to merge, or discard this patch.
Sources/Reports.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1013,7 +1013,7 @@
 block discarded – undo
1013 1013
  * @param string $title The title of the separator
1014 1014
  * @param null|string $custom_table The ID of the custom table
1015 1015
  *
1016
- * @return void|bool Returns false if there are no tables
1016
+ * @return null|false Returns false if there are no tables
1017 1017
  */
1018 1018
 function addSeparator($title = '', $custom_table = null)
1019 1019
 {
Please login to merge, or discard this patch.
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 3
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -454,8 +473,9 @@  discard block
 block discarded – undo
454 473
 			foreach ($member_groups as $id_group => $name)
455 474
 			{
456 475
 				// Don't overwrite the key column!
457
-				if ($id_group === 'col')
458
-					continue;
476
+				if ($id_group === 'col') {
477
+									continue;
478
+				}
459 479
 
460 480
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
461 481
 
@@ -477,16 +497,18 @@  discard block
 block discarded – undo
477 497
 				}
478 498
 
479 499
 				// Now actually make the data for the group look right.
480
-				if (empty($curData[$id_group]))
481
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
482
-				elseif ($curData[$id_group] == 1)
483
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
484
-				else
485
-					$curData[$id_group] = 'x';
500
+				if (empty($curData[$id_group])) {
501
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
502
+				} elseif ($curData[$id_group] == 1) {
503
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
504
+				} else {
505
+									$curData[$id_group] = 'x';
506
+				}
486 507
 
487 508
 				// Embolden those permissions different from global (makes it a lot easier!)
488
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
489
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
509
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
510
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
511
+				}
490 512
 			}
491 513
 
492 514
 			// Now add the data for this permission.
@@ -516,15 +538,17 @@  discard block
 block discarded – undo
516 538
 	);
517 539
 	while ($row = $smcFunc['db_fetch_assoc']($request))
518 540
 	{
519
-		if (trim($row['member_groups']) == '')
520
-			$groups = array(1);
521
-		else
522
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
541
+		if (trim($row['member_groups']) == '') {
542
+					$groups = array(1);
543
+		} else {
544
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
545
+		}
523 546
 
524
-		if (trim($row['deny_member_groups']) == '')
525
-			$denyGroups = array();
526
-		else
527
-			$denyGroups = explode(',', $row['deny_member_groups']);
547
+		if (trim($row['deny_member_groups']) == '') {
548
+					$denyGroups = array();
549
+		} else {
550
+					$denyGroups = explode(',', $row['deny_member_groups']);
551
+		}
528 552
 
529 553
 		$boards[$row['id_board']] = array(
530 554
 			'id' => $row['id_board'],
@@ -548,8 +572,9 @@  discard block
 block discarded – undo
548 572
 	);
549 573
 
550 574
 	// Add on the boards!
551
-	foreach ($boards as $board)
552
-		$mgSettings['board_' . $board['id']] = $board['name'];
575
+	foreach ($boards as $board) {
576
+			$mgSettings['board_' . $board['id']] = $board['name'];
577
+	}
553 578
 
554 579
 	// Add all the membergroup settings, plus we'll be adding in columns!
555 580
 	setKeys('cols', $mgSettings);
@@ -594,8 +619,9 @@  discard block
 block discarded – undo
594 619
 			'icons' => ''
595 620
 		),
596 621
 	);
597
-	while ($row = $smcFunc['db_fetch_assoc']($request))
598
-		$rows[] = $row;
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$rows[] = $row;
624
+	}
599 625
 	$smcFunc['db_free_result']($request);
600 626
 
601 627
 	foreach ($rows as $row)
@@ -611,8 +637,9 @@  discard block
 block discarded – undo
611 637
 		);
612 638
 
613 639
 		// Board permissions.
614
-		foreach ($boards as $board)
615
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
640
+		foreach ($boards as $board) {
641
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
642
+		}
616 643
 
617 644
 		addData($group);
618 645
 	}
@@ -632,16 +659,18 @@  discard block
 block discarded – undo
632 659
 
633 660
 	if (isset($_REQUEST['groups']))
634 661
 	{
635
-		if (!is_array($_REQUEST['groups']))
636
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
637
-		foreach ($_REQUEST['groups'] as $k => $dummy)
638
-			$_REQUEST['groups'][$k] = (int) $dummy;
662
+		if (!is_array($_REQUEST['groups'])) {
663
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
664
+		}
665
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
666
+					$_REQUEST['groups'][$k] = (int) $dummy;
667
+		}
639 668
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
640 669
 
641 670
 		$clause = 'id_group IN ({array_int:groups})';
671
+	} else {
672
+			$clause = 'id_group != {int:moderator_group}';
642 673
 	}
643
-	else
644
-		$clause = 'id_group != {int:moderator_group}';
645 674
 
646 675
 	// Get all the possible membergroups, except admin!
647 676
 	$request = $smcFunc['db_query']('', '
@@ -659,12 +688,14 @@  discard block
 block discarded – undo
659 688
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
660 689
 		)
661 690
 	);
662
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
663
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
664
-	else
665
-		$groups = array('col' => '');
666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
667
-		$groups[$row['id_group']] = $row['group_name'];
691
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
692
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
693
+	} else {
694
+			$groups = array('col' => '');
695
+	}
696
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
697
+			$groups[$row['id_group']] = $row['group_name'];
698
+	}
668 699
 	$smcFunc['db_free_result']($request);
669 700
 
670 701
 	// Make sure that every group is represented!
@@ -688,8 +719,9 @@  discard block
 block discarded – undo
688 719
 		$disabled_permissions[] = 'calendar_edit_own';
689 720
 		$disabled_permissions[] = 'calendar_edit_any';
690 721
 	}
691
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
692
-		$disabled_permissions[] = 'issue_warning';
722
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
723
+			$disabled_permissions[] = 'issue_warning';
724
+	}
693 725
 
694 726
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
695 727
 
@@ -710,15 +742,17 @@  discard block
 block discarded – undo
710 742
 	$curData = array();
711 743
 	while ($row = $smcFunc['db_fetch_assoc']($request))
712 744
 	{
713
-		if (in_array($row['permission'], $disabled_permissions))
714
-			continue;
745
+		if (in_array($row['permission'], $disabled_permissions)) {
746
+					continue;
747
+		}
715 748
 
716 749
 		// If this is a new permission flush the last row.
717 750
 		if ($row['permission'] != $lastPermission)
718 751
 		{
719 752
 			// Send the data!
720
-			if ($lastPermission !== null)
721
-				addData($curData);
753
+			if ($lastPermission !== null) {
754
+							addData($curData);
755
+			}
722 756
 
723 757
 			// Add the permission name in the left column.
724 758
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -727,10 +761,11 @@  discard block
 block discarded – undo
727 761
 		}
728 762
 
729 763
 		// Good stuff - add the permission to the list!
730
-		if ($row['add_deny'])
731
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
732
-		else
733
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
764
+		if ($row['add_deny']) {
765
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
766
+		} else {
767
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
768
+		}
734 769
 	}
735 770
 	$smcFunc['db_free_result']($request);
736 771
 
@@ -760,8 +795,9 @@  discard block
 block discarded – undo
760 795
 		)
761 796
 	);
762 797
 	$boards = array();
763
-	while ($row = $smcFunc['db_fetch_assoc']($request))
764
-		$boards[$row['id_board']] = $row['name'];
798
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+			$boards[$row['id_board']] = $row['name'];
800
+	}
765 801
 	$smcFunc['db_free_result']($request);
766 802
 
767 803
 	// Get every moderator.
@@ -793,12 +829,14 @@  discard block
 block discarded – undo
793 829
 	while ($row = $smcFunc['db_fetch_assoc']($request))
794 830
 	{
795 831
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
796
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
797
-			$moderators[$row['id_member']][] = $row['id_board'];
832
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
833
+					$moderators[$row['id_member']][] = $row['id_board'];
834
+		}
798 835
 
799 836
 		// We don't have them listed as a moderator yet
800
-		if (!array_key_exists($row['id_member'], $local_mods))
801
-			$local_mods[$row['id_member']] = $row['id_member'];
837
+		if (!array_key_exists($row['id_member'], $local_mods)) {
838
+					$local_mods[$row['id_member']] = $row['id_member'];
839
+		}
802 840
 	}
803 841
 
804 842
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -811,8 +849,9 @@  discard block
 block discarded – undo
811 849
 	$allStaff = array_unique($allStaff);
812 850
 
813 851
 	// This is a bit of a cop out - but we're protecting their forum, really!
814
-	if (count($allStaff) > 300)
815
-		fatal_lang_error('report_error_too_many_staff');
852
+	if (count($allStaff) > 300) {
853
+			fatal_lang_error('report_error_too_many_staff');
854
+	}
816 855
 
817 856
 	// Get all the possible membergroups!
818 857
 	$request = $smcFunc['db_query']('', '
@@ -822,8 +861,9 @@  discard block
 block discarded – undo
822 861
 		)
823 862
 	);
824 863
 	$groups = array(0 => $txt['full_member']);
825
-	while ($row = $smcFunc['db_fetch_assoc']($request))
826
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
864
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
865
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
866
+	}
827 867
 	$smcFunc['db_free_result']($request);
828 868
 
829 869
 	// All the fields we'll show.
@@ -864,19 +904,20 @@  discard block
 block discarded – undo
864 904
 		);
865 905
 
866 906
 		// What do they moderate?
867
-		if (in_array($row['id_member'], $global_mods))
868
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
869
-		elseif (isset($moderators[$row['id_member']]))
907
+		if (in_array($row['id_member'], $global_mods)) {
908
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
909
+		} elseif (isset($moderators[$row['id_member']]))
870 910
 		{
871 911
 			// Get the names
872
-			foreach ($moderators[$row['id_member']] as $board)
873
-				if (isset($boards[$board]))
912
+			foreach ($moderators[$row['id_member']] as $board) {
913
+							if (isset($boards[$board]))
874 914
 					$staffData['moderates'][] = $boards[$board];
915
+			}
875 916
 
876 917
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
918
+		} else {
919
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 920
 		}
878
-		else
879
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
880 921
 
881 922
 		// Next add the main data.
882 923
 		addData($staffData);
@@ -904,8 +945,9 @@  discard block
 block discarded – undo
904 945
 	global $context;
905 946
 
906 947
 	// Set the table count if needed.
907
-	if (empty($context['table_count']))
908
-		$context['table_count'] = 0;
948
+	if (empty($context['table_count'])) {
949
+			$context['table_count'] = 0;
950
+	}
909 951
 
910 952
 	// Create the table!
911 953
 	$context['tables'][$context['table_count']] = array(
@@ -955,16 +997,18 @@  discard block
 block discarded – undo
955 997
 	global $context;
956 998
 
957 999
 	// No tables? Create one even though we are probably already in a bad state!
958
-	if (empty($context['table_count']))
959
-		newTable();
1000
+	if (empty($context['table_count'])) {
1001
+			newTable();
1002
+	}
960 1003
 
961 1004
 	// Specific table?
962
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
963
-		return false;
964
-	elseif ($custom_table !== null)
965
-		$table = $custom_table;
966
-	else
967
-		$table = $context['current_table'];
1005
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1006
+			return false;
1007
+	} elseif ($custom_table !== null) {
1008
+			$table = $custom_table;
1009
+	} else {
1010
+			$table = $context['current_table'];
1011
+	}
968 1012
 
969 1013
 	// If we have keys, sanitise the data...
970 1014
 	if (!empty($context['keys']))
@@ -976,11 +1020,11 @@  discard block
 block discarded – undo
976 1020
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
977 1021
 			);
978 1022
 			// Special "hack" the adding separators when doing data by column.
979
-			if (substr($key, 0, 5) == '#sep#')
980
-				$data[$key]['separator'] = true;
1023
+			if (substr($key, 0, 5) == '#sep#') {
1024
+							$data[$key]['separator'] = true;
1025
+			}
981 1026
 		}
982
-	}
983
-	else
1027
+	} else
984 1028
 	{
985 1029
 		$data = $inc_data;
986 1030
 		foreach ($data as $key => $value)
@@ -988,8 +1032,9 @@  discard block
 block discarded – undo
988 1032
 			$data[$key] = array(
989 1033
 				'v' => $value,
990 1034
 			);
991
-			if (substr($key, 0, 5) == '#sep#')
992
-				$data[$key]['separator'] = true;
1035
+			if (substr($key, 0, 5) == '#sep#') {
1036
+							$data[$key]['separator'] = true;
1037
+			}
993 1038
 		}
994 1039
 	}
995 1040
 
@@ -1002,8 +1047,9 @@  discard block
 block discarded – undo
1002 1047
 	// Otherwise, tricky!
1003 1048
 	else
1004 1049
 	{
1005
-		foreach ($data as $key => $item)
1006
-			$context['tables'][$table]['data'][$key][] = $item;
1050
+		foreach ($data as $key => $item) {
1051
+					$context['tables'][$table]['data'][$key][] = $item;
1052
+		}
1007 1053
 	}
1008 1054
 }
1009 1055
 
@@ -1020,16 +1066,18 @@  discard block
 block discarded – undo
1020 1066
 	global $context;
1021 1067
 
1022 1068
 	// No tables - return?
1023
-	if (empty($context['table_count']))
1024
-		return;
1069
+	if (empty($context['table_count'])) {
1070
+			return;
1071
+	}
1025 1072
 
1026 1073
 	// Specific table?
1027
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1028
-		return false;
1029
-	elseif ($custom_table !== null)
1030
-		$table = $custom_table;
1031
-	else
1032
-		$table = $context['current_table'];
1074
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1075
+			return false;
1076
+	} elseif ($custom_table !== null) {
1077
+			$table = $custom_table;
1078
+	} else {
1079
+			$table = $context['current_table'];
1080
+	}
1033 1081
 
1034 1082
 	// Plumb in the separator
1035 1083
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1050,8 +1098,9 @@  discard block
 block discarded – undo
1050 1098
 {
1051 1099
 	global $context;
1052 1100
 
1053
-	if (empty($context['tables']))
1054
-		return;
1101
+	if (empty($context['tables'])) {
1102
+			return;
1103
+	}
1055 1104
 
1056 1105
 	// Loop through each table counting up some basic values, to help with the templating.
1057 1106
 	foreach ($context['tables'] as $id => $table)
@@ -1062,12 +1111,13 @@  discard block
 block discarded – undo
1062 1111
 		$context['tables'][$id]['column_count'] = count($curElement);
1063 1112
 
1064 1113
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1065
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1066
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1067
-		elseif ($table['width']['normal'] != 'auto')
1068
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1069
-		else
1070
-			$context['tables'][$id]['max_width'] = 'auto';
1114
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1115
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1116
+		} elseif ($table['width']['normal'] != 'auto') {
1117
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1118
+		} else {
1119
+					$context['tables'][$id]['max_width'] = 'auto';
1120
+		}
1071 1121
 	}
1072 1122
 }
1073 1123
 
@@ -1092,10 +1142,11 @@  discard block
 block discarded – undo
1092 1142
 	global $context;
1093 1143
 
1094 1144
 	// Do we want to use the keys of the keys as the keys? :P
1095
-	if ($reverse)
1096
-		$context['keys'] = array_flip($keys);
1097
-	else
1098
-		$context['keys'] = $keys;
1145
+	if ($reverse) {
1146
+			$context['keys'] = array_flip($keys);
1147
+	} else {
1148
+			$context['keys'] = $keys;
1149
+	}
1099 1150
 
1100 1151
 	// Rows or columns?
1101 1152
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	// Build the reports button array.
113 113
 	$context['report_buttons'] = array(
114 114
 		'generate_reports' => array('text' => 'generate_reports', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports', 'active' => true),
115
-		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type']. ';st=print', 'custom' => 'target="_blank"'),
115
+		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type'] . ';st=print', 'custom' => 'target="_blank"'),
116 116
 	);
117 117
 
118 118
 	// Allow mods to add additional buttons here
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	$request = $smcFunc['db_query']('', '
345 345
 		SELECT id_board, id_group
346 346
 		FROM {db_prefix}moderator_groups
347
-		WHERE ' . $board_clause .' AND ' . $group_clause,
347
+		WHERE ' . $board_clause . ' AND ' . $group_clause,
348 348
 		array(
349 349
 		)
350 350
 	);
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -807,7 +807,7 @@
 block discarded – undo
807 807
 /**
808 808
  * Send a group of emails from the mail queue.
809 809
  *
810
- * @param bool|int $number The number to send each loop through or false to use the standard limits
810
+ * @param integer $number The number to send each loop through or false to use the standard limits
811 811
  * @param bool $override_limit Whether to bypass the limit
812 812
  * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs)
813 813
  * @return bool Whether things were sent
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,7 +384,7 @@
 block discarded – undo
384 384
 	clean_cache();
385 385
 
386 386
 	// If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
387
-	list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
387
+	list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
388 388
 	if ($modSettings['warning_decrement'])
389 389
 	{
390 390
 		// Find every member who has a warning level...
Please login to merge, or discard this patch.
Braces   +282 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc, $modSettings;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -651,8 +686,9 @@  discard block
 block discarded – undo
651 686
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
652 687
 
653 688
 		// Did they not elect to choose this?
654
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
655
-			continue;
689
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
690
+					continue;
691
+		}
656 692
 
657 693
 		// Right character set!
658 694
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -668,39 +704,43 @@  discard block
 block discarded – undo
668 704
 		if (isset($types['topic']))
669 705
 		{
670 706
 			$titled = false;
671
-			foreach ($types['topic'] as $id => $board)
672
-				foreach ($board['lines'] as $topic)
707
+			foreach ($types['topic'] as $id => $board) {
708
+							foreach ($board['lines'] as $topic)
673 709
 					if (in_array($mid, $topic['members']))
674 710
 					{
675 711
 						if (!$titled)
676 712
 						{
677 713
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
714
+			}
678 715
 							$titled = true;
679 716
 						}
680 717
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
681 718
 					}
682
-			if ($titled)
683
-				$email['body'] .= "\n";
719
+			if ($titled) {
720
+							$email['body'] .= "\n";
721
+			}
684 722
 		}
685 723
 
686 724
 		// What about replies?
687 725
 		if (isset($types['reply']))
688 726
 		{
689 727
 			$titled = false;
690
-			foreach ($types['reply'] as $id => $board)
691
-				foreach ($board['lines'] as $topic)
728
+			foreach ($types['reply'] as $id => $board) {
729
+							foreach ($board['lines'] as $topic)
692 730
 					if (in_array($mid, $topic['members']))
693 731
 					{
694 732
 						if (!$titled)
695 733
 						{
696 734
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
735
+			}
697 736
 							$titled = true;
698 737
 						}
699 738
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
700 739
 					}
701 740
 
702
-			if ($titled)
703
-				$email['body'] .= "\n";
741
+			if ($titled) {
742
+							$email['body'] .= "\n";
743
+			}
704 744
 		}
705 745
 
706 746
 		// Finally, moderation actions!
@@ -709,24 +749,27 @@  discard block
 block discarded – undo
709 749
 			$titled = false;
710 750
 			foreach ($types as $note_type => $type)
711 751
 			{
712
-				if ($note_type == 'topic' || $note_type == 'reply')
713
-					continue;
752
+				if ($note_type == 'topic' || $note_type == 'reply') {
753
+									continue;
754
+				}
714 755
 
715
-				foreach ($type as $id => $board)
716
-					foreach ($board['lines'] as $topic)
756
+				foreach ($type as $id => $board) {
757
+									foreach ($board['lines'] as $topic)
717 758
 						if (in_array($mid, $topic['members']))
718 759
 						{
719 760
 							if (!$titled)
720 761
 							{
721 762
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
763
+				}
722 764
 								$titled = true;
723 765
 							}
724 766
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
725 767
 						}
726 768
 			}
727 769
 		}
728
-		if ($titled)
729
-			$email['body'] .= "\n";
770
+		if ($titled) {
771
+					$email['body'] .= "\n";
772
+		}
730 773
 
731 774
 		// Then just say our goodbyes!
732 775
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -754,8 +797,7 @@  discard block
 block discarded – undo
754 797
 				'not_daily' => 0,
755 798
 			)
756 799
 		);
757
-	}
758
-	else
800
+	} else
759 801
 	{
760 802
 		// Clear any only weekly ones, and stop us from sending daily again.
761 803
 		$smcFunc['db_query']('', '
@@ -817,16 +859,19 @@  discard block
 block discarded – undo
817 859
 	global $modSettings, $smcFunc, $sourcedir;
818 860
 
819 861
 	// Are we intending another script to be sending out the queue?
820
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
821
-		return false;
862
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
863
+			return false;
864
+	}
822 865
 
823 866
 	// By default send 5 at once.
824
-	if (!$number)
825
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
867
+	if (!$number) {
868
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
869
+	}
826 870
 
827 871
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
828
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
829
-		return false;
872
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
873
+			return false;
874
+	}
830 875
 
831 876
 	// By default move the next sending on by 10 seconds, and require an affected row.
832 877
 	if (!$override_limit)
@@ -843,8 +888,9 @@  discard block
 block discarded – undo
843 888
 				'last_send' => $modSettings['mail_next_send'],
844 889
 			)
845 890
 		);
846
-		if ($smcFunc['db_affected_rows']() == 0)
847
-			return false;
891
+		if ($smcFunc['db_affected_rows']() == 0) {
892
+					return false;
893
+		}
848 894
 		$modSettings['mail_next_send'] = time() + $delay;
849 895
 	}
850 896
 
@@ -865,8 +911,9 @@  discard block
 block discarded – undo
865 911
 			$mn += $number;
866 912
 		}
867 913
 		// No more I'm afraid, return!
868
-		else
869
-			return false;
914
+		else {
915
+					return false;
916
+		}
870 917
 
871 918
 		// Reflect that we're about to send some, do it now to be safe.
872 919
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -901,14 +948,15 @@  discard block
 block discarded – undo
901 948
 	$smcFunc['db_free_result']($request);
902 949
 
903 950
 	// Delete, delete, delete!!!
904
-	if (!empty($ids))
905
-		$smcFunc['db_query']('', '
951
+	if (!empty($ids)) {
952
+			$smcFunc['db_query']('', '
906 953
 			DELETE FROM {db_prefix}mail_queue
907 954
 			WHERE id_mail IN ({array_int:mail_list})',
908 955
 			array(
909 956
 				'mail_list' => $ids,
910 957
 			)
911 958
 		);
959
+	}
912 960
 
913 961
 	// Don't believe we have any left?
914 962
 	if (count($ids) < $number)
@@ -926,11 +974,13 @@  discard block
 block discarded – undo
926 974
 		);
927 975
 	}
928 976
 
929
-	if (empty($ids))
930
-		return false;
977
+	if (empty($ids)) {
978
+			return false;
979
+	}
931 980
 
932
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
933
-		require_once($sourcedir . '/Subs-Post.php');
981
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
982
+			require_once($sourcedir . '/Subs-Post.php');
983
+	}
934 984
 
935 985
 	// Send each email, yea!
936 986
 	$failed_emails = array();
@@ -950,15 +1000,17 @@  discard block
 block discarded – undo
950 1000
 
951 1001
 			// Try to stop a timeout, this would be bad...
952 1002
 			@set_time_limit(300);
953
-			if (function_exists('apache_reset_timeout'))
954
-				@apache_reset_timeout();
1003
+			if (function_exists('apache_reset_timeout')) {
1004
+							@apache_reset_timeout();
1005
+			}
1006
+		} else {
1007
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
955 1008
 		}
956
-		else
957
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
958 1009
 
959 1010
 		// Hopefully it sent?
960
-		if (!$result)
961
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1011
+		if (!$result) {
1012
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1013
+		}
962 1014
 	}
963 1015
 
964 1016
 	// Any emails that didn't send?
@@ -973,8 +1025,8 @@  discard block
 block discarded – undo
973 1025
 		);
974 1026
 
975 1027
 		// If we have failed to many times, tell mail to wait a bit and try again.
976
-		if ($modSettings['mail_failed_attempts'] > 5)
977
-			$smcFunc['db_query']('', '
1028
+		if ($modSettings['mail_failed_attempts'] > 5) {
1029
+					$smcFunc['db_query']('', '
978 1030
 				UPDATE {db_prefix}settings
979 1031
 				SET value = {string:next_mail_send}
980 1032
 				WHERE variable = {literal:mail_next_send}
@@ -983,6 +1035,7 @@  discard block
 block discarded – undo
983 1035
 					'next_mail_send' => time() + 60,
984 1036
 					'last_send' => $modSettings['mail_next_send'],
985 1037
 			));
1038
+		}
986 1039
 
987 1040
 		// Add our email back to the queue, manually.
988 1041
 		$smcFunc['db_insert']('insert',
@@ -995,8 +1048,8 @@  discard block
 block discarded – undo
995 1048
 		return false;
996 1049
 	}
997 1050
 	// We where unable to send the email, clear our failed attempts.
998
-	elseif (!empty($modSettings['mail_failed_attempts']))
999
-		$smcFunc['db_query']('', '
1051
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1052
+			$smcFunc['db_query']('', '
1000 1053
 			UPDATE {db_prefix}settings
1001 1054
 			SET value = {string:zero}
1002 1055
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1004,6 +1057,7 @@  discard block
 block discarded – undo
1004 1057
 				'zero' => '0',
1005 1058
 				'mail_failed_attempts' => 'mail_failed_attempts',
1006 1059
 		));
1060
+	}
1007 1061
 
1008 1062
 	// Had something to send...
1009 1063
 	return true;
@@ -1020,16 +1074,18 @@  discard block
 block discarded – undo
1020 1074
 	global $modSettings, $smcFunc;
1021 1075
 
1022 1076
 	$task_query = '';
1023
-	if (!is_array($tasks))
1024
-		$tasks = array($tasks);
1077
+	if (!is_array($tasks)) {
1078
+			$tasks = array($tasks);
1079
+	}
1025 1080
 
1026 1081
 	// Actually have something passed?
1027 1082
 	if (!empty($tasks))
1028 1083
 	{
1029
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1030
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1031
-		else
1032
-			$task_query = ' AND task IN ({array_string:tasks})';
1084
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1085
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1086
+		} else {
1087
+					$task_query = ' AND task IN ({array_string:tasks})';
1088
+		}
1033 1089
 	}
1034 1090
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1035 1091
 
@@ -1050,20 +1106,22 @@  discard block
 block discarded – undo
1050 1106
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1051 1107
 
1052 1108
 		// Only bother moving the task if it's out of place or we're forcing it!
1053
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1054
-			$tasks[$row['id_task']] = $next_time;
1055
-		else
1056
-			$next_time = $row['next_time'];
1109
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1110
+					$tasks[$row['id_task']] = $next_time;
1111
+		} else {
1112
+					$next_time = $row['next_time'];
1113
+		}
1057 1114
 
1058 1115
 		// If this is sooner than the current next task, make this the next task.
1059
-		if ($next_time < $nextTaskTime)
1060
-			$nextTaskTime = $next_time;
1116
+		if ($next_time < $nextTaskTime) {
1117
+					$nextTaskTime = $next_time;
1118
+		}
1061 1119
 	}
1062 1120
 	$smcFunc['db_free_result']($request);
1063 1121
 
1064 1122
 	// Now make the changes!
1065
-	foreach ($tasks as $id => $time)
1066
-		$smcFunc['db_query']('', '
1123
+	foreach ($tasks as $id => $time) {
1124
+			$smcFunc['db_query']('', '
1067 1125
 			UPDATE {db_prefix}scheduled_tasks
1068 1126
 			SET next_time = {int:next_time}
1069 1127
 			WHERE id_task = {int:id_task}',
@@ -1072,11 +1130,13 @@  discard block
 block discarded – undo
1072 1130
 				'id_task' => $id,
1073 1131
 			)
1074 1132
 		);
1133
+	}
1075 1134
 
1076 1135
 	// If the next task is now different update.
1077
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1078
-		updateSettings(array('next_task_time' => $nextTaskTime));
1079
-}
1136
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1137
+			updateSettings(array('next_task_time' => $nextTaskTime));
1138
+	}
1139
+	}
1080 1140
 
1081 1141
 /**
1082 1142
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1089,8 +1149,9 @@  discard block
 block discarded – undo
1089 1149
 function next_time($regularity, $unit, $offset)
1090 1150
 {
1091 1151
 	// Just in case!
1092
-	if ($regularity == 0)
1093
-		$regularity = 2;
1152
+	if ($regularity == 0) {
1153
+			$regularity = 2;
1154
+	}
1094 1155
 
1095 1156
 	$curHour = date('H', time());
1096 1157
 	$curMin = date('i', time());
@@ -1102,15 +1163,16 @@  discard block
 block discarded – undo
1102 1163
 		$off = date('i', $offset);
1103 1164
 
1104 1165
 		// If it's now just pretend it ain't,
1105
-		if ($off == $curMin)
1106
-			$next_time = time() + $regularity;
1107
-		else
1166
+		if ($off == $curMin) {
1167
+					$next_time = time() + $regularity;
1168
+		} else
1108 1169
 		{
1109 1170
 			// Make sure that the offset is always in the past.
1110 1171
 			$off = $off > $curMin ? $off - 60 : $off;
1111 1172
 
1112
-			while ($off <= $curMin)
1113
-				$off += $regularity;
1173
+			while ($off <= $curMin) {
1174
+							$off += $regularity;
1175
+			}
1114 1176
 
1115 1177
 			// Now we know when the time should be!
1116 1178
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1130,11 +1192,13 @@  discard block
 block discarded – undo
1130 1192
 		// Default we'll jump in hours.
1131 1193
 		$applyOffset = 3600;
1132 1194
 		// 24 hours = 1 day.
1133
-		if ($unit == 'd')
1134
-			$applyOffset = 86400;
1195
+		if ($unit == 'd') {
1196
+					$applyOffset = 86400;
1197
+		}
1135 1198
 		// Otherwise a week.
1136
-		if ($unit == 'w')
1137
-			$applyOffset = 604800;
1199
+		if ($unit == 'w') {
1200
+					$applyOffset = 604800;
1201
+		}
1138 1202
 
1139 1203
 		$applyOffset *= $regularity;
1140 1204
 
@@ -1171,8 +1235,9 @@  discard block
 block discarded – undo
1171 1235
 		$settings[$row['variable']] = $row['value'];
1172 1236
 
1173 1237
 		// Is this the default theme?
1174
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1175
-			$settings['default_' . $row['variable']] = $row['value'];
1238
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1239
+					$settings['default_' . $row['variable']] = $row['value'];
1240
+		}
1176 1241
 	}
1177 1242
 	$smcFunc['db_free_result']($result);
1178 1243
 
@@ -1182,12 +1247,14 @@  discard block
 block discarded – undo
1182 1247
 		$settings['template_dirs'] = array($settings['theme_dir']);
1183 1248
 
1184 1249
 		// Based on theme (if there is one).
1185
-		if (!empty($settings['base_theme_dir']))
1186
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1250
+		if (!empty($settings['base_theme_dir'])) {
1251
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1252
+		}
1187 1253
 
1188 1254
 		// Lastly the default theme.
1189
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1190
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1255
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1256
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1257
+		}
1191 1258
 	}
1192 1259
 
1193 1260
 	// Assume we want this.
@@ -1333,8 +1400,9 @@  discard block
 block discarded – undo
1333 1400
 	// Ok should we prune the logs?
1334 1401
 	if (!empty($modSettings['pruningOptions']))
1335 1402
 	{
1336
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1337
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1403
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1404
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1405
+		}
1338 1406
 
1339 1407
 		if (!empty($modSettings['pruneErrorLog']))
1340 1408
 		{
@@ -1400,8 +1468,9 @@  discard block
 block discarded – undo
1400 1468
 				)
1401 1469
 			);
1402 1470
 
1403
-			while ($row = $smcFunc['db_fetch_row']($result))
1404
-				$reports[] = $row[0];
1471
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1472
+							$reports[] = $row[0];
1473
+			}
1405 1474
 
1406 1475
 			$smcFunc['db_free_result']($result);
1407 1476
 
@@ -1557,8 +1626,9 @@  discard block
 block discarded – undo
1557 1626
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1558 1627
 
1559 1628
 		// Send the actual email.
1560
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1561
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1629
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1630
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1631
+		}
1562 1632
 
1563 1633
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1564 1634
 		{
@@ -1581,18 +1651,19 @@  discard block
 block discarded – undo
1581 1651
 	}
1582 1652
 
1583 1653
 	// Insert the alerts if any
1584
-	if (!empty($alert_rows))
1585
-		$smcFunc['db_insert']('',
1654
+	if (!empty($alert_rows)) {
1655
+			$smcFunc['db_insert']('',
1586 1656
 			'{db_prefix}user_alerts',
1587 1657
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1588 1658
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1589 1659
 			$alert_rows,
1590 1660
 			array()
1591 1661
 		);
1662
+	}
1592 1663
 
1593 1664
 	// Mark the reminder as sent.
1594
-	if (!empty($subs_reminded))
1595
-		$smcFunc['db_query']('', '
1665
+	if (!empty($subs_reminded)) {
1666
+			$smcFunc['db_query']('', '
1596 1667
 			UPDATE {db_prefix}log_subscribed
1597 1668
 			SET reminder_sent = {int:reminder_sent}
1598 1669
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1601,6 +1672,7 @@  discard block
 block discarded – undo
1601 1672
 				'reminder_sent' => 1,
1602 1673
 			)
1603 1674
 		);
1675
+	}
1604 1676
 
1605 1677
 	return true;
1606 1678
 }
@@ -1616,13 +1688,13 @@  discard block
 block discarded – undo
1616 1688
 	// We need to know where this thing is going.
1617 1689
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1618 1690
 	{
1619
-		if (!is_array($modSettings['attachmentUploadDir']))
1620
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1691
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1692
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1693
+		}
1621 1694
 
1622 1695
 		// Just use the current path for temp files.
1623 1696
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1624
-	}
1625
-	else
1697
+	} else
1626 1698
 	{
1627 1699
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1628 1700
 	}
@@ -1641,14 +1713,16 @@  discard block
 block discarded – undo
1641 1713
 
1642 1714
 		while ($file = readdir($dir))
1643 1715
 		{
1644
-			if ($file == '.' || $file == '..')
1645
-				continue;
1716
+			if ($file == '.' || $file == '..') {
1717
+							continue;
1718
+			}
1646 1719
 
1647 1720
 			if (strpos($file, 'post_tmp_') !== false)
1648 1721
 			{
1649 1722
 				// Temp file is more than 5 hours old!
1650
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1651
-					@unlink($attach_dir . '/' . $file);
1723
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1724
+									@unlink($attach_dir . '/' . $file);
1725
+				}
1652 1726
 			}
1653 1727
 		}
1654 1728
 		closedir($dir);
@@ -1681,8 +1755,9 @@  discard block
 block discarded – undo
1681 1755
 		)
1682 1756
 	);
1683 1757
 
1684
-	while ($row = $smcFunc['db_fetch_row']($request))
1685
-		$topics[] = $row[0];
1758
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1759
+			$topics[] = $row[0];
1760
+	}
1686 1761
 	$smcFunc['db_free_result']($request);
1687 1762
 
1688 1763
 	// Zap, your gone
@@ -1702,8 +1777,9 @@  discard block
 block discarded – undo
1702 1777
 {
1703 1778
 	global $smcFunc, $sourcedir, $modSettings;
1704 1779
 
1705
-	if (empty($modSettings['drafts_keep_days']))
1706
-		return true;
1780
+	if (empty($modSettings['drafts_keep_days'])) {
1781
+			return true;
1782
+	}
1707 1783
 
1708 1784
 	// init
1709 1785
 	$drafts = array();
@@ -1721,8 +1797,9 @@  discard block
 block discarded – undo
1721 1797
 		)
1722 1798
 	);
1723 1799
 
1724
-	while ($row = $smcFunc['db_fetch_row']($request))
1725
-		$drafts[] = (int) $row[0];
1800
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1801
+			$drafts[] = (int) $row[0];
1802
+	}
1726 1803
 	$smcFunc['db_free_result']($request);
1727 1804
 
1728 1805
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Admin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
 /**
20 20
  * Get a list of versions that are currently installed on the server.
21
- * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
21
+ * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
22 22
  * @return array An array of versions (keys are same as what was in $checkFor, values are the versions)
23 23
  */
24 24
 function getServerVersions($checkFor)
Please login to merge, or discard this patch.
Braces   +124 added lines, -89 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 a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_engine']();
@@ -74,24 +74,31 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	// If we're using memcache we need the server info.
77
-	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
78
-		get_memcached_server();
77
+	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
78
+			get_memcached_server();
79
+	}
79 80
 
80 81
 	// Check to see if we have any accelerators installed...
81
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
82
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
83
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
84
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
85
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
86
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
87
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
88
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
82
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
83
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
+	}
85
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
86
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
87
+	}
88
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
89
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
90
+	}
91
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
92
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
93
+	}
89 94
 
90
-	if (in_array('php', $checkFor))
91
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
95
+	if (in_array('php', $checkFor)) {
96
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
97
+	}
92 98
 
93
-	if (in_array('server', $checkFor))
94
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
99
+	if (in_array('server', $checkFor)) {
100
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
101
+	}
95 102
 
96 103
 	return $versions;
97 104
 }
@@ -131,11 +138,13 @@  discard block
 block discarded – undo
131 138
 		fclose($fp);
132 139
 
133 140
 		// The comment looks rougly like... that.
134
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
135
-			$version_info['file_versions']['SSI.php'] = $match[1];
141
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
142
+					$version_info['file_versions']['SSI.php'] = $match[1];
143
+		}
136 144
 		// Not found!  This is bad.
137
-		else
138
-			$version_info['file_versions']['SSI.php'] = '??';
145
+		else {
146
+					$version_info['file_versions']['SSI.php'] = '??';
147
+		}
139 148
 	}
140 149
 
141 150
 	// Do the paid subscriptions handler?
@@ -146,11 +155,13 @@  discard block
 block discarded – undo
146 155
 		fclose($fp);
147 156
 
148 157
 		// Found it?
149
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
150
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
158
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
159
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
160
+		}
151 161
 		// If we haven't how do we all get paid?
152
-		else
153
-			$version_info['file_versions']['subscriptions.php'] = '??';
162
+		else {
163
+					$version_info['file_versions']['subscriptions.php'] = '??';
164
+		}
154 165
 	}
155 166
 
156 167
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -165,11 +176,13 @@  discard block
 block discarded – undo
165 176
 			fclose($fp);
166 177
 
167 178
 			// Look for the version comment in the file header.
168
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
169
-				$version_info['file_versions'][$entry] = $match[1];
179
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
180
+							$version_info['file_versions'][$entry] = $match[1];
181
+			}
170 182
 			// It wasn't found, but the file was... show a '??'.
171
-			else
172
-				$version_info['file_versions'][$entry] = '??';
183
+			else {
184
+							$version_info['file_versions'][$entry] = '??';
185
+			}
173 186
 		}
174 187
 	}
175 188
 	$sources_dir->close();
@@ -188,11 +201,13 @@  discard block
 block discarded – undo
188 201
 				fclose($fp);
189 202
 
190 203
 				// Look for the version comment in the file header.
191
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
192
-					$version_info['tasks_versions'][$entry] = $match[1];
204
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
205
+									$version_info['tasks_versions'][$entry] = $match[1];
206
+				}
193 207
 				// It wasn't found, but the file was... show a '??'.
194
-				else
195
-					$version_info['tasks_versions'][$entry] = '??';
208
+				else {
209
+									$version_info['tasks_versions'][$entry] = '??';
210
+				}
196 211
 			}
197 212
 		}
198 213
 		$tasks_dir->close();
@@ -200,8 +215,9 @@  discard block
 block discarded – undo
200 215
 
201 216
 	// Load all the files in the default template directory - and the current theme if applicable.
202 217
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
203
-	if ($settings['theme_id'] != 1)
204
-		$directories += array('template_versions' => $settings['theme_dir']);
218
+	if ($settings['theme_id'] != 1) {
219
+			$directories += array('template_versions' => $settings['theme_dir']);
220
+	}
205 221
 
206 222
 	foreach ($directories as $type => $dirname)
207 223
 	{
@@ -216,11 +232,13 @@  discard block
 block discarded – undo
216 232
 				fclose($fp);
217 233
 
218 234
 				// Look for the version comment in the file header.
219
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
220
-					$version_info[$type][$entry] = $match[1];
235
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
236
+									$version_info[$type][$entry] = $match[1];
237
+				}
221 238
 				// It wasn't found, but the file was... show a '??'.
222
-				else
223
-					$version_info[$type][$entry] = '??';
239
+				else {
240
+									$version_info[$type][$entry] = '??';
241
+				}
224 242
 			}
225 243
 		}
226 244
 		$this_dir->close();
@@ -241,11 +259,13 @@  discard block
 block discarded – undo
241 259
 			list ($name, $language) = explode('.', $entry);
242 260
 
243 261
 			// Look for the version comment in the file header.
244
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
245
-				$version_info['default_language_versions'][$language][$name] = $match[1];
262
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
263
+							$version_info['default_language_versions'][$language][$name] = $match[1];
264
+			}
246 265
 			// It wasn't found, but the file was... show a '??'.
247
-			else
248
-				$version_info['default_language_versions'][$language][$name] = '??';
266
+			else {
267
+							$version_info['default_language_versions'][$language][$name] = '??';
268
+			}
249 269
 		}
250 270
 	}
251 271
 	$this_dir->close();
@@ -260,8 +280,9 @@  discard block
 block discarded – undo
260 280
 		ksort($version_info['tasks_versions']);
261 281
 
262 282
 		// For languages sort each language too.
263
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
264
-			ksort($version_info['default_language_versions'][$language]);
283
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
284
+					ksort($version_info['default_language_versions'][$language]);
285
+		}
265 286
 	}
266 287
 	return $version_info;
267 288
 }
@@ -303,27 +324,31 @@  discard block
 block discarded – undo
303 324
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
304 325
 
305 326
 	// Break it up based on \r or \n, and then clean out extra characters.
306
-	if (strpos($settingsArray, "\n") !== false)
307
-		$settingsArray = explode("\n", $settingsArray);
308
-	elseif (strpos($settingsArray, "\r") !== false)
309
-		$settingsArray = explode("\r", $settingsArray);
310
-	else
311
-		return;
327
+	if (strpos($settingsArray, "\n") !== false) {
328
+			$settingsArray = explode("\n", $settingsArray);
329
+	} elseif (strpos($settingsArray, "\r") !== false) {
330
+			$settingsArray = explode("\r", $settingsArray);
331
+	} else {
332
+			return;
333
+	}
312 334
 
313 335
 	// Presumably, the file has to have stuff in it for this function to be called :P.
314
-	if (count($settingsArray) < 10)
315
-		return;
336
+	if (count($settingsArray) < 10) {
337
+			return;
338
+	}
316 339
 
317 340
 	// remove any /r's that made there way in here
318
-	foreach ($settingsArray as $k => $dummy)
319
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
341
+	foreach ($settingsArray as $k => $dummy) {
342
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
343
+	}
320 344
 
321 345
 	// go line by line and see whats changing
322 346
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
323 347
 	{
324 348
 		// Don't trim or bother with it if it's not a variable.
325
-		if (substr($settingsArray[$i], 0, 1) != '$')
326
-			continue;
349
+		if (substr($settingsArray[$i], 0, 1) != '$') {
350
+					continue;
351
+		}
327 352
 
328 353
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
329 354
 
@@ -335,8 +360,7 @@  discard block
 block discarded – undo
335 360
 			{
336 361
 				updateDbLastError($val);
337 362
 				unset($config_vars[$var]);
338
-			}
339
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
363
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
340 364
 			{
341 365
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
342 366
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -347,34 +371,39 @@  discard block
 block discarded – undo
347 371
 		}
348 372
 
349 373
 		// End of the file ... maybe
350
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
351
-			$end = $i;
374
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
375
+					$end = $i;
376
+		}
352 377
 	}
353 378
 
354 379
 	// This should never happen, but apparently it is happening.
355
-	if (empty($end) || $end < 10)
356
-		$end = count($settingsArray) - 1;
380
+	if (empty($end) || $end < 10) {
381
+			$end = count($settingsArray) - 1;
382
+	}
357 383
 
358 384
 	// Still more variables to go?  Then lets add them at the end.
359 385
 	if (!empty($config_vars))
360 386
 	{
361
-		if (trim($settingsArray[$end]) == '?' . '>')
362
-			$settingsArray[$end++] = '';
363
-		else
364
-			$end++;
387
+		if (trim($settingsArray[$end]) == '?' . '>') {
388
+					$settingsArray[$end++] = '';
389
+		} else {
390
+					$end++;
391
+		}
365 392
 
366 393
 		// Add in any newly defined vars that were passed
367
-		foreach ($config_vars as $var => $val)
368
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
394
+		foreach ($config_vars as $var => $val) {
395
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
396
+		}
369 397
 
370 398
 		$settingsArray[$end] = '?' . '>';
399
+	} else {
400
+			$settingsArray[$end] = trim($settingsArray[$end]);
371 401
 	}
372
-	else
373
-		$settingsArray[$end] = trim($settingsArray[$end]);
374 402
 
375 403
 	// Sanity error checking: the file needs to be at least 12 lines.
376
-	if (count($settingsArray) < 12)
377
-		return;
404
+	if (count($settingsArray) < 12) {
405
+			return;
406
+	}
378 407
 
379 408
 	// Try to avoid a few pitfalls:
380 409
 	//  - like a possible race condition,
@@ -382,8 +411,9 @@  discard block
 block discarded – undo
382 411
 	//
383 412
 	// Check before you act: if cache is enabled, we can do a simple write test
384 413
 	// to validate that we even write things on this filesystem.
385
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
386
-		$cachedir = $boarddir . '/cache';
414
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
415
+			$cachedir = $boarddir . '/cache';
416
+	}
387 417
 
388 418
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
389 419
 	if ($test_fp)
@@ -419,16 +449,18 @@  discard block
 block discarded – undo
419 449
 			// Well this is not good at all, lets see if we can save this
420 450
 			$context['settings_message'] = 'settings_error';
421 451
 
422
-			if (file_exists($boarddir . '/Settings_bak.php'))
423
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
452
+			if (file_exists($boarddir . '/Settings_bak.php')) {
453
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
454
+			}
424 455
 		}
425 456
 	}
426 457
 
427 458
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
428 459
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
429
-	if (function_exists('opcache_invalidate'))
430
-		opcache_invalidate($boarddir . '/Settings.php', true);
431
-}
460
+	if (function_exists('opcache_invalidate')) {
461
+			opcache_invalidate($boarddir . '/Settings.php', true);
462
+	}
463
+	}
432 464
 
433 465
 /**
434 466
  * Saves the time of the last db error for the error log
@@ -454,8 +486,9 @@  discard block
 block discarded – undo
454 486
 	global $options, $context, $smcFunc, $settings, $user_info;
455 487
 
456 488
 	// This must exist!
457
-	if (!isset($context['admin_preferences']))
458
-		return false;
489
+	if (!isset($context['admin_preferences'])) {
490
+			return false;
491
+	}
459 492
 
460 493
 	// This is what we'll be saving.
461 494
 	$options['admin_preferences'] = json_encode($context['admin_preferences']);
@@ -519,8 +552,9 @@  discard block
 block discarded – undo
519 552
 	$emails_sent = array();
520 553
 	while ($row = $smcFunc['db_fetch_assoc']($request))
521 554
 	{
522
-		if (empty($prefs[$row['id_member']]['announcements']))
523
-			continue;
555
+		if (empty($prefs[$row['id_member']]['announcements'])) {
556
+					continue;
557
+		}
524 558
 
525 559
 		// Stick their particulars in the replacement data.
526 560
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -539,11 +573,12 @@  discard block
 block discarded – undo
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
541 575
 	// Any additional users we must email this to?
542
-	if (!empty($additional_recipients))
543
-		foreach ($additional_recipients as $recipient)
576
+	if (!empty($additional_recipients)) {
577
+			foreach ($additional_recipients as $recipient)
544 578
 		{
545 579
 			if (in_array($recipient['email'], $emails_sent))
546 580
 				continue;
581
+	}
547 582
 
548 583
 			$replacements['IDMEMBER'] = $recipient['id'];
549 584
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
  *
151 151
  * @param bool $local Whether we want local cookies
152 152
  * @param bool $global Whether we want global cookies
153
- * @return array An array to set the cookie on with domain and path in it, in that order
153
+ * @return string An array to set the cookie on with domain and path in it, in that order
154 154
  */
155 155
 function url_parts($local, $global)
156 156
 {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 	// This ensures you can't search someones email address if you can't see it.
394 394
 	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395 395
 		$email_condition = '
396
-			OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
396
+			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397 397
 	else
398 398
 		$email_condition = '';
399 399
 
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 		LIMIT {int:limit}',
413 413
 		array(
414 414
 			'buddy_list' => $user_info['buddies'],
415
-			'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'',
416
-			'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'',
415
+			'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'',
416
+			'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'',
417 417
 			'email_condition' => $email_condition,
418 418
 			'limit' => $max,
419 419
 		)
Please login to merge, or discard this patch.
Braces   +160 added lines, -115 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
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 		$array = smf_json_decode($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
@@ -62,8 +64,9 @@  discard block
 block discarded – undo
62 64
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
63 65
 
64 66
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
65
-	if (empty($id) && !empty($modSettings['globalCookies']))
66
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
67
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
68
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
69
+	}
67 70
 
68 71
 	// Any alias URLs?  This is mainly for use with frames, etc.
69 72
 	if (!empty($modSettings['forum_alias_urls']))
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
81 84
 
82
-			if ($cookie_url[0] == '')
83
-				$cookie_url[0] = strtok($alias, '/');
85
+			if ($cookie_url[0] == '') {
86
+							$cookie_url[0] = strtok($alias, '/');
87
+			}
84 88
 
85 89
 			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
86 90
 		}
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
 	$identifier = $cookiename . '_tfa';
127 131
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
128 132
 
129
-	if ($preserve)
130
-		$cookie_length = 81600 * 30;
133
+	if ($preserve) {
134
+			$cookie_length = 81600 * 30;
135
+	}
131 136
 
132 137
 	// Get the data and path to set it on.
133 138
 	$data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve));
@@ -137,8 +142,9 @@  discard block
 block discarded – undo
137 142
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
138 143
 
139 144
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
140
-	if (empty($id) && !empty($modSettings['globalCookies']))
141
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
145
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
146
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
147
+	}
142 148
 
143 149
 	$_COOKIE[$identifier] = $data;
144 150
 }
@@ -160,23 +166,28 @@  discard block
 block discarded – undo
160 166
 	$parsed_url = parse_url($boardurl);
161 167
 
162 168
 	// Is local cookies off?
163
-	if (empty($parsed_url['path']) || !$local)
164
-		$parsed_url['path'] = '';
169
+	if (empty($parsed_url['path']) || !$local) {
170
+			$parsed_url['path'] = '';
171
+	}
165 172
 
166
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
167
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
173
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
174
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
175
+	}
168 176
 
169 177
 	// Globalize cookies across domains (filter out IP-addresses)?
170
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
171
-		$parsed_url['host'] = '.' . $parts[1];
178
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
179
+			$parsed_url['host'] = '.' . $parts[1];
180
+	}
172 181
 
173 182
 	// We shouldn't use a host at all if both options are off.
174
-	elseif (!$local && !$global)
175
-		$parsed_url['host'] = '';
183
+	elseif (!$local && !$global) {
184
+			$parsed_url['host'] = '';
185
+	}
176 186
 
177 187
 	// The host also shouldn't be set if there aren't any dots in it.
178
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
179
-		$parsed_url['host'] = '';
188
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
189
+			$parsed_url['host'] = '';
190
+	}
180 191
 
181 192
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
182 193
 }
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 	createToken('login');
196 207
 
197 208
 	// Never redirect to an attachment
198
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
199
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
209
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
210
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
211
+	}
200 212
 
201 213
 	$context['sub_template'] = 'kick_guest';
202 214
 	$context['page_title'] = $txt['login'];
@@ -251,10 +263,12 @@  discard block
 block discarded – undo
251 263
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
252 264
 		log_error($txt['security_wrong'], 'critical');
253 265
 
254
-		if (isset($_POST[$type . '_hash_pass']))
255
-			unset($_POST[$type . '_hash_pass']);
256
-		if (isset($_POST[$type . '_pass']))
257
-			unset($_POST[$type . '_pass']);
266
+		if (isset($_POST[$type . '_hash_pass'])) {
267
+					unset($_POST[$type . '_hash_pass']);
268
+		}
269
+		if (isset($_POST[$type . '_pass'])) {
270
+					unset($_POST[$type . '_pass']);
271
+		}
258 272
 
259 273
 		$context['incorrect_password'] = true;
260 274
 	}
@@ -267,15 +281,17 @@  discard block
 block discarded – undo
267 281
 
268 282
 	// Now go through $_POST.  Make sure the session hash is sent.
269 283
 	$_POST[$context['session_var']] = $context['session_id'];
270
-	foreach ($_POST as $k => $v)
271
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
284
+	foreach ($_POST as $k => $v) {
285
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
286
+	}
272 287
 
273 288
 	// Now we'll use the admin_login sub template of the Login template.
274 289
 	$context['sub_template'] = 'admin_login';
275 290
 
276 291
 	// And title the page something like "Login".
277
-	if (!isset($context['page_title']))
278
-		$context['page_title'] = $txt['login'];
292
+	if (!isset($context['page_title'])) {
293
+			$context['page_title'] = $txt['login'];
294
+	}
279 295
 
280 296
 	// The type of action.
281 297
 	$context['sessionCheckType'] = $type;
@@ -298,14 +314,15 @@  discard block
 block discarded – undo
298 314
 {
299 315
 	global $smcFunc;
300 316
 
301
-	if (!is_array($v))
302
-		return '
317
+	if (!is_array($v)) {
318
+			return '
303 319
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
304
-	else
320
+	} else
305 321
 	{
306 322
 		$ret = '';
307
-		foreach ($v as $k2 => $v2)
308
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
323
+		foreach ($v as $k2 => $v2) {
324
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
325
+		}
309 326
 
310 327
 		return $ret;
311 328
 	}
@@ -332,18 +349,20 @@  discard block
 block discarded – undo
332 349
 		foreach ($get as $k => $v)
333 350
 		{
334 351
 			// Only if it's not already in the $scripturl!
335
-			if (!isset($temp[$k]))
336
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
352
+			if (!isset($temp[$k])) {
353
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
354
+			}
337 355
 			// If it changed, put it out there, but with an ampersand.
338
-			elseif ($temp[$k] != $get[$k])
339
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
356
+			elseif ($temp[$k] != $get[$k]) {
357
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
358
+			}
340 359
 		}
341
-	}
342
-	else
360
+	} else
343 361
 	{
344 362
 		// Add up all the data from $_GET into get_data.
345
-		foreach ($get as $k => $v)
346
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
363
+		foreach ($get as $k => $v) {
364
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
365
+		}
347 366
 	}
348 367
 
349 368
 	$query_string = substr($query_string, 0, -1);
@@ -366,8 +385,9 @@  discard block
 block discarded – undo
366 385
 	global $scripturl, $user_info, $smcFunc;
367 386
 
368 387
 	// If it's not already an array, make it one.
369
-	if (!is_array($names))
370
-		$names = explode(',', $names);
388
+	if (!is_array($names)) {
389
+			$names = explode(',', $names);
390
+	}
371 391
 
372 392
 	$maybe_email = false;
373 393
 	foreach ($names as $i => $name)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 		$maybe_email |= strpos($name, '@') !== false;
379 399
 
380 400
 		// Make it so standard wildcards will work. (* and ?)
381
-		if ($use_wildcards)
382
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
383
-		else
384
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
401
+		if ($use_wildcards) {
402
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
403
+		} else {
404
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
405
+		}
385 406
 	}
386 407
 
387 408
 	// What are we using to compare?
@@ -391,11 +412,12 @@  discard block
 block discarded – undo
391 412
 	$results = array();
392 413
 
393 414
 	// This ensures you can't search someones email address if you can't see it.
394
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395
-		$email_condition = '
415
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
416
+			$email_condition = '
396 417
 			OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397
-	else
398
-		$email_condition = '';
418
+	} else {
419
+			$email_condition = '';
420
+	}
399 421
 
400 422
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
401 423
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -453,10 +475,11 @@  discard block
 block discarded – undo
453 475
 	$context['template_layers'] = array();
454 476
 	$context['sub_template'] = 'find_members';
455 477
 
456
-	if (isset($_REQUEST['search']))
457
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
458
-	else
459
-		$_REQUEST['start'] = 0;
478
+	if (isset($_REQUEST['search'])) {
479
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
+	} else {
481
+			$_REQUEST['start'] = 0;
482
+	}
460 483
 
461 484
 	// Allow the user to pass the input to be added to to the box.
462 485
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -497,10 +520,10 @@  discard block
 block discarded – undo
497 520
 		);
498 521
 
499 522
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
523
+	} else {
524
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
+	}
500 526
 	}
501
-	else
502
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
503
-}
504 527
 
505 528
 /**
506 529
  * Outputs each member name on its own line.
@@ -516,8 +539,9 @@  discard block
 block discarded – undo
516 539
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
517 540
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
518 541
 
519
-	if (function_exists('iconv'))
520
-		header('Content-Type: text/plain; charset=UTF-8');
542
+	if (function_exists('iconv')) {
543
+			header('Content-Type: text/plain; charset=UTF-8');
544
+	}
521 545
 
522 546
 	$request = $smcFunc['db_query']('', '
523 547
 		SELECT real_name
@@ -537,14 +561,16 @@  discard block
 block discarded – undo
537 561
 		if (function_exists('iconv'))
538 562
 		{
539 563
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
540
-			if ($utf8)
541
-				$row['real_name'] = $utf8;
564
+			if ($utf8) {
565
+							$row['real_name'] = $utf8;
566
+			}
542 567
 		}
543 568
 
544 569
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
545 570
 
546
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
547
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
571
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
572
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
573
+		}
548 574
 
549 575
 		echo $row['real_name'], "\n";
550 576
 	}
@@ -601,9 +627,9 @@  discard block
 block discarded – undo
601 627
 
602 628
 		// Update the database...
603 629
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
630
+	} else {
631
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
604 632
 	}
605
-	else
606
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
607 633
 
608 634
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
609 635
 
@@ -634,31 +660,37 @@  discard block
 block discarded – undo
634 660
 	$errors = array();
635 661
 
636 662
 	// Don't use too long a name.
637
-	if ($smcFunc['strlen']($username) > 25)
638
-		$errors[] = array('lang', 'error_long_name');
663
+	if ($smcFunc['strlen']($username) > 25) {
664
+			$errors[] = array('lang', 'error_long_name');
665
+	}
639 666
 
640 667
 	// No name?!  How can you register with no name?
641
-	if ($username == '')
642
-		$errors[] = array('lang', 'need_username');
668
+	if ($username == '') {
669
+			$errors[] = array('lang', 'need_username');
670
+	}
643 671
 
644 672
 	// Only these characters are permitted.
645
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
646
-		$errors[] = array('lang', 'error_invalid_characters_username');
673
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
674
+			$errors[] = array('lang', 'error_invalid_characters_username');
675
+	}
647 676
 
648
-	if (stristr($username, $txt['guest_title']) !== false)
649
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
677
+	if (stristr($username, $txt['guest_title']) !== false) {
678
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
679
+	}
650 680
 
651 681
 	if ($check_reserved_name)
652 682
 	{
653 683
 		require_once($sourcedir . '/Subs-Members.php');
654
-		if (isReservedName($username, $memID, false))
655
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
684
+		if (isReservedName($username, $memID, false)) {
685
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
686
+		}
656 687
 	}
657 688
 
658
-	if ($return_error)
659
-		return $errors;
660
-	elseif (empty($errors))
661
-		return null;
689
+	if ($return_error) {
690
+			return $errors;
691
+	} elseif (empty($errors)) {
692
+			return null;
693
+	}
662 694
 
663 695
 	loadLanguage('Errors');
664 696
 	$error = $errors[0];
@@ -684,22 +716,26 @@  discard block
 block discarded – undo
684 716
 	global $modSettings, $smcFunc;
685 717
 
686 718
 	// Perform basic requirements first.
687
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
688
-		return 'short';
719
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
720
+			return 'short';
721
+	}
689 722
 
690 723
 	// Is this enough?
691
-	if (empty($modSettings['password_strength']))
692
-		return null;
724
+	if (empty($modSettings['password_strength'])) {
725
+			return null;
726
+	}
693 727
 
694 728
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
695
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
696
-		return 'restricted_words';
697
-	elseif ($smcFunc['strpos']($password, $username) !== false)
698
-		return 'restricted_words';
729
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
730
+			return 'restricted_words';
731
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
732
+			return 'restricted_words';
733
+	}
699 734
 
700 735
 	// If just medium, we're done.
701
-	if ($modSettings['password_strength'] == 1)
702
-		return null;
736
+	if ($modSettings['password_strength'] == 1) {
737
+			return null;
738
+	}
703 739
 
704 740
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
705 741
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -731,14 +767,16 @@  discard block
 block discarded – undo
731 767
 			)
732 768
 		);
733 769
 		$groups = array();
734
-		while ($row = $smcFunc['db_fetch_assoc']($request))
735
-			$groups[] = $row['id_group'];
770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
771
+					$groups[] = $row['id_group'];
772
+		}
736 773
 		$smcFunc['db_free_result']($request);
737 774
 
738
-		if (empty($groups))
739
-			$group_query = '0=1';
740
-		else
741
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
775
+		if (empty($groups)) {
776
+					$group_query = '0=1';
777
+		} else {
778
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
779
+		}
742 780
 	}
743 781
 
744 782
 	// Then, same again, just the boards this time!
@@ -748,10 +786,11 @@  discard block
 block discarded – undo
748 786
 	{
749 787
 		$boards = boardsAllowedTo('moderate_board', true);
750 788
 
751
-		if (empty($boards))
752
-			$board_query = '0=1';
753
-		else
754
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
789
+		if (empty($boards)) {
790
+					$board_query = '0=1';
791
+		} else {
792
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
793
+		}
755 794
 	}
756 795
 
757 796
 	// What boards are they the moderator of?
@@ -766,8 +805,9 @@  discard block
 block discarded – undo
766 805
 				'current_member' => $user_info['id'],
767 806
 			)
768 807
 		);
769
-		while ($row = $smcFunc['db_fetch_assoc']($request))
770
-			$boards_mod[] = $row['id_board'];
808
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
809
+					$boards_mod[] = $row['id_board'];
810
+		}
771 811
 		$smcFunc['db_free_result']($request);
772 812
 
773 813
 		// Can any of the groups they're in moderate any of the boards?
@@ -779,8 +819,9 @@  discard block
 block discarded – undo
779 819
 				'groups' => $user_info['groups'],
780 820
 			)
781 821
 		);
782
-		while ($row = $smcFunc['db_fetch_assoc']($request))
783
-			$boards_mod[] = $row['id_board'];
822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
823
+					$boards_mod[] = $row['id_board'];
824
+		}
784 825
 		$smcFunc['db_free_result']($request);
785 826
 
786 827
 		// Just in case we've got duplicates here...
@@ -825,10 +866,12 @@  discard block
 block discarded – undo
825 866
 	global $modSettings;
826 867
 
827 868
 	// In case a customization wants to override the default settings
828
-	if ($httponly === null)
829
-		$httponly = !empty($modSettings['httponlyCookies']);
830
-	if ($secure === null)
831
-		$secure = !empty($modSettings['secureCookies']);
869
+	if ($httponly === null) {
870
+			$httponly = !empty($modSettings['httponlyCookies']);
871
+	}
872
+	if ($secure === null) {
873
+			$secure = !empty($modSettings['secureCookies']);
874
+	}
832 875
 
833 876
 	// Intercept cookie?
834 877
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -848,8 +891,9 @@  discard block
 block discarded – undo
848 891
 function hash_password($username, $password, $cost = null)
849 892
 {
850 893
 	global $sourcedir, $smcFunc, $modSettings;
851
-	if (!function_exists('password_hash'))
852
-		require_once($sourcedir . '/Subs-Password.php');
894
+	if (!function_exists('password_hash')) {
895
+			require_once($sourcedir . '/Subs-Password.php');
896
+	}
853 897
 
854 898
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
855 899
 
@@ -881,8 +925,9 @@  discard block
 block discarded – undo
881 925
 function hash_verify_password($username, $password, $hash)
882 926
 {
883 927
 	global $sourcedir, $smcFunc;
884
-	if (!function_exists('password_verify'))
885
-		require_once($sourcedir . '/Subs-Password.php');
928
+	if (!function_exists('password_verify')) {
929
+			require_once($sourcedir . '/Subs-Password.php');
930
+	}
886 931
 
887 932
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
888 933
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-mysqli.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  * Backtrace, log, try to fix.
531 531
  *
532 532
  * @param string $db_string The DB string
533
- * @param object $connection The connection to use (if null, $db_connection is used)
533
+ * @param resource $connection The connection to use (if null, $db_connection is used)
534 534
  */
535 535
 function smf_db_error($db_string, $connection = null)
536 536
 {
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
  * @param array $data The data to insert
726 726
  * @param array $keys The keys for the table
727 727
  * @param bool $disable_trans Whether to disable transactions
728
- * @param object $connection The connection to use (if null, $db_connection is used)
728
+ * @param resource $connection The connection to use (if null, $db_connection is used)
729 729
  */
730 730
 function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $disable_trans = false, $connection = null)
731 731
 {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 	
71 71
 	if ($connection) {
72 72
 		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
73
+			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
74 74
 		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
75
+			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
76 76
 	}
77 77
 
78 78
 	// Something's wrong, show an error if its fatal (which we assume it is)
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 						$replacement[$key] = 'null';
283 283
 					if (!isValidIP($value))
284 284
 						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
285
-					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
285
+					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
286 286
 				}
287 287
 
288 288
 				return implode(', ', $replacement);
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
  * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards.
870 870
  * @return string The escaped string
871 871
  */
872
-function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false)
872
+function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false)
873 873
 {
874 874
 	$replacements = array(
875 875
 		'%' => '\%',
Please login to merge, or discard this patch.
Braces   +241 added lines, -176 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,49 +222,55 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'float':
250
-			if (!is_numeric($replacement))
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (!is_numeric($replacement)) {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			}
252 274
 			return (string) (float) $replacement;
253 275
 		break;
254 276
 
@@ -262,10 +284,12 @@  discard block
 block discarded – undo
262 284
 		break;
263 285
 
264 286
 		case 'inet':
265
-			if ($replacement == 'null' || $replacement == '')
266
-				return 'null';
267
-			if (!isValidIP($replacement))
268
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			if ($replacement == 'null' || $replacement == '') {
288
+							return 'null';
289
+			}
290
+			if (!isValidIP($replacement)) {
291
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
292
+			}
269 293
 			//we don't use the native support of mysql > 5.6.2
270 294
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
271 295
 		break;
@@ -273,22 +297,25 @@  discard block
 block discarded – undo
273 297
 		case 'array_inet':
274 298
 			if (is_array($replacement))
275 299
 			{
276
-				if (empty($replacement))
277
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+				if (empty($replacement)) {
301
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
302
+				}
278 303
 
279 304
 				foreach ($replacement as $key => $value)
280 305
 				{
281
-					if ($replacement == 'null' || $replacement == '')
282
-						$replacement[$key] = 'null';
283
-					if (!isValidIP($value))
284
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306
+					if ($replacement == 'null' || $replacement == '') {
307
+											$replacement[$key] = 'null';
308
+					}
309
+					if (!isValidIP($value)) {
310
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
311
+					}
285 312
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
286 313
 				}
287 314
 
288 315
 				return implode(', ', $replacement);
316
+			} else {
317
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
289 318
 			}
290
-			else
291
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
292 319
 		break;
293 320
 
294 321
 		default:
@@ -364,22 +391,25 @@  discard block
 block discarded – undo
364 391
 		// Are we in SSI mode?  If so try that username and password first
365 392
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
366 393
 		{
367
-			if (empty($db_persist))
368
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
369
-			else
370
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
394
+			if (empty($db_persist)) {
395
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
396
+			} else {
397
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
398
+			}
371 399
 		}
372 400
 		// Fall back to the regular username and password if need be
373 401
 		if (!$db_connection)
374 402
 		{
375
-			if (empty($db_persist))
376
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
377
-			else
378
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
403
+			if (empty($db_persist)) {
404
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
405
+			} else {
406
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
407
+			}
379 408
 		}
380 409
 
381
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
382
-			$db_connection = false;
410
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
411
+					$db_connection = false;
412
+		}
383 413
 
384 414
 		$connection = $db_connection;
385 415
 	}
@@ -387,18 +417,20 @@  discard block
 block discarded – undo
387 417
 	// One more query....
388 418
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
389 419
 
390
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
391
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
420
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
421
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
422
+	}
392 423
 
393 424
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
394 425
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
395 426
 	{
396 427
 		// Add before LIMIT
397
-		if ($pos = strpos($db_string, 'LIMIT '))
398
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
399
-		else
400
-			// Append it.
428
+		if ($pos = strpos($db_string, 'LIMIT ')) {
429
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
430
+		} else {
431
+					// Append it.
401 432
 			$db_string .= "\n\t\t\tORDER BY null";
433
+		}
402 434
 	}
403 435
 
404 436
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -420,8 +452,9 @@  discard block
 block discarded – undo
420 452
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
421 453
 
422 454
 		// Initialize $db_cache if not already initialized.
423
-		if (!isset($db_cache))
424
-			$db_cache = array();
455
+		if (!isset($db_cache)) {
456
+					$db_cache = array();
457
+		}
425 458
 
426 459
 		if (!empty($_SESSION['debug_redirect']))
427 460
 		{
@@ -447,17 +480,18 @@  discard block
 block discarded – undo
447 480
 		while (true)
448 481
 		{
449 482
 			$pos = strpos($db_string, '\'', $pos + 1);
450
-			if ($pos === false)
451
-				break;
483
+			if ($pos === false) {
484
+							break;
485
+			}
452 486
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
453 487
 
454 488
 			while (true)
455 489
 			{
456 490
 				$pos1 = strpos($db_string, '\'', $pos + 1);
457 491
 				$pos2 = strpos($db_string, '\\', $pos + 1);
458
-				if ($pos1 === false)
459
-					break;
460
-				elseif ($pos2 == false || $pos2 > $pos1)
492
+				if ($pos1 === false) {
493
+									break;
494
+				} elseif ($pos2 == false || $pos2 > $pos1)
461 495
 				{
462 496
 					$pos = $pos1;
463 497
 					break;
@@ -473,29 +507,35 @@  discard block
 block discarded – undo
473 507
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
474 508
 
475 509
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
476
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
477
-			$fail = true;
510
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
511
+					$fail = true;
512
+		}
478 513
 		// Trying to change passwords, slow us down, or something?
479
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
480
-			$fail = true;
481
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
482
-			$fail = true;
514
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
515
+					$fail = true;
516
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
517
+					$fail = true;
518
+		}
483 519
 
484
-		if (!empty($fail) && function_exists('log_error'))
485
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
520
+		if (!empty($fail) && function_exists('log_error')) {
521
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
522
+		}
486 523
 	}
487 524
 
488
-	if (empty($db_unbuffered))
489
-		$ret = @mysqli_query($connection, $db_string);
490
-	else
491
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
525
+	if (empty($db_unbuffered)) {
526
+			$ret = @mysqli_query($connection, $db_string);
527
+	} else {
528
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
529
+	}
492 530
 
493
-	if ($ret === false && empty($db_values['db_error_skip']))
494
-		$ret = smf_db_error($db_string, $connection);
531
+	if ($ret === false && empty($db_values['db_error_skip'])) {
532
+			$ret = smf_db_error($db_string, $connection);
533
+	}
495 534
 
496 535
 	// Debugging.
497
-	if (isset($db_show_debug) && $db_show_debug === true)
498
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
536
+	if (isset($db_show_debug) && $db_show_debug === true) {
537
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
538
+	}
499 539
 
500 540
 	return $ret;
501 541
 }
@@ -544,12 +584,13 @@  discard block
 block discarded – undo
544 584
 	// Decide which connection to use
545 585
 	$connection = $connection === null ? $db_connection : $connection;
546 586
 
547
-	if ($type == 'begin')
548
-		return @mysqli_query($connection, 'BEGIN');
549
-	elseif ($type == 'rollback')
550
-		return @mysqli_query($connection, 'ROLLBACK');
551
-	elseif ($type == 'commit')
552
-		return @mysqli_query($connection, 'COMMIT');
587
+	if ($type == 'begin') {
588
+			return @mysqli_query($connection, 'BEGIN');
589
+	} elseif ($type == 'rollback') {
590
+			return @mysqli_query($connection, 'ROLLBACK');
591
+	} elseif ($type == 'commit') {
592
+			return @mysqli_query($connection, 'COMMIT');
593
+	}
553 594
 
554 595
 	return false;
555 596
 }
@@ -589,8 +630,9 @@  discard block
 block discarded – undo
589 630
 	//    2013: Lost connection to server during query.
590 631
 
591 632
 	// Log the error.
592
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
593
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
633
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
634
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
635
+	}
594 636
 
595 637
 	// Database error auto fixing ;).
596 638
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -599,8 +641,9 @@  discard block
 block discarded – undo
599 641
 		$old_cache = @$modSettings['cache_enable'];
600 642
 		$modSettings['cache_enable'] = '1';
601 643
 
602
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
603
-			$db_last_error = max(@$db_last_error, $temp);
644
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
645
+					$db_last_error = max(@$db_last_error, $temp);
646
+		}
604 647
 
605 648
 		if (@$db_last_error < time() - 3600 * 24 * 3)
606 649
 		{
@@ -616,8 +659,9 @@  discard block
 block discarded – undo
616 659
 					foreach ($tables as $table)
617 660
 					{
618 661
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
619
-						if (trim($table) != '')
620
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
662
+						if (trim($table) != '') {
663
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
664
+						}
621 665
 					}
622 666
 				}
623 667
 
@@ -626,8 +670,9 @@  discard block
 block discarded – undo
626 670
 			// Table crashed.  Let's try to fix it.
627 671
 			elseif ($query_errno == 1016)
628 672
 			{
629
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
630
-					$fix_tables = array('`' . $match[1] . '`');
673
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
674
+									$fix_tables = array('`' . $match[1] . '`');
675
+				}
631 676
 			}
632 677
 			// Indexes crashed.  Should be easy to fix!
633 678
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -646,13 +691,15 @@  discard block
 block discarded – undo
646 691
 
647 692
 			// Make a note of the REPAIR...
648 693
 			cache_put_data('db_last_error', time(), 600);
649
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
650
-				updateSettingsFile(array('db_last_error' => time()));
694
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
695
+							updateSettingsFile(array('db_last_error' => time()));
696
+			}
651 697
 
652 698
 			// Attempt to find and repair the broken table.
653
-			foreach ($fix_tables as $table)
654
-				$smcFunc['db_query']('', "
699
+			foreach ($fix_tables as $table) {
700
+							$smcFunc['db_query']('', "
655 701
 					REPAIR TABLE $table", false, false);
702
+			}
656 703
 
657 704
 			// And send off an email!
658 705
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -661,11 +708,12 @@  discard block
 block discarded – undo
661 708
 
662 709
 			// Try the query again...?
663 710
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
664
-			if ($ret !== false)
665
-				return $ret;
711
+			if ($ret !== false) {
712
+							return $ret;
713
+			}
714
+		} else {
715
+					$modSettings['cache_enable'] = $old_cache;
666 716
 		}
667
-		else
668
-			$modSettings['cache_enable'] = $old_cache;
669 717
 
670 718
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
671 719
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -675,22 +723,25 @@  discard block
 block discarded – undo
675 723
 				// Are we in SSI mode?  If so try that username and password first
676 724
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
677 725
 				{
678
-					if (empty($db_persist))
679
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
680
-					else
681
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
726
+					if (empty($db_persist)) {
727
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
728
+					} else {
729
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
730
+					}
682 731
 				}
683 732
 				// Fall back to the regular username and password if need be
684 733
 				if (!$db_connection)
685 734
 				{
686
-					if (empty($db_persist))
687
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
688
-					else
689
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
735
+					if (empty($db_persist)) {
736
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
737
+					} else {
738
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
739
+					}
690 740
 				}
691 741
 
692
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
693
-					$db_connection = false;
742
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
743
+									$db_connection = false;
744
+				}
694 745
 			}
695 746
 
696 747
 			if ($db_connection)
@@ -701,24 +752,27 @@  discard block
 block discarded – undo
701 752
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
702 753
 
703 754
 					$new_errno = mysqli_errno($db_connection);
704
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
705
-						break;
755
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
756
+											break;
757
+					}
706 758
 				}
707 759
 
708 760
 				// If it failed again, shucks to be you... we're not trying it over and over.
709
-				if ($ret !== false)
710
-					return $ret;
761
+				if ($ret !== false) {
762
+									return $ret;
763
+				}
711 764
 			}
712 765
 		}
713 766
 		// Are they out of space, perhaps?
714 767
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
715 768
 		{
716
-			if (!isset($txt))
717
-				$query_error .= ' - check database storage space.';
718
-			else
769
+			if (!isset($txt)) {
770
+							$query_error .= ' - check database storage space.';
771
+			} else
719 772
 			{
720
-				if (!isset($txt['mysql_error_space']))
721
-					loadLanguage('Errors');
773
+				if (!isset($txt['mysql_error_space'])) {
774
+									loadLanguage('Errors');
775
+				}
722 776
 
723 777
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
724 778
 			}
@@ -726,15 +780,17 @@  discard block
 block discarded – undo
726 780
 	}
727 781
 
728 782
 	// Nothing's defined yet... just die with it.
729
-	if (empty($context) || empty($txt))
730
-		die($query_error);
783
+	if (empty($context) || empty($txt)) {
784
+			die($query_error);
785
+	}
731 786
 
732 787
 	// Show an error message, if possible.
733 788
 	$context['error_title'] = $txt['database_error'];
734
-	if (allowedTo('admin_forum'))
735
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
736
-	else
737
-		$context['error_message'] = $txt['try_again'];
789
+	if (allowedTo('admin_forum')) {
790
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
791
+	} else {
792
+			$context['error_message'] = $txt['try_again'];
793
+	}
738 794
 
739 795
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
740 796
 	{
@@ -763,25 +819,28 @@  discard block
 block discarded – undo
763 819
 	$connection = $connection === null ? $db_connection : $connection;
764 820
 
765 821
 	// With nothing to insert, simply return.
766
-	if (empty($data))
767
-		return;
822
+	if (empty($data)) {
823
+			return;
824
+	}
768 825
 
769 826
 	// Replace the prefix holder with the actual prefix.
770 827
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
771 828
 
772 829
 	// Inserting data as a single row can be done as a single array.
773
-	if (!is_array($data[array_rand($data)]))
774
-		$data = array($data);
830
+	if (!is_array($data[array_rand($data)])) {
831
+			$data = array($data);
832
+	}
775 833
 
776 834
 	// Create the mold for a single row insert.
777 835
 	$insertData = '(';
778 836
 	foreach ($columns as $columnName => $type)
779 837
 	{
780 838
 		// Are we restricting the length?
781
-		if (strpos($type, 'string-') !== false)
782
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
783
-		else
784
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
839
+		if (strpos($type, 'string-') !== false) {
840
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
841
+		} else {
842
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
843
+		}
785 844
 	}
786 845
 	$insertData = substr($insertData, 0, -2) . ')';
787 846
 
@@ -790,8 +849,9 @@  discard block
 block discarded – undo
790 849
 
791 850
 	// Here's where the variables are injected to the query.
792 851
 	$insertRows = array();
793
-	foreach ($data as $dataRow)
794
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
852
+	foreach ($data as $dataRow) {
853
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
854
+	}
795 855
 
796 856
 	// Determine the method of insertion.
797 857
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -822,8 +882,9 @@  discard block
 block discarded – undo
822 882
  */
823 883
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
824 884
 {
825
-	if (empty($log_message))
826
-		$log_message = $error_message;
885
+	if (empty($log_message)) {
886
+			$log_message = $error_message;
887
+	}
827 888
 
828 889
 	foreach (debug_backtrace() as $step)
829 890
 	{
@@ -842,12 +903,14 @@  discard block
 block discarded – undo
842 903
 	}
843 904
 
844 905
 	// A special case - we want the file and line numbers for debugging.
845
-	if ($error_type == 'return')
846
-		return array($file, $line);
906
+	if ($error_type == 'return') {
907
+			return array($file, $line);
908
+	}
847 909
 
848 910
 	// Is always a critical error.
849
-	if (function_exists('log_error'))
850
-		log_error($log_message, 'critical', $file, $line);
911
+	if (function_exists('log_error')) {
912
+			log_error($log_message, 'critical', $file, $line);
913
+	}
851 914
 
852 915
 	if (function_exists('fatal_error'))
853 916
 	{
@@ -855,12 +918,12 @@  discard block
 block discarded – undo
855 918
 
856 919
 		// Cannot continue...
857 920
 		exit;
921
+	} elseif ($error_type) {
922
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
923
+	} else {
924
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
925
+	}
858 926
 	}
859
-	elseif ($error_type)
860
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
861
-	else
862
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
863
-}
864 927
 
865 928
 /**
866 929
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -877,10 +940,11 @@  discard block
 block discarded – undo
877 940
 		'\\' => '\\\\',
878 941
 	);
879 942
 
880
-	if ($translate_human_wildcards)
881
-		$replacements += array(
943
+	if ($translate_human_wildcards) {
944
+			$replacements += array(
882 945
 			'*' => '%',
883 946
 		);
947
+	}
884 948
 
885 949
 	return strtr($string, $replacements);
886 950
 }
@@ -894,8 +958,9 @@  discard block
 block discarded – undo
894 958
  */
895 959
 function smf_is_resource($result)
896 960
 {
897
-	if ($result instanceof mysqli_result)
898
-		return true;
961
+	if ($result instanceof mysqli_result) {
962
+			return true;
963
+	}
899 964
 
900 965
 	return false;
901 966
 }
Please login to merge, or discard this patch.