Completed
Pull Request — release-2.1 (#5005)
by Martyn
09:25 queued 03:14
created
Smileys/alienine/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +163 added lines, -122 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -276,14 +282,15 @@  discard block
 block discarded – undo
276 282
 		call_integration_hook('integrate_view_members_params', array(&$params));
277 283
 
278 284
 		$search_params = array();
279
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
280
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
281
-		elseif (!empty($_POST))
285
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
286
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
287
+		} elseif (!empty($_POST))
282 288
 		{
283 289
 			$search_params['types'] = $_POST['types'];
284
-			foreach ($params as $param_name => $param_info)
285
-				if (isset($_POST[$param_name]))
290
+			foreach ($params as $param_name => $param_info) {
291
+							if (isset($_POST[$param_name]))
286 292
 					$search_params[$param_name] = $_POST[$param_name];
293
+			}
287 294
 		}
288 295
 
289 296
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -296,34 +303,38 @@  discard block
 block discarded – undo
296 303
 		foreach ($params as $param_name => $param_info)
297 304
 		{
298 305
 			// Not filled in?
299
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
300
-				continue;
306
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
307
+							continue;
308
+			}
301 309
 
302 310
 			// Make sure numeric values are really numeric.
303
-			if (in_array($param_info['type'], array('int', 'age')))
304
-				$search_params[$param_name] = (int) $search_params[$param_name];
311
+			if (in_array($param_info['type'], array('int', 'age'))) {
312
+							$search_params[$param_name] = (int) $search_params[$param_name];
313
+			}
305 314
 			// Date values have to match the specified format.
306 315
 			elseif ($param_info['type'] == 'date')
307 316
 			{
308 317
 				// Check if this date format is valid.
309
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
310
-					continue;
318
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
319
+									continue;
320
+				}
311 321
 
312 322
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
313
-			}
314
-			elseif ($param_info['type'] == 'inet')
323
+			} elseif ($param_info['type'] == 'inet')
315 324
 			{
316 325
 				$search_params[$param_name] = ip2range($search_params[$param_name]);
317
-				if (empty($search_params[$param_name]))
318
-					continue;
326
+				if (empty($search_params[$param_name])) {
327
+									continue;
328
+				}
319 329
 			}
320 330
 
321 331
 			// Those values that are in some kind of range (<, <=, =, >=, >).
322 332
 			if (!empty($param_info['range']))
323 333
 			{
324 334
 				// Default to '=', just in case...
325
-				if (empty($range_trans[$search_params['types'][$param_name]]))
326
-					$search_params['types'][$param_name] = '=';
335
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
336
+									$search_params['types'][$param_name] = '=';
337
+				}
327 338
 
328 339
 				// Handle special case 'age'.
329 340
 				if ($param_info['type'] == 'age')
@@ -351,16 +362,17 @@  discard block
 block discarded – undo
351 362
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
352 363
 				{
353 364
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
365
+				} else {
366
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
354 367
 				}
355
-				else
356
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
357 368
 			}
358 369
 			// Checkboxes.
359 370
 			elseif ($param_info['type'] == 'checkbox')
360 371
 			{
361 372
 				// Each checkbox or no checkbox at all is checked -> ignore.
362
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
363
-					continue;
373
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
374
+									continue;
375
+				}
364 376
 
365 377
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
366 378
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
@@ -372,24 +384,23 @@  discard block
 block discarded – undo
372 384
 				{
373 385
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
374 386
 					$where_params[$param_name] = $search_params[$param_name][0];
375
-				}
376
-				elseif (count($search_params[$param_name]) === 2)
387
+				} elseif (count($search_params[$param_name]) === 2)
377 388
 				{
378 389
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
379 390
 					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
380 391
 					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
381 392
 				}
382 393
 				
383
-			}
384
-			elseif ($param_info['type'] != 'groups')
394
+			} elseif ($param_info['type'] != 'groups')
385 395
 			{
386 396
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
387 397
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
388 398
 
389
-				if ($smcFunc['db_case_sensitive'])
390
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
391
-				else
392
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
399
+				if ($smcFunc['db_case_sensitive']) {
400
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
401
+				} else {
402
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
403
+				}
393 404
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
394 405
 			}
395 406
 		}
@@ -405,16 +416,18 @@  discard block
 block discarded – undo
405 416
 		}
406 417
 
407 418
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
408
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
409
-			foreach ($search_params['membergroups'][2] as $mg)
419
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
420
+					foreach ($search_params['membergroups'][2] as $mg)
410 421
 			{
411 422
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
423
+		}
412 424
 				$where_params['add_group_' . $mg] = $mg;
413 425
 			}
414 426
 
415 427
 		// Combine the one or two membergroup parts into one query part linked with an OR.
416
-		if (!empty($mg_query_parts))
417
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
428
+		if (!empty($mg_query_parts)) {
429
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
430
+		}
418 431
 
419 432
 		// Get all selected post count related membergroups.
420 433
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -426,9 +439,9 @@  discard block
 block discarded – undo
426 439
 		// Construct the where part of the query.
427 440
 		$where = empty($query_parts) ? '1=1' : implode('
428 441
 			AND ', $query_parts);
442
+	} else {
443
+			$search_url_params = null;
429 444
 	}
430
-	else
431
-		$search_url_params = null;
432 445
 
433 446
 	// Construct the additional URL part with the query info in it.
434 447
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -551,28 +564,32 @@  discard block
 block discarded – undo
551 564
 					'function' => function($rowData) use ($txt)
552 565
 					{
553 566
 						// Calculate number of days since last online.
554
-						if (empty($rowData['last_login']))
555
-							$difference = $txt['never'];
556
-						else
567
+						if (empty($rowData['last_login'])) {
568
+													$difference = $txt['never'];
569
+						} else
557 570
 						{
558 571
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
559 572
 
560 573
 							// Today.
561
-							if (empty($num_days_difference))
562
-								$difference = $txt['viewmembers_today'];
574
+							if (empty($num_days_difference)) {
575
+															$difference = $txt['viewmembers_today'];
576
+							}
563 577
 
564 578
 							// Yesterday.
565
-							elseif ($num_days_difference == 1)
566
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
579
+							elseif ($num_days_difference == 1) {
580
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
581
+							}
567 582
 
568 583
 							// X days ago.
569
-							else
570
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
584
+							else {
585
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
586
+							}
571 587
 						}
572 588
 
573 589
 						// Show it in italics if they're not activated...
574
-						if ($rowData['is_activated'] % 10 != 1)
575
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
590
+						if ($rowData['is_activated'] % 10 != 1) {
591
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
592
+						}
576 593
 
577 594
 						return $difference;
578 595
 					},
@@ -624,8 +641,9 @@  discard block
 block discarded – undo
624 641
 	);
625 642
 
626 643
 	// Without enough permissions, don't show 'delete members' checkboxes.
627
-	if (!allowedTo('profile_remove_any'))
628
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
644
+	if (!allowedTo('profile_remove_any')) {
645
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
646
+	}
629 647
 
630 648
 	require_once($sourcedir . '/Subs-List.php');
631 649
 	createList($listOptions);
@@ -668,17 +686,18 @@  discard block
 block discarded – undo
668 686
 	);
669 687
 	while ($row = $smcFunc['db_fetch_assoc']($request))
670 688
 	{
671
-		if ($row['min_posts'] == -1)
672
-			$context['membergroups'][] = array(
689
+		if ($row['min_posts'] == -1) {
690
+					$context['membergroups'][] = array(
673 691
 				'id' => $row['id_group'],
674 692
 				'name' => $row['group_name'],
675 693
 				'can_be_additional' => true
676 694
 			);
677
-		else
678
-			$context['postgroups'][] = array(
695
+		} else {
696
+					$context['postgroups'][] = array(
679 697
 				'id' => $row['id_group'],
680 698
 				'name' => $row['group_name']
681 699
 			);
700
+		}
682 701
 	}
683 702
 	$smcFunc['db_free_result']($request);
684 703
 
@@ -705,8 +724,9 @@  discard block
 block discarded – undo
705 724
 	$context['page_title'] = $txt['admin_members'];
706 725
 	$context['sub_template'] = 'admin_browse';
707 726
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
708
-	if (isset($context['tabs'][$context['browse_type']]))
709
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
727
+	if (isset($context['tabs'][$context['browse_type']])) {
728
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
729
+	}
710 730
 
711 731
 	// Allowed filters are those we can have, in theory.
712 732
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -717,18 +737,20 @@  discard block
 block discarded – undo
717 737
 	foreach ($context['activation_numbers'] as $type => $amount)
718 738
 	{
719 739
 		// We have some of these...
720
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
721
-			$context['available_filters'][] = array(
740
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
741
+					$context['available_filters'][] = array(
722 742
 				'type' => $type,
723 743
 				'amount' => $amount,
724 744
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
725 745
 				'selected' => $type == $context['current_filter']
726 746
 			);
747
+		}
727 748
 	}
728 749
 
729 750
 	// If the filter was not sent, set it to whatever has people in it!
730
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
731
-		$context['current_filter'] = $context['available_filters'][0]['type'];
751
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
752
+			$context['current_filter'] = $context['available_filters'][0]['type'];
753
+	}
732 754
 
733 755
 	// This little variable is used to determine if we should flag where we are looking.
734 756
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -743,44 +765,47 @@  discard block
 block discarded – undo
743 765
 	);
744 766
 
745 767
 	// Are we showing duplicate information?
746
-	if (isset($_GET['showdupes']))
747
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
768
+	if (isset($_GET['showdupes'])) {
769
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
770
+	}
748 771
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
749 772
 
750 773
 	// Determine which actions we should allow on this page.
751 774
 	if ($context['browse_type'] == 'approve')
752 775
 	{
753 776
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
754
-		if ($context['current_filter'] == 4)
755
-			$context['allowed_actions'] = array(
777
+		if ($context['current_filter'] == 4) {
778
+					$context['allowed_actions'] = array(
756 779
 				'reject' => $txt['admin_browse_w_approve_deletion'],
757 780
 				'ok' => $txt['admin_browse_w_reject'],
758 781
 			);
759
-		else
760
-			$context['allowed_actions'] = array(
782
+		} else {
783
+					$context['allowed_actions'] = array(
761 784
 				'ok' => $txt['admin_browse_w_approve'],
762 785
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
763 786
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
764 787
 				'reject' => $txt['admin_browse_w_reject'],
765 788
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
766 789
 			);
767
-	}
768
-	elseif ($context['browse_type'] == 'activate')
769
-		$context['allowed_actions'] = array(
790
+		}
791
+	} elseif ($context['browse_type'] == 'activate') {
792
+			$context['allowed_actions'] = array(
770 793
 			'ok' => $txt['admin_browse_w_activate'],
771 794
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
772 795
 			'delete' => $txt['admin_browse_w_delete'],
773 796
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
774 797
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
775 798
 		);
799
+	}
776 800
 
777 801
 	// Create an option list for actions allowed to be done with selected members.
778 802
 	$allowed_actions = '
779 803
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
780 804
 			<option value="" disabled>-----------------------------</option>';
781
-	foreach ($context['allowed_actions'] as $key => $desc)
782
-		$allowed_actions .= '
805
+	foreach ($context['allowed_actions'] as $key => $desc) {
806
+			$allowed_actions .= '
783 807
 			<option value="' . $key . '">' . $desc . '</option>';
808
+	}
784 809
 
785 810
 	// Setup the Javascript function for selecting an action for the list.
786 811
 	$javascript = '
@@ -792,15 +817,16 @@  discard block
 block discarded – undo
792 817
 			var message = "";';
793 818
 
794 819
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
795
-	if ($context['current_filter'] == 4)
796
-		$javascript .= '
820
+	if ($context['current_filter'] == 4) {
821
+			$javascript .= '
797 822
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
798 823
 				message = "' . $txt['admin_browse_w_delete'] . '";
799 824
 			else
800 825
 				message = "' . $txt['admin_browse_w_reject'] . '";';
826
+	}
801 827
 	// Otherwise a nice standard message.
802
-	else
803
-		$javascript .= '
828
+	else {
829
+			$javascript .= '
804 830
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
805 831
 				message = "' . $txt['admin_browse_w_delete'] . '";
806 832
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -809,6 +835,7 @@  discard block
 block discarded – undo
809 835
 				message = "' . $txt['admin_browse_w_remind'] . '";
810 836
 			else
811 837
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
838
+	}
812 839
 	$javascript .= '
813 840
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
814 841
 				document.forms.postForm.submit();
@@ -941,10 +968,11 @@  discard block
 block discarded – undo
941 968
 						$member_links = array();
942 969
 						foreach ($rowData['duplicate_members'] as $member)
943 970
 						{
944
-							if ($member['id'])
945
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
946
-							else
947
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
971
+							if ($member['id']) {
972
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
973
+							} else {
974
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
975
+							}
948 976
 						}
949 977
 						return implode(', ', $member_links);
950 978
 					},
@@ -993,14 +1021,16 @@  discard block
 block discarded – undo
993 1021
 	);
994 1022
 
995 1023
 	// Pick what column to actually include if we're showing duplicates.
996
-	if ($context['show_duplicates'])
997
-		unset($listOptions['columns']['email']);
998
-	else
999
-		unset($listOptions['columns']['duplicates']);
1024
+	if ($context['show_duplicates']) {
1025
+			unset($listOptions['columns']['email']);
1026
+	} else {
1027
+			unset($listOptions['columns']['duplicates']);
1028
+	}
1000 1029
 
1001 1030
 	// Only show hostname on duplicates as it takes a lot of time.
1002
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
1003
-		unset($listOptions['columns']['hostname']);
1031
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1032
+			unset($listOptions['columns']['hostname']);
1033
+	}
1004 1034
 
1005 1035
 	// Is there any need to show filters?
1006 1036
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -1008,9 +1038,10 @@  discard block
 block discarded – undo
1008 1038
 		$filterOptions = '
1009 1039
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
1010 1040
 			<select name="filter" onchange="this.form.submit();">';
1011
-		foreach ($context['available_filters'] as $filter)
1012
-			$filterOptions .= '
1041
+		foreach ($context['available_filters'] as $filter) {
1042
+					$filterOptions .= '
1013 1043
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1044
+		}
1014 1045
 		$filterOptions .= '
1015 1046
 			</select>
1016 1047
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -1022,12 +1053,13 @@  discard block
 block discarded – undo
1022 1053
 	}
1023 1054
 
1024 1055
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
1025
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
1026
-		$listOptions['additional_rows'][] = array(
1056
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1057
+			$listOptions['additional_rows'][] = array(
1027 1058
 			'position' => 'above_column_headers',
1028 1059
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
1029 1060
 			'class' => 'smalltext floatright',
1030 1061
 		);
1062
+	}
1031 1063
 
1032 1064
 	// Now that we have all the options, create the list.
1033 1065
 	require_once($sourcedir . '/Subs-List.php');
@@ -1057,12 +1089,14 @@  discard block
 block discarded – undo
1057 1089
 	$current_filter = (int) $_REQUEST['orig_filter'];
1058 1090
 
1059 1091
 	// If we are applying a filter do just that - then redirect.
1060
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1061
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1092
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1093
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1094
+	}
1062 1095
 
1063 1096
 	// Nothing to do?
1064
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1065
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1097
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1098
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1099
+	}
1066 1100
 
1067 1101
 	// Are we dealing with members who have been waiting for > set amount of time?
1068 1102
 	if (isset($_POST['time_passed']))
@@ -1075,8 +1109,9 @@  discard block
 block discarded – undo
1075 1109
 	else
1076 1110
 	{
1077 1111
 		$members = array();
1078
-		foreach ($_POST['todoAction'] as $id)
1079
-			$members[] = (int) $id;
1112
+		foreach ($_POST['todoAction'] as $id) {
1113
+					$members[] = (int) $id;
1114
+		}
1080 1115
 		$condition = '
1081 1116
 			AND id_member IN ({array_int:members})';
1082 1117
 	}
@@ -1097,8 +1132,9 @@  discard block
 block discarded – undo
1097 1132
 	$member_count = $smcFunc['db_num_rows']($request);
1098 1133
 
1099 1134
 	// If no results then just return!
1100
-	if ($member_count == 0)
1101
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1135
+	if ($member_count == 0) {
1136
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1137
+	}
1102 1138
 
1103 1139
 	$member_info = array();
1104 1140
 	$members = array();
@@ -1137,8 +1173,9 @@  discard block
 block discarded – undo
1137 1173
 		// Do we have to let the integration code know about the activations?
1138 1174
 		if (!empty($modSettings['integrate_activate']))
1139 1175
 		{
1140
-			foreach ($member_info as $member)
1141
-				call_integration_hook('integrate_activate', array($member['username']));
1176
+			foreach ($member_info as $member) {
1177
+							call_integration_hook('integrate_activate', array($member['username']));
1178
+			}
1142 1179
 		}
1143 1180
 
1144 1181
 		// Check for email.
@@ -1268,20 +1305,23 @@  discard block
 block discarded – undo
1268 1305
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1269 1306
 
1270 1307
 		require_once($sourcedir . '/Logging.php');
1271
-		foreach ($member_info as $member)
1272
-			logAction($log_action, array('member' => $member['id']), 'admin');
1308
+		foreach ($member_info as $member) {
1309
+					logAction($log_action, array('member' => $member['id']), 'admin');
1310
+		}
1273 1311
 	}
1274 1312
 
1275 1313
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1276
-	if (in_array($current_filter, array(3, 4, 5)))
1277
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1314
+	if (in_array($current_filter, array(3, 4, 5))) {
1315
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1316
+	}
1278 1317
 
1279 1318
 	// Update the member's stats. (but, we know the member didn't change their name.)
1280 1319
 	updateStats('member', false);
1281 1320
 
1282 1321
 	// If they haven't been deleted, update the post group statistics on them...
1283
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1284
-		updateStats('postgroups', $members);
1322
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1323
+			updateStats('postgroups', $members);
1324
+	}
1285 1325
 
1286 1326
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1287 1327
 }
@@ -1306,10 +1346,11 @@  discard block
 block discarded – undo
1306 1346
 	$dis = time() - $old;
1307 1347
 
1308 1348
 	// Before midnight?
1309
-	if ($dis < $sinceMidnight)
1310
-		return 0;
1311
-	else
1312
-		$dis -= $sinceMidnight;
1349
+	if ($dis < $sinceMidnight) {
1350
+			return 0;
1351
+	} else {
1352
+			$dis -= $sinceMidnight;
1353
+	}
1313 1354
 
1314 1355
 	// Divide out the seconds in a day to get the number of days.
1315 1356
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Packages/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
cron.php 1 patch
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -41,37 +41,43 @@  discard block
 block discarded – undo
41 41
 define('TIME_START', microtime(true));
42 42
 
43 43
 // Just being safe...
44
-foreach (array('db_character_set', 'cachedir') as $variable)
44
+foreach (array('db_character_set', 'cachedir') as $variable) {
45 45
 	if (isset($GLOBALS[$variable]))
46 46
 		unset($GLOBALS[$variable]);
47
+}
47 48
 
48 49
 // Get the forum's settings for database and file paths.
49 50
 require_once(dirname(__FILE__) . '/Settings.php');
50 51
 
51 52
 // Make absolutely sure the cache directory is defined.
52
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
53
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
53 54
 	$cachedir = $boarddir . '/cache';
55
+}
54 56
 
55 57
 // Don't do john didley if the forum's been shut down competely.
56
-if ($maintenance == 2)
58
+if ($maintenance == 2) {
57 59
 	die($mmessage);
60
+}
58 61
 
59 62
 // Fix for using the current directory as a path.
60
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
61 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
62 66
 
63 67
 // Have we already turned this off? If so, exist gracefully.
64
-if (file_exists($cachedir . '/cron.lock'))
68
+if (file_exists($cachedir . '/cron.lock')) {
65 69
 	obExit_cron();
70
+}
66 71
 
67 72
 // Before we go any further, if this is not a CLI request, we need to do some checking.
68 73
 if (!FROM_CLI)
69 74
 {
70 75
 	// We will clean up $_GET shortly. But we want to this ASAP.
71 76
 	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
72
-	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
73
-		obExit_cron();
74
-}
77
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) {
78
+			obExit_cron();
79
+	}
80
+	}
75 81
 
76 82
 // Load the most important includes. In general, a background should be loading its own dependencies.
77 83
 require_once($sourcedir . '/Errors.php');
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 	global $smcFunc;
124 130
 
125 131
 	// Check we haven't run over our time limit.
126
-	if (microtime(true) - TIME_START > MAX_CRON_TIME)
127
-		return false;
132
+	if (microtime(true) - TIME_START > MAX_CRON_TIME) {
133
+			return false;
134
+	}
128 135
 
129 136
 	// Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that,
130 137
 	// a task that was claimed but failed for whatever reason and failed long enough ago. We should not care
@@ -159,14 +166,12 @@  discard block
 block discarded – undo
159 166
 			// Update the time and go back.
160 167
 			$row['claimed_time'] = time();
161 168
 			return $row;
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any.
166 172
 			return fetch_task();
167 173
 		}
168
-	}
169
-	else
174
+	} else
170 175
 	{
171 176
 		// No dice. Clean up and go home.
172 177
 		$smcFunc['db_free_result']($request);
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	if (!empty($task_details['task_file']))
188 193
 	{
189 194
 		$include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
190
-		if (file_exists($include))
191
-			require_once($include);
195
+		if (file_exists($include)) {
196
+					require_once($include);
197
+		}
192 198
 	}
193 199
 
194 200
 	if (empty($task_details['task_class']))
@@ -204,8 +210,7 @@  discard block
 block discarded – undo
204 210
 		$details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true);
205 211
 		$bgtask = new $task_details['task_class']($details);
206 212
 		return $bgtask->execute();
207
-	}
208
-	else
213
+	} else
209 214
 	{
210 215
 		log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')');
211 216
 		return true; // So we clear it from the queue.
@@ -224,8 +229,9 @@  discard block
 block discarded – undo
224 229
 	$scripturl = $boardurl . '/index.php';
225 230
 
226 231
 	// These keys shouldn't be set...ever.
227
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
228
-		die('Invalid request variable.');
232
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
233
+			die('Invalid request variable.');
234
+	}
229 235
 
230 236
 	// Save some memory.. (since we don't use these anyway.)
231 237
 	unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
@@ -246,26 +252,28 @@  discard block
 block discarded – undo
246 252
 	global $modSettings;
247 253
 
248 254
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
249
-	if (error_reporting() == 0)
250
-		return;
255
+	if (error_reporting() == 0) {
256
+			return;
257
+	}
251 258
 
252 259
 	$error_type = 'cron';
253 260
 
254 261
 	log_error($error_level . ': ' . $error_string, $error_type, $file, $line);
255 262
 
256 263
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
257
-	if ($error_level % 255 == E_ERROR)
258
-		die('No direct access...');
259
-}
264
+	if ($error_level % 255 == E_ERROR) {
265
+			die('No direct access...');
266
+	}
267
+	}
260 268
 
261 269
 /**
262 270
  * The exit function
263 271
  */
264 272
 function obExit_cron()
265 273
 {
266
-	if (FROM_CLI)
267
-		die(0);
268
-	else
274
+	if (FROM_CLI) {
275
+			die(0);
276
+	} else
269 277
 	{
270 278
 		header('content-type: image/gif');
271 279
 		die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
Please login to merge, or discard this patch.
Sources/Subscriptions-PayPal.php 1 patch
Braces   +83 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
 // This won't be dedicated without this - this must exist in each gateway!
15 15
 // SMF Payment Gateway: paypal
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Class for returning available form data for this gateway
@@ -118,8 +119,7 @@  discard block
 block discarded – undo
118 119
 		{
119 120
 			$return_data['hidden']['p3'] = 1;
120 121
 			$return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1));
121
-		}
122
-		else
122
+		} else
123 123
 		{
124 124
 			preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match);
125 125
 			$unit = $match[1];
@@ -130,14 +130,15 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 
132 132
 		// If it's repeatable do some javascript to respect this idea.
133
-		if (!empty($sub_data['repeatable']))
134
-			$return_data['javascript'] = '
133
+		if (!empty($sub_data['repeatable'])) {
134
+					$return_data['javascript'] = '
135 135
 				document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();">' . $txt['paid_make_recurring'] . '</label><br>\');
136 136
 
137 137
 				function switchPaypalRecur()
138 138
 				{
139 139
 					document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick";
140 140
 				}';
141
+		}
141 142
 
142 143
 		return $return_data;
143 144
 	}
@@ -160,20 +161,24 @@  discard block
 block discarded – undo
160 161
 		global $modSettings;
161 162
 
162 163
 		// Has the user set up an email address?
163
-		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email'])))
164
-			return false;
164
+		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) {
165
+					return false;
166
+		}
165 167
 		// Check the correct transaction types are even here.
166
-		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email'])))
167
-			return false;
168
+		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) {
169
+					return false;
170
+		}
168 171
 		// Correct email address?
169
-		if (!isset($_POST['business']))
170
-			$_POST['business'] = $_POST['receiver_email'];
172
+		if (!isset($_POST['business'])) {
173
+					$_POST['business'] = $_POST['receiver_email'];
174
+		}
171 175
 
172 176
 		// Are we testing?
173
-		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
174
-			return false;
175
-		elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails']))))
176
-			return false;
177
+		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
178
+					return false;
179
+		} elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) {
180
+					return false;
181
+		}
177 182
 		return true;
178 183
 	}
179 184
 
@@ -192,15 +197,17 @@  discard block
 block discarded – undo
192 197
 		global $modSettings, $txt;
193 198
 
194 199
 		// Put this to some default value.
195
-		if (!isset($_POST['txn_type']))
196
-			$_POST['txn_type'] = '';
200
+		if (!isset($_POST['txn_type'])) {
201
+					$_POST['txn_type'] = '';
202
+		}
197 203
 
198 204
 		// Build the request string - starting with the minimum requirement.
199 205
 		$requestString = 'cmd=_notify-validate';
200 206
 
201 207
 		// Now my dear, add all the posted bits in the order we got them
202
-		foreach ($_POST as $k => $v)
203
-			$requestString .= '&' . $k . '=' . urlencode($v);
208
+		foreach ($_POST as $k => $v) {
209
+					$requestString .= '&' . $k . '=' . urlencode($v);
210
+		}
204 211
 
205 212
 		// Can we use curl?
206 213
 		if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr'))
@@ -240,14 +247,16 @@  discard block
 block discarded – undo
240 247
 			$header .= 'connection: close' . "\r\n\r\n";
241 248
 
242 249
 			// Open the connection.
243
-			if (!empty($modSettings['paidsubs_test']))
244
-				$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
245
-			else
246
-				$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
250
+			if (!empty($modSettings['paidsubs_test'])) {
251
+							$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
252
+			} else {
253
+							$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
254
+			}
247 255
 
248 256
 			// Did it work?
249
-			if (!$fp)
250
-				generateSubscriptionError($txt['paypal_could_not_connect']);
257
+			if (!$fp) {
258
+							generateSubscriptionError($txt['paypal_could_not_connect']);
259
+			}
251 260
 
252 261
 			// Put the data to the port.
253 262
 			fputs($fp, $header . $requestString);
@@ -256,8 +265,9 @@  discard block
 block discarded – undo
256 265
 			while (!feof($fp))
257 266
 			{
258 267
 				$this->return_data = fgets($fp, 1024);
259
-				if (strcmp(trim($this->return_data), 'VERIFIED') === 0)
260
-					break;
268
+				if (strcmp(trim($this->return_data), 'VERIFIED') === 0) {
269
+									break;
270
+				}
261 271
 			}
262 272
 
263 273
 			// Clean up.
@@ -265,28 +275,34 @@  discard block
 block discarded – undo
265 275
 		}
266 276
 
267 277
 		// If this isn't verified then give up...
268
-		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0)
269
-			exit;
278
+		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) {
279
+					exit;
280
+		}
270 281
 
271 282
 		// Check that this is intended for us.
272
-		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
273
-			exit;
283
+		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
284
+					exit;
285
+		}
274 286
 
275 287
 		// Is this a subscription - and if so is it a secondary payment that we need to process?
276 288
 		// If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding.
277
-		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false)
278
-			$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
279
-		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false))
280
-			// Calculate the subscription it relates to!
289
+		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) {
290
+					$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
291
+		}
292
+		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) {
293
+					// Calculate the subscription it relates to!
281 294
 			$this->_findSubscription();
295
+		}
282 296
 
283 297
 		// Verify the currency!
284
-		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code']))
285
-			exit;
298
+		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) {
299
+					exit;
300
+		}
286 301
 
287 302
 		// Can't exist if it doesn't contain anything.
288
-		if (empty($_POST['item_number']))
289
-			exit;
303
+		if (empty($_POST['item_number'])) {
304
+					exit;
305
+		}
290 306
 
291 307
 		// Return the id_sub and id_member
292 308
 		return explode('+', $_POST['item_number']);
@@ -299,10 +315,11 @@  discard block
 block discarded – undo
299 315
 	 */
300 316
 	public function isRefund()
301 317
 	{
302
-		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed'))
303
-			return true;
304
-		else
305
-			return false;
318
+		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) {
319
+					return true;
320
+		} else {
321
+					return false;
322
+		}
306 323
 	}
307 324
 
308 325
 	/**
@@ -312,10 +329,11 @@  discard block
 block discarded – undo
312 329
 	 */
313 330
 	public function isSubscription()
314 331
 	{
315
-		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed')
316
-			return true;
317
-		else
318
-			return false;
332
+		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') {
333
+					return true;
334
+		} else {
335
+					return false;
336
+		}
319 337
 	}
320 338
 
321 339
 	/**
@@ -325,10 +343,11 @@  discard block
 block discarded – undo
325 343
 	 */
326 344
 	public function isPayment()
327 345
 	{
328
-		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept')
329
-			return true;
330
-		else
331
-			return false;
346
+		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') {
347
+					return true;
348
+		} else {
349
+					return false;
350
+		}
332 351
 	}
333 352
 
334 353
 	/**
@@ -341,10 +360,11 @@  discard block
 block discarded – undo
341 360
 		// subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment
342 361
 		// Neither require us to *do* anything as per performCancel().
343 362
 		// subscr_eot, if sent, indicates an end of payments term.
344
-		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot')
345
-			return true;
346
-		else
347
-			return false;
363
+		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') {
364
+					return true;
365
+		} else {
366
+					return false;
367
+		}
348 368
 	}
349 369
 
350 370
 	/**
@@ -408,8 +428,9 @@  discard block
 block discarded – undo
408 428
 		global $smcFunc;
409 429
 
410 430
 		// Assume we have this?
411
-		if (empty($_POST['subscr_id']))
412
-			return false;
431
+		if (empty($_POST['subscr_id'])) {
432
+					return false;
433
+		}
413 434
 
414 435
 		// Do we have this in the database?
415 436
 		$request = $smcFunc['db_query']('', '
@@ -438,11 +459,12 @@  discard block
 block discarded – undo
438 459
 						'payer_email' => $_POST['payer_email'],
439 460
 					)
440 461
 				);
441
-				if ($smcFunc['db_num_rows']($request) === 0)
442
-					return false;
462
+				if ($smcFunc['db_num_rows']($request) === 0) {
463
+									return false;
464
+				}
465
+			} else {
466
+							return false;
443 467
 			}
444
-			else
445
-				return false;
446 468
 		}
447 469
 		list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request);
448 470
 		$_POST['item_number'] = $member_id . '+' . $subscription_id;
Please login to merge, or discard this patch.
Sources/News.php 1 patch
Braces   +226 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version, $settings;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -64,8 +66,9 @@  discard block
 block discarded – undo
64 66
 	if (!empty($_REQUEST['c']) && empty($board))
65 67
 	{
66 68
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
67
-		foreach ($_REQUEST['c'] as $i => $c)
68
-			$_REQUEST['c'][$i] = (int) $c;
69
+		foreach ($_REQUEST['c'] as $i => $c) {
70
+					$_REQUEST['c'][$i] = (int) $c;
71
+		}
69 72
 
70 73
 		if (count($_REQUEST['c']) == 1)
71 74
 		{
@@ -101,18 +104,20 @@  discard block
 block discarded – undo
101 104
 		}
102 105
 		$smcFunc['db_free_result']($request);
103 106
 
104
-		if (!empty($boards))
105
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
107
+		if (!empty($boards)) {
108
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
109
+		}
106 110
 
107 111
 		// Try to limit the number of messages we look through.
108
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
109
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
110
-	}
111
-	elseif (!empty($_REQUEST['boards']))
112
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
113
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
114
+		}
115
+	} elseif (!empty($_REQUEST['boards']))
112 116
 	{
113 117
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
114
-		foreach ($_REQUEST['boards'] as $i => $b)
115
-			$_REQUEST['boards'][$i] = (int) $b;
118
+		foreach ($_REQUEST['boards'] as $i => $b) {
119
+					$_REQUEST['boards'][$i] = (int) $b;
120
+		}
116 121
 
117 122
 		$request = $smcFunc['db_query']('', '
118 123
 			SELECT b.id_board, b.num_posts, b.name
@@ -128,29 +133,32 @@  discard block
 block discarded – undo
128 133
 
129 134
 		// Either the board specified doesn't exist or you have no access.
130 135
 		$num_boards = $smcFunc['db_num_rows']($request);
131
-		if ($num_boards == 0)
132
-			fatal_lang_error('no_board');
136
+		if ($num_boards == 0) {
137
+					fatal_lang_error('no_board');
138
+		}
133 139
 
134 140
 		$total_posts = 0;
135 141
 		$boards = array();
136 142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
137 143
 		{
138
-			if ($num_boards == 1)
139
-				$feed_meta['title'] = ' - ' . strip_tags($row['name']);
144
+			if ($num_boards == 1) {
145
+							$feed_meta['title'] = ' - ' . strip_tags($row['name']);
146
+			}
140 147
 
141 148
 			$boards[] = $row['id_board'];
142 149
 			$total_posts += $row['num_posts'];
143 150
 		}
144 151
 		$smcFunc['db_free_result']($request);
145 152
 
146
-		if (!empty($boards))
147
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
153
+		if (!empty($boards)) {
154
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
155
+		}
148 156
 
149 157
 		// The more boards, the more we're going to look through...
150
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
151
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
152
-	}
153
-	elseif (!empty($board))
158
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
159
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
160
+		}
161
+	} elseif (!empty($board))
154 162
 	{
155 163
 		$request = $smcFunc['db_query']('', '
156 164
 			SELECT num_posts
@@ -170,10 +178,10 @@  discard block
 block discarded – undo
170 178
 		$query_this_board = 'b.id_board = ' . $board;
171 179
 
172 180
 		// Try to look through just a few messages, if at all possible.
173
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
174
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
175
-	}
176
-	else
181
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
182
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
183
+		}
184
+	} else
177 185
 	{
178 186
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
179 187
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -196,30 +204,35 @@  discard block
 block discarded – undo
196 204
 	// Easy adding of sub actions
197 205
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
198 206
 
199
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
200
-		$_GET['sa'] = 'recent';
207
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
208
+			$_GET['sa'] = 'recent';
209
+	}
201 210
 
202 211
 	// We only want some information, not all of it.
203 212
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
204
-	foreach (array('board', 'boards', 'c') as $var)
205
-		if (isset($_REQUEST[$var]))
213
+	foreach (array('board', 'boards', 'c') as $var) {
214
+			if (isset($_REQUEST[$var]))
206 215
 			$cachekey[] = $_REQUEST[$var];
216
+	}
207 217
 	$cachekey = md5($smcFunc['json_encode']($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
208 218
 	$cache_t = microtime();
209 219
 
210 220
 	// Get the associative array representing the xml.
211
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
212
-		$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
221
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
222
+			$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
223
+	}
213 224
 	if (empty($xml_data))
214 225
 	{
215 226
 		$call = call_helper($subActions[$_GET['sa']][0], true);
216 227
 
217
-		if (!empty($call))
218
-			$xml_data = call_user_func($call, $xml_format);
228
+		if (!empty($call)) {
229
+					$xml_data = call_user_func($call, $xml_format);
230
+		}
219 231
 
220 232
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
221
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
222
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
233
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
234
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
235
+		}
223 236
 	}
224 237
 
225 238
 	$feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : '');
@@ -259,43 +272,49 @@  discard block
 block discarded – undo
259 272
 	call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa']));
260 273
 
261 274
 	// These can't be empty
262
-	foreach (array('title', 'desc', 'source') as $mkey)
263
-		$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
275
+	foreach (array('title', 'desc', 'source') as $mkey) {
276
+			$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
277
+	}
264 278
 
265 279
 	// Sanitize basic feed metadata values
266
-	foreach ($feed_meta as $mkey => $mvalue)
267
-		$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
280
+	foreach ($feed_meta as $mkey => $mvalue) {
281
+			$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
282
+	}
268 283
 
269 284
 	$ns_string = '';
270 285
 	if (!empty($namespaces[$xml_format]))
271 286
 	{
272
-		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl)
273
-			$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
287
+		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) {
288
+					$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
289
+		}
274 290
 	}
275 291
 
276 292
 	$extraFeedTags_string = '';
277 293
 	if (!empty($extraFeedTags[$xml_format]))
278 294
 	{
279 295
 		$indent = "\t" . ($xml_format !== 'atom' ? "\t" : '');
280
-		foreach ($extraFeedTags[$xml_format] as $extraTag)
281
-			$extraFeedTags_string .= "\n" . $indent . $extraTag;
296
+		foreach ($extraFeedTags[$xml_format] as $extraTag) {
297
+					$extraFeedTags_string .= "\n" . $indent . $extraTag;
298
+		}
282 299
 	}
283 300
 
284 301
 	// This is an xml file....
285 302
 	ob_end_clean();
286
-	if (!empty($modSettings['enableCompressedOutput']))
287
-		@ob_start('ob_gzhandler');
288
-	else
289
-		ob_start();
303
+	if (!empty($modSettings['enableCompressedOutput'])) {
304
+			@ob_start('ob_gzhandler');
305
+	} else {
306
+			ob_start();
307
+	}
290 308
 
291
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
292
-		header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
293
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
294
-		header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
295
-	elseif ($xml_format == 'atom')
296
-		header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
297
-	elseif ($xml_format == 'rdf')
298
-		header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
309
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
310
+			header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
311
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
312
+			header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
313
+	} elseif ($xml_format == 'atom') {
314
+			header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
315
+	} elseif ($xml_format == 'rdf') {
316
+			header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
317
+	}
299 318
 
300 319
 	// First, output the xml header.
301 320
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -303,10 +322,11 @@  discard block
 block discarded – undo
303 322
 	// Are we outputting an rss feed or one with more information?
304 323
 	if ($xml_format == 'rss' || $xml_format == 'rss2')
305 324
 	{
306
-		if ($xml_format == 'rss2')
307
-			foreach ($_REQUEST as $var => $val)
325
+		if ($xml_format == 'rss2') {
326
+					foreach ($_REQUEST as $var => $val)
308 327
 				if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
309 328
 					$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
329
+		}
310 330
 
311 331
 		// Start with an RSS 2.0 header.
312 332
 		echo '
@@ -327,9 +347,10 @@  discard block
 block discarded – undo
327 347
 		<language>' . $feed_meta['language'] . '</language>' : '';
328 348
 
329 349
 		// RSS2 calls for this.
330
-		if ($xml_format == 'rss2')
331
-			echo '
350
+		if ($xml_format == 'rss2') {
351
+					echo '
332 352
 		<atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />';
353
+		}
333 354
 
334 355
 		echo $extraFeedTags_string;
335 356
 
@@ -340,12 +361,12 @@  discard block
 block discarded – undo
340 361
 		echo '
341 362
 	</channel>
342 363
 </rss>';
343
-	}
344
-	elseif ($xml_format == 'atom')
364
+	} elseif ($xml_format == 'atom')
345 365
 	{
346
-		foreach ($_REQUEST as $var => $val)
347
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
366
+		foreach ($_REQUEST as $var => $val) {
367
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
348 368
 				$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
369
+		}
349 370
 
350 371
 		echo '
351 372
 <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '>
@@ -371,8 +392,7 @@  discard block
 block discarded – undo
371 392
 
372 393
 		echo '
373 394
 </feed>';
374
-	}
375
-	elseif ($xml_format == 'rdf')
395
+	} elseif ($xml_format == 'rdf')
376 396
 	{
377 397
 		echo '
378 398
 <rdf:RDF', $ns_string, '>
@@ -437,13 +457,15 @@  discard block
 block discarded – undo
437 457
 {
438 458
 	global $modSettings, $context, $scripturl;
439 459
 
440
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
441
-		return $val;
460
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
461
+			return $val;
462
+	}
442 463
 
443 464
 	call_integration_hook('integrate_fix_url', array(&$val));
444 465
 
445
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
446
-		return $val;
466
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
467
+			return $val;
468
+	}
447 469
 
448 470
 	$val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl)
449 471
 		{
@@ -466,8 +488,9 @@  discard block
 block discarded – undo
466 488
 	global $smcFunc;
467 489
 
468 490
 	// Do we even need to do this?
469
-	if (strpbrk($data, '<>&') == false && $force !== true)
470
-		return $data;
491
+	if (strpbrk($data, '<>&') == false && $force !== true) {
492
+			return $data;
493
+	}
471 494
 
472 495
 	$cdata = '<![CDATA[';
473 496
 
@@ -477,49 +500,55 @@  discard block
 block discarded – undo
477 500
 			$smcFunc['strpos']($data, '&', $pos),
478 501
 			$smcFunc['strpos']($data, ']', $pos),
479 502
 		);
480
-		if ($ns != '')
481
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
503
+		if ($ns != '') {
504
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
505
+		}
482 506
 		foreach ($positions as $k => $dummy)
483 507
 		{
484
-			if ($dummy === false)
485
-				unset($positions[$k]);
508
+			if ($dummy === false) {
509
+							unset($positions[$k]);
510
+			}
486 511
 		}
487 512
 
488 513
 		$old = $pos;
489 514
 		$pos = empty($positions) ? $n : min($positions);
490 515
 
491
-		if ($pos - $old > 0)
492
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
493
-		if ($pos >= $n)
494
-			break;
516
+		if ($pos - $old > 0) {
517
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
518
+		}
519
+		if ($pos >= $n) {
520
+					break;
521
+		}
495 522
 
496 523
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
497 524
 		{
498 525
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
499
-			if ($pos2 === false)
500
-				$pos2 = $n;
501
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
502
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
503
-			else
504
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
526
+			if ($pos2 === false) {
527
+							$pos2 = $n;
528
+			}
529
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
530
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
531
+			} else {
532
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
533
+			}
505 534
 			$pos = $pos2 + 1;
506
-		}
507
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
535
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
508 536
 		{
509 537
 			$cdata .= ']]>&#093;<![CDATA[';
510 538
 			$pos++;
511
-		}
512
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
539
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
513 540
 		{
514 541
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
515
-			if ($pos2 === false)
516
-				$pos2 = $n;
542
+			if ($pos2 === false) {
543
+							$pos2 = $n;
544
+			}
517 545
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
518 546
 
519
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
520
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
521
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
522
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
547
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
548
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
549
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
550
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
551
+			}
523 552
 
524 553
 			$pos = $pos2 + 1;
525 554
 		}
@@ -559,8 +588,9 @@  discard block
 block discarded – undo
559 588
 		'gender',
560 589
 		'blurb',
561 590
 	);
562
-	if ($xml_format != 'atom')
563
-		$keysToCdata[] = 'category';
591
+	if ($xml_format != 'atom') {
592
+			$keysToCdata[] = 'category';
593
+	}
564 594
 
565 595
 	if (!empty($forceCdataKeys))
566 596
 	{
@@ -577,8 +607,9 @@  discard block
 block discarded – undo
577 607
 		$attrs = isset($element['attributes']) ? $element['attributes'] : null;
578 608
 
579 609
 		// Skip it, it's been set to null.
580
-		if ($key === null || ($val === null && $attrs === null))
581
-			continue;
610
+		if ($key === null || ($val === null && $attrs === null)) {
611
+					continue;
612
+		}
582 613
 
583 614
 		$forceCdata = in_array($key, $forceCdataKeys);
584 615
 		$ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : '';
@@ -591,16 +622,16 @@  discard block
 block discarded – undo
591 622
 
592 623
 		if (!empty($attrs))
593 624
 		{
594
-			foreach ($attrs as $attr_key => $attr_value)
595
-				echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
625
+			foreach ($attrs as $attr_key => $attr_value) {
626
+							echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
627
+			}
596 628
 		}
597 629
 
598 630
 		// If it's empty, simply output an empty element.
599 631
 		if (empty($val))
600 632
 		{
601 633
 			echo ' />';
602
-		}
603
-		else
634
+		} else
604 635
 		{
605 636
 			echo '>';
606 637
 
@@ -612,11 +643,13 @@  discard block
 block discarded – undo
612 643
 				echo "\n", str_repeat("\t", $i);
613 644
 			}
614 645
 			// A string with returns in it.... show this as a multiline element.
615
-			elseif (strpos($val, "\n") !== false)
616
-				echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
646
+			elseif (strpos($val, "\n") !== false) {
647
+							echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
648
+			}
617 649
 			// A simple string.
618
-			else
619
-				echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
650
+			else {
651
+							echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
652
+			}
620 653
 
621 654
 			// Ending tag.
622 655
 			echo '</', $key, '>';
@@ -636,8 +669,9 @@  discard block
 block discarded – undo
636 669
 {
637 670
 	global $scripturl, $smcFunc;
638 671
 
639
-	if (!allowedTo('view_mlist'))
640
-		return array();
672
+	if (!allowedTo('view_mlist')) {
673
+			return array();
674
+	}
641 675
 
642 676
 	// Find the most recent members.
643 677
 	$request = $smcFunc['db_query']('', '
@@ -656,8 +690,8 @@  discard block
 block discarded – undo
656 690
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member'];
657 691
 
658 692
 		// Make the data look rss-ish.
659
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
660
-			$data[] = array(
693
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
694
+					$data[] = array(
661 695
 				'tag' => 'item',
662 696
 				'content' => array(
663 697
 					array(
@@ -685,8 +719,8 @@  discard block
 block discarded – undo
685 719
 					),
686 720
 				),
687 721
 			);
688
-		elseif ($xml_format == 'rdf')
689
-			$data[] = array(
722
+		} elseif ($xml_format == 'rdf') {
723
+					$data[] = array(
690 724
 				'tag' => 'item',
691 725
 				'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']),
692 726
 				'content' => array(
@@ -704,8 +738,8 @@  discard block
 block discarded – undo
704 738
 					),
705 739
 				),
706 740
 			);
707
-		elseif ($xml_format == 'atom')
708
-			$data[] = array(
741
+		} elseif ($xml_format == 'atom') {
742
+					$data[] = array(
709 743
 				'tag' => 'entry',
710 744
 				'content' => array(
711 745
 					array(
@@ -734,9 +768,10 @@  discard block
 block discarded – undo
734 768
 					),
735 769
 				),
736 770
 			);
771
+		}
737 772
 		// More logical format for the data, but harder to apply.
738
-		else
739
-			$data[] = array(
773
+		else {
774
+					$data[] = array(
740 775
 				'tag' => 'member',
741 776
 				'content' => array(
742 777
 					array(
@@ -757,6 +792,7 @@  discard block
 block discarded – undo
757 792
 					),
758 793
 				),
759 794
 			);
795
+		}
760 796
 	}
761 797
 	$smcFunc['db_free_result']($request);
762 798
 
@@ -817,22 +853,24 @@  discard block
 block discarded – undo
817 853
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
818 854
 		{
819 855
 			$smcFunc['db_free_result']($request);
820
-			if (empty($_REQUEST['boards']) && empty($board))
821
-				unset($context['optimize_msg']['lowest']);
822
-			else
823
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
856
+			if (empty($_REQUEST['boards']) && empty($board)) {
857
+							unset($context['optimize_msg']['lowest']);
858
+			} else {
859
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
860
+			}
824 861
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
825 862
 			$loops++;
863
+		} else {
864
+					$done = true;
826 865
 		}
827
-		else
828
-			$done = true;
829 866
 	}
830 867
 	$data = array();
831 868
 	while ($row = $smcFunc['db_fetch_assoc']($request))
832 869
 	{
833 870
 		// Limit the length of the message, if the option is set.
834
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
835
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
871
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
872
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
873
+		}
836 874
 
837 875
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
838 876
 
@@ -859,8 +897,9 @@  discard block
 block discarded – undo
859 897
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
860 898
 			{
861 899
 				// Include approved attachments only
862
-				if ($attach['approved'])
863
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
900
+				if ($attach['approved']) {
901
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
902
+				}
864 903
 			}
865 904
 			$smcFunc['db_free_result']($attach_request);
866 905
 
@@ -868,16 +907,17 @@  discard block
 block discarded – undo
868 907
 			if (!empty($loaded_attachments))
869 908
 			{
870 909
 				uasort($loaded_attachments, function($a, $b) {
871
-					if ($a['filesize'] == $b['filesize'])
872
-					        return 0;
910
+					if ($a['filesize'] == $b['filesize']) {
911
+										        return 0;
912
+					}
873 913
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
874 914
 				});
915
+			} else {
916
+							$loaded_attachments = null;
875 917
 			}
876
-			else
877
-				$loaded_attachments = null;
918
+		} else {
919
+					$loaded_attachments = null;
878 920
 		}
879
-		else
880
-			$loaded_attachments = null;
881 921
 
882 922
 		// Create a GUID for this topic using the tag URI scheme
883 923
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic'];
@@ -894,9 +934,9 @@  discard block
 block discarded – undo
894 934
 					'length' => $attachment['filesize'],
895 935
 					'type' => $attachment['mime_type'],
896 936
 				);
937
+			} else {
938
+							$enclosure = null;
897 939
 			}
898
-			else
899
-				$enclosure = null;
900 940
 
901 941
 			$data[] = array(
902 942
 				'tag' => 'item',
@@ -942,8 +982,7 @@  discard block
 block discarded – undo
942 982
 					),
943 983
 				),
944 984
 			);
945
-		}
946
-		elseif ($xml_format == 'rdf')
985
+		} elseif ($xml_format == 'rdf')
947 986
 		{
948 987
 			$data[] = array(
949 988
 				'tag' => 'item',
@@ -967,8 +1006,7 @@  discard block
 block discarded – undo
967 1006
 					),
968 1007
 				),
969 1008
 			);
970
-		}
971
-		elseif ($xml_format == 'atom')
1009
+		} elseif ($xml_format == 'atom')
972 1010
 		{
973 1011
 			// Only one attachment allowed
974 1012
 			if (!empty($loaded_attachments))
@@ -980,9 +1018,9 @@  discard block
 block discarded – undo
980 1018
 					'length' => $attachment['filesize'],
981 1019
 					'type' => $attachment['mime_type'],
982 1020
 				);
1021
+			} else {
1022
+							$enclosure = null;
983 1023
 			}
984
-			else
985
-				$enclosure = null;
986 1024
 
987 1025
 			$data[] = array(
988 1026
 				'tag' => 'entry',
@@ -1082,9 +1120,9 @@  discard block
 block discarded – undo
1082 1120
 						)
1083 1121
 					);
1084 1122
 				}
1123
+			} else {
1124
+							$attachments = null;
1085 1125
 			}
1086
-			else
1087
-				$attachments = null;
1088 1126
 
1089 1127
 			$data[] = array(
1090 1128
 				'tag' => 'article',
@@ -1202,22 +1240,25 @@  discard block
 block discarded – undo
1202 1240
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
1203 1241
 		{
1204 1242
 			$smcFunc['db_free_result']($request);
1205
-			if (empty($_REQUEST['boards']) && empty($board))
1206
-				unset($context['optimize_msg']['lowest']);
1207
-			else
1208
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1243
+			if (empty($_REQUEST['boards']) && empty($board)) {
1244
+							unset($context['optimize_msg']['lowest']);
1245
+			} else {
1246
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1247
+			}
1209 1248
 			$loops++;
1249
+		} else {
1250
+					$done = true;
1210 1251
 		}
1211
-		else
1212
-			$done = true;
1213 1252
 	}
1214 1253
 	$messages = array();
1215
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1216
-		$messages[] = $row['id_msg'];
1254
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1255
+			$messages[] = $row['id_msg'];
1256
+	}
1217 1257
 	$smcFunc['db_free_result']($request);
1218 1258
 
1219
-	if (empty($messages))
1220
-		return array();
1259
+	if (empty($messages)) {
1260
+			return array();
1261
+	}
1221 1262
 
1222 1263
 	// Find the most recent posts this user can see.
1223 1264
 	$request = $smcFunc['db_query']('', '
@@ -1247,8 +1288,9 @@  discard block
 block discarded – undo
1247 1288
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1248 1289
 	{
1249 1290
 		// Limit the length of the message, if the option is set.
1250
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
1251
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1291
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
1292
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1293
+		}
1252 1294
 
1253 1295
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1254 1296
 
@@ -1275,8 +1317,9 @@  discard block
 block discarded – undo
1275 1317
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
1276 1318
 			{
1277 1319
 				// Include approved attachments only
1278
-				if ($attach['approved'])
1279
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1320
+				if ($attach['approved']) {
1321
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1322
+				}
1280 1323
 			}
1281 1324
 			$smcFunc['db_free_result']($attach_request);
1282 1325
 
@@ -1284,16 +1327,17 @@  discard block
 block discarded – undo
1284 1327
 			if (!empty($loaded_attachments))
1285 1328
 			{
1286 1329
 				uasort($loaded_attachments, function($a, $b) {
1287
-					if ($a['filesize'] == $b['filesize'])
1288
-					        return 0;
1330
+					if ($a['filesize'] == $b['filesize']) {
1331
+										        return 0;
1332
+					}
1289 1333
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1290 1334
 				});
1335
+			} else {
1336
+							$loaded_attachments = null;
1291 1337
 			}
1292
-			else
1293
-				$loaded_attachments = null;
1338
+		} else {
1339
+					$loaded_attachments = null;
1294 1340
 		}
1295
-		else
1296
-			$loaded_attachments = null;
1297 1341
 
1298 1342
 		// Create a GUID for this post using the tag URI scheme
1299 1343
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg'];
@@ -1310,9 +1354,9 @@  discard block
 block discarded – undo
1310 1354
 					'length' => $attachment['filesize'],
1311 1355
 					'type' => $attachment['mime_type'],
1312 1356
 				);
1357
+			} else {
1358
+							$enclosure = null;
1313 1359
 			}
1314
-			else
1315
-				$enclosure = null;
1316 1360
 
1317 1361
 			$data[] = array(
1318 1362
 				'tag' => 'item',
@@ -1358,8 +1402,7 @@  discard block
 block discarded – undo
1358 1402
 					),
1359 1403
 				),
1360 1404
 			);
1361
-		}
1362
-		elseif ($xml_format == 'rdf')
1405
+		} elseif ($xml_format == 'rdf')
1363 1406
 		{
1364 1407
 			$data[] = array(
1365 1408
 				'tag' => 'item',
@@ -1383,8 +1426,7 @@  discard block
 block discarded – undo
1383 1426
 					),
1384 1427
 				),
1385 1428
 			);
1386
-		}
1387
-		elseif ($xml_format == 'atom')
1429
+		} elseif ($xml_format == 'atom')
1388 1430
 		{
1389 1431
 			// Only one attachment allowed
1390 1432
 			if (!empty($loaded_attachments))
@@ -1396,9 +1438,9 @@  discard block
 block discarded – undo
1396 1438
 					'length' => $attachment['filesize'],
1397 1439
 					'type' => $attachment['mime_type'],
1398 1440
 				);
1441
+			} else {
1442
+							$enclosure = null;
1399 1443
 			}
1400
-			else
1401
-				$enclosure = null;
1402 1444
 
1403 1445
 			$data[] = array(
1404 1446
 				'tag' => 'entry',
@@ -1498,9 +1540,9 @@  discard block
 block discarded – undo
1498 1540
 						)
1499 1541
 					);
1500 1542
 				}
1543
+			} else {
1544
+							$attachments = null;
1501 1545
 			}
1502
-			else
1503
-				$attachments = null;
1504 1546
 
1505 1547
 			$data[] = array(
1506 1548
 				'tag' => 'recent-post',
@@ -1619,14 +1661,16 @@  discard block
 block discarded – undo
1619 1661
 	global $scripturl, $memberContext, $user_profile, $user_info;
1620 1662
 
1621 1663
 	// You must input a valid user....
1622
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
1623
-		return array();
1664
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
1665
+			return array();
1666
+	}
1624 1667
 
1625 1668
 	// Make sure the id is a number and not "I like trying to hack the database".
1626 1669
 	$_GET['u'] = (int) $_GET['u'];
1627 1670
 	// Load the member's contextual information!
1628
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
1629
-		return array();
1671
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
1672
+			return array();
1673
+	}
1630 1674
 
1631 1675
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
1632 1676
 	$profile = &$memberContext[$_GET['u']];
@@ -1668,8 +1712,7 @@  discard block
 block discarded – undo
1668 1712
 				),
1669 1713
 			)
1670 1714
 		);
1671
-	}
1672
-	elseif ($xml_format == 'rdf')
1715
+	} elseif ($xml_format == 'rdf')
1673 1716
 	{
1674 1717
 		$data[] = array(
1675 1718
 			'tag' => 'item',
@@ -1693,8 +1736,7 @@  discard block
 block discarded – undo
1693 1736
 				),
1694 1737
 			)
1695 1738
 		);
1696
-	}
1697
-	elseif ($xml_format == 'atom')
1739
+	} elseif ($xml_format == 'atom')
1698 1740
 	{
1699 1741
 		$data[] = array(
1700 1742
 			'tag' => 'entry',
@@ -1747,8 +1789,7 @@  discard block
 block discarded – undo
1747 1789
 				),
1748 1790
 			)
1749 1791
 		);
1750
-	}
1751
-	else
1792
+	} else
1752 1793
 	{
1753 1794
 		$data = array(
1754 1795
 			array(
Please login to merge, or discard this patch.
Sources/Calendar.php 1 patch
Braces   +122 added lines, -97 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -88,22 +91,25 @@  discard block
 block discarded – undo
88 91
 	$context['page_title'] = $txt['calendar'];
89 92
 
90 93
 	// Ensure a default view is defined
91
-	if (empty($modSettings['calendar_default_view']))
92
-		$modSettings['calendar_default_view'] = 'viewlist';
94
+	if (empty($modSettings['calendar_default_view'])) {
95
+			$modSettings['calendar_default_view'] = 'viewlist';
96
+	}
93 97
 
94 98
 	// What view do we want?
95
-	if (isset($_GET['viewweek']))
96
-		$context['calendar_view'] = 'viewweek';
97
-	elseif (isset($_GET['viewmonth']))
98
-		$context['calendar_view'] = 'viewmonth';
99
-	elseif (isset($_GET['viewlist']))
100
-		$context['calendar_view'] = 'viewlist';
101
-	else
102
-		$context['calendar_view'] = $modSettings['calendar_default_view'];
99
+	if (isset($_GET['viewweek'])) {
100
+			$context['calendar_view'] = 'viewweek';
101
+	} elseif (isset($_GET['viewmonth'])) {
102
+			$context['calendar_view'] = 'viewmonth';
103
+	} elseif (isset($_GET['viewlist'])) {
104
+			$context['calendar_view'] = 'viewlist';
105
+	} else {
106
+			$context['calendar_view'] = $modSettings['calendar_default_view'];
107
+	}
103 108
 
104 109
 	// Don't let search engines index the non-default calendar pages
105
-	if ($context['calendar_view'] !== $modSettings['calendar_default_view'])
106
-		$context['robot_no_index'] = true;
110
+	if ($context['calendar_view'] !== $modSettings['calendar_default_view']) {
111
+			$context['robot_no_index'] = true;
112
+	}
107 113
 
108 114
 	// Get the current day of month...
109 115
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -164,16 +170,19 @@  discard block
 block discarded – undo
164 170
 	);
165 171
 
166 172
 	// Make sure the year and month are in valid ranges.
167
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
168
-		fatal_lang_error('invalid_month', false);
169
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
170
-		fatal_lang_error('invalid_year', false);
173
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
174
+			fatal_lang_error('invalid_month', false);
175
+	}
176
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
177
+			fatal_lang_error('invalid_year', false);
178
+	}
171 179
 	// If we have a day clean that too.
172 180
 	if ($context['calendar_view'] != 'viewmonth')
173 181
 	{
174 182
 		$isValid = checkdate($curPage['month'], $curPage['day'], $curPage['year']);
175
-		if (!$isValid)
176
-			fatal_lang_error('invalid_day', false);
183
+		if (!$isValid) {
184
+					fatal_lang_error('invalid_day', false);
185
+		}
177 186
 	}
178 187
 
179 188
 	// Load all the context information needed to show the calendar grid.
@@ -195,23 +204,26 @@  discard block
 block discarded – undo
195 204
 	);
196 205
 
197 206
 	// Load up the main view.
198
-	if ($context['calendar_view'] == 'viewlist')
199
-		$context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions);
200
-	elseif ($context['calendar_view'] == 'viewweek')
201
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
202
-	else
203
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
207
+	if ($context['calendar_view'] == 'viewlist') {
208
+			$context['calendar_grid_main'] = getCalendarList($curPage['start_date'], $curPage['end_date'], $calendarOptions);
209
+	} elseif ($context['calendar_view'] == 'viewweek') {
210
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
211
+	} else {
212
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
213
+	}
204 214
 
205 215
 	// Load up the previous and next months.
206 216
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
207 217
 
208 218
 	// Only show previous month if it isn't pre-January of the min-year
209
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
210
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
219
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
220
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
221
+	}
211 222
 
212 223
 	// Only show next month if it isn't post-December of the max-year
213
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
214
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
224
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
225
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
226
+	}
215 227
 
216 228
 	// Basic template stuff.
217 229
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -231,8 +243,9 @@  discard block
 block discarded – undo
231 243
 	$context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0;
232 244
 
233 245
 	// Set the page title to mention the month or week, too
234
-	if ($context['calendar_view'] != 'viewlist')
235
-		$context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
246
+	if ($context['calendar_view'] != 'viewlist') {
247
+			$context['page_title'] .= ' - ' . ($context['calendar_view'] == 'viewweek' ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
248
+	}
236 249
 
237 250
 	// Load up the linktree!
238 251
 	$context['linktree'][] = array(
@@ -245,17 +258,19 @@  discard block
 block discarded – undo
245 258
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
246 259
 	);
247 260
 	// If applicable, add the current week to the linktree.
248
-	if ($context['calendar_view'] == 'viewweek')
249
-		$context['linktree'][] = array(
261
+	if ($context['calendar_view'] == 'viewweek') {
262
+			$context['linktree'][] = array(
250 263
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
251 264
 			'name' => $context['calendar_grid_main']['week_title'],
252 265
 		);
266
+	}
253 267
 
254 268
 	// Build the calendar button array.
255 269
 	$context['calendar_buttons'] = array();
256 270
 
257
-	if ($context['can_post'])
258
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
271
+	if ($context['can_post']) {
272
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
273
+	}
259 274
 
260 275
 	// Allow mods to add additional buttons here
261 276
 	call_integration_hook('integrate_calendar_buttons');
@@ -284,14 +299,16 @@  discard block
 block discarded – undo
284 299
 	require_once($sourcedir . '/Subs.php');
285 300
 
286 301
 	// Cast this for safety...
287
-	if (isset($_REQUEST['eventid']))
288
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
302
+	if (isset($_REQUEST['eventid'])) {
303
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
304
+	}
289 305
 
290 306
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
291
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
292
-		$time_string = '%k:%M';
293
-	else
294
-		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
308
+			$time_string = '%k:%M';
309
+	} else {
310
+			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
311
+	}
295 312
 
296 313
 	$js_time_string = str_replace(
297 314
 		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -305,12 +322,14 @@  discard block
 block discarded – undo
305 322
 		checkSession();
306 323
 
307 324
 		// Validate the post...
308
-		if (!isset($_POST['link_to_board']))
309
-			validateEventPost();
325
+		if (!isset($_POST['link_to_board'])) {
326
+					validateEventPost();
327
+		}
310 328
 
311 329
 		// If you're not allowed to edit any events, you have to be the poster.
312
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
313
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
330
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
331
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
332
+		}
314 333
 
315 334
 		// New - and directing?
316 335
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -333,8 +352,9 @@  discard block
 block discarded – undo
333 352
 		}
334 353
 
335 354
 		// Deleting...
336
-		elseif (isset($_REQUEST['deleteevent']))
337
-			removeEvent($_REQUEST['eventid']);
355
+		elseif (isset($_REQUEST['deleteevent'])) {
356
+					removeEvent($_REQUEST['eventid']);
357
+		}
338 358
 
339 359
 		// ... or just update it?
340 360
 		else
@@ -357,15 +377,13 @@  discard block
 block discarded – undo
357 377
 			$year = $d['year'];
358 378
 			$month = $d['month'];
359 379
 			$day = $d['day'];
360
-		}
361
-		elseif (isset($_POST['start_datetime']))
380
+		} elseif (isset($_POST['start_datetime']))
362 381
 		{
363 382
 			$d = date_parse($_POST['start_datetime']);
364 383
 			$year = $d['year'];
365 384
 			$month = $d['month'];
366 385
 			$day = $d['day'];
367
-		}
368
-		else
386
+		} else
369 387
 		{
370 388
 			$today = getdate();
371 389
 			$year = isset($_POST['year']) ? $_POST['year'] : $today['year'];
@@ -399,13 +417,13 @@  discard block
 block discarded – undo
399 417
 		$context['event'] = array_merge($context['event'], $eventDatetimes);
400 418
 
401 419
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
402
-	}
403
-	else
420
+	} else
404 421
 	{
405 422
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
406 423
 
407
-		if ($context['event'] === false)
408
-			fatal_lang_error('no_access', false);
424
+		if ($context['event'] === false) {
425
+					fatal_lang_error('no_access', false);
426
+		}
409 427
 
410 428
 		// If it has a board, then they should be editing it within the topic.
411 429
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -416,10 +434,11 @@  discard block
 block discarded – undo
416 434
 		}
417 435
 
418 436
 		// Make sure the user is allowed to edit this event.
419
-		if ($context['event']['member'] != $user_info['id'])
420
-			isAllowedTo('calendar_edit_any');
421
-		elseif (!allowedTo('calendar_edit_any'))
422
-			isAllowedTo('calendar_edit_own');
437
+		if ($context['event']['member'] != $user_info['id']) {
438
+					isAllowedTo('calendar_edit_any');
439
+		} elseif (!allowedTo('calendar_edit_any')) {
440
+					isAllowedTo('calendar_edit_own');
441
+		}
423 442
 	}
424 443
 
425 444
 	// An all day event? Set up some nice defaults in case the user wants to change that
@@ -453,8 +472,7 @@  discard block
 block discarded – undo
453 472
 	{
454 473
 		// You can post new events but can't link them to anything...
455 474
 		$context['event']['categories'] = array();
456
-	}
457
-	else
475
+	} else
458 476
 	{
459 477
 		// Load the list of boards and categories in the context.
460 478
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -541,12 +559,14 @@  discard block
 block discarded – undo
541 559
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
542 560
 
543 561
 	// You can't export if the calendar export feature is off.
544
-	if (empty($modSettings['cal_export']))
545
-		fatal_lang_error('calendar_export_off', false);
562
+	if (empty($modSettings['cal_export'])) {
563
+			fatal_lang_error('calendar_export_off', false);
564
+	}
546 565
 
547 566
 	// Goes without saying that this is required.
548
-	if (!isset($_REQUEST['eventid']))
549
-		fatal_lang_error('no_access', false);
567
+	if (!isset($_REQUEST['eventid'])) {
568
+			fatal_lang_error('no_access', false);
569
+	}
550 570
 
551 571
 	// This is kinda wanted.
552 572
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -554,15 +574,17 @@  discard block
 block discarded – undo
554 574
 	// Load up the event in question and check it exists.
555 575
 	$event = getEventProperties($_REQUEST['eventid']);
556 576
 
557
-	if ($event === false)
558
-		fatal_lang_error('no_access', false);
577
+	if ($event === false) {
578
+			fatal_lang_error('no_access', false);
579
+	}
559 580
 
560 581
 	// Check the title isn't too long - iCal requires some formatting if so.
561 582
 	$title = str_split($event['title'], 30);
562 583
 	foreach ($title as $id => $line)
563 584
 	{
564
-		if ($id != 0)
565
-			$title[$id] = ' ' . $title[$id];
585
+		if ($id != 0) {
586
+					$title[$id] = ' ' . $title[$id];
587
+		}
566 588
 		$title[$id] .= "\n";
567 589
 	}
568 590
 
@@ -575,8 +597,7 @@  discard block
 block discarded – undo
575 597
 	{
576 598
 		$datestart = date_format($start_date, 'Ymd\THis');
577 599
 		$dateend = date_format($end_date, 'Ymd\THis');
578
-	}
579
-	else
600
+	} else
580 601
 	{
581 602
 		$datestart = date_format($start_date, 'Ymd');
582 603
 
@@ -597,15 +618,18 @@  discard block
 block discarded – undo
597 618
 	$filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n";
598 619
 
599 620
 	// event has a duration
600
-	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate'])
601
-		$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
621
+	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) {
622
+			$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
623
+	}
602 624
 
603 625
 	// event has changed? advance the sequence for this UID
604
-	if ($event['sequence'] > 0)
605
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
626
+	if ($event['sequence'] > 0) {
627
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
628
+	}
606 629
 
607
-	if (!empty($event['location']))
608
-		$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
630
+	if (!empty($event['location'])) {
631
+			$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
632
+	}
609 633
 
610 634
 	$filecontents .= 'SUMMARY:' . implode('', $title);
611 635
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -614,23 +638,26 @@  discard block
 block discarded – undo
614 638
 
615 639
 	// Send some standard headers.
616 640
 	ob_end_clean();
617
-	if (!empty($modSettings['enableCompressedOutput']))
618
-		@ob_start('ob_gzhandler');
619
-	else
620
-		ob_start();
641
+	if (!empty($modSettings['enableCompressedOutput'])) {
642
+			@ob_start('ob_gzhandler');
643
+	} else {
644
+			ob_start();
645
+	}
621 646
 
622 647
 	// Send the file headers
623 648
 	header('pragma: ');
624 649
 	header('cache-control: no-cache');
625
-	if (!isBrowser('gecko'))
626
-		header('content-transfer-encoding: binary');
650
+	if (!isBrowser('gecko')) {
651
+			header('content-transfer-encoding: binary');
652
+	}
627 653
 	header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
628 654
 	header('last-modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
629 655
 	header('accept-ranges: bytes');
630 656
 	header('connection: close');
631 657
 	header('content-disposition: attachment; filename="' . $event['title'] . '.ics"');
632
-	if (empty($modSettings['enableCompressedOutput']))
633
-		header('content-length: ' . $smcFunc['strlen']($filecontents));
658
+	if (empty($modSettings['enableCompressedOutput'])) {
659
+			header('content-length: ' . $smcFunc['strlen']($filecontents));
660
+	}
634 661
 
635 662
 	// This is a calendar item!
636 663
 	header('content-type: text/calendar');
@@ -669,20 +696,17 @@  discard block
 block discarded – undo
669 696
 		$context['sub_template'] = 'bcd';
670 697
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
671 698
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoMSI6WzIsMV0sImgyIjpbOCw0LDIsMV0sIm0xIjpbNCwyLDFdLCJtMiI6WzgsNCwyLDFdLCJzMSI6WzQsMiwxXSwiczIiOls4LDQsMiwxXX0='), true);
672
-	}
673
-	elseif (!$omfg && !isset($_REQUEST['time']))
699
+	} elseif (!$omfg && !isset($_REQUEST['time']))
674 700
 	{
675 701
 		$context['sub_template'] = 'hms';
676 702
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
677 703
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJoIjpbMTYsOCw0LDIsMV0sIm0iOlszMiwxNiw4LDQsMiwxXSwicyI6WzMyLDE2LDgsNCwyLDFdfQ'), true);
678
-	}
679
-	elseif ($omfg)
704
+	} elseif ($omfg)
680 705
 	{
681 706
 		$context['sub_template'] = 'omfg';
682 707
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
683 708
 		$context['clockicons'] = $smcFunc['json_decode'](base64_decode('eyJ5ZWFyIjpbNjQsMzIsMTYsOCw0LDIsMV0sIm1vbnRoIjpbOCw0LDIsMV0sImRheSI6WzE2LDgsNCwyLDFdLCJob3VyIjpbMTYsOCw0LDIsMV0sIm1pbiI6WzMyLDE2LDgsNCwyLDFdLCJzZWMiOlszMiwxNiw4LDQsMiwxXX0='), true);
684
-	}
685
-	elseif (isset($_REQUEST['time']))
709
+	} elseif (isset($_REQUEST['time']))
686 710
 	{
687 711
 		$context['sub_template'] = 'thetime';
688 712
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -736,12 +760,13 @@  discard block
 block discarded – undo
736 760
 			),
737 761
 		);
738 762
 
739
-		foreach ($context['clockicons'] as $t => $vs)
740
-			foreach ($vs as $v => $dumb)
763
+		foreach ($context['clockicons'] as $t => $vs) {
764
+					foreach ($vs as $v => $dumb)
741 765
 			{
742 766
 				if ($$t >= $v)
743 767
 				{
744 768
 					$$t -= $v;
769
+		}
745 770
 					$context['clockicons'][$t][$v] = true;
746 771
 				}
747 772
 			}
Please login to merge, or discard this patch.
Sources/Attachments.php 1 patch
Braces   +102 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -119,19 +123,21 @@  discard block
 block discarded – undo
119 123
 	public function add()
120 124
 	{
121 125
 		// You gotta be able to post attachments.
122
-		if (!$this->_canPostAttachment)
123
-			return $this->setResponse(array(
126
+		if (!$this->_canPostAttachment) {
127
+					return $this->setResponse(array(
124 128
 				'text' => 'attached_file_cannot',
125 129
 				'type' => 'error',
126 130
 				'data' => false,
127 131
 			));
132
+		}
128 133
 
129 134
 		// Process them at once!
130 135
 		$this->processAttachments();
131 136
 
132 137
 		// The attachments was created and moved the the right folder, time to update the DB.
133
-		if (!empty($_SESSION['temp_attachments']))
134
-			$this->createAtttach();
138
+		if (!empty($_SESSION['temp_attachments'])) {
139
+					$this->createAtttach();
140
+		}
135 141
 
136 142
 		// Set the response.
137 143
 		$this->setResponse();
@@ -144,8 +150,9 @@  discard block
 block discarded – undo
144 150
 	{
145 151
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
146 152
 
147
-		if (!isset($_FILES['attachment']['name']))
148
-			$_FILES['attachment']['tmp_name'] = array();
153
+		if (!isset($_FILES['attachment']['name'])) {
154
+					$_FILES['attachment']['tmp_name'] = array();
155
+		}
149 156
 
150 157
 		// If there are attachments, calculate the total size and how many.
151 158
 		$context['attachments']['total_size'] = 0;
@@ -155,25 +162,30 @@  discard block
 block discarded – undo
155 162
 		if (isset($_REQUEST['msg']))
156 163
 		{
157 164
 			$context['attachments']['quantity'] = count($context['current_attachments']);
158
-			foreach ($context['current_attachments'] as $attachment)
159
-				$context['attachments']['total_size'] += $attachment['size'];
165
+			foreach ($context['current_attachments'] as $attachment) {
166
+							$context['attachments']['total_size'] += $attachment['size'];
167
+			}
160 168
 		}
161 169
 
162 170
 		// A bit of house keeping first.
163
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
164
-			unset($_SESSION['temp_attachments']);
171
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
172
+					unset($_SESSION['temp_attachments']);
173
+		}
165 174
 
166 175
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
167
-		if (!isset($_SESSION['temp_attachments']))
168
-			$_SESSION['temp_attachments'] = array();
176
+		if (!isset($_SESSION['temp_attachments'])) {
177
+					$_SESSION['temp_attachments'] = array();
178
+		}
169 179
 
170 180
 		// Make sure we're uploading to the right place.
171
-		if (!empty($modSettings['automanage_attachments']))
172
-			automanage_attachments_check_directory();
181
+		if (!empty($modSettings['automanage_attachments'])) {
182
+					automanage_attachments_check_directory();
183
+		}
173 184
 
174 185
 		// Is the attachments folder actually there?
175
-		if (!empty($context['dir_creation_error']))
176
-			$this->_generalErrors[] = $context['dir_creation_error'];
186
+		if (!empty($context['dir_creation_error'])) {
187
+					$this->_generalErrors[] = $context['dir_creation_error'];
188
+		}
177 189
 
178 190
 		// The current attach folder ha some issues...
179 191
 		elseif (!is_dir($this->_attchDir))
@@ -198,13 +210,12 @@  discard block
 block discarded – undo
198 210
 			);
199 211
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
200 212
 			$smcFunc['db_free_result']($request);
201
-		}
202
-
203
-		else
204
-			$context['attachments'] = array(
213
+		} else {
214
+					$context['attachments'] = array(
205 215
 				'quantity' => 0,
206 216
 				'total_size' => 0,
207 217
 			);
218
+		}
208 219
 
209 220
 		// Check for other general errors here.
210 221
 
@@ -212,9 +223,10 @@  discard block
 block discarded – undo
212 223
 		if (!empty($this->_generalErrors))
213 224
 		{
214 225
 			// And delete the files 'cos they ain't going nowhere.
215
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
216
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
226
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
227
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
217 228
 					unlink($_FILES['attachment']['tmp_name'][$n]);
229
+			}
218 230
 
219 231
 			$_FILES['attachment']['tmp_name'] = array();
220 232
 
@@ -225,26 +237,29 @@  discard block
 block discarded – undo
225 237
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
226 238
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
227 239
 		{
228
-			if ($_FILES['attachment']['name'][$n] == '')
229
-				continue;
240
+			if ($_FILES['attachment']['name'][$n] == '') {
241
+							continue;
242
+			}
230 243
 
231 244
 			// First, let's first check for PHP upload errors.
232 245
 			$errors = array();
233 246
 			if (!empty($_FILES['attachment']['error'][$n]))
234 247
 			{
235
-				if ($_FILES['attachment']['error'][$n] == 2)
236
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
237
-
238
-				else
239
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
248
+				if ($_FILES['attachment']['error'][$n] == 2) {
249
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
250
+				} else {
251
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
252
+				}
240 253
 
241 254
 				// Log this one, because...
242
-				if ($_FILES['attachment']['error'][$n] == 6)
243
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
255
+				if ($_FILES['attachment']['error'][$n] == 6) {
256
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				}
244 258
 
245 259
 				// Weird, no errors were cached, still fill out a generic one.
246
-				if (empty($errors))
247
-					$errors[] = 'attach_php_error';
260
+				if (empty($errors)) {
261
+									$errors[] = 'attach_php_error';
262
+				}
248 263
 			}
249 264
 
250 265
 			// Try to move and rename the file before doing any more checks on it.
@@ -256,8 +271,9 @@  discard block
 block discarded – undo
256 271
 			{
257 272
 				// The reported MIME type of the attachment might not be reliable.
258 273
 				// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
259
-				if (function_exists('mime_content_type'))
260
-					$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
274
+				if (function_exists('mime_content_type')) {
275
+									$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
276
+				}
261 277
 
262 278
 				$_SESSION['temp_attachments'][$attachID] = array(
263 279
 					'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -269,16 +285,18 @@  discard block
 block discarded – undo
269 285
 				);
270 286
 
271 287
 				// Move the file to the attachments folder with a temp name for now.
272
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
273
-					smf_chmod($destName, 0644);
288
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
289
+									smf_chmod($destName, 0644);
290
+				}
274 291
 
275 292
 				// This is madness!!
276 293
 				else
277 294
 				{
278 295
 					// File couldn't be moved.
279 296
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
280
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
281
-						unlink($_FILES['attachment']['tmp_name'][$n]);
297
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
298
+											unlink($_FILES['attachment']['tmp_name'][$n]);
299
+					}
282 300
 				}
283 301
 			}
284 302
 
@@ -291,13 +309,15 @@  discard block
 block discarded – undo
291 309
 					'errors' => $errors,
292 310
 				);
293 311
 
294
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
295
-					unlink($_FILES['attachment']['tmp_name'][$n]);
312
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
313
+									unlink($_FILES['attachment']['tmp_name'][$n]);
314
+				}
296 315
 			}
297 316
 
298 317
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
299
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
300
-				attachmentChecks($attachID);
318
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
319
+							attachmentChecks($attachID);
320
+			}
301 321
 		}
302 322
 
303 323
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -344,14 +364,15 @@  discard block
 block discarded – undo
344 364
 
345 365
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
346 366
 
347
-					if (!empty($attachmentOptions['thumb']))
348
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					if (!empty($attachmentOptions['thumb'])) {
368
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
369
+					}
349 370
 
350
-					if ($this->_msg)
351
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					if ($this->_msg) {
372
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
373
+					}
352 374
 				}
353
-			}
354
-			else
375
+			} else
355 376
 			{
356 377
 				// Sort out the errors for display and delete any associated files.
357 378
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -363,14 +384,16 @@  discard block
 block discarded – undo
363 384
 					if (!is_array($error))
364 385
 					{
365 386
 						$attachmentOptions['errors'][] = $txt[$error];
366
-						if (in_array($error, $log_these))
367
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
387
+						if (in_array($error, $log_these)) {
388
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
389
+						}
390
+					} else {
391
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
368 392
 					}
369
-					else
370
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
371 393
 				}
372
-				if (file_exists($attachment['tmp_name']))
373
-					unlink($attachment['tmp_name']);
394
+				if (file_exists($attachment['tmp_name'])) {
395
+									unlink($attachment['tmp_name']);
396
+				}
374 397
 			}
375 398
 
376 399
 			// You don't need to know.
@@ -382,8 +405,9 @@  discard block
 block discarded – undo
382 405
 		}
383 406
 
384 407
 		// Temp save this on the db.
385
-		if (!empty($_SESSION['already_attached']))
386
-			$this->_attachSuccess = $_SESSION['already_attached'];
408
+		if (!empty($_SESSION['already_attached'])) {
409
+					$this->_attachSuccess = $_SESSION['already_attached'];
410
+		}
387 411
 
388 412
 		unset($_SESSION['temp_attachments']);
389 413
 	}
@@ -403,14 +427,16 @@  discard block
 block discarded – undo
403 427
 		if ($this->_sa == 'add')
404 428
 		{
405 429
 			// Is there any generic errors? made some sense out of them!
406
-			if ($this->_generalErrors)
407
-				foreach ($this->_generalErrors as $k => $v)
430
+			if ($this->_generalErrors) {
431
+							foreach ($this->_generalErrors as $k => $v)
408 432
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
433
+			}
409 434
 
410 435
 			// Gotta urlencode the filename.
411
-			if ($this->_attachResults)
412
-				foreach ($this->_attachResults as $k => $v)
436
+			if ($this->_attachResults) {
437
+							foreach ($this->_attachResults as $k => $v)
413 438
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
439
+			}
414 440
 
415 441
 			$this->_response = array(
416 442
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -419,9 +445,10 @@  discard block
 block discarded – undo
419 445
 		}
420 446
 
421 447
 		// Rest of us mere mortals gets no special treatment...
422
-		elseif (!empty($data))
423
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
448
+		elseif (!empty($data)) {
449
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
424 450
 				$this->_response['text'] = $txt[$data['text']];
451
+		}
425 452
 	}
426 453
 
427 454
 	protected function sendResponse()
@@ -430,11 +457,11 @@  discard block
 block discarded – undo
430 457
 
431 458
 		ob_end_clean();
432 459
 
433
-		if (!empty($modSettings['CompressedOutput']))
434
-			@ob_start('ob_gzhandler');
435
-
436
-		else
437
-			ob_start();
460
+		if (!empty($modSettings['CompressedOutput'])) {
461
+					@ob_start('ob_gzhandler');
462
+		} else {
463
+					ob_start();
464
+		}
438 465
 
439 466
 		// Set the header.
440 467
 		header('content-type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.
other/Settings.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -185,17 +185,21 @@  discard block
 block discarded – undo
185 185
 $tasksdir = $sourcedir . '/tasks';
186 186
 
187 187
 # Make sure the paths are correct... at least try to fix them.
188
-if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt'))
188
+if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) {
189 189
 	$boarddir = dirname(__FILE__);
190
-if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources'))
190
+}
191
+if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) {
191 192
 	$sourcedir = $boarddir . '/Sources';
192
-if (!file_exists($cachedir) && file_exists($boarddir . '/cache'))
193
+}
194
+if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) {
193 195
 	$cachedir = $boarddir . '/cache';
196
+}
194 197
 
195 198
 ########## Error-Catching ##########
196 199
 # Note: You shouldn't touch these settings.
197
-if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'))
200
+if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) {
198 201
 	include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php');
202
+}
199 203
 
200 204
 if (!isset($db_last_error))
201 205
 {
@@ -207,10 +211,11 @@  discard block
 block discarded – undo
207 211
 if (file_exists(dirname(__FILE__) . '/install.php'))
208 212
 {
209 213
 	$secure = false;
210
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
211
-		$secure = true;
212
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
213
-		$secure = true;
214
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
215
+			$secure = true;
216
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
217
+			$secure = true;
218
+	}
214 219
 
215 220
 	header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit;
216 221
 }
Please login to merge, or discard this patch.