Completed
Pull Request — release-2.1 (#3761)
by Rick
07:38
created
Sources/Memberlist.php 1 patch
Braces   +78 added lines, -61 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
  * Shows a listing of registered members.
@@ -110,8 +111,9 @@  discard block
 block discarded – undo
110 111
 
111 112
 	$context['custom_profile_fields'] = getCustFieldsMList();
112 113
 
113
-	if (!empty($context['custom_profile_fields']['columns']))
114
-		$context['columns'] += $context['custom_profile_fields']['columns'];
114
+	if (!empty($context['custom_profile_fields']['columns'])) {
115
+			$context['columns'] += $context['custom_profile_fields']['columns'];
116
+	}
115 117
 
116 118
 	$context['colspan'] = 0;
117 119
 	$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
@@ -147,12 +149,12 @@  discard block
 block discarded – undo
147 149
 	call_integration_hook('integrate_memberlist_buttons');
148 150
 
149 151
 	// Jump to the sub action.
150
-	if (isset($subActions[$context['listing_by']]))
151
-		call_helper($subActions[$context['listing_by']][1]);
152
-
153
-	else
154
-		call_helper($subActions['all'][1]);
155
-}
152
+	if (isset($subActions[$context['listing_by']])) {
153
+			call_helper($subActions[$context['listing_by']][1]);
154
+	} else {
155
+			call_helper($subActions['all'][1]);
156
+	}
157
+	}
156 158
 
157 159
 /**
158 160
  * List all members, page by page, with sorting.
@@ -177,8 +179,9 @@  discard block
 block discarded – undo
177 179
 	if ($use_cache)
178 180
 	{
179 181
 		// Maybe there's something cached already.
180
-		if (!empty($modSettings['memberlist_cache']))
181
-			$memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true);
182
+		if (!empty($modSettings['memberlist_cache'])) {
183
+					$memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true);
184
+		}
182 185
 
183 186
 		// The chunk size for the cached index.
184 187
 		$cache_step_size = 500;
@@ -234,13 +237,15 @@  discard block
 block discarded – undo
234 237
 	}
235 238
 
236 239
 	// Set defaults for sort (real_name) and start. (0)
237
-	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
238
-		$_REQUEST['sort'] = 'real_name';
240
+	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
241
+			$_REQUEST['sort'] = 'real_name';
242
+	}
239 243
 
240 244
 	if (!is_numeric($_REQUEST['start']))
241 245
 	{
242
-		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0)
243
-			fatal_error('Hacker?', false);
246
+		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) {
247
+					fatal_error('Hacker?', false);
248
+		}
244 249
 
245 250
 		$_REQUEST['start'] = $match[0];
246 251
 
@@ -259,16 +264,18 @@  discard block
 block discarded – undo
259 264
 	}
260 265
 
261 266
 	$context['letter_links'] = '';
262
-	for ($i = 97; $i < 123; $i++)
263
-		$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
267
+	for ($i = 97; $i < 123; $i++) {
268
+			$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
269
+	}
264 270
 
265 271
 	// Sort out the column information.
266 272
 	foreach ($context['columns'] as $col => $column_details)
267 273
 	{
268 274
 		$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0';
269 275
 
270
-		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
271
-			$context['columns'][$col]['href'] .= ';desc';
276
+		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
277
+					$context['columns'][$col]['href'] .= ';desc';
278
+		}
272 279
 
273 280
 		$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
274 281
 		$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -317,8 +324,9 @@  discard block
 block discarded – undo
317 324
 	elseif ($use_cache && $_REQUEST['sort'] === 'real_name')
318 325
 	{
319 326
 		$first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
320
-		if ($first_offset < 0)
321
-			$first_offset = 0;
327
+		if ($first_offset < 0) {
328
+					$first_offset = 0;
329
+		}
322 330
 		$second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
323 331
 
324 332
 		$where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
@@ -395,12 +403,13 @@  discard block
 block discarded – undo
395 403
 		)
396 404
 	);
397 405
 	$context['custom_search_fields'] = array();
398
-	while ($row = $smcFunc['db_fetch_assoc']($request))
399
-		$context['custom_search_fields'][$row['col_name']] = array(
406
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
407
+			$context['custom_search_fields'][$row['col_name']] = array(
400 408
 			'colname' => $row['col_name'],
401 409
 			'name' => $row['field_name'],
402 410
 			'desc' => $row['field_desc'],
403 411
 		);
412
+	}
404 413
 	$smcFunc['db_free_result']($request);
405 414
 
406 415
 	// They're searching..
@@ -413,23 +422,27 @@  discard block
 block discarded – undo
413 422
 		$context['old_search_value'] = urlencode($_REQUEST['search']);
414 423
 
415 424
 		// No fields?  Use default...
416
-		if (empty($_POST['fields']))
417
-			$_POST['fields'] = array('name');
425
+		if (empty($_POST['fields'])) {
426
+					$_POST['fields'] = array('name');
427
+		}
418 428
 
419 429
 		// Set defaults for how the results are sorted
420
-		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
421
-			$_REQUEST['sort'] = 'real_name';
430
+		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
431
+					$_REQUEST['sort'] = 'real_name';
432
+		}
422 433
 
423 434
 		// Build the column link / sort information.
424 435
 		foreach ($context['columns'] as $col => $column_details)
425 436
 		{
426 437
 			$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col;
427 438
 
428
-			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
429
-				$context['columns'][$col]['href'] .= ';desc';
439
+			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
440
+							$context['columns'][$col]['href'] .= ';desc';
441
+			}
430 442
 
431
-			if (isset($_POST['search']) && isset($_POST['fields']))
432
-				$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
443
+			if (isset($_POST['search']) && isset($_POST['fields'])) {
444
+							$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
445
+			}
433 446
 
434 447
 			$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
435 448
 			$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -452,8 +465,7 @@  discard block
 block discarded – undo
452 465
 		{
453 466
 			$fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name');
454 467
 			$search_fields[] = 'name';
455
-		}
456
-		else
468
+		} else
457 469
 		{
458 470
 			$fields = array();
459 471
 			$search_fields = array();
@@ -478,9 +490,10 @@  discard block
 block discarded – undo
478 490
 			$search_fields[] = 'email';
479 491
 		}
480 492
 
481
-		if ($smcFunc['db_case_sensitive'])
482
-			foreach ($fields as $key => $field)
493
+		if ($smcFunc['db_case_sensitive']) {
494
+					foreach ($fields as $key => $field)
483 495
 				$fields[$key] = 'LOWER(' . $field . ')';
496
+		}
484 497
 
485 498
 		$customJoin = array();
486 499
 		$customCount = 10;
@@ -499,8 +512,9 @@  discard block
 block discarded – undo
499 512
 		}
500 513
 
501 514
 		// No search fields? That means you're trying to hack things
502
-		if (empty($search_fields))
503
-			fatal_lang_error('invalid_search_string', false);
515
+		if (empty($search_fields)) {
516
+					fatal_lang_error('invalid_search_string', false);
517
+		}
504 518
 
505 519
 		$query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}');
506 520
 
@@ -538,8 +552,7 @@  discard block
 block discarded – undo
538 552
 		);
539 553
 		printMemberListRows($request);
540 554
 		$smcFunc['db_free_result']($request);
541
-	}
542
-	else
555
+	} else
543 556
 	{
544 557
 		// These are all the possible fields.
545 558
 		$context['search_fields'] = array(
@@ -554,14 +567,14 @@  discard block
 block discarded – undo
554 567
 		{
555 568
 			unset($context['search_fields']['email']);
556 569
 			$context['search_defaults'] = array('name');
557
-		}
558
-		else
570
+		} else
559 571
 		{
560 572
 			$context['search_defaults'] = array('name', 'email');
561 573
 		}
562 574
 
563
-		foreach ($context['custom_search_fields'] as $field)
564
-			$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
575
+		foreach ($context['custom_search_fields'] as $field) {
576
+					$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
577
+		}
565 578
 
566 579
 		$context['sub_template'] = 'search';
567 580
 		$context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : '');
@@ -603,12 +616,14 @@  discard block
 block discarded – undo
603 616
 	$smcFunc['db_free_result']($result);
604 617
 
605 618
 	// Avoid division by zero...
606
-	if ($most_posts == 0)
607
-		$most_posts = 1;
619
+	if ($most_posts == 0) {
620
+			$most_posts = 1;
621
+	}
608 622
 
609 623
 	$members = array();
610
-	while ($row = $smcFunc['db_fetch_assoc']($request))
611
-		$members[] = $row['id_member'];
624
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
625
+			$members[] = $row['id_member'];
626
+	}
612 627
 
613 628
 	// Load all the members for display.
614 629
 	loadMemberData($members);
@@ -616,8 +631,9 @@  discard block
 block discarded – undo
616 631
 	$context['members'] = array();
617 632
 	foreach ($members as $member)
618 633
 	{
619
-		if (!loadMemberContext($member))
620
-			continue;
634
+		if (!loadMemberContext($member)) {
635
+					continue;
636
+		}
621 637
 
622 638
 		$context['members'][$member] = $memberContext[$member];
623 639
 		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
@@ -634,20 +650,21 @@  discard block
 block discarded – undo
634 650
 					continue;
635 651
 				}
636 652
 
637
-				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key]))
638
-					$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
639
-
640
-				elseif ($column['type'] == 'check')
641
-					$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
653
+				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) {
654
+									$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
655
+				} elseif ($column['type'] == 'check') {
656
+									$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
657
+				}
642 658
 
643 659
 				// Enclosing the user input within some other text?
644
-				if (!empty($column['enclose']))
645
-					$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
660
+				if (!empty($column['enclose'])) {
661
+									$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
646 662
 						'{SCRIPTURL}' => $scripturl,
647 663
 						'{IMAGES_URL}' => $settings['images_url'],
648 664
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
649 665
 						'{INPUT}' => $context['members'][$member]['options'][$key],
650 666
 					));
667
+				}
651 668
 			}
652 669
 		}
653 670
 	}
@@ -688,17 +705,17 @@  discard block
 block discarded – undo
688 705
 		);
689 706
 
690 707
 		// Get the right sort method depending on the cust field type.
691
-		if ($row['field_type'] != 'check')
692
-			$cpf['columns'][$row['col_name']]['sort'] = array(
708
+		if ($row['field_type'] != 'check') {
709
+					$cpf['columns'][$row['col_name']]['sort'] = array(
693 710
 				'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC',
694 711
 				'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC'
695 712
 			);
696
-
697
-		else
698
-			$cpf['columns'][$row['col_name']]['sort'] = array(
713
+		} else {
714
+					$cpf['columns'][$row['col_name']]['sort'] = array(
699 715
 				'down' => 't' . $row['col_name'] . '.value DESC',
700 716
 				'up' => 't' . $row['col_name'] . '.value ASC'
701 717
 			);
718
+		}
702 719
 
703 720
 		$cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' .  $row['col_name'] . ' ON (t' .  $row['col_name'] . '.variable = {literal:' .  $row['col_name'] . '} AND t' .  $row['col_name'] . '.id_theme = 1 AND t' .  $row['col_name'] . '.id_member = mem.id_member)';
704 721
 	}
Please login to merge, or discard this patch.
Sources/DbExtra-postgresql.php 1 patch
Braces   +37 added lines, -27 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -32,7 +33,8 @@  discard block
 block discarded – undo
32 33
 			'db_get_version' => 'smf_db_get_version',
33 34
 			'db_get_engine' => 'smf_db_get_engine',
34 35
 		);
35
-}
36
+	}
37
+	}
36 38
 
37 39
 /**
38 40
  * Backup $table to $backup_table.
@@ -48,13 +50,14 @@  discard block
 block discarded – undo
48 50
 
49 51
 	// Do we need to drop it first?
50 52
 	$tables = smf_db_list_tables(false, $backup_table);
51
-	if (!empty($tables))
52
-		$smcFunc['db_query']('', '
53
+	if (!empty($tables)) {
54
+			$smcFunc['db_query']('', '
53 55
 			DROP TABLE {raw:backup_table}',
54 56
 			array(
55 57
 				'backup_table' => $backup_table,
56 58
 			)
57 59
 		);
60
+	}
58 61
 
59 62
 	/**
60 63
 	 * @todo Should we create backups of sequences as well?
@@ -117,8 +120,9 @@  discard block
 block discarded – undo
117 120
 			)
118 121
 		);
119 122
 
120
-	if (!$request)
121
-		return -1;
123
+	if (!$request) {
124
+			return -1;
125
+	}
122 126
 
123 127
 	$request = $smcFunc['db_query']('', '
124 128
 		SELECT pg_relation_size(C.oid) AS "size"
@@ -136,11 +140,12 @@  discard block
 block discarded – undo
136 140
 	$row = $smcFunc['db_fetch_assoc']($request);
137 141
 	$smcFunc['db_free_result']($request);
138 142
 
139
-	if (isset($row['size']))
140
-			return ($old_size - $row['size']) / 1024;
141
-	else
142
-		return 0;
143
-}
143
+	if (isset($row['size'])) {
144
+				return ($old_size - $row['size']) / 1024;
145
+	} else {
146
+			return 0;
147
+	}
148
+	}
144 149
 
145 150
 /**
146 151
  * This function lists all tables in the database.
@@ -167,8 +172,9 @@  discard block
 block discarded – undo
167 172
 	);
168 173
 
169 174
 	$tables = array();
170
-	while ($row = $smcFunc['db_fetch_row']($request))
171
-		$tables[] = $row[0];
175
+	while ($row = $smcFunc['db_fetch_row']($request)) {
176
+			$tables[] = $row[0];
177
+	}
172 178
 	$smcFunc['db_free_result']($request);
173 179
 
174 180
 	return $tables;
@@ -209,12 +215,14 @@  discard block
 block discarded – undo
209 215
 	);
210 216
 	while ($row = $smcFunc['db_fetch_assoc']($result))
211 217
 	{
212
-		if ($row['data_type'] == 'character varying')
213
-			$row['data_type'] = 'varchar';
214
-		elseif ($row['data_type'] == 'character')
215
-			$row['data_type'] = 'char';
216
-		if ($row['character_maximum_length'])
217
-			$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
218
+		if ($row['data_type'] == 'character varying') {
219
+					$row['data_type'] = 'varchar';
220
+		} elseif ($row['data_type'] == 'character') {
221
+					$row['data_type'] = 'char';
222
+		}
223
+		if ($row['character_maximum_length']) {
224
+					$row['data_type'] .= '(' . $row['character_maximum_length'] . ')';
225
+		}
218 226
 
219 227
 		// Make the CREATE for this column.
220 228
 		$schema_create .= ' "' . $row['column_name'] . '" ' . $row['data_type'] . ($row['is_nullable'] != 'YES' ? ' NOT NULL' : '');
@@ -265,13 +273,14 @@  discard block
 block discarded – undo
265 273
 	{
266 274
 		if ($row['is_primary'])
267 275
 		{
268
-			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
269
-				continue;
276
+			if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
277
+							continue;
278
+			}
270 279
 
271 280
 			$index_create .= $crlf . 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY ("' . $matches[1] . '");';
281
+		} else {
282
+					$index_create .= $crlf . $row['inddef'] . ';';
272 283
 		}
273
-		else
274
-			$index_create .= $crlf . $row['inddef'] . ';';
275 284
 	}
276 285
 	$smcFunc['db_free_result']($result);
277 286
 
@@ -289,8 +298,9 @@  discard block
 block discarded – undo
289 298
 {
290 299
 	static $ver;
291 300
 
292
-	if(!empty($ver))
293
-		return $ver;
301
+	if(!empty($ver)) {
302
+			return $ver;
303
+	}
294 304
 
295 305
 	global $smcFunc;
296 306
 
Please login to merge, or discard this patch.
Sources/ManageScheduledTasks.php 1 patch
Braces   +54 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -40,10 +41,11 @@  discard block
 block discarded – undo
40 41
 	);
41 42
 
42 43
 	// We need to find what's the action.
43
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
44
-		$context['sub_action'] = $_REQUEST['sa'];
45
-	else
46
-		$context['sub_action'] = 'tasks';
44
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
45
+			$context['sub_action'] = $_REQUEST['sa'];
46
+	} else {
47
+			$context['sub_action'] = 'tasks';
48
+	}
47 49
 
48 50
 	// Now for the lovely tabs. That we all love.
49 51
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -90,9 +92,10 @@  discard block
 block discarded – undo
90 92
 
91 93
 		// Enable and disable as required.
92 94
 		$enablers = array(0);
93
-		foreach ($_POST['enable_task'] as $id => $enabled)
94
-			if ($enabled)
95
+		foreach ($_POST['enable_task'] as $id => $enabled) {
96
+					if ($enabled)
95 97
 				$enablers[] = (int) $id;
98
+		}
96 99
 
97 100
 		// Do the update!
98 101
 		$smcFunc['db_query']('', '
@@ -130,8 +133,9 @@  discard block
 block discarded – undo
130 133
 
131 134
 		// Lets figure out which ones they want to run.
132 135
 		$tasks = array();
133
-		foreach ($_POST['run_task'] as $task => $dummy)
134
-			$tasks[] = (int) $task;
136
+		foreach ($_POST['run_task'] as $task => $dummy) {
137
+					$tasks[] = (int) $task;
138
+		}
135 139
 
136 140
 		// Load up the tasks.
137 141
 		$request = $smcFunc['db_query']('', '
@@ -151,36 +155,41 @@  discard block
 block discarded – undo
151 155
 		while ($row = $smcFunc['db_fetch_assoc']($request))
152 156
 		{
153 157
 			// What kind of task are we handling?
154
-			if (!empty($row['callable']))
155
-				$task_string = $row['callable'];
158
+			if (!empty($row['callable'])) {
159
+							$task_string = $row['callable'];
160
+			}
156 161
 
157 162
 			// Default SMF task or old mods?
158
-			elseif (function_exists('scheduled_' . $row['task']))
159
-				$task_string = 'scheduled_' . $row['task'];
163
+			elseif (function_exists('scheduled_' . $row['task'])) {
164
+							$task_string = 'scheduled_' . $row['task'];
165
+			}
160 166
 
161 167
 			// One last resource, the task name.
162
-			elseif (!empty($row['task']))
163
-				$task_string = $row['task'];
168
+			elseif (!empty($row['task'])) {
169
+							$task_string = $row['task'];
170
+			}
164 171
 
165 172
 			$start_time = microtime();
166 173
 			// The functions got to exist for us to use it.
167
-			if (empty($task_string))
168
-				continue;
174
+			if (empty($task_string)) {
175
+							continue;
176
+			}
169 177
 
170 178
 			// Try to stop a timeout, this would be bad...
171 179
 			@set_time_limit(300);
172
-			if (function_exists('apache_reset_timeout'))
173
-				@apache_reset_timeout();
180
+			if (function_exists('apache_reset_timeout')) {
181
+							@apache_reset_timeout();
182
+			}
174 183
 
175 184
 			// Get the callable.
176 185
 			$callable_task = call_helper($task_string, true);
177 186
 
178 187
 			// Perform the task.
179
-			if (!empty($callable_task))
180
-				$completed = call_user_func($callable_task);
181
-
182
-			else
183
-				$completed = false;
188
+			if (!empty($callable_task)) {
189
+							$completed = call_user_func($callable_task);
190
+			} else {
191
+							$completed = false;
192
+			}
184 193
 
185 194
 			// Log that we did it ;)
186 195
 			if ($completed)
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 		$smcFunc['db_free_result']($request);
198 207
 
199 208
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
200
-		if (!empty($context['scheduled_errors']))
201
-			$_SESSION['st_error'] = $context['scheduled_errors'];
209
+		if (!empty($context['scheduled_errors'])) {
210
+					$_SESSION['st_error'] = $context['scheduled_errors'];
211
+		}
202 212
 
203 213
 		redirectexit('action=admin;area=scheduledtasks;done');
204 214
 	}
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 	$context['server_time'] = timeformat(time(), false, 'server');
371 381
 
372 382
 	// Cleaning...
373
-	if (!isset($_GET['tid']))
374
-		fatal_lang_error('no_access', false);
383
+	if (!isset($_GET['tid'])) {
384
+			fatal_lang_error('no_access', false);
385
+	}
375 386
 	$_GET['tid'] = (int) $_GET['tid'];
376 387
 
377 388
 	// Saving?
@@ -387,10 +398,12 @@  discard block
 block discarded – undo
387 398
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
388 399
 
389 400
 		// If a half is empty then assume zero offset!
390
-		if (!isset($matches[2]) || $matches[2] > 59)
391
-			$matches[2] = 0;
392
-		if (!isset($matches[1]) || $matches[1] > 23)
393
-			$matches[1] = 0;
401
+		if (!isset($matches[2]) || $matches[2] > 59) {
402
+					$matches[2] = 0;
403
+		}
404
+		if (!isset($matches[1]) || $matches[1] > 23) {
405
+					$matches[1] = 0;
406
+		}
394 407
 
395 408
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
396 409
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -400,8 +413,9 @@  discard block
 block discarded – undo
400 413
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
401 414
 
402 415
 		// Don't allow one minute intervals.
403
-		if ($interval == 1 && $unit == 'm')
404
-			$interval = 2;
416
+		if ($interval == 1 && $unit == 'm') {
417
+					$interval = 2;
418
+		}
405 419
 
406 420
 		// Is it disabled?
407 421
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -439,8 +453,9 @@  discard block
 block discarded – undo
439 453
 	);
440 454
 
441 455
 	// Should never, ever, happen!
442
-	if ($smcFunc['db_num_rows']($request) == 0)
443
-		fatal_lang_error('no_access', false);
456
+	if ($smcFunc['db_num_rows']($request) == 0) {
457
+			fatal_lang_error('no_access', false);
458
+	}
444 459
 
445 460
 	while ($row = $smcFunc['db_fetch_assoc']($request))
446 461
 	{
@@ -598,13 +613,14 @@  discard block
 block discarded – undo
598 613
 		)
599 614
 	);
600 615
 	$log_entries = array();
601
-	while ($row = $smcFunc['db_fetch_assoc']($request))
602
-		$log_entries[] = array(
616
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
617
+			$log_entries[] = array(
603 618
 			'id' => $row['id_log'],
604 619
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
605 620
 			'time_run' => $row['time_run'],
606 621
 			'time_taken' => $row['time_taken'],
607 622
 		);
623
+	}
608 624
 	$smcFunc['db_free_result']($request);
609 625
 
610 626
 	return $log_entries;
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 1 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-Menu.php 1 patch
Braces   +87 added lines, -63 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
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,41 +116,45 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124
-						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125
-							$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
126
-						elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
127
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
128
-						elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
129
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
130
-						elseif (isset($area['icon']))
131
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
132
-						else
133
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
134
-
135
-						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
136
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
137
-						elseif (isset($area['icon']))
132
+						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') {
133
+													$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
134
+						} elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) {
135
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
136
+						} elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) {
137
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
138
+						} elseif (isset($area['icon'])) {
139
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
140
+						} else {
141
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
142
+						}
143
+
144
+						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) {
145
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
146
+						} elseif (isset($area['icon']))
138 147
 						{
139
-							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
140
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
141
-							elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
142
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
148
+							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) {
149
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
150
+							} elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) {
151
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
152
+							}
143 153
 
144 154
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
155
+						} else {
156
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
145 157
 						}
146
-						else
147
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
148 158
 
149 159
 						// Some areas may be listed but not active, which we show as greyed out.
150 160
 						$menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']);
@@ -158,35 +168,41 @@  discard block
 block discarded – undo
158 168
 							{
159 169
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
160 170
 								{
161
-									if ($first_sa == null)
162
-										$first_sa = $sa;
171
+									if ($first_sa == null) {
172
+																			$first_sa = $sa;
173
+									}
163 174
 
164 175
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
165 176
 									// Custom URL?
166
-									if (isset($sub['url']))
167
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
177
+									if (isset($sub['url'])) {
178
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
179
+									}
168 180
 
169 181
 									// A bit complicated - but is this set?
170 182
 									if ($menu_context['current_area'] == $area_id)
171 183
 									{
172 184
 										// Save which is the first...
173
-										if (empty($first_sa))
174
-											$first_sa = $sa;
185
+										if (empty($first_sa)) {
186
+																					$first_sa = $sa;
187
+										}
175 188
 
176 189
 										// Is this the current subsection?
177
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
178
-											$menu_context['current_subsection'] = $sa;
190
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
191
+																					$menu_context['current_subsection'] = $sa;
192
+										}
179 193
 										// Otherwise is it the default?
180
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
181
-											$menu_context['current_subsection'] = $sa;
194
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
195
+																					$menu_context['current_subsection'] = $sa;
196
+										}
182 197
 									}
183 198
 
184 199
 									// Let's assume this is the last, for now.
185 200
 									$last_sa = $sa;
186 201
 								}
187 202
 								// Mark it as disabled...
188
-								else
189
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
203
+								else {
204
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
205
+								}
190 206
 							}
191 207
 
192 208
 							// Set which one is first, last and selected in the group.
@@ -195,8 +211,9 @@  discard block
 block discarded – undo
195 211
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
196 212
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
197 213
 
198
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
199
-									$menu_context['current_subsection'] = $first_sa;
214
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
215
+																	$menu_context['current_subsection'] = $first_sa;
216
+								}
200 217
 							}
201 218
 						}
202 219
 					}
@@ -230,23 +247,26 @@  discard block
 block discarded – undo
230 247
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
231 248
 
232 249
 	// If we didn't find the area we were looking for go to a default one.
233
-	if (isset($backup_area) && empty($found_section))
234
-		$menu_context['current_area'] = $backup_area;
250
+	if (isset($backup_area) && empty($found_section)) {
251
+			$menu_context['current_area'] = $backup_area;
252
+	}
235 253
 
236 254
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
237 255
 	if (!empty($menu_context['current_section']))
238 256
 	{
239 257
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
240 258
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
241
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
242
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
259
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
260
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
261
+		}
243 262
 
244
-		foreach ($menu_context['sections'] as $section_id => $section)
245
-			foreach ($section['areas'] as $area_id => $area)
263
+		foreach ($menu_context['sections'] as $section_id => $section) {
264
+					foreach ($section['areas'] as $area_id => $area)
246 265
 			{
247 266
 				if (!isset($menu_context['sections'][$section_id]['url']))
248 267
 				{
249 268
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
269
+		}
250 270
 					break;
251 271
 				}
252 272
 			}
@@ -257,8 +277,9 @@  discard block
 block discarded – undo
257 277
 	{
258 278
 		// Never happened!
259 279
 		$context['max_menu_id']--;
260
-		if ($context['max_menu_id'] == 0)
261
-			unset($context['max_menu_id']);
280
+		if ($context['max_menu_id'] == 0) {
281
+					unset($context['max_menu_id']);
282
+		}
262 283
 
263 284
 		return false;
264 285
 	}
@@ -269,8 +290,9 @@  discard block
 block discarded – undo
269 290
 	$context['template_layers'][] = $menu_context['layer_name'];
270 291
 
271 292
 	// Check we had something - for sanity sake.
272
-	if (empty($include_data))
273
-		return false;
293
+	if (empty($include_data)) {
294
+			return false;
295
+	}
274 296
 
275 297
 	// Finally - return information on the selected item.
276 298
 	$include_data += array(
@@ -293,12 +315,14 @@  discard block
 block discarded – undo
293 315
 	global $context;
294 316
 
295 317
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
296
-	if (!isset($context[$menu_name]))
297
-		return false;
318
+	if (!isset($context[$menu_name])) {
319
+			return false;
320
+	}
298 321
 
299 322
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
300
-	if ($layer_index !== false)
301
-		unset($context['template_layers'][$layer_index]);
323
+	if ($layer_index !== false) {
324
+			unset($context['template_layers'][$layer_index]);
325
+	}
302 326
 
303 327
 	unset($context[$menu_name]);
304 328
 }
Please login to merge, or discard this patch.
Sources/Class-Package.php 1 patch
Braces   +266 added lines, -199 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
  * Class xmlArray
@@ -65,8 +66,9 @@  discard block
 block discarded – undo
65 66
 		}
66 67
 
67 68
 		// Is the input an array? (ie. passed from file()?)
68
-		if (is_array($data))
69
-			$data = implode('', $data);
69
+		if (is_array($data)) {
70
+					$data = implode('', $data);
71
+		}
70 72
 
71 73
 		// Remove any xml declaration or doctype, and parse out comments and CDATA.
72 74
 		$data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data)));
@@ -101,8 +103,9 @@  discard block
 block discarded – undo
101 103
 		// Get the element, in array form.
102 104
 		$array = $this->path($path);
103 105
 
104
-		if ($array === false)
105
-			return false;
106
+		if ($array === false) {
107
+					return false;
108
+		}
106 109
 
107 110
 		// Getting elements into this is a bit complicated...
108 111
 		if ($get_elements && !is_string($array))
@@ -113,8 +116,9 @@  discard block
 block discarded – undo
113 116
 			foreach ($array->array as $val)
114 117
 			{
115 118
 				// Skip the name and any attributes.
116
-				if (is_array($val))
117
-					$temp .= $this->_xml($val, null);
119
+				if (is_array($val)) {
120
+									$temp .= $this->_xml($val, null);
121
+				}
118 122
 			}
119 123
 
120 124
 			// Just get the XML data and then take out the CDATAs.
@@ -156,32 +160,35 @@  discard block
 block discarded – undo
156 160
 			elseif (substr($el, 0, 1) == '@')
157 161
 			{
158 162
 				// It simplifies things if the attribute is already there ;).
159
-				if (isset($array[$el]))
160
-					return $array[$el];
161
-				else
163
+				if (isset($array[$el])) {
164
+									return $array[$el];
165
+				} else
162 166
 				{
163 167
 					$trace = debug_backtrace();
164 168
 					$i = 0;
165
-					while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this))
166
-						$i++;
169
+					while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) {
170
+											$i++;
171
+					}
167 172
 					$debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')';
168 173
 
169 174
 					// Cause an error.
170
-					if ($this->debug_level & E_NOTICE)
171
-						trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE);
175
+					if ($this->debug_level & E_NOTICE) {
176
+											trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE);
177
+					}
172 178
 					return false;
173 179
 				}
180
+			} else {
181
+							$lvl = null;
174 182
 			}
175
-			else
176
-				$lvl = null;
177 183
 
178 184
 			// Find this element.
179 185
 			$array = $this->_path($array, $el, $lvl);
180 186
 		}
181 187
 
182 188
 		// Clean up after $lvl, for $return_full.
183
-		if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']'))
184
-			$array = array('name' => $el . '[]', $array);
189
+		if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) {
190
+					$array = array('name' => $el . '[]', $array);
191
+		}
185 192
 
186 193
 		// Create the right type of class...
187 194
 		$newClass = get_class($this);
@@ -216,10 +223,11 @@  discard block
 block discarded – undo
216 223
 				$el = substr($el, 0, strpos($el, '['));
217 224
 			}
218 225
 			// Find an attribute.
219
-			elseif (substr($el, 0, 1) == '@')
220
-				return isset($array[$el]);
221
-			else
222
-				$lvl = null;
226
+			elseif (substr($el, 0, 1) == '@') {
227
+							return isset($array[$el]);
228
+			} else {
229
+							$lvl = null;
230
+			}
223 231
 
224 232
 			// Find this element.
225 233
 			$array = $this->_path($array, $el, $lvl, true);
@@ -244,8 +252,9 @@  discard block
 block discarded – undo
244 252
 		$i = 0;
245 253
 		foreach ($temp->array as $item)
246 254
 		{
247
-			if (is_array($item))
248
-				$i++;
255
+			if (is_array($item)) {
256
+							$i++;
257
+			}
249 258
 		}
250 259
 
251 260
 		return $i;
@@ -269,8 +278,9 @@  discard block
 block discarded – undo
269 278
 		foreach ($xml->array as $val)
270 279
 		{
271 280
 			// Skip these, they aren't elements.
272
-			if (!is_array($val) || $val['name'] == '!')
273
-				continue;
281
+			if (!is_array($val) || $val['name'] == '!') {
282
+							continue;
283
+			}
274 284
 
275 285
 			// Create the right type of class...
276 286
 			$newClass = get_class($this);
@@ -297,14 +307,16 @@  discard block
 block discarded – undo
297 307
 			$path = $this->path($path);
298 308
 
299 309
 			// The path was not found
300
-			if ($path === false)
301
-				return false;
310
+			if ($path === false) {
311
+							return false;
312
+			}
302 313
 
303 314
 			$path = $path->array;
304 315
 		}
305 316
 		// Just use the current array.
306
-		else
307
-			$path = $this->array;
317
+		else {
318
+					$path = $this->array;
319
+		}
308 320
 
309 321
 		// Add the xml declaration to the front.
310 322
 		return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0);
@@ -326,14 +338,16 @@  discard block
 block discarded – undo
326 338
 			$path = $this->path($path);
327 339
 
328 340
 			// The path was not found
329
-			if ($path === false)
330
-				return false;
341
+			if ($path === false) {
342
+							return false;
343
+			}
331 344
 
332 345
 			$path = $path->array;
333 346
 		}
334 347
 		// No, so just use the current array.
335
-		else
336
-			$path = $this->array;
348
+		else {
349
+					$path = $this->array;
350
+		}
337 351
 
338 352
 		return $this->_array($path);
339 353
 	}
@@ -355,8 +369,9 @@  discard block
 block discarded – undo
355 369
 		{
356 370
 			// Find and remove the next tag.
357 371
 			preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match);
358
-			if (isset($match[0]))
359
-				$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1);
372
+			if (isset($match[0])) {
373
+							$data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1);
374
+			}
360 375
 
361 376
 			// Didn't find a tag?  Keep looping....
362 377
 			if (!isset($match[1]) || $match[1] == '')
@@ -367,11 +382,12 @@  discard block
 block discarded – undo
367 382
 					$text_value = $this->_from_cdata($data);
368 383
 					$data = '';
369 384
 
370
-					if ($text_value != '')
371
-						$current[] = array(
385
+					if ($text_value != '') {
386
+											$current[] = array(
372 387
 							'name' => '!',
373 388
 							'value' => $text_value
374 389
 						);
390
+					}
375 391
 				}
376 392
 				// If the < isn't immediately next to the current position... more data.
377 393
 				elseif (strpos($data, '<') > 0)
@@ -379,11 +395,12 @@  discard block
 block discarded – undo
379 395
 					$text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<')));
380 396
 					$data = substr($data, strpos($data, '<'));
381 397
 
382
-					if ($text_value != '')
383
-						$current[] = array(
398
+					if ($text_value != '') {
399
+											$current[] = array(
384 400
 							'name' => '!',
385 401
 							'value' => $text_value
386 402
 						);
403
+					}
387 404
 				}
388 405
 				// If we're looking at a </something> with no start, kill it.
389 406
 				elseif (strpos($data, '<') !== false && strpos($data, '<') == 0)
@@ -393,22 +410,23 @@  discard block
 block discarded – undo
393 410
 						$text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1)));
394 411
 						$data = substr($data, strpos($data, '<', 1));
395 412
 
396
-						if ($text_value != '')
397
-							$current[] = array(
413
+						if ($text_value != '') {
414
+													$current[] = array(
398 415
 								'name' => '!',
399 416
 								'value' => $text_value
400 417
 							);
401
-					}
402
-					else
418
+						}
419
+					} else
403 420
 					{
404 421
 						$text_value = $this->_from_cdata($data);
405 422
 						$data = '';
406 423
 
407
-						if ($text_value != '')
408
-							$current[] = array(
424
+						if ($text_value != '') {
425
+													$current[] = array(
409 426
 								'name' => '!',
410 427
 								'value' => $text_value
411 428
 							);
429
+						}
412 430
 					}
413 431
 				}
414 432
 
@@ -425,8 +443,9 @@  discard block
 block discarded – undo
425 443
 			{
426 444
 				// Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way.
427 445
 				$last_tag_end = strpos($data, '</' . $match[1]. '>');
428
-				if ($last_tag_end === false)
429
-					continue;
446
+				if ($last_tag_end === false) {
447
+									continue;
448
+				}
430 449
 
431 450
 				$offset = 0;
432 451
 				while (1 == 1)
@@ -434,16 +453,17 @@  discard block
 block discarded – undo
434 453
 					// Where is the next start tag?
435 454
 					$next_tag_start = strpos($data, '<' . $match[1], $offset);
436 455
 					// If the next start tag is after the last end tag then we've found the right close.
437
-					if ($next_tag_start === false || $next_tag_start > $last_tag_end)
438
-						break;
456
+					if ($next_tag_start === false || $next_tag_start > $last_tag_end) {
457
+											break;
458
+					}
439 459
 
440 460
 					// If not then find the next ending tag.
441 461
 					$next_tag_end = strpos($data, '</' . $match[1]. '>', $offset);
442 462
 
443 463
 					// Didn't find one? Then just use the last and sod it.
444
-					if ($next_tag_end === false)
445
-						break;
446
-					else
464
+					if ($next_tag_end === false) {
465
+											break;
466
+					} else
447 467
 					{
448 468
 						$last_tag_end = $next_tag_end;
449 469
 						$offset = $next_tag_start + 1;
@@ -457,16 +477,17 @@  discard block
 block discarded – undo
457 477
 				if (!empty($inner_match))
458 478
 				{
459 479
 					// Parse the inner data.
460
-					if (strpos($inner_match, '<') !== false)
461
-						$el += $this->_parse($inner_match);
462
-					elseif (trim($inner_match) != '')
480
+					if (strpos($inner_match, '<') !== false) {
481
+											$el += $this->_parse($inner_match);
482
+					} elseif (trim($inner_match) != '')
463 483
 					{
464 484
 						$text_value = $this->_from_cdata($inner_match);
465
-						if ($text_value != '')
466
-							$el[] = array(
485
+						if ($text_value != '') {
486
+													$el[] = array(
467 487
 								'name' => '!',
468 488
 								'value' => $text_value
469 489
 							);
490
+						}
470 491
 					}
471 492
 				}
472 493
 			}
@@ -478,8 +499,9 @@  discard block
 block discarded – undo
478 499
 				preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER);
479 500
 
480 501
 				// Set them as @attribute-name.
481
-				foreach ($attr as $match_attr)
482
-					$el['@' . $match_attr[1]] = $match_attr[2];
502
+				foreach ($attr as $match_attr) {
503
+									$el['@' . $match_attr[1]] = $match_attr[2];
504
+				}
483 505
 			}
484 506
 		}
485 507
 
@@ -503,16 +525,18 @@  discard block
 block discarded – undo
503 525
 		if (is_array($array) && !isset($array['name']))
504 526
 		{
505 527
 			$temp = '';
506
-			foreach ($array as $val)
507
-				$temp .= $this->_xml($val, $indent);
528
+			foreach ($array as $val) {
529
+							$temp .= $this->_xml($val, $indent);
530
+			}
508 531
 			return $temp;
509 532
 		}
510 533
 
511 534
 		// This is just text!
512
-		if ($array['name'] == '!')
513
-			return $indentation . '<![CDATA[' . $array['value'] . ']]>';
514
-		elseif (substr($array['name'], -2) == '[]')
515
-			$array['name'] = substr($array['name'], 0, -2);
535
+		if ($array['name'] == '!') {
536
+					return $indentation . '<![CDATA[' . $array['value'] . ']]>';
537
+		} elseif (substr($array['name'], -2) == '[]') {
538
+					$array['name'] = substr($array['name'], 0, -2);
539
+		}
516 540
 
517 541
 		// Start the element.
518 542
 		$output = $indentation . '<' . $array['name'];
@@ -523,9 +547,9 @@  discard block
 block discarded – undo
523 547
 		// Run through and recursively output all the elements or attrbutes inside this.
524 548
 		foreach ($array as $k => $v)
525 549
 		{
526
-			if (substr($k, 0, 1) == '@')
527
-				$output .= ' ' . substr($k, 1) . '="' . $v . '"';
528
-			elseif (is_array($v))
550
+			if (substr($k, 0, 1) == '@') {
551
+							$output .= ' ' . substr($k, 1) . '="' . $v . '"';
552
+			} elseif (is_array($v))
529 553
 			{
530 554
 				$output_el .= $this->_xml($v, $indent === null ? null : $indent + 1);
531 555
 				$inside_elements = true;
@@ -533,10 +557,11 @@  discard block
 block discarded – undo
533 557
 		}
534 558
 
535 559
 		// Indent, if necessary.... then close the tag.
536
-		if ($inside_elements)
537
-			$output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>';
538
-		else
539
-			$output .= ' />';
560
+		if ($inside_elements) {
561
+					$output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>';
562
+		} else {
563
+					$output .= ' />';
564
+		}
540 565
 
541 566
 		return $output;
542 567
 	}
@@ -553,19 +578,22 @@  discard block
 block discarded – undo
553 578
 		$text = '';
554 579
 		foreach ($array as $value)
555 580
 		{
556
-			if (!is_array($value) || !isset($value['name']))
557
-				continue;
581
+			if (!is_array($value) || !isset($value['name'])) {
582
+							continue;
583
+			}
558 584
 
559
-			if ($value['name'] == '!')
560
-				$text .= $value['value'];
561
-			else
562
-				$return[$value['name']] = $this->_array($value);
585
+			if ($value['name'] == '!') {
586
+							$text .= $value['value'];
587
+			} else {
588
+							$return[$value['name']] = $this->_array($value);
589
+			}
563 590
 		}
564 591
 
565
-		if (empty($return))
566
-			return $text;
567
-		else
568
-			return $return;
592
+		if (empty($return)) {
593
+					return $text;
594
+		} else {
595
+					return $return;
596
+		}
569 597
 	}
570 598
 
571 599
 	/**
@@ -583,24 +611,28 @@  discard block
 block discarded – undo
583 611
 		foreach ($parts as $part)
584 612
 		{
585 613
 			// Handle XML comments.
586
-			if (!$inCdata && $part === '<!--')
587
-				$inComment = true;
588
-			if ($inComment && $part === '-->')
589
-				$inComment = false;
590
-			elseif ($inComment)
591
-				continue;
614
+			if (!$inCdata && $part === '<!--') {
615
+							$inComment = true;
616
+			}
617
+			if ($inComment && $part === '-->') {
618
+							$inComment = false;
619
+			} elseif ($inComment) {
620
+							continue;
621
+			}
592 622
 
593 623
 			// Handle Cdata blocks.
594
-			elseif (!$inComment && $part === '<![CDATA[')
595
-				$inCdata = true;
596
-			elseif ($inCdata && $part === ']]>')
597
-				$inCdata = false;
598
-			elseif ($inCdata)
599
-				$output .= htmlentities($part, ENT_QUOTES);
624
+			elseif (!$inComment && $part === '<![CDATA[') {
625
+							$inCdata = true;
626
+			} elseif ($inCdata && $part === ']]>') {
627
+							$inCdata = false;
628
+			} elseif ($inCdata) {
629
+							$output .= htmlentities($part, ENT_QUOTES);
630
+			}
600 631
 
601 632
 			// Everything else is kept as is.
602
-			else
603
-				$output .= $part;
633
+			else {
634
+							$output .= $part;
635
+			}
604 636
 		}
605 637
 
606 638
 		return $output;
@@ -635,22 +667,26 @@  discard block
 block discarded – undo
635 667
 	protected function _fetch($array)
636 668
 	{
637 669
 		// Don't return anything if this is just a string.
638
-		if (is_string($array))
639
-			return '';
670
+		if (is_string($array)) {
671
+					return '';
672
+		}
640 673
 
641 674
 		$temp = '';
642 675
 		foreach ($array as $text)
643 676
 		{
644 677
 			// This means it's most likely an attribute or the name itself.
645
-			if (!isset($text['name']))
646
-				continue;
678
+			if (!isset($text['name'])) {
679
+							continue;
680
+			}
647 681
 
648 682
 			// This is text!
649
-			if ($text['name'] == '!')
650
-				$temp .= $text['value'];
683
+			if ($text['name'] == '!') {
684
+							$temp .= $text['value'];
685
+			}
651 686
 			// Another element - dive in ;).
652
-			else
653
-				$temp .= $this->_fetch($text);
687
+			else {
688
+							$temp .= $this->_fetch($text);
689
+			}
654 690
 		}
655 691
 
656 692
 		// Return all the bits and pieces we've put together.
@@ -669,12 +705,14 @@  discard block
 block discarded – undo
669 705
 	protected function _path($array, $path, $level, $no_error = false)
670 706
 	{
671 707
 		// Is $array even an array?  It might be false!
672
-		if (!is_array($array))
673
-			return false;
708
+		if (!is_array($array)) {
709
+					return false;
710
+		}
674 711
 
675 712
 		// Asking for *no* path?
676
-		if ($path == '' || $path == '.')
677
-			return $array;
713
+		if ($path == '' || $path == '.') {
714
+					return $array;
715
+		}
678 716
 		$paths = explode('|', $path);
679 717
 
680 718
 		// A * means all elements of any name.
@@ -685,16 +723,18 @@  discard block
 block discarded – undo
685 723
 		// Check each element.
686 724
 		foreach ($array as $value)
687 725
 		{
688
-			if (!is_array($value) || $value['name'] === '!')
689
-				continue;
726
+			if (!is_array($value) || $value['name'] === '!') {
727
+							continue;
728
+			}
690 729
 
691 730
 			if ($show_all || in_array($value['name'], $paths))
692 731
 			{
693 732
 				// Skip elements before "the one".
694
-				if ($level !== null && $level > 0)
695
-					$level--;
696
-				else
697
-					$results[] = $value;
733
+				if ($level !== null && $level > 0) {
734
+									$level--;
735
+				} else {
736
+									$results[] = $value;
737
+				}
698 738
 			}
699 739
 		}
700 740
 
@@ -703,21 +743,25 @@  discard block
 block discarded – undo
703 743
 		{
704 744
 			$trace = debug_backtrace();
705 745
 			$i = 0;
706
-			while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this))
707
-				$i++;
746
+			while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) {
747
+							$i++;
748
+			}
708 749
 			$debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'];
709 750
 
710 751
 			// Cause an error.
711
-			if ($this->debug_level & E_NOTICE && !$no_error)
712
-				trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE);
752
+			if ($this->debug_level & E_NOTICE && !$no_error) {
753
+							trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE);
754
+			}
713 755
 			return false;
714 756
 		}
715 757
 		// Only one result.
716
-		elseif (count($results) == 1 || $level !== null)
717
-			return $results[0];
758
+		elseif (count($results) == 1 || $level !== null) {
759
+					return $results[0];
760
+		}
718 761
 		// Return the result set.
719
-		else
720
-			return $results + array('name' => $path . '[]');
762
+		else {
763
+					return $results + array('name' => $path . '[]');
764
+		}
721 765
 	}
722 766
 }
723 767
 
@@ -764,8 +808,9 @@  discard block
 block discarded – undo
764 808
 		$this->error = false;
765 809
 		$this->pasv = array();
766 810
 
767
-		if ($ftp_server !== null)
768
-			$this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
811
+		if ($ftp_server !== null) {
812
+					$this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
813
+		}
769 814
 	}
770 815
 
771 816
 	/**
@@ -778,14 +823,16 @@  discard block
 block discarded – undo
778 823
 	 */
779 824
 	public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
780 825
 	{
781
-		if (strpos($ftp_server, 'ftp://') === 0)
782
-			$ftp_server = substr($ftp_server, 6);
783
-		elseif (strpos($ftp_server, 'ftps://') === 0)
784
-			$ftp_server = 'ssl://' . substr($ftp_server, 7);
785
-		if (strpos($ftp_server, 'http://') === 0)
786
-			$ftp_server = substr($ftp_server, 7);
787
-		elseif (strpos($ftp_server, 'https://') === 0)
788
-			$ftp_server = substr($ftp_server, 8);
826
+		if (strpos($ftp_server, 'ftp://') === 0) {
827
+					$ftp_server = substr($ftp_server, 6);
828
+		} elseif (strpos($ftp_server, 'ftps://') === 0) {
829
+					$ftp_server = 'ssl://' . substr($ftp_server, 7);
830
+		}
831
+		if (strpos($ftp_server, 'http://') === 0) {
832
+					$ftp_server = substr($ftp_server, 7);
833
+		} elseif (strpos($ftp_server, 'https://') === 0) {
834
+					$ftp_server = substr($ftp_server, 8);
835
+		}
789 836
 		$ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
790 837
 
791 838
 		// Connect to the FTP server.
@@ -834,12 +881,14 @@  discard block
 block discarded – undo
834 881
 	 */
835 882
 	public function chdir($ftp_path)
836 883
 	{
837
-		if (!is_resource($this->connection))
838
-			return false;
884
+		if (!is_resource($this->connection)) {
885
+					return false;
886
+		}
839 887
 
840 888
 		// No slash on the end, please...
841
-		if ($ftp_path !== '/' && substr($ftp_path, -1) === '/')
842
-			$ftp_path = substr($ftp_path, 0, -1);
889
+		if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') {
890
+					$ftp_path = substr($ftp_path, 0, -1);
891
+		}
843 892
 
844 893
 		fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
845 894
 		if (!$this->check_response(250))
@@ -860,11 +909,13 @@  discard block
 block discarded – undo
860 909
 	 */
861 910
 	public function chmod($ftp_file, $chmod)
862 911
 	{
863
-		if (!is_resource($this->connection))
864
-			return false;
912
+		if (!is_resource($this->connection)) {
913
+					return false;
914
+		}
865 915
 
866
-		if ($ftp_file == '')
867
-			$ftp_file = '.';
916
+		if ($ftp_file == '') {
917
+					$ftp_file = '.';
918
+		}
868 919
 
869 920
 		// Do we have a file or a dir?
870 921
 		$is_dir = is_dir($ftp_file);
@@ -880,9 +931,7 @@  discard block
 block discarded – undo
880 931
 			{
881 932
 				$is_writable = true;
882 933
 				break;
883
-			}
884
-
885
-			else
934
+			} else
886 935
 			{
887 936
 				// Convert the chmod value from octal (0777) to text ("777").
888 937
 				fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n");
@@ -905,8 +954,9 @@  discard block
 block discarded – undo
905 954
 	public function unlink($ftp_file)
906 955
 	{
907 956
 		// We are actually connected, right?
908
-		if (!is_resource($this->connection))
909
-			return false;
957
+		if (!is_resource($this->connection)) {
958
+					return false;
959
+		}
910 960
 
911 961
 		// Delete file X.
912 962
 		fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
@@ -935,9 +985,9 @@  discard block
 block discarded – undo
935 985
 	{
936 986
 		// Wait for a response that isn't continued with -, but don't wait too long.
937 987
 		$time = time();
938
-		do
939
-			$this->last_message = fgets($this->connection, 1024);
940
-		while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5);
988
+		do {
989
+					$this->last_message = fgets($this->connection, 1024);
990
+		} while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5);
941 991
 
942 992
 		// Was the desired response returned?
943 993
 		return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
@@ -951,15 +1001,16 @@  discard block
 block discarded – undo
951 1001
 	public function passive()
952 1002
 	{
953 1003
 		// We can't create a passive data connection without a primary one first being there.
954
-		if (!is_resource($this->connection))
955
-			return false;
1004
+		if (!is_resource($this->connection)) {
1005
+					return false;
1006
+		}
956 1007
 
957 1008
 		// Request a passive connection - this means, we'll talk to you, you don't talk to us.
958 1009
 		@fwrite($this->connection, 'PASV' . "\r\n");
959 1010
 		$time = time();
960
-		do
961
-			$response = fgets($this->connection, 1024);
962
-		while (strpos($response, ' ', 3) !== 3 && time() - $time < 5);
1011
+		do {
1012
+					$response = fgets($this->connection, 1024);
1013
+		} while (strpos($response, ' ', 3) !== 3 && time() - $time < 5);
963 1014
 
964 1015
 		// If it's not 227, we weren't given an IP and port, which means it failed.
965 1016
 		if (strpos($response, '227 ') !== 0)
@@ -990,12 +1041,14 @@  discard block
 block discarded – undo
990 1041
 	public function create_file($ftp_file)
991 1042
 	{
992 1043
 		// First, we have to be connected... very important.
993
-		if (!is_resource($this->connection))
994
-			return false;
1044
+		if (!is_resource($this->connection)) {
1045
+					return false;
1046
+		}
995 1047
 
996 1048
 		// I'd like one passive mode, please!
997
-		if (!$this->passive())
998
-			return false;
1049
+		if (!$this->passive()) {
1050
+					return false;
1051
+		}
999 1052
 
1000 1053
 		// Seems logical enough, so far...
1001 1054
 		fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
@@ -1030,12 +1083,14 @@  discard block
 block discarded – undo
1030 1083
 	public function list_dir($ftp_path = '', $search = false)
1031 1084
 	{
1032 1085
 		// Are we even connected...?
1033
-		if (!is_resource($this->connection))
1034
-			return false;
1086
+		if (!is_resource($this->connection)) {
1087
+					return false;
1088
+		}
1035 1089
 
1036 1090
 		// Passive... non-agressive...
1037
-		if (!$this->passive())
1038
-			return false;
1091
+		if (!$this->passive()) {
1092
+					return false;
1093
+		}
1039 1094
 
1040 1095
 		// Get the listing!
1041 1096
 		fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
@@ -1051,8 +1106,9 @@  discard block
 block discarded – undo
1051 1106
 
1052 1107
 		// Read in the file listing.
1053 1108
 		$data = '';
1054
-		while (!feof($fp))
1055
-			$data .= fread($fp, 4096);
1109
+		while (!feof($fp)) {
1110
+					$data .= fread($fp, 4096);
1111
+		}
1056 1112
 		fclose($fp);
1057 1113
 
1058 1114
 		// Everything go okay?
@@ -1074,21 +1130,23 @@  discard block
 block discarded – undo
1074 1130
 	 */
1075 1131
 	public function locate($file, $listing = null)
1076 1132
 	{
1077
-		if ($listing === null)
1078
-			$listing = $this->list_dir('', true);
1133
+		if ($listing === null) {
1134
+					$listing = $this->list_dir('', true);
1135
+		}
1079 1136
 		$listing = explode("\n", $listing);
1080 1137
 
1081 1138
 		@fwrite($this->connection, 'PWD' . "\r\n");
1082 1139
 		$time = time();
1083
-		do
1084
-			$response = fgets($this->connection, 1024);
1085
-		while ($response[3] != ' ' && time() - $time < 5);
1140
+		do {
1141
+					$response = fgets($this->connection, 1024);
1142
+		} while ($response[3] != ' ' && time() - $time < 5);
1086 1143
 
1087 1144
 		// Check for 257!
1088
-		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
1089
-			$current_dir = strtr($match[1], array('""' => '"'));
1090
-		else
1091
-			$current_dir = '';
1145
+		if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) {
1146
+					$current_dir = strtr($match[1], array('""' => '"'));
1147
+		} else {
1148
+					$current_dir = '';
1149
+		}
1092 1150
 
1093 1151
 		for ($i = 0, $n = count($listing); $i < $n; $i++)
1094 1152
 		{
@@ -1101,12 +1159,15 @@  discard block
 block discarded – undo
1101 1159
 			// Okay, this file's name is:
1102 1160
 			$listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
1103 1161
 
1104
-			if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
1105
-				return $listing[$i];
1106
-			if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
1107
-				return $listing[$i];
1108
-			if (basename($listing[$i]) == $file || $listing[$i] == $file)
1109
-				return $listing[$i];
1162
+			if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) {
1163
+							return $listing[$i];
1164
+			}
1165
+			if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) {
1166
+							return $listing[$i];
1167
+			}
1168
+			if (basename($listing[$i]) == $file || $listing[$i] == $file) {
1169
+							return $listing[$i];
1170
+			}
1110 1171
 		}
1111 1172
 
1112 1173
 		return false;
@@ -1121,8 +1182,9 @@  discard block
 block discarded – undo
1121 1182
 	public function create_dir($ftp_dir)
1122 1183
 	{
1123 1184
 		// We must be connected to the server to do something.
1124
-		if (!is_resource($this->connection))
1125
-			return false;
1185
+		if (!is_resource($this->connection)) {
1186
+					return false;
1187
+		}
1126 1188
 
1127 1189
 		// Make this new beautiful directory!
1128 1190
 		fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
@@ -1154,35 +1216,40 @@  discard block
 block discarded – undo
1154 1216
 
1155 1217
 				$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
1156 1218
 
1157
-				if (substr($path, -1) == '/')
1158
-					$path = substr($path, 0, -1);
1219
+				if (substr($path, -1) == '/') {
1220
+									$path = substr($path, 0, -1);
1221
+				}
1159 1222
 
1160
-				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
1161
-					$path .= dirname($_SERVER['PHP_SELF']);
1223
+				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) {
1224
+									$path .= dirname($_SERVER['PHP_SELF']);
1225
+				}
1226
+			} elseif (strpos($filesystem_path, '/var/www/') === 0) {
1227
+							$path = substr($filesystem_path, 8);
1228
+			} else {
1229
+							$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1162 1230
 			}
1163
-			elseif (strpos($filesystem_path, '/var/www/') === 0)
1164
-				$path = substr($filesystem_path, 8);
1165
-			else
1166
-				$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1231
+		} else {
1232
+					$path = '';
1167 1233
 		}
1168
-		else
1169
-			$path = '';
1170 1234
 
1171 1235
 		if (is_resource($this->connection) && $this->list_dir($path) == '')
1172 1236
 		{
1173 1237
 			$data = $this->list_dir('', true);
1174 1238
 
1175
-			if ($lookup_file === null)
1176
-				$lookup_file = $_SERVER['PHP_SELF'];
1239
+			if ($lookup_file === null) {
1240
+							$lookup_file = $_SERVER['PHP_SELF'];
1241
+			}
1177 1242
 
1178 1243
 			$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
1179
-			if ($found_path == false)
1180
-				$found_path = dirname($this->locate(basename($lookup_file)));
1181
-			if ($found_path != false)
1182
-				$path = $found_path;
1244
+			if ($found_path == false) {
1245
+							$found_path = dirname($this->locate(basename($lookup_file)));
1246
+			}
1247
+			if ($found_path != false) {
1248
+							$path = $found_path;
1249
+			}
1250
+		} elseif (is_resource($this->connection)) {
1251
+					$found_path = true;
1183 1252
 		}
1184
-		elseif (is_resource($this->connection))
1185
-			$found_path = true;
1186 1253
 
1187 1254
 		return array($username, $path, isset($found_path));
1188 1255
 	}
Please login to merge, or discard this patch.
Sources/Mentions.php 1 patch
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 			)
51 51
 		);
52 52
 		$members = array();
53
-		while ($row = $smcFunc['db_fetch_assoc']($request))
54
-			$members[$row['id_member']] = array(
53
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
54
+					$members[$row['id_member']] = array(
55 55
 				'id' => $row['id_member'],
56 56
 				'real_name' => $row['real_name'],
57 57
 				'email_address' => $row['email_address'],
@@ -62,6 +62,7 @@  discard block
 block discarded – undo
62 62
 				),
63 63
 				'lngfile' => $row['lngfile'],
64 64
 			);
65
+		}
65 66
 		$smcFunc['db_free_result']($request);
66 67
 
67 68
 		return $members;
@@ -83,13 +84,14 @@  discard block
 block discarded – undo
83 84
 
84 85
 		call_integration_hook('mention_insert_' . $content_type, array($content_id, &$members));
85 86
 
86
-		foreach ($members as $member)
87
-			$smcFunc['db_insert']('ignore',
87
+		foreach ($members as $member) {
88
+					$smcFunc['db_insert']('ignore',
88 89
 				'{db_prefix}mentions',
89 90
 				array('content_id' => 'int', 'content_type' => 'string', 'id_member' => 'int', 'id_mentioned' => 'int', 'time' => 'int'),
90 91
 				array((int) $content_id, $content_type, $id_member, $member['id'], time()),
91 92
 				array('content_id', 'content_type', 'id_mentioned')
92 93
 			);
94
+		}
93 95
 	}
94 96
 
95 97
 	/**
@@ -103,8 +105,9 @@  discard block
 block discarded – undo
103 105
 	 */
104 106
 	public static function getBody($body, array $members)
105 107
 	{
106
-		foreach ($members as $member)
107
-			$body = str_ireplace(static::$char . $member['real_name'], '[member=' . $member['id'] . ']' . $member['real_name'] . '[/member]', $body);
108
+		foreach ($members as $member) {
109
+					$body = str_ireplace(static::$char . $member['real_name'], '[member=' . $member['id'] . ']' . $member['real_name'] . '[/member]', $body);
110
+		}
108 111
 
109 112
 		return $body;
110 113
 	}
@@ -123,8 +126,9 @@  discard block
 block discarded – undo
123 126
 
124 127
 		$possible_names = self::getPossibleMentions($body);
125 128
 
126
-		if (empty($possible_names) || !allowedTo('mention'))
127
-			return array();
129
+		if (empty($possible_names) || !allowedTo('mention')) {
130
+					return array();
131
+		}
128 132
 
129 133
 		$request = $smcFunc['db_query']('', '
130 134
 			SELECT id_member, real_name
@@ -140,8 +144,9 @@  discard block
 block discarded – undo
140 144
 		$members = array();
141 145
 		while ($row = $smcFunc['db_fetch_assoc']($request))
142 146
 		{
143
-			if (stripos($body, static::$char . $row['real_name']) === false)
144
-				continue;
147
+			if (stripos($body, static::$char . $row['real_name']) === false) {
148
+							continue;
149
+			}
145 150
 
146 151
 			$members[$row['id_member']] = array(
147 152
 				'id' => $row['id_member'],
@@ -185,8 +190,9 @@  discard block
 block discarded – undo
185 190
 		$body = htmlspecialchars_decode(preg_replace('~<br\s*/?\>~', "\n", str_replace('&nbsp;', ' ', $body)), ENT_QUOTES);
186 191
 
187 192
 		// Remove quotes, we don't want to get double mentions.
188
-		while (preg_match('~\[quote[^\]]*\](.+?)\[\/quote\]~s', $body))
189
-			$body = preg_replace('~\[quote[^\]]*\](.+?)\[\/quote\]~s', '', $body);
193
+		while (preg_match('~\[quote[^\]]*\](.+?)\[\/quote\]~s', $body)) {
194
+					$body = preg_replace('~\[quote[^\]]*\](.+?)\[\/quote\]~s', '', $body);
195
+		}
190 196
 
191 197
 		$matches = array();
192 198
 		$string = str_split($body);
@@ -197,9 +203,9 @@  discard block
 block discarded – undo
197 203
 			{
198 204
 				$depth++;
199 205
 				$matches[] = array();
206
+			} elseif ($char == "\n") {
207
+							$depth = 0;
200 208
 			}
201
-			elseif ($char == "\n")
202
-				$depth = 0;
203 209
 
204 210
 			for ($i = $depth; $i > 0; $i--)
205 211
 			{
@@ -212,8 +218,9 @@  discard block
 block discarded – undo
212 218
 			}
213 219
 		}
214 220
 
215
-		foreach ($matches as $k => $match)
216
-			$matches[$k] = substr(implode('', $match), 1);
221
+		foreach ($matches as $k => $match) {
222
+					$matches[$k] = substr(implode('', $match), 1);
223
+		}
217 224
 
218 225
 		// Names can have spaces, other breaks, or they can't...we try to match every possible
219 226
 		// combination.
@@ -223,8 +230,9 @@  discard block
 block discarded – undo
223 230
 			$match = preg_split('/([^\w])/', $match, -1, PREG_SPLIT_DELIM_CAPTURE);
224 231
 			$count = count($match);
225 232
 			
226
-			for ($i = 1; $i <= $count; $i++)
227
-				$names[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim'](implode('', array_slice($match, 0, $i))));
233
+			for ($i = 1; $i <= $count; $i++) {
234
+							$names[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim'](implode('', array_slice($match, 0, $i))));
235
+			}
228 236
 		}
229 237
 
230 238
 		$names = array_unique($names);
Please login to merge, or discard this patch.
Sources/ManageSettings.php 1 patch
Braces   +273 added lines, -199 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
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -205,16 +206,18 @@  discard block
 block discarded – undo
205 206
 	{
206 207
 		$all_zones = timezone_identifiers_list();
207 208
 		// Make sure we set the value to the same as the printed value.
208
-		foreach ($all_zones as $zone)
209
-			$config_vars['default_timezone'][2][$zone] = $zone;
209
+		foreach ($all_zones as $zone) {
210
+					$config_vars['default_timezone'][2][$zone] = $zone;
211
+		}
212
+	} else {
213
+			unset($config_vars['default_timezone']);
210 214
 	}
211
-	else
212
-		unset($config_vars['default_timezone']);
213 215
 
214 216
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
215 217
 
216
-	if ($return_config)
217
-		return $config_vars;
218
+	if ($return_config) {
219
+			return $config_vars;
220
+	}
218 221
 
219 222
 	// Saving?
220 223
 	if (isset($_GET['save']))
@@ -222,8 +225,9 @@  discard block
 block discarded – undo
222 225
 		checkSession();
223 226
 
224 227
 		// Prevent absurd boundaries here - make it a day tops.
225
-		if (isset($_POST['lastActive']))
226
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
228
+		if (isset($_POST['lastActive'])) {
229
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
230
+		}
227 231
 
228 232
 		call_integration_hook('integrate_save_basic_settings');
229 233
 
@@ -268,8 +272,9 @@  discard block
 block discarded – undo
268 272
 
269 273
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
270 274
 
271
-	if ($return_config)
272
-		return $config_vars;
275
+	if ($return_config) {
276
+			return $config_vars;
277
+	}
273 278
 
274 279
 	// Setup the template.
275 280
 	require_once($sourcedir . '/ManageServer.php');
@@ -286,13 +291,15 @@  discard block
 block discarded – undo
286 291
 
287 292
 		// Clean up the tags.
288 293
 		$bbcTags = array();
289
-		foreach (parse_bbc(false) as $tag)
290
-			$bbcTags[] = $tag['tag'];
294
+		foreach (parse_bbc(false) as $tag) {
295
+					$bbcTags[] = $tag['tag'];
296
+		}
291 297
 
292
-		if (!isset($_POST['disabledBBC_enabledTags']))
293
-			$_POST['disabledBBC_enabledTags'] = array();
294
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
295
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
298
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
299
+					$_POST['disabledBBC_enabledTags'] = array();
300
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
301
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
302
+		}
296 303
 		// Work out what is actually disabled!
297 304
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
298 305
 
@@ -336,8 +343,9 @@  discard block
 block discarded – undo
336 343
 
337 344
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
338 345
 
339
-	if ($return_config)
340
-		return $config_vars;
346
+	if ($return_config) {
347
+			return $config_vars;
348
+	}
341 349
 
342 350
 	// Saving?
343 351
 	if (isset($_GET['save']))
@@ -378,8 +386,9 @@  discard block
 block discarded – undo
378 386
 
379 387
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
380 388
 
381
-	if ($return_config)
382
-		return $config_vars;
389
+	if ($return_config) {
390
+			return $config_vars;
391
+	}
383 392
 
384 393
 	// Saving?
385 394
 	if (isset($_GET['save']))
@@ -417,8 +426,9 @@  discard block
 block discarded – undo
417 426
 
418 427
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
419 428
 
420
-	if ($return_config)
421
-		return $config_vars;
429
+	if ($return_config) {
430
+			return $config_vars;
431
+	}
422 432
 
423 433
 	// Saving?
424 434
 	if (isset($_GET['save']))
@@ -462,8 +472,8 @@  discard block
 block discarded – undo
462 472
 			'enable' => array('check', 'warning_enable'),
463 473
 	);
464 474
 
465
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
466
-		$config_vars += array(
475
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
476
+			$config_vars += array(
467 477
 			'',
468 478
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
469 479
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -472,15 +482,18 @@  discard block
 block discarded – undo
472 482
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
473 483
 				array('permissions', 'view_warning'),
474 484
 		);
485
+	}
475 486
 
476 487
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
477 488
 
478
-	if ($return_config)
479
-		return $config_vars;
489
+	if ($return_config) {
490
+			return $config_vars;
491
+	}
480 492
 
481 493
 	// Cannot use moderation if post moderation is not enabled.
482
-	if (!$modSettings['postmod_active'])
483
-		unset($config_vars['moderate']);
494
+	if (!$modSettings['postmod_active']) {
495
+			unset($config_vars['moderate']);
496
+	}
484 497
 
485 498
 	// Will need the utility functions from here.
486 499
 	require_once($sourcedir . '/ManageServer.php');
@@ -505,16 +518,16 @@  discard block
 block discarded – undo
505 518
 				'warning_watch' => 10,
506 519
 				'warning_mute' => 60,
507 520
 			);
508
-			if ($modSettings['postmod_active'])
509
-				$vars['warning_moderate'] = 35;
521
+			if ($modSettings['postmod_active']) {
522
+							$vars['warning_moderate'] = 35;
523
+			}
510 524
 
511 525
 			foreach ($vars as $var => $value)
512 526
 			{
513 527
 				$config_vars[] = array('int', $var);
514 528
 				$_POST[$var] = $value;
515 529
 			}
516
-		}
517
-		else
530
+		} else
518 531
 		{
519 532
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
520 533
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -595,8 +608,9 @@  discard block
 block discarded – undo
595 608
 
596 609
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
597 610
 
598
-	if ($return_config)
599
-		return $config_vars;
611
+	if ($return_config) {
612
+			return $config_vars;
613
+	}
600 614
 
601 615
 	// You need to be an admin to edit settings!
602 616
 	isAllowedTo('admin_forum');
@@ -630,8 +644,9 @@  discard block
 block discarded – undo
630 644
 
631 645
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
632 646
 	{
633
-		if (empty($context['settings_insert_above']))
634
-			$context['settings_insert_above'] = '';
647
+		if (empty($context['settings_insert_above'])) {
648
+					$context['settings_insert_above'] = '';
649
+		}
635 650
 
636 651
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
637 652
 	}
@@ -674,8 +689,9 @@  discard block
 block discarded – undo
674 689
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
675 690
 
676 691
 		// Hack in guest requiring verification!
677
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
678
-			$_POST['posts_require_captcha'] = -1;
692
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
693
+					$_POST['posts_require_captcha'] = -1;
694
+		}
679 695
 
680 696
 		$save_vars = $config_vars;
681 697
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -692,14 +708,16 @@  discard block
 block discarded – undo
692 708
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
693 709
 		{
694 710
 			// If we had some questions for this language before, but don't now, delete everything from that language.
695
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
696
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
711
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
712
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
713
+			}
697 714
 
698 715
 			// Now step through and see if any existing questions no longer exist.
699
-			if (!empty($context['qa_by_lang'][$lang_id]))
700
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
716
+			if (!empty($context['qa_by_lang'][$lang_id])) {
717
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
701 718
 					if (empty($_POST['question'][$lang_id][$q_id]))
702 719
 						$changes['delete'][] = $q_id;
720
+			}
703 721
 
704 722
 			// Now let's see if there are new questions or ones that need updating.
705 723
 			if (isset($_POST['question'][$lang_id]))
@@ -708,14 +726,16 @@  discard block
 block discarded – undo
708 726
 				{
709 727
 					// Ignore junky ids.
710 728
 					$q_id = (int) $q_id;
711
-					if ($q_id <= 0)
712
-						continue;
729
+					if ($q_id <= 0) {
730
+											continue;
731
+					}
713 732
 
714 733
 					// Check the question isn't empty (because they want to delete it?)
715 734
 					if (empty($question) || trim($question) == '')
716 735
 					{
717
-						if (isset($context['question_answers'][$q_id]))
718
-							$changes['delete'][] = $q_id;
736
+						if (isset($context['question_answers'][$q_id])) {
737
+													$changes['delete'][] = $q_id;
738
+						}
719 739
 						continue;
720 740
 					}
721 741
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -723,19 +743,22 @@  discard block
 block discarded – undo
723 743
 					// Get the answers. Firstly check there actually might be some.
724 744
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
725 745
 					{
726
-						if (isset($context['question_answers'][$q_id]))
727
-							$changes['delete'][] = $q_id;
746
+						if (isset($context['question_answers'][$q_id])) {
747
+													$changes['delete'][] = $q_id;
748
+						}
728 749
 						continue;
729 750
 					}
730 751
 					// Now get them and check that they might be viable.
731 752
 					$answers = array();
732
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
733
-						if (!empty($answer) && trim($answer) !== '')
753
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
754
+											if (!empty($answer) && trim($answer) !== '')
734 755
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
756
+					}
735 757
 					if (empty($answers))
736 758
 					{
737
-						if (isset($context['question_answers'][$q_id]))
738
-							$changes['delete'][] = $q_id;
759
+						if (isset($context['question_answers'][$q_id])) {
760
+													$changes['delete'][] = $q_id;
761
+						}
739 762
 						continue;
740 763
 					}
741 764
 					$answers = json_encode($answers);
@@ -745,16 +768,17 @@  discard block
 block discarded – undo
745 768
 					{
746 769
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
747 770
 						$changes['insert'][] = array($lang_id, $question, $answers);
748
-					}
749
-					else
771
+					} else
750 772
 					{
751 773
 						// It's an existing question. Let's see what's changed, if anything.
752
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
753
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
774
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
775
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
776
+						}
754 777
 					}
755 778
 
756
-					if (!isset($qs_per_lang[$lang_id]))
757
-						$qs_per_lang[$lang_id] = 0;
779
+					if (!isset($qs_per_lang[$lang_id])) {
780
+											$qs_per_lang[$lang_id] = 0;
781
+					}
758 782
 					$qs_per_lang[$lang_id]++;
759 783
 				}
760 784
 			}
@@ -804,8 +828,9 @@  discard block
 block discarded – undo
804 828
 
805 829
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
806 830
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
807
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
808
-			$_POST['qa_verification_number'] = $count_questions;
831
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
832
+					$_POST['qa_verification_number'] = $count_questions;
833
+		}
809 834
 
810 835
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
811 836
 
@@ -820,24 +845,27 @@  discard block
 block discarded – undo
820 845
 
821 846
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
822 847
 	$_SESSION['visual_verification_code'] = '';
823
-	for ($i = 0; $i < 6; $i++)
824
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
848
+	for ($i = 0; $i < 6; $i++) {
849
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
850
+	}
825 851
 
826 852
 	// Some javascript for CAPTCHA.
827 853
 	$context['settings_post_javascript'] = '';
828
-	if ($context['use_graphic_library'])
829
-		$context['settings_post_javascript'] .= '
854
+	if ($context['use_graphic_library']) {
855
+			$context['settings_post_javascript'] .= '
830 856
 		function refreshImages()
831 857
 		{
832 858
 			var imageType = document.getElementById(\'visual_verification_type\').value;
833 859
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
834 860
 		}';
861
+	}
835 862
 
836 863
 	// Show the image itself, or text saying we can't.
837
-	if ($context['use_graphic_library'])
838
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
839
-	else
840
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
864
+	if ($context['use_graphic_library']) {
865
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
866
+	} else {
867
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
868
+	}
841 869
 
842 870
 	// Hack for PM spam settings.
843 871
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -847,9 +875,10 @@  discard block
 block discarded – undo
847 875
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
848 876
 
849 877
 	// Some minor javascript for the guest post setting.
850
-	if ($modSettings['posts_require_captcha'])
851
-		$context['settings_post_javascript'] .= '
878
+	if ($modSettings['posts_require_captcha']) {
879
+			$context['settings_post_javascript'] .= '
852 880
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
881
+	}
853 882
 
854 883
 	// And everything else.
855 884
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -896,8 +925,9 @@  discard block
 block discarded – undo
896 925
 
897 926
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
898 927
 
899
-	if ($return_config)
900
-		return $config_vars;
928
+	if ($return_config) {
929
+			return $config_vars;
930
+	}
901 931
 
902 932
 	// Setup the template.
903 933
 	$context['page_title'] = $txt['signature_settings'];
@@ -952,8 +982,9 @@  discard block
 block discarded – undo
952 982
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
953 983
 
954 984
 				// Max characters...
955
-				if (!empty($sig_limits[1]))
956
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
985
+				if (!empty($sig_limits[1])) {
986
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
987
+				}
957 988
 				// Max lines...
958 989
 				if (!empty($sig_limits[2]))
959 990
 				{
@@ -963,8 +994,9 @@  discard block
 block discarded – undo
963 994
 						if ($sig[$i] == "\n")
964 995
 						{
965 996
 							$count++;
966
-							if ($count >= $sig_limits[2])
967
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
997
+							if ($count >= $sig_limits[2]) {
998
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
999
+							}
968 1000
 						}
969 1001
 					}
970 1002
 				}
@@ -975,17 +1007,19 @@  discard block
 block discarded – undo
975 1007
 					{
976 1008
 						$limit_broke = 0;
977 1009
 						// Attempt to allow all sizes of abuse, so to speak.
978
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
979
-							$limit_broke = $sig_limits[7] . 'px';
980
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
981
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
982
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
983
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
984
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
985
-							$limit_broke = 'large';
986
-
987
-						if ($limit_broke)
988
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1010
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1011
+													$limit_broke = $sig_limits[7] . 'px';
1012
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1013
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1014
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1015
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1016
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1017
+													$limit_broke = 'large';
1018
+						}
1019
+
1020
+						if ($limit_broke) {
1021
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1022
+						}
989 1023
 					}
990 1024
 				}
991 1025
 
@@ -1041,32 +1075,34 @@  discard block
 block discarded – undo
1041 1075
 											$img_offset = false;
1042 1076
 										}
1043 1077
 									}
1078
+								} else {
1079
+																	$replaces[$image] = '';
1044 1080
 								}
1045
-								else
1046
-									$replaces[$image] = '';
1047 1081
 
1048 1082
 								continue;
1049 1083
 							}
1050 1084
 
1051 1085
 							// Does it have predefined restraints? Width first.
1052
-							if ($matches[6][$key])
1053
-								$matches[2][$key] = $matches[6][$key];
1086
+							if ($matches[6][$key]) {
1087
+															$matches[2][$key] = $matches[6][$key];
1088
+							}
1054 1089
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1055 1090
 							{
1056 1091
 								$width = $sig_limits[5];
1057 1092
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1093
+							} elseif ($matches[2][$key]) {
1094
+															$width = $matches[2][$key];
1058 1095
 							}
1059
-							elseif ($matches[2][$key])
1060
-								$width = $matches[2][$key];
1061 1096
 							// ... and height.
1062 1097
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1063 1098
 							{
1064 1099
 								$height = $sig_limits[6];
1065
-								if ($width != -1)
1066
-									$width = $width * ($height / $matches[4][$key]);
1100
+								if ($width != -1) {
1101
+																	$width = $width * ($height / $matches[4][$key]);
1102
+								}
1103
+							} elseif ($matches[4][$key]) {
1104
+															$height = $matches[4][$key];
1067 1105
 							}
1068
-							elseif ($matches[4][$key])
1069
-								$height = $matches[4][$key];
1070 1106
 
1071 1107
 							// If the dimensions are still not fixed - we need to check the actual image.
1072 1108
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1084,12 +1120,13 @@  discard block
 block discarded – undo
1084 1120
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1085 1121
 									{
1086 1122
 										$height = $sig_limits[6];
1087
-										if ($width == -1)
1088
-											$width = $sizes[0];
1123
+										if ($width == -1) {
1124
+																					$width = $sizes[0];
1125
+										}
1089 1126
 										$width = $width * ($height / $sizes[1]);
1127
+									} elseif ($width != -1) {
1128
+																			$height = $sizes[1];
1090 1129
 									}
1091
-									elseif ($width != -1)
1092
-										$height = $sizes[1];
1093 1130
 								}
1094 1131
 							}
1095 1132
 
@@ -1102,8 +1139,9 @@  discard block
 block discarded – undo
1102 1139
 							// Record that we got one.
1103 1140
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1104 1141
 						}
1105
-						if (!empty($replaces))
1106
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1142
+						if (!empty($replaces)) {
1143
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1144
+						}
1107 1145
 					}
1108 1146
 				}
1109 1147
 				// Try to fix disabled tags.
@@ -1115,18 +1153,20 @@  discard block
 block discarded – undo
1115 1153
 
1116 1154
 				$sig = strtr($sig, array("\n" => '<br>'));
1117 1155
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1118
-				if ($sig != $row['signature'])
1119
-					$changes[$row['id_member']] = $sig;
1156
+				if ($sig != $row['signature']) {
1157
+									$changes[$row['id_member']] = $sig;
1158
+				}
1159
+			}
1160
+			if ($smcFunc['db_num_rows']($request) == 0) {
1161
+							$done = true;
1120 1162
 			}
1121
-			if ($smcFunc['db_num_rows']($request) == 0)
1122
-				$done = true;
1123 1163
 			$smcFunc['db_free_result']($request);
1124 1164
 
1125 1165
 			// Do we need to delete what we have?
1126 1166
 			if (!empty($changes))
1127 1167
 			{
1128
-				foreach ($changes as $id => $sig)
1129
-					$smcFunc['db_query']('', '
1168
+				foreach ($changes as $id => $sig) {
1169
+									$smcFunc['db_query']('', '
1130 1170
 						UPDATE {db_prefix}members
1131 1171
 						SET signature = {string:signature}
1132 1172
 						WHERE id_member = {int:id_member}',
@@ -1135,11 +1175,13 @@  discard block
 block discarded – undo
1135 1175
 							'signature' => $sig,
1136 1176
 						)
1137 1177
 					);
1178
+				}
1138 1179
 			}
1139 1180
 
1140 1181
 			$_GET['step'] += 50;
1141
-			if (!$done)
1142
-				pauseSignatureApplySettings();
1182
+			if (!$done) {
1183
+							pauseSignatureApplySettings();
1184
+			}
1143 1185
 		}
1144 1186
 		$settings_applied = true;
1145 1187
 	}
@@ -1157,8 +1199,9 @@  discard block
 block discarded – undo
1157 1199
 	);
1158 1200
 
1159 1201
 	// Temporarily make each setting a modSetting!
1160
-	foreach ($context['signature_settings'] as $key => $value)
1161
-		$modSettings['signature_' . $key] = $value;
1202
+	foreach ($context['signature_settings'] as $key => $value) {
1203
+			$modSettings['signature_' . $key] = $value;
1204
+	}
1162 1205
 
1163 1206
 	// Make sure we check the right tags!
1164 1207
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1170,23 +1213,26 @@  discard block
 block discarded – undo
1170 1213
 
1171 1214
 		// Clean up the tag stuff!
1172 1215
 		$bbcTags = array();
1173
-		foreach (parse_bbc(false) as $tag)
1174
-			$bbcTags[] = $tag['tag'];
1216
+		foreach (parse_bbc(false) as $tag) {
1217
+					$bbcTags[] = $tag['tag'];
1218
+		}
1175 1219
 
1176
-		if (!isset($_POST['signature_bbc_enabledTags']))
1177
-			$_POST['signature_bbc_enabledTags'] = array();
1178
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1179
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1220
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1221
+					$_POST['signature_bbc_enabledTags'] = array();
1222
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1223
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1224
+		}
1180 1225
 
1181 1226
 		$sig_limits = array();
1182 1227
 		foreach ($context['signature_settings'] as $key => $value)
1183 1228
 		{
1184
-			if ($key == 'allow_smileys')
1185
-				continue;
1186
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1187
-				$sig_limits[] = -1;
1188
-			else
1189
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1229
+			if ($key == 'allow_smileys') {
1230
+							continue;
1231
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1232
+							$sig_limits[] = -1;
1233
+			} else {
1234
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1235
+			}
1190 1236
 		}
1191 1237
 
1192 1238
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1219,12 +1265,14 @@  discard block
 block discarded – undo
1219 1265
 
1220 1266
 	// Try get more time...
1221 1267
 	@set_time_limit(600);
1222
-	if (function_exists('apache_reset_timeout'))
1223
-		@apache_reset_timeout();
1268
+	if (function_exists('apache_reset_timeout')) {
1269
+			@apache_reset_timeout();
1270
+	}
1224 1271
 
1225 1272
 	// Have we exhausted all the time we allowed?
1226
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1227
-		return;
1273
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1274
+			return;
1275
+	}
1228 1276
 
1229 1277
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1230 1278
 	$context['page_title'] = $txt['not_done_title'];
@@ -1270,9 +1318,10 @@  discard block
 block discarded – undo
1270 1318
 		$disable_fields = array_flip($standard_fields);
1271 1319
 		if (!empty($_POST['active']))
1272 1320
 		{
1273
-			foreach ($_POST['active'] as $value)
1274
-				if (isset($disable_fields[$value]))
1321
+			foreach ($_POST['active'] as $value) {
1322
+							if (isset($disable_fields[$value]))
1275 1323
 					unset($disable_fields[$value]);
1324
+			}
1276 1325
 		}
1277 1326
 		// What we have left!
1278 1327
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1281,16 +1330,18 @@  discard block
 block discarded – undo
1281 1330
 		$reg_fields = array();
1282 1331
 		if (!empty($_POST['reg']))
1283 1332
 		{
1284
-			foreach ($_POST['reg'] as $value)
1285
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1333
+			foreach ($_POST['reg'] as $value) {
1334
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1286 1335
 					$reg_fields[] = $value;
1336
+			}
1287 1337
 		}
1288 1338
 		// What we have left!
1289 1339
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1290 1340
 
1291 1341
 		$_SESSION['adm-save'] = true;
1292
-		if (!empty($changes))
1293
-			updateSettings($changes);
1342
+		if (!empty($changes)) {
1343
+					updateSettings($changes);
1344
+		}
1294 1345
 	}
1295 1346
 
1296 1347
 	createToken('admin-scp');
@@ -1393,11 +1444,13 @@  discard block
 block discarded – undo
1393 1444
 					{
1394 1445
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br />';
1395 1446
 
1396
-						if ($rowData['field_order'] > 1)
1397
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1447
+						if ($rowData['field_order'] > 1) {
1448
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1449
+						}
1398 1450
 
1399
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1400
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1451
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1452
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1453
+						}
1401 1454
 
1402 1455
 						$return .= '</p>';
1403 1456
 
@@ -1535,16 +1588,16 @@  discard block
 block discarded – undo
1535 1588
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1536 1589
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1537 1590
 
1538
-		foreach ($standard_fields as $field)
1539
-			$list[] = array(
1591
+		foreach ($standard_fields as $field) {
1592
+					$list[] = array(
1540 1593
 				'id' => $field,
1541 1594
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1542 1595
 				'disabled' => in_array($field, $disabled_fields),
1543 1596
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1544 1597
 				'can_show_register' => !in_array($field, $fields_no_registration),
1545 1598
 			);
1546
-	}
1547
-	else
1599
+		}
1600
+	} else
1548 1601
 	{
1549 1602
 		// Load all the fields.
1550 1603
 		$request = $smcFunc['db_query']('', '
@@ -1558,8 +1611,9 @@  discard block
 block discarded – undo
1558 1611
 				'items_per_page' => $items_per_page,
1559 1612
 			)
1560 1613
 		);
1561
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1562
-			$list[] = $row;
1614
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1615
+					$list[] = $row;
1616
+		}
1563 1617
 		$smcFunc['db_free_result']($request);
1564 1618
 	}
1565 1619
 
@@ -1625,9 +1679,9 @@  discard block
 block discarded – undo
1625 1679
 		$context['field'] = array();
1626 1680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1627 1681
 		{
1628
-			if ($row['field_type'] == 'textarea')
1629
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1630
-			else
1682
+			if ($row['field_type'] == 'textarea') {
1683
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1684
+			} else
1631 1685
 			{
1632 1686
 				$rows = 3;
1633 1687
 				$cols = 30;
@@ -1663,8 +1717,8 @@  discard block
 block discarded – undo
1663 1717
 	}
1664 1718
 
1665 1719
 	// Setup the default values as needed.
1666
-	if (empty($context['field']))
1667
-		$context['field'] = array(
1720
+	if (empty($context['field'])) {
1721
+			$context['field'] = array(
1668 1722
 			'name' => '',
1669 1723
 			'col_name' => '???',
1670 1724
 			'desc' => '',
@@ -1689,6 +1743,7 @@  discard block
 block discarded – undo
1689 1743
 			'enclose' => '',
1690 1744
 			'placement' => 0,
1691 1745
 		);
1746
+	}
1692 1747
 
1693 1748
 	// Are we moving it?
1694 1749
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1697,8 +1752,10 @@  discard block
 block discarded – undo
1697 1752
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1698 1753
 
1699 1754
 		// Is this a valid position?
1700
-		if ($new_order <= 0 || $new_order > $order_count)
1701
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1755
+		if ($new_order <= 0 || $new_order > $order_count) {
1756
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1757
+		}
1758
+		// @todo implement an error handler
1702 1759
 
1703 1760
 		// All good, proceed.
1704 1761
 		$smcFunc['db_query']('','
@@ -1729,12 +1786,14 @@  discard block
 block discarded – undo
1729 1786
 		validateToken('admin-ecp');
1730 1787
 
1731 1788
 		// Everyone needs a name - even the (bracket) unknown...
1732
-		if (trim($_POST['field_name']) == '')
1733
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1789
+		if (trim($_POST['field_name']) == '') {
1790
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1791
+		}
1734 1792
 
1735 1793
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1736
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1737
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1794
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1795
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1796
+		}
1738 1797
 
1739 1798
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1740 1799
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1751,8 +1810,9 @@  discard block
 block discarded – undo
1751 1810
 
1752 1811
 		// Some masking stuff...
1753 1812
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1754
-		if ($mask == 'regex' && isset($_POST['regex']))
1755
-			$mask .= $_POST['regex'];
1813
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1814
+					$mask .= $_POST['regex'];
1815
+		}
1756 1816
 
1757 1817
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1758 1818
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1771,8 +1831,9 @@  discard block
 block discarded – undo
1771 1831
 				$v = strtr($v, array(',' => ''));
1772 1832
 
1773 1833
 				// Nada, zip, etc...
1774
-				if (trim($v) == '')
1775
-					continue;
1834
+				if (trim($v) == '') {
1835
+									continue;
1836
+				}
1776 1837
 
1777 1838
 				// Otherwise, save it boy.
1778 1839
 				$field_options .= $v . ',';
@@ -1780,15 +1841,17 @@  discard block
 block discarded – undo
1780 1841
 				$newOptions[$k] = $v;
1781 1842
 
1782 1843
 				// Is it default?
1783
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1784
-					$default = $v;
1844
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1845
+									$default = $v;
1846
+				}
1785 1847
 			}
1786 1848
 			$field_options = substr($field_options, 0, -1);
1787 1849
 		}
1788 1850
 
1789 1851
 		// Text area has default has dimensions
1790
-		if ($_POST['field_type'] == 'textarea')
1791
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1852
+		if ($_POST['field_type'] == 'textarea') {
1853
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1854
+		}
1792 1855
 
1793 1856
 		// Come up with the unique name?
1794 1857
 		if (empty($context['fid']))
@@ -1797,32 +1860,36 @@  discard block
 block discarded – undo
1797 1860
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1798 1861
 
1799 1862
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1800
-			if (isset($matches[1]))
1801
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1802
-			else
1803
-				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1863
+			if (isset($matches[1])) {
1864
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1865
+			} else {
1866
+							$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1867
+			}
1804 1868
 
1805 1869
 			// Make sure this is unique.
1806 1870
 			$current_fields = array();
1807 1871
 			$request = $smcFunc['db_query']('', '
1808 1872
 				SELECT id_field, col_name
1809 1873
 				FROM {db_prefix}custom_fields');
1810
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1811
-				$current_fields[$row['id_field']] = $row['col_name'];
1874
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1875
+							$current_fields[$row['id_field']] = $row['col_name'];
1876
+			}
1812 1877
 			$smcFunc['db_free_result']($request);
1813 1878
 
1814 1879
 			$unique = false;
1815 1880
 			for ($i = 0; !$unique && $i < 9; $i ++)
1816 1881
 			{
1817
-				if (!in_array($col_name, $current_fields))
1818
-					$unique = true;
1819
-				else
1820
-					$col_name = $initial_col_name . $i;
1882
+				if (!in_array($col_name, $current_fields)) {
1883
+									$unique = true;
1884
+				} else {
1885
+									$col_name = $initial_col_name . $i;
1886
+				}
1821 1887
 			}
1822 1888
 
1823 1889
 			// Still not a unique column name? Leave it up to the user, then.
1824
-			if (!$unique)
1825
-				fatal_lang_error('custom_option_not_unique');
1890
+			if (!$unique) {
1891
+							fatal_lang_error('custom_option_not_unique');
1892
+			}
1826 1893
 		}
1827 1894
 		// Work out what to do with the user data otherwise...
1828 1895
 		else
@@ -1850,8 +1917,9 @@  discard block
 block discarded – undo
1850 1917
 				// Work out what's changed!
1851 1918
 				foreach ($context['field']['options'] as $k => $option)
1852 1919
 				{
1853
-					if (trim($option) == '')
1854
-						continue;
1920
+					if (trim($option) == '') {
1921
+											continue;
1922
+					}
1855 1923
 
1856 1924
 					// Still exists?
1857 1925
 					if (in_array($option, $newOptions))
@@ -1865,8 +1933,8 @@  discard block
 block discarded – undo
1865 1933
 				foreach ($optionChanges as $k => $option)
1866 1934
 				{
1867 1935
 					// Just been renamed?
1868
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1869
-						$smcFunc['db_query']('', '
1936
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1937
+											$smcFunc['db_query']('', '
1870 1938
 							UPDATE {db_prefix}themes
1871 1939
 							SET value = {string:new_value}
1872 1940
 							WHERE variable = {string:current_column}
@@ -1879,6 +1947,7 @@  discard block
 block discarded – undo
1879 1947
 								'old_value' => $option,
1880 1948
 							)
1881 1949
 						);
1950
+					}
1882 1951
 				}
1883 1952
 			}
1884 1953
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1921,8 +1990,8 @@  discard block
 block discarded – undo
1921 1990
 			);
1922 1991
 
1923 1992
 			// Just clean up any old selects - these are a pain!
1924
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1925
-				$smcFunc['db_query']('', '
1993
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
1994
+							$smcFunc['db_query']('', '
1926 1995
 					DELETE FROM {db_prefix}themes
1927 1996
 					WHERE variable = {string:current_column}
1928 1997
 						AND value NOT IN ({array_string:new_option_values})
@@ -1933,8 +2002,8 @@  discard block
 block discarded – undo
1933 2002
 						'current_column' => $context['field']['col_name'],
1934 2003
 					)
1935 2004
 				);
1936
-		}
1937
-		else
2005
+			}
2006
+		} else
1938 2007
 		{
1939 2008
 			// Gotta figure it out the order.
1940 2009
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2108,11 +2177,13 @@  discard block
 block discarded – undo
2108 2177
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2109 2178
 
2110 2179
 	$prune_toggle_dt = array();
2111
-	foreach ($prune_toggle as $item)
2112
-		$prune_toggle_dt[] = 'setting_' . $item;
2180
+	foreach ($prune_toggle as $item) {
2181
+			$prune_toggle_dt[] = 'setting_' . $item;
2182
+	}
2113 2183
 
2114
-	if ($return_config)
2115
-		return $config_vars;
2184
+	if ($return_config) {
2185
+			return $config_vars;
2186
+	}
2116 2187
 
2117 2188
 	addInlineJavaScript('
2118 2189
 	function togglePruned()
@@ -2150,15 +2221,16 @@  discard block
 block discarded – undo
2150 2221
 			$vals = array();
2151 2222
 			foreach ($config_vars as $index => $dummy)
2152 2223
 			{
2153
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2154
-					continue;
2224
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2225
+									continue;
2226
+				}
2155 2227
 
2156 2228
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2157 2229
 			}
2158 2230
 			$_POST['pruningOptions'] = implode(',', $vals);
2231
+		} else {
2232
+					$_POST['pruningOptions'] = '';
2159 2233
 		}
2160
-		else
2161
-			$_POST['pruningOptions'] = '';
2162 2234
 
2163 2235
 		saveDBSettings($savevar);
2164 2236
 		$_SESSION['adm-save'] = true;
@@ -2170,10 +2242,11 @@  discard block
 block discarded – undo
2170 2242
 	$context['sub_template'] = 'show_settings';
2171 2243
 
2172 2244
 	// Get the actual values
2173
-	if (!empty($modSettings['pruningOptions']))
2174
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2175
-	else
2176
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2245
+	if (!empty($modSettings['pruningOptions'])) {
2246
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2247
+	} else {
2248
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2249
+	}
2177 2250
 
2178 2251
 	prepareDBSettingContext($config_vars);
2179 2252
 }
@@ -2195,8 +2268,9 @@  discard block
 block discarded – undo
2195 2268
 	// Make it even easier to add new settings.
2196 2269
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2197 2270
 
2198
-	if ($return_config)
2199
-		return $config_vars;
2271
+	if ($return_config) {
2272
+			return $config_vars;
2273
+	}
2200 2274
 
2201 2275
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2202 2276
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +263 added lines, -203 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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type. '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:'.$ip_number.'} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,44 +466,45 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
465 486
 	}
466 487
 
467 488
 	// Now that we have the mod cache taken care of lets setup a cache for the number of mod reports still open
468
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
469
-		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
470
-	elseif ($_SESSION['mc']['bq'] != '0=1')
489
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
490
+			$context['open_mod_reports'] = $_SESSION['rc']['reports'];
491
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
471 492
 	{
472 493
 		require_once($sourcedir . '/Subs-ReportedContent.php');
473 494
 		recountOpenReports('posts');
495
+	} else {
496
+			$context['open_mod_reports'] = 0;
474 497
 	}
475
-	else
476
-		$context['open_mod_reports'] = 0;
477 498
 
478
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
479
-		$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
480
-	elseif (allowedTo('moderate_forum'))
499
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
500
+			$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
501
+	} elseif (allowedTo('moderate_forum'))
481 502
 	{
482 503
 		require_once($sourcedir . '/Subs-ReportedContent.php');
483 504
 		recountOpenReports('members');
505
+	} else {
506
+			$context['open_member_reports'] = 0;
484 507
 	}
485
-	else
486
-		$context['open_member_reports'] = 0;
487 508
 
488 509
 }
489 510
 
@@ -500,8 +521,9 @@  discard block
 block discarded – undo
500 521
 	global $user_info, $smcFunc;
501 522
 
502 523
 	// Don't log web accelerators, it's very confusing...
503
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
504
-		return;
524
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
525
+			return;
526
+	}
505 527
 
506 528
 	$smcFunc['db_insert']('',
507 529
 		'{db_prefix}log_banned',
@@ -511,8 +533,8 @@  discard block
 block discarded – undo
511 533
 	);
512 534
 
513 535
 	// One extra point for these bans.
514
-	if (!empty($ban_ids))
515
-		$smcFunc['db_query']('', '
536
+	if (!empty($ban_ids)) {
537
+			$smcFunc['db_query']('', '
516 538
 			UPDATE {db_prefix}ban_items
517 539
 			SET hits = hits + 1
518 540
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -520,7 +542,8 @@  discard block
 block discarded – undo
520 542
 				'ban_ids' => $ban_ids,
521 543
 			)
522 544
 		);
523
-}
545
+	}
546
+	}
524 547
 
525 548
 /**
526 549
  * Checks if a given email address might be banned.
@@ -536,8 +559,9 @@  discard block
 block discarded – undo
536 559
 	global $txt, $smcFunc;
537 560
 
538 561
 	// Can't ban an empty email
539
-	if (empty($email) || trim($email) == '')
540
-		return;
562
+	if (empty($email) || trim($email) == '') {
563
+			return;
564
+	}
541 565
 
542 566
 	// Let's start with the bans based on your IP/hostname/memberID...
543 567
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -610,16 +634,18 @@  discard block
 block discarded – undo
610 634
 	if ($type == 'post')
611 635
 	{
612 636
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
613
-		if ($check !== $sc)
614
-			$error = 'session_timeout';
637
+		if ($check !== $sc) {
638
+					$error = 'session_timeout';
639
+		}
615 640
 	}
616 641
 
617 642
 	// How about $_GET['sesc']?
618 643
 	elseif ($type == 'get')
619 644
 	{
620 645
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
621
-		if ($check !== $sc)
622
-			$error = 'session_verify_fail';
646
+		if ($check !== $sc) {
647
+					$error = 'session_verify_fail';
648
+		}
623 649
 	}
624 650
 
625 651
 	// Or can it be in either?
@@ -627,13 +653,15 @@  discard block
 block discarded – undo
627 653
 	{
628 654
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
629 655
 
630
-		if ($check !== $sc)
631
-			$error = 'session_verify_fail';
656
+		if ($check !== $sc) {
657
+					$error = 'session_verify_fail';
658
+		}
632 659
 	}
633 660
 
634 661
 	// Verify that they aren't changing user agents on us - that could be bad.
635
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
636
-		$error = 'session_verify_fail';
662
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
663
+			$error = 'session_verify_fail';
664
+	}
637 665
 
638 666
 	// Make sure a page with session check requirement is not being prefetched.
639 667
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -644,30 +672,35 @@  discard block
 block discarded – undo
644 672
 	}
645 673
 
646 674
 	// Check the referring site - it should be the same server at least!
647
-	if (isset($_SESSION['request_referer']))
648
-		$referrer = $_SESSION['request_referer'];
649
-	else
650
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
675
+	if (isset($_SESSION['request_referer'])) {
676
+			$referrer = $_SESSION['request_referer'];
677
+	} else {
678
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
679
+	}
651 680
 	if (!empty($referrer['host']))
652 681
 	{
653
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
654
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
655
-		else
656
-			$real_host = $_SERVER['HTTP_HOST'];
682
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
683
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
684
+		} else {
685
+					$real_host = $_SERVER['HTTP_HOST'];
686
+		}
657 687
 
658 688
 		$parsed_url = parse_url($boardurl);
659 689
 
660 690
 		// Are global cookies on?  If so, let's check them ;).
661 691
 		if (!empty($modSettings['globalCookies']))
662 692
 		{
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
664
-				$parsed_url['host'] = $parts[1];
693
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
694
+							$parsed_url['host'] = $parts[1];
695
+			}
665 696
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
667
-				$referrer['host'] = $parts[1];
697
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
698
+							$referrer['host'] = $parts[1];
699
+			}
668 700
 
669
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
670
-				$real_host = $parts[1];
701
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
702
+							$real_host = $parts[1];
703
+			}
671 704
 		}
672 705
 
673 706
 		// Okay: referrer must either match parsed_url or real_host.
@@ -685,12 +718,14 @@  discard block
 block discarded – undo
685 718
 		$log_error = true;
686 719
 	}
687 720
 
688
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
689
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
721
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
722
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
723
+	}
690 724
 
691 725
 	// Everything is ok, return an empty string.
692
-	if (!isset($error))
693
-		return '';
726
+	if (!isset($error)) {
727
+			return '';
728
+	}
694 729
 	// A session error occurred, show the error.
695 730
 	elseif ($is_fatal)
696 731
 	{
@@ -699,13 +734,14 @@  discard block
 block discarded – undo
699 734
 			ob_end_clean();
700 735
 			header('HTTP/1.1 403 Forbidden - Session timeout');
701 736
 			die;
737
+		} else {
738
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 739
 		}
703
-		else
704
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
705 740
 	}
706 741
 	// A session error occurred, return the error to the calling function.
707
-	else
708
-		return $error;
742
+	else {
743
+			return $error;
744
+	}
709 745
 
710 746
 	// We really should never fall through here, for very important reasons.  Let's make sure.
711 747
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -721,10 +757,9 @@  discard block
 block discarded – undo
721 757
 {
722 758
 	global $modSettings;
723 759
 
724
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
725
-		return true;
726
-
727
-	else
760
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
761
+			return true;
762
+	} else
728 763
 	{
729 764
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
730 765
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -775,9 +810,9 @@  discard block
 block discarded – undo
775 810
 			$return = $_SESSION['token'][$type . '-' . $action][3];
776 811
 			unset($_SESSION['token'][$type . '-' . $action]);
777 812
 			return $return;
813
+		} else {
814
+					return '';
778 815
 		}
779
-		else
780
-			return '';
781 816
 	}
782 817
 
783 818
 	// This nasty piece of code validates a token.
@@ -808,12 +843,14 @@  discard block
 block discarded – undo
808 843
 		fatal_lang_error('token_verify_fail', false);
809 844
 	}
810 845
 	// Remove this token as its useless
811
-	else
812
-		unset($_SESSION['token'][$type . '-' . $action]);
846
+	else {
847
+			unset($_SESSION['token'][$type . '-' . $action]);
848
+	}
813 849
 
814 850
 	// Randomly check if we should remove some older tokens.
815
-	if (mt_rand(0, 138) == 23)
816
-		cleanTokens();
851
+	if (mt_rand(0, 138) == 23) {
852
+			cleanTokens();
853
+	}
817 854
 
818 855
 	return false;
819 856
 }
@@ -828,14 +865,16 @@  discard block
 block discarded – undo
828 865
 function cleanTokens($complete = false)
829 866
 {
830 867
 	// We appreciate cleaning up after yourselves.
831
-	if (!isset($_SESSION['token']))
832
-		return;
868
+	if (!isset($_SESSION['token'])) {
869
+			return;
870
+	}
833 871
 
834 872
 	// Clean up tokens, trying to give enough time still.
835
-	foreach ($_SESSION['token'] as $key => $data)
836
-		if ($data[2] + 10800 < time() || $complete)
873
+	foreach ($_SESSION['token'] as $key => $data) {
874
+			if ($data[2] + 10800 < time() || $complete)
837 875
 			unset($_SESSION['token'][$key]);
838
-}
876
+	}
877
+	}
839 878
 
840 879
 /**
841 880
  * Check whether a form has been submitted twice.
@@ -853,37 +892,40 @@  discard block
 block discarded – undo
853 892
 {
854 893
 	global $context;
855 894
 
856
-	if (!isset($_SESSION['forms']))
857
-		$_SESSION['forms'] = array();
895
+	if (!isset($_SESSION['forms'])) {
896
+			$_SESSION['forms'] = array();
897
+	}
858 898
 
859 899
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
860 900
 	if ($action == 'register')
861 901
 	{
862 902
 		$context['form_sequence_number'] = 0;
863
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
864
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
903
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
904
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
905
+		}
865 906
 	}
866 907
 	// Check whether the submitted number can be found in the session.
867 908
 	elseif ($action == 'check')
868 909
 	{
869
-		if (!isset($_REQUEST['seqnum']))
870
-			return true;
871
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
910
+		if (!isset($_REQUEST['seqnum'])) {
911
+					return true;
912
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
872 913
 		{
873 914
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
874 915
 			return true;
916
+		} elseif ($is_fatal) {
917
+					fatal_lang_error('error_form_already_submitted', false);
918
+		} else {
919
+					return false;
875 920
 		}
876
-		elseif ($is_fatal)
877
-			fatal_lang_error('error_form_already_submitted', false);
878
-		else
879
-			return false;
880 921
 	}
881 922
 	// Don't check, just free the stack number.
882
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
883
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
884
-	elseif ($action != 'free')
885
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
886
-}
923
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
924
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
925
+	} elseif ($action != 'free') {
926
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
927
+	}
928
+	}
887 929
 
888 930
 /**
889 931
  * Check the user's permissions.
@@ -900,16 +942,19 @@  discard block
 block discarded – undo
900 942
 	global $user_info, $smcFunc;
901 943
 
902 944
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
903
-	if (empty($permission))
904
-		return true;
945
+	if (empty($permission)) {
946
+			return true;
947
+	}
905 948
 
906 949
 	// You're never allowed to do something if your data hasn't been loaded yet!
907
-	if (empty($user_info))
908
-		return false;
950
+	if (empty($user_info)) {
951
+			return false;
952
+	}
909 953
 
910 954
 	// Administrators are supermen :P.
911
-	if ($user_info['is_admin'])
912
-		return true;
955
+	if ($user_info['is_admin']) {
956
+			return true;
957
+	}
913 958
 
914 959
 	// Let's ensure this is an array.
915 960
 	$permission = (array)$permission;
@@ -917,14 +962,16 @@  discard block
 block discarded – undo
917 962
 	// Are we checking the _current_ board, or some other boards?
918 963
 	if ($boards === null)
919 964
 	{
920
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
921
-			return true;
965
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
966
+					return true;
967
+		}
922 968
 		// You aren't allowed, by default.
923
-		else
924
-			return false;
969
+		else {
970
+					return false;
971
+		}
972
+	} elseif (!is_array($boards)) {
973
+			$boards = array($boards);
925 974
 	}
926
-	elseif (!is_array($boards))
927
-		$boards = array($boards);
928 975
 
929 976
 	$request = $smcFunc['db_query']('', '
930 977
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -947,12 +994,14 @@  discard block
 block discarded – undo
947 994
 	);
948 995
 
949 996
 	// Make sure they can do it on all of the boards.
950
-	if ($smcFunc['db_num_rows']($request) != count($boards))
951
-		return false;
997
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
998
+			return false;
999
+	}
952 1000
 
953 1001
 	$result = true;
954
-	while ($row = $smcFunc['db_fetch_assoc']($request))
955
-		$result &= !empty($row['add_deny']);
1002
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+			$result &= !empty($row['add_deny']);
1004
+	}
956 1005
 	$smcFunc['db_free_result']($request);
957 1006
 
958 1007
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1017,9 +1066,10 @@  discard block
 block discarded – undo
1017 1066
 
1018 1067
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1019 1068
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1020
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1021
-		validateSession();
1022
-}
1069
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1070
+			validateSession();
1071
+	}
1072
+	}
1023 1073
 
1024 1074
 /**
1025 1075
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1038,8 +1088,9 @@  discard block
 block discarded – undo
1038 1088
 	global $user_info, $smcFunc;
1039 1089
 
1040 1090
 	// Arrays are nice, most of the time.
1041
-	if (!is_array($permissions))
1042
-		$permissions = array($permissions);
1091
+	if (!is_array($permissions)) {
1092
+			$permissions = array($permissions);
1093
+	}
1043 1094
 
1044 1095
 	/*
1045 1096
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1051,13 +1102,14 @@  discard block
 block discarded – undo
1051 1102
 	// Administrators are all powerful, sorry.
1052 1103
 	if ($user_info['is_admin'])
1053 1104
 	{
1054
-		if ($simple)
1055
-			return array(0);
1056
-		else
1105
+		if ($simple) {
1106
+					return array(0);
1107
+		} else
1057 1108
 		{
1058 1109
 			$boards = array();
1059
-			foreach ($permissions as $permission)
1060
-				$boards[$permission] = array(0);
1110
+			foreach ($permissions as $permission) {
1111
+							$boards[$permission] = array(0);
1112
+			}
1061 1113
 
1062 1114
 			return $boards;
1063 1115
 		}
@@ -1089,31 +1141,32 @@  discard block
 block discarded – undo
1089 1141
 	{
1090 1142
 		if ($simple)
1091 1143
 		{
1092
-			if (empty($row['add_deny']))
1093
-				$deny_boards[] = $row['id_board'];
1094
-			else
1095
-				$boards[] = $row['id_board'];
1096
-		}
1097
-		else
1144
+			if (empty($row['add_deny'])) {
1145
+							$deny_boards[] = $row['id_board'];
1146
+			} else {
1147
+							$boards[] = $row['id_board'];
1148
+			}
1149
+		} else
1098 1150
 		{
1099
-			if (empty($row['add_deny']))
1100
-				$deny_boards[$row['permission']][] = $row['id_board'];
1101
-			else
1102
-				$boards[$row['permission']][] = $row['id_board'];
1151
+			if (empty($row['add_deny'])) {
1152
+							$deny_boards[$row['permission']][] = $row['id_board'];
1153
+			} else {
1154
+							$boards[$row['permission']][] = $row['id_board'];
1155
+			}
1103 1156
 		}
1104 1157
 	}
1105 1158
 	$smcFunc['db_free_result']($request);
1106 1159
 
1107
-	if ($simple)
1108
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1109
-	else
1160
+	if ($simple) {
1161
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1162
+	} else
1110 1163
 	{
1111 1164
 		foreach ($permissions as $permission)
1112 1165
 		{
1113 1166
 			// never had it to start with
1114
-			if (empty($boards[$permission]))
1115
-				$boards[$permission] = array();
1116
-			else
1167
+			if (empty($boards[$permission])) {
1168
+							$boards[$permission] = array();
1169
+			} else
1117 1170
 			{
1118 1171
 				// Or it may have been removed
1119 1172
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1149,10 +1202,11 @@  discard block
 block discarded – undo
1149 1202
 
1150 1203
 
1151 1204
 	// Moderators are free...
1152
-	if (!allowedTo('moderate_board'))
1153
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1154
-	else
1155
-		$timeLimit = 2;
1205
+	if (!allowedTo('moderate_board')) {
1206
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1207
+	} else {
1208
+			$timeLimit = 2;
1209
+	}
1156 1210
 
1157 1211
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1158 1212
 
@@ -1179,8 +1233,9 @@  discard block
 block discarded – undo
1179 1233
 	if ($smcFunc['db_affected_rows']() != 1)
1180 1234
 	{
1181 1235
 		// Spammer!  You only have to wait a *few* seconds!
1182
-		if (!$only_return_result)
1183
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1236
+		if (!$only_return_result) {
1237
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1238
+		}
1184 1239
 
1185 1240
 		return true;
1186 1241
 	}
@@ -1198,11 +1253,13 @@  discard block
 block discarded – undo
1198 1253
  */
1199 1254
 function secureDirectory($path, $attachments = false)
1200 1255
 {
1201
-	if (empty($path))
1202
-		return 'empty_path';
1256
+	if (empty($path)) {
1257
+			return 'empty_path';
1258
+	}
1203 1259
 
1204
-	if (!is_writable($path))
1205
-		return 'path_not_writable';
1260
+	if (!is_writable($path)) {
1261
+			return 'path_not_writable';
1262
+	}
1206 1263
 
1207 1264
 	$directoryname = basename($path);
1208 1265
 
@@ -1214,9 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 
1215 1272
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1216 1273
 
1217
-	if (file_exists($path . '/.htaccess'))
1218
-		$errors[] = 'htaccess_exists';
1219
-	else
1274
+	if (file_exists($path . '/.htaccess')) {
1275
+			$errors[] = 'htaccess_exists';
1276
+	} else
1220 1277
 	{
1221 1278
 		$fh = @fopen($path . '/.htaccess', 'w');
1222 1279
 		if ($fh) {
@@ -1228,9 +1285,9 @@  discard block
 block discarded – undo
1228 1285
 		$errors[] = 'htaccess_cannot_create_file';
1229 1286
 	}
1230 1287
 
1231
-	if (file_exists($path . '/index.php'))
1232
-		$errors[] = 'index-php_exists';
1233
-	else
1288
+	if (file_exists($path . '/index.php')) {
1289
+			$errors[] = 'index-php_exists';
1290
+	} else
1234 1291
 	{
1235 1292
 		$fh = @fopen($path . '/index.php', 'w');
1236 1293
 		if ($fh) {
@@ -1257,11 +1314,12 @@  discard block
 block discarded – undo
1257 1314
 		$errors[] = 'index-php_cannot_create_file';
1258 1315
 	}
1259 1316
 
1260
-	if (!empty($errors))
1261
-		return $errors;
1262
-	else
1263
-		return true;
1264
-}
1317
+	if (!empty($errors)) {
1318
+			return $errors;
1319
+	} else {
1320
+			return true;
1321
+	}
1322
+	}
1265 1323
 
1266 1324
 /**
1267 1325
 * This sets the X-Frame-Options header.
@@ -1274,14 +1332,16 @@  discard block
 block discarded – undo
1274 1332
 	global $modSettings;
1275 1333
 
1276 1334
 	$option = 'SAMEORIGIN';
1277
-	if (is_null($override) && !empty($modSettings['frame_security']))
1278
-		$option = $modSettings['frame_security'];
1279
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1280
-		$option = $override;
1335
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1336
+			$option = $modSettings['frame_security'];
1337
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1338
+			$option = $override;
1339
+	}
1281 1340
 
1282 1341
 	// Don't bother setting the header if we have disabled it.
1283
-	if ($option == 'DISABLE')
1284
-		return;
1342
+	if ($option == 'DISABLE') {
1343
+			return;
1344
+	}
1285 1345
 
1286 1346
 	// Finally set it.
1287 1347
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.