Completed
Pull Request — release-2.1 (#4166)
by 01
10:19
created
Sources/Profile-View.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2605,7 +2605,7 @@
 block discarded – undo
2605 2605
  * @param int $start Which item to start with (for pagination purposes)
2606 2606
  * @param int $items_per_page How many items to show on each page
2607 2607
  * @param string $sort A string indicating how to sort the results
2608
- * @param int $memID The ID of the member
2608
+ * @param string $memID The ID of the member
2609 2609
  * @return array An array of information about the user's group requests
2610 2610
  */
2611 2611
 function list_getGroupRequests($start, $items_per_page, $sort, $memID)
Please login to merge, or discard this patch.
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']) || substr($context['member']['birthdate'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -582,10 +612,11 @@  discard block
 block discarded – undo
582 612
 
583 613
 	$range_limit = '';
584 614
 
585
-	if ($context['is_topics'])
586
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
587
-	else
588
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
615
+	if ($context['is_topics']) {
616
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
617
+	} else {
618
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
619
+	}
589 620
 
590 621
 	$maxIndex = $maxPerPage;
591 622
 
@@ -611,9 +642,9 @@  discard block
 block discarded – undo
611 642
 		{
612 643
 			$margin *= 5;
613 644
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
645
+		} else {
646
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
614 647
 		}
615
-		else
616
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
617 648
 	}
618 649
 
619 650
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 					'max' => $maxIndex,
646 677
 				)
647 678
 			);
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			$request = $smcFunc['db_query']('', '
652 682
 				SELECT
@@ -675,8 +705,9 @@  discard block
 block discarded – undo
675 705
 		}
676 706
 
677 707
 		// Make sure we quit this loop.
678
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
679
-			break;
708
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
709
+					break;
710
+		}
680 711
 		$looped = true;
681 712
 		$range_limit = '';
682 713
 	}
@@ -720,19 +751,21 @@  discard block
 block discarded – undo
720 751
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
721 752
 		);
722 753
 
723
-		if ($user_info['id'] == $row['id_member_started'])
724
-			$board_ids['own'][$row['id_board']][] = $counter;
754
+		if ($user_info['id'] == $row['id_member_started']) {
755
+					$board_ids['own'][$row['id_board']][] = $counter;
756
+		}
725 757
 		$board_ids['any'][$row['id_board']][] = $counter;
726 758
 	}
727 759
 	$smcFunc['db_free_result']($request);
728 760
 
729 761
 	// All posts were retrieved in reverse order, get them right again.
730
-	if ($reverse)
731
-		$context['posts'] = array_reverse($context['posts'], true);
762
+	if ($reverse) {
763
+			$context['posts'] = array_reverse($context['posts'], true);
764
+	}
732 765
 
733 766
 	// These are all the permissions that are different from board to board..
734
-	if ($context['is_topics'])
735
-		$permissions = array(
767
+	if ($context['is_topics']) {
768
+			$permissions = array(
736 769
 			'own' => array(
737 770
 				'post_reply_own' => 'can_reply',
738 771
 			),
@@ -740,8 +773,8 @@  discard block
 block discarded – undo
740 773
 				'post_reply_any' => 'can_reply',
741 774
 			)
742 775
 		);
743
-	else
744
-		$permissions = array(
776
+	} else {
777
+			$permissions = array(
745 778
 			'own' => array(
746 779
 				'post_reply_own' => 'can_reply',
747 780
 				'delete_own' => 'can_delete',
@@ -751,6 +784,7 @@  discard block
 block discarded – undo
751 784
 				'delete_any' => 'can_delete',
752 785
 			)
753 786
 		);
787
+	}
754 788
 
755 789
 	// For every permission in the own/any lists...
756 790
 	foreach ($permissions as $type => $list)
@@ -761,19 +795,22 @@  discard block
 block discarded – undo
761 795
 			$boards = boardsAllowedTo($permission);
762 796
 
763 797
 			// Hmm, they can do it on all boards, can they?
764
-			if (!empty($boards) && $boards[0] == 0)
765
-				$boards = array_keys($board_ids[$type]);
798
+			if (!empty($boards) && $boards[0] == 0) {
799
+							$boards = array_keys($board_ids[$type]);
800
+			}
766 801
 
767 802
 			// Now go through each board they can do the permission on.
768 803
 			foreach ($boards as $board_id)
769 804
 			{
770 805
 				// There aren't any posts displayed from this board.
771
-				if (!isset($board_ids[$type][$board_id]))
772
-					continue;
806
+				if (!isset($board_ids[$type][$board_id])) {
807
+									continue;
808
+				}
773 809
 
774 810
 				// Set the permission to true ;).
775
-				foreach ($board_ids[$type][$board_id] as $counter)
776
-					$context['posts'][$counter][$allowed] = true;
811
+				foreach ($board_ids[$type][$board_id] as $counter) {
812
+									$context['posts'][$counter][$allowed] = true;
813
+				}
777 814
 			}
778 815
 		}
779 816
 	}
@@ -804,8 +841,9 @@  discard block
 block discarded – undo
804 841
 	$boardsAllowed = boardsAllowedTo('view_attachments');
805 842
 
806 843
 	// Make sure we can't actually see anything...
807
-	if (empty($boardsAllowed))
808
-		$boardsAllowed = array(-1);
844
+	if (empty($boardsAllowed)) {
845
+			$boardsAllowed = array(-1);
846
+	}
809 847
 
810 848
 	require_once($sourcedir . '/Subs-List.php');
811 849
 
@@ -956,8 +994,8 @@  discard block
 block discarded – undo
956 994
 		)
957 995
 	);
958 996
 	$attachments = array();
959
-	while ($row = $smcFunc['db_fetch_assoc']($request))
960
-		$attachments[] = array(
997
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
998
+			$attachments[] = array(
961 999
 			'id' => $row['id_attach'],
962 1000
 			'filename' => $row['filename'],
963 1001
 			'downloads' => $row['downloads'],
@@ -969,6 +1007,7 @@  discard block
 block discarded – undo
969 1007
 			'board_name' => $row['name'],
970 1008
 			'approved' => $row['approved'],
971 1009
 		);
1010
+	}
972 1011
 
973 1012
 	$smcFunc['db_free_result']($request);
974 1013
 
@@ -1023,8 +1062,9 @@  discard block
 block discarded – undo
1023 1062
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1024 1063
 
1025 1064
 	// Only the owner can see the list (if the function is enabled of course)
1026
-	if ($user_info['id'] != $memID)
1027
-		return;
1065
+	if ($user_info['id'] != $memID) {
1066
+			return;
1067
+	}
1028 1068
 
1029 1069
 	require_once($sourcedir . '/Subs-List.php');
1030 1070
 
@@ -1170,8 +1210,9 @@  discard block
 block discarded – undo
1170 1210
 	);
1171 1211
 
1172 1212
 	$topics = array();
1173
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1174
-		$topics[] = $row['id_topic'];
1213
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1214
+			$topics[] = $row['id_topic'];
1215
+	}
1175 1216
 
1176 1217
 	$smcFunc['db_free_result']($request);
1177 1218
 
@@ -1191,8 +1232,9 @@  discard block
 block discarded – undo
1191 1232
 				'topics' => $topics,
1192 1233
 			)
1193 1234
 		);
1194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1195
-			$topicsInfo[] = $row;
1235
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1236
+					$topicsInfo[] = $row;
1237
+		}
1196 1238
 		$smcFunc['db_free_result']($request);
1197 1239
 	}
1198 1240
 
@@ -1240,8 +1282,9 @@  discard block
 block discarded – undo
1240 1282
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1241 1283
 
1242 1284
 	// Is the load average too high to allow searching just now?
1243
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1244
-		fatal_lang_error('loadavg_userstats_disabled', false);
1285
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1286
+			fatal_lang_error('loadavg_userstats_disabled', false);
1287
+	}
1245 1288
 
1246 1289
 	// General user statistics.
1247 1290
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1399,11 +1442,13 @@  discard block
 block discarded – undo
1399 1442
 	}
1400 1443
 	$smcFunc['db_free_result']($result);
1401 1444
 
1402
-	if ($maxPosts > 0)
1403
-		for ($hour = 0; $hour < 24; $hour++)
1445
+	if ($maxPosts > 0) {
1446
+			for ($hour = 0;
1447
+	}
1448
+	$hour < 24; $hour++)
1404 1449
 		{
1405
-			if (!isset($context['posts_by_time'][$hour]))
1406
-				$context['posts_by_time'][$hour] = array(
1450
+			if (!isset($context['posts_by_time'][$hour])) {
1451
+							$context['posts_by_time'][$hour] = array(
1407 1452
 					'hour' => $hour,
1408 1453
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1409 1454
 					'posts' => 0,
@@ -1411,7 +1456,7 @@  discard block
 block discarded – undo
1411 1456
 					'relative_percent' => 0,
1412 1457
 					'is_last' => $hour == 23,
1413 1458
 				);
1414
-			else
1459
+			} else
1415 1460
 			{
1416 1461
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1417 1462
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1444,8 +1489,9 @@  discard block
 block discarded – undo
1444 1489
 
1445 1490
 	foreach ($subActions as $sa => $action)
1446 1491
 	{
1447
-		if (!allowedTo($action[2]))
1448
-			unset($subActions[$sa]);
1492
+		if (!allowedTo($action[2])) {
1493
+					unset($subActions[$sa]);
1494
+		}
1449 1495
 	}
1450 1496
 
1451 1497
 	// Create the tabs for the template.
@@ -1463,15 +1509,18 @@  discard block
 block discarded – undo
1463 1509
 	);
1464 1510
 
1465 1511
 	// Moderation must be on to track edits.
1466
-	if (empty($modSettings['userlog_enabled']))
1467
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1512
+	if (empty($modSettings['userlog_enabled'])) {
1513
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1514
+	}
1468 1515
 
1469 1516
 	// Group requests must be active to show it...
1470
-	if (empty($modSettings['show_group_membership']))
1471
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1517
+	if (empty($modSettings['show_group_membership'])) {
1518
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1519
+	}
1472 1520
 
1473
-	if (empty($subActions))
1474
-		fatal_lang_error('no_access', false);
1521
+	if (empty($subActions)) {
1522
+			fatal_lang_error('no_access', false);
1523
+	}
1475 1524
 
1476 1525
 	$keys = array_keys($subActions);
1477 1526
 	$default = array_shift($keys);
@@ -1484,9 +1533,10 @@  discard block
 block discarded – undo
1484 1533
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1485 1534
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1486 1535
 
1487
-	if (!empty($call))
1488
-		call_user_func($call, $memID);
1489
-}
1536
+	if (!empty($call)) {
1537
+			call_user_func($call, $memID);
1538
+	}
1539
+	}
1490 1540
 
1491 1541
 /**
1492 1542
  * Handles tracking a user's activity
@@ -1502,8 +1552,9 @@  discard block
 block discarded – undo
1502 1552
 	isAllowedTo('moderate_forum');
1503 1553
 
1504 1554
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1505
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1506
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1555
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1556
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1557
+	}
1507 1558
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1508 1559
 
1509 1560
 	// Set the options for the list component.
@@ -1669,8 +1720,9 @@  discard block
 block discarded – undo
1669 1720
 			)
1670 1721
 		);
1671 1722
 		$message_members = array();
1672
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1673
-			$message_members[] = $row['id_member'];
1723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+					$message_members[] = $row['id_member'];
1725
+		}
1674 1726
 		$smcFunc['db_free_result']($request);
1675 1727
 
1676 1728
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1685,8 +1737,9 @@  discard block
 block discarded – undo
1685 1737
 					'ip_list' => $ips,
1686 1738
 				)
1687 1739
 			);
1688
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1689
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1740
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1741
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1742
+			}
1690 1743
 			$smcFunc['db_free_result']($request);
1691 1744
 		}
1692 1745
 
@@ -1700,8 +1753,9 @@  discard block
 block discarded – undo
1700 1753
 				'ip_list' => $ips,
1701 1754
 			)
1702 1755
 		);
1703
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1704
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1756
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1757
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1758
+		}
1705 1759
 		$smcFunc['db_free_result']($request);
1706 1760
 	}
1707 1761
 }
@@ -1761,8 +1815,8 @@  discard block
 block discarded – undo
1761 1815
 		))
1762 1816
 	);
1763 1817
 	$error_messages = array();
1764
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1765
-		$error_messages[] = array(
1818
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1819
+			$error_messages[] = array(
1766 1820
 			'ip' => inet_dtop($row['ip']),
1767 1821
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1768 1822
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1770,6 +1824,7 @@  discard block
 block discarded – undo
1770 1824
 			'time' => timeformat($row['log_time']),
1771 1825
 			'timestamp' => forum_time(true, $row['log_time']),
1772 1826
 		);
1827
+	}
1773 1828
 	$smcFunc['db_free_result']($request);
1774 1829
 
1775 1830
 	return $error_messages;
@@ -1832,8 +1887,8 @@  discard block
 block discarded – undo
1832 1887
 		))
1833 1888
 	);
1834 1889
 	$messages = array();
1835
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1836
-		$messages[] = array(
1890
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1891
+			$messages[] = array(
1837 1892
 			'ip' => inet_dtop($row['poster_ip']),
1838 1893
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1839 1894
 			'board' => array(
@@ -1846,6 +1901,7 @@  discard block
 block discarded – undo
1846 1901
 			'time' => timeformat($row['poster_time']),
1847 1902
 			'timestamp' => forum_time(true, $row['poster_time'])
1848 1903
 		);
1904
+	}
1849 1905
 	$smcFunc['db_free_result']($request);
1850 1906
 
1851 1907
 	return $messages;
@@ -1872,19 +1928,20 @@  discard block
 block discarded – undo
1872 1928
 		$context['sub_template'] = 'trackIP';
1873 1929
 		$context['page_title'] = $txt['profile'];
1874 1930
 		$context['base_url'] = $scripturl . '?action=trackip';
1875
-	}
1876
-	else
1931
+	} else
1877 1932
 	{
1878 1933
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1879 1934
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1880 1935
 	}
1881 1936
 
1882 1937
 	// Searching?
1883
-	if (isset($_REQUEST['searchip']))
1884
-		$context['ip'] = trim($_REQUEST['searchip']);
1938
+	if (isset($_REQUEST['searchip'])) {
1939
+			$context['ip'] = trim($_REQUEST['searchip']);
1940
+	}
1885 1941
 
1886
-	if (isValidIP($context['ip']) === false)
1887
-		fatal_lang_error('invalid_tracking_ip', false);
1942
+	if (isValidIP($context['ip']) === false) {
1943
+			fatal_lang_error('invalid_tracking_ip', false);
1944
+	}
1888 1945
 
1889 1946
 	//mysql didn't support like search with varbinary
1890 1947
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1892,8 +1949,9 @@  discard block
 block discarded – undo
1892 1949
 	$ip_var = $context['ip'];
1893 1950
 	$ip_string = '= {inet:ip_address}';
1894 1951
 
1895
-	if (empty($context['tracking_area']))
1896
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1952
+	if (empty($context['tracking_area'])) {
1953
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1954
+	}
1897 1955
 
1898 1956
 	$request = $smcFunc['db_query']('', '
1899 1957
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1904,8 +1962,9 @@  discard block
 block discarded – undo
1904 1962
 		)
1905 1963
 	);
1906 1964
 	$context['ips'] = array();
1907
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1908
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1965
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1966
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1967
+	}
1909 1968
 	$smcFunc['db_free_result']($request);
1910 1969
 
1911 1970
 	ksort($context['ips']);
@@ -2134,8 +2193,9 @@  discard block
 block discarded – undo
2134 2193
 		foreach ($context['whois_servers'] as $whois)
2135 2194
 		{
2136 2195
 			// Strip off the "decimal point" and anything following...
2137
-			if (in_array((int) $context['ip'], $whois['range']))
2138
-				$context['auto_whois_server'] = $whois;
2196
+			if (in_array((int) $context['ip'], $whois['range'])) {
2197
+							$context['auto_whois_server'] = $whois;
2198
+			}
2139 2199
 		}
2140 2200
 	}
2141 2201
 }
@@ -2152,10 +2212,11 @@  discard block
 block discarded – undo
2152 2212
 	// Gonna want this for the list.
2153 2213
 	require_once($sourcedir . '/Subs-List.php');
2154 2214
 
2155
-	if ($memID == 0)
2156
-		$context['base_url'] = $scripturl . '?action=trackip';
2157
-	else
2158
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2215
+	if ($memID == 0) {
2216
+			$context['base_url'] = $scripturl . '?action=trackip';
2217
+	} else {
2218
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2219
+	}
2159 2220
 
2160 2221
 	// Start with the user messages.
2161 2222
 	$listOptions = array(
@@ -2265,12 +2326,13 @@  discard block
 block discarded – undo
2265 2326
 		)
2266 2327
 	);
2267 2328
 	$logins = array();
2268
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2269
-		$logins[] = array(
2329
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2330
+			$logins[] = array(
2270 2331
 			'time' => timeformat($row['time']),
2271 2332
 			'ip' => inet_dtop($row['ip']),
2272 2333
 			'ip2' => inet_dtop($row['ip2']),
2273 2334
 		);
2335
+	}
2274 2336
 	$smcFunc['db_free_result']($request);
2275 2337
 
2276 2338
 	return $logins;
@@ -2295,11 +2357,12 @@  discard block
 block discarded – undo
2295 2357
 		)
2296 2358
 	);
2297 2359
 	$context['custom_field_titles'] = array();
2298
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2299
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2360
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2361
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2300 2362
 			'title' => $row['field_name'],
2301 2363
 			'parse_bbc' => $row['bbc'],
2302 2364
 		);
2365
+	}
2303 2366
 	$smcFunc['db_free_result']($request);
2304 2367
 
2305 2368
 	// Set the options for the error lists.
@@ -2438,19 +2501,22 @@  discard block
 block discarded – undo
2438 2501
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2439 2502
 	{
2440 2503
 		$extra = smf_json_decode($row['extra'], true);
2441
-		if (!empty($extra['applicator']))
2442
-			$members[] = $extra['applicator'];
2504
+		if (!empty($extra['applicator'])) {
2505
+					$members[] = $extra['applicator'];
2506
+		}
2443 2507
 
2444 2508
 		// Work out what the name of the action is.
2445
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2446
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2447
-		elseif (isset($txt[$row['action']]))
2448
-			$action_text = $txt[$row['action']];
2509
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2510
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2511
+		} elseif (isset($txt[$row['action']])) {
2512
+					$action_text = $txt[$row['action']];
2513
+		}
2449 2514
 		// Custom field?
2450
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2451
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2452
-		else
2453
-			$action_text = $row['action'];
2515
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2516
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2517
+		} else {
2518
+					$action_text = $row['action'];
2519
+		}
2454 2520
 
2455 2521
 		// Parse BBC?
2456 2522
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2482,13 +2548,15 @@  discard block
 block discarded – undo
2482 2548
 			)
2483 2549
 		);
2484 2550
 		$members = array();
2485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2486
-			$members[$row['id_member']] = $row['real_name'];
2551
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2552
+					$members[$row['id_member']] = $row['real_name'];
2553
+		}
2487 2554
 		$smcFunc['db_free_result']($request);
2488 2555
 
2489
-		foreach ($edits as $key => $value)
2490
-			if (isset($members[$value['id_member']]))
2556
+		foreach ($edits as $key => $value) {
2557
+					if (isset($members[$value['id_member']]))
2491 2558
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2559
+		}
2492 2560
 	}
2493 2561
 
2494 2562
 	return $edits;
@@ -2689,10 +2757,11 @@  discard block
 block discarded – undo
2689 2757
 	$context['board'] = $board;
2690 2758
 
2691 2759
 	// Determine which groups this user is in.
2692
-	if (empty($user_profile[$memID]['additional_groups']))
2693
-		$curGroups = array();
2694
-	else
2695
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2760
+	if (empty($user_profile[$memID]['additional_groups'])) {
2761
+			$curGroups = array();
2762
+	} else {
2763
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2764
+	}
2696 2765
 	$curGroups[] = $user_profile[$memID]['id_group'];
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2698 2767
 
@@ -2712,28 +2781,30 @@  discard block
 block discarded – undo
2712 2781
 	$context['no_access_boards'] = array();
2713 2782
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2714 2783
 	{
2715
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2716
-			$context['no_access_boards'][] = array(
2784
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2785
+					$context['no_access_boards'][] = array(
2717 2786
 				'id' => $row['id_board'],
2718 2787
 				'name' => $row['name'],
2719 2788
 				'is_last' => false,
2720 2789
 			);
2721
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2722
-			$context['boards'][$row['id_board']] = array(
2790
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2791
+					$context['boards'][$row['id_board']] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'selected' => $board == $row['id_board'],
2726 2795
 				'profile' => $row['id_profile'],
2727 2796
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2728 2797
 			);
2798
+		}
2729 2799
 	}
2730 2800
 	$smcFunc['db_free_result']($request);
2731 2801
 
2732 2802
 	require_once($sourcedir . '/Subs-Boards.php');
2733 2803
 	sortBoards($context['boards']);
2734 2804
 
2735
-	if (!empty($context['no_access_boards']))
2736
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2805
+	if (!empty($context['no_access_boards'])) {
2806
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2807
+	}
2737 2808
 
2738 2809
 	$context['member']['permissions'] = array(
2739 2810
 		'general' => array(),
@@ -2742,8 +2813,9 @@  discard block
 block discarded – undo
2742 2813
 
2743 2814
 	// If you're an admin we know you can do everything, we might as well leave.
2744 2815
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2745
-	if ($context['member']['has_all_permissions'])
2746
-		return;
2816
+	if ($context['member']['has_all_permissions']) {
2817
+			return;
2818
+	}
2747 2819
 
2748 2820
 	$denied = array();
2749 2821
 
@@ -2762,21 +2834,24 @@  discard block
 block discarded – undo
2762 2834
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2763 2835
 	{
2764 2836
 		// We don't know about this permission, it doesn't exist :P.
2765
-		if (!isset($txt['permissionname_' . $row['permission']]))
2766
-			continue;
2837
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2838
+					continue;
2839
+		}
2767 2840
 
2768
-		if (empty($row['add_deny']))
2769
-			$denied[] = $row['permission'];
2841
+		if (empty($row['add_deny'])) {
2842
+					$denied[] = $row['permission'];
2843
+		}
2770 2844
 
2771 2845
 		// Permissions that end with _own or _any consist of two parts.
2772
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2773
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2774
-		else
2775
-			$name = $txt['permissionname_' . $row['permission']];
2846
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2847
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2848
+		} else {
2849
+					$name = $txt['permissionname_' . $row['permission']];
2850
+		}
2776 2851
 
2777 2852
 		// Add this permission if it doesn't exist yet.
2778
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2779
-			$context['member']['permissions']['general'][$row['permission']] = array(
2853
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2854
+					$context['member']['permissions']['general'][$row['permission']] = array(
2780 2855
 				'id' => $row['permission'],
2781 2856
 				'groups' => array(
2782 2857
 					'allowed' => array(),
@@ -2786,6 +2861,7 @@  discard block
 block discarded – undo
2786 2861
 				'is_denied' => false,
2787 2862
 				'is_global' => true,
2788 2863
 			);
2864
+		}
2789 2865
 
2790 2866
 		// Add the membergroup to either the denied or the allowed groups.
2791 2867
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2819,18 +2895,20 @@  discard block
 block discarded – undo
2819 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2820 2896
 	{
2821 2897
 		// We don't know about this permission, it doesn't exist :P.
2822
-		if (!isset($txt['permissionname_' . $row['permission']]))
2823
-			continue;
2898
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2899
+					continue;
2900
+		}
2824 2901
 
2825 2902
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2826
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2827
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2828
-		else
2829
-			$name = $txt['permissionname_' . $row['permission']];
2903
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2904
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2905
+		} else {
2906
+					$name = $txt['permissionname_' . $row['permission']];
2907
+		}
2830 2908
 
2831 2909
 		// Create the structure for this permission.
2832
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2833
-			$context['member']['permissions']['board'][$row['permission']] = array(
2910
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2911
+					$context['member']['permissions']['board'][$row['permission']] = array(
2834 2912
 				'id' => $row['permission'],
2835 2913
 				'groups' => array(
2836 2914
 					'allowed' => array(),
@@ -2840,6 +2918,7 @@  discard block
 block discarded – undo
2840 2918
 				'is_denied' => false,
2841 2919
 				'is_global' => empty($board),
2842 2920
 			);
2921
+		}
2843 2922
 
2844 2923
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2845 2924
 
@@ -2858,8 +2937,9 @@  discard block
 block discarded – undo
2858 2937
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2859 2938
 
2860 2939
 	// Firstly, can we actually even be here?
2861
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2862
-		fatal_lang_error('no_access', false);
2940
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2941
+			fatal_lang_error('no_access', false);
2942
+	}
2863 2943
 
2864 2944
 	// Make sure things which are disabled stay disabled.
2865 2945
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2946,9 +3026,10 @@  discard block
 block discarded – undo
2946 3026
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2947 3027
 	);
2948 3028
 	$context['current_level'] = 0;
2949
-	foreach ($context['level_effects'] as $limit => $dummy)
2950
-		if ($context['member']['warning'] >= $limit)
3029
+	foreach ($context['level_effects'] as $limit => $dummy) {
3030
+			if ($context['member']['warning'] >= $limit)
2951 3031
 			$context['current_level'] = $limit;
2952
-}
3032
+	}
3033
+	}
2953 3034
 
2954 3035
 ?>
2955 3036
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/QueryString.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
  * Validates a IPv6 address. returns true if it is ipv6.
326 326
  *
327 327
  * @param string $ip The ip address to be validated
328
- * @return boolean Whether the specified IP is a valid IPv6 address
328
+ * @return false|string Whether the specified IP is a valid IPv6 address
329 329
  */
330 330
 function isValidIPv6($ip)
331 331
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -426,8 +426,8 @@
 block discarded – undo
426 426
 */
427 427
 function matchIPtoCIDR($ip_address, $cidr_address)
428 428
 {
429
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
429
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
431 431
 }
432 432
 
433 433
 /**
Please login to merge, or discard this patch.
Braces   +181 added lines, -128 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
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,8 +201,9 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193 208
 		elseif (strpos($_REQUEST['topic'], '.') !== false)
194 209
 		{
@@ -199,19 +214,22 @@  discard block
 block discarded – undo
199 214
 
200 215
 		// Now make sure the online log gets the right number.
201 216
 		$_GET['topic'] = $topic;
217
+	} else {
218
+			$topic = 0;
202 219
 	}
203
-	else
204
-		$topic = 0;
205 220
 
206 221
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
207
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
208
-		$_REQUEST['start'] = 0;
222
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
223
+			$_REQUEST['start'] = 0;
224
+	}
209 225
 
210 226
 	// The action needs to be a string and not an array or anything else
211
-	if (isset($_REQUEST['action']))
212
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
213
-	if (isset($_GET['action']))
214
-		$_GET['action'] = (string) $_GET['action'];
227
+	if (isset($_REQUEST['action'])) {
228
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
229
+	}
230
+	if (isset($_GET['action'])) {
231
+			$_GET['action'] = (string) $_GET['action'];
232
+	}
215 233
 
216 234
 	// Some mail providers like to encode semicolons in activation URLs...
217 235
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -237,29 +255,33 @@  discard block
 block discarded – undo
237 255
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
238 256
 
239 257
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
240
-	if (!isset($modSettings['proxy_ip_header']))
241
-		$modSettings['proxy_ip_header'] = 'autodetect';
258
+	if (!isset($modSettings['proxy_ip_header'])) {
259
+			$modSettings['proxy_ip_header'] = 'autodetect';
260
+	}
242 261
 
243 262
 	// Which headers are we going to check for Reverse Proxy IP headers?
244
-	if ($modSettings['proxy_ip_header'] == 'disabled')
245
-		$reverseIPheaders = array();
246
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
247
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
248
-	else
249
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
263
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
264
+			$reverseIPheaders = array();
265
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
266
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
267
+	} else {
268
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
269
+	}
250 270
 
251 271
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
252 272
 	foreach ($reverseIPheaders as $proxyIPheader)
253 273
 	{
254 274
 		// Ignore if this is not set.
255
-		if (!isset($_SERVER[$proxyIPheader]))
256
-			continue;
275
+		if (!isset($_SERVER[$proxyIPheader])) {
276
+					continue;
277
+		}
257 278
 
258 279
 		if (!empty($modSettings['proxy_ip_servers']))
259 280
 		{
260
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
261
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
281
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
282
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
262 283
 					continue;
284
+			}
263 285
 		}
264 286
 
265 287
 		// If there are commas, get the last one.. probably.
@@ -279,8 +301,9 @@  discard block
 block discarded – undo
279 301
 
280 302
 						// Just incase we have a legacy IPv4 address.
281 303
 						// @ TODO: Convert to IPv6.
282
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
283
-							continue;
304
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
305
+													continue;
306
+						}
284 307
 					}
285 308
 
286 309
 					continue;
@@ -292,36 +315,40 @@  discard block
 block discarded – undo
292 315
 			}
293 316
 		}
294 317
 		// Otherwise just use the only one.
295
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
296
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
297
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
318
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
319
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
320
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
298 321
 		{
299 322
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
300 323
 
301 324
 			// Just incase we have a legacy IPv4 address.
302 325
 			// @ TODO: Convert to IPv6.
303
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
304
-				continue;
326
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
327
+							continue;
328
+			}
305 329
 		}
306 330
 	}
307 331
 
308 332
 	// Make sure we know the URL of the current request.
309
-	if (empty($_SERVER['REQUEST_URI']))
310
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
311
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
312
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
313
-	else
314
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
333
+	if (empty($_SERVER['REQUEST_URI'])) {
334
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
335
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
336
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
337
+	} else {
338
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
339
+	}
315 340
 
316 341
 	// And make sure HTTP_USER_AGENT is set.
317 342
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
318 343
 
319 344
 	// Some final checking.
320
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
321
-		$_SERVER['BAN_CHECK_IP'] = '';
322
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
323
-		$_SERVER['REMOTE_ADDR'] = '';
324
-}
345
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
346
+			$_SERVER['BAN_CHECK_IP'] = '';
347
+	}
348
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
349
+			$_SERVER['REMOTE_ADDR'] = '';
350
+	}
351
+	}
325 352
 
326 353
 /**
327 354
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -332,8 +359,9 @@  discard block
 block discarded – undo
332 359
 function isValidIPv6($ip)
333 360
 {
334 361
 	//looking for :
335
-	if (strpos($ip, ':') === false)
336
-		return false;
362
+	if (strpos($ip, ':') === false) {
363
+			return false;
364
+	}
337 365
 
338 366
 	//check valid address
339 367
 	return inet_pton($ip);
@@ -350,15 +378,17 @@  discard block
 block discarded – undo
350 378
 	static $expanded = array();
351 379
 
352 380
 	// Check if we have done this already.
353
-	if (isset($expanded[$ip]))
354
-		return $expanded[$ip];
381
+	if (isset($expanded[$ip])) {
382
+			return $expanded[$ip];
383
+	}
355 384
 
356 385
 	// Expand the IP out.
357 386
 	$expanded_ip = explode(':', expandIPv6($ip));
358 387
 
359 388
 	$new_ip = array();
360
-	foreach ($expanded_ip as $int)
361
-		$new_ip[] = hexdec($int);
389
+	foreach ($expanded_ip as $int) {
390
+			$new_ip[] = hexdec($int);
391
+	}
362 392
 
363 393
 	// Save this incase of repeated use.
364 394
 	$expanded[$ip] = $new_ip;
@@ -378,8 +408,9 @@  discard block
 block discarded – undo
378 408
 	static $converted = array();
379 409
 
380 410
 	// Check if we have done this already.
381
-	if (isset($converted[$addr]))
382
-		return $converted[$addr];
411
+	if (isset($converted[$addr])) {
412
+			return $converted[$addr];
413
+	}
383 414
 
384 415
 	// Check if there are segments missing, insert if necessary.
385 416
 	if (strpos($addr, '::') !== false)
@@ -389,18 +420,20 @@  discard block
 block discarded – undo
389 420
 		$part[1] = explode(':', $part[1]);
390 421
 		$missing = array();
391 422
 
392
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
393
-			array_push($missing, '0000');
423
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
424
+					array_push($missing, '0000');
425
+		}
394 426
 
395 427
 		$part = array_merge($part[0], $missing, $part[1]);
428
+	} else {
429
+			$part = explode(':', $addr);
396 430
 	}
397
-	else
398
-		$part = explode(':', $addr);
399 431
 
400 432
 	// Pad each segment until it has 4 digits.
401
-	foreach ($part as &$p)
402
-		while (strlen($p) < 4)
433
+	foreach ($part as &$p) {
434
+			while (strlen($p) < 4)
403 435
 			$p = '0' . $p;
436
+	}
404 437
 
405 438
 	unset($p);
406 439
 
@@ -411,11 +444,12 @@  discard block
 block discarded – undo
411 444
 	$converted[$addr] = $result;
412 445
 
413 446
 	// Quick check to make sure the length is as expected.
414
-	if (!$strict_check || strlen($result) == 39)
415
-		return $result;
416
-	else
417
-		return false;
418
-}
447
+	if (!$strict_check || strlen($result) == 39) {
448
+			return $result;
449
+	} else {
450
+			return false;
451
+	}
452
+	}
419 453
 
420 454
 
421 455
 /**
@@ -446,15 +480,17 @@  discard block
 block discarded – undo
446 480
 {
447 481
 	global $smcFunc;
448 482
 
449
-	if (!is_array($var))
450
-		return $smcFunc['db_escape_string']($var);
483
+	if (!is_array($var)) {
484
+			return $smcFunc['db_escape_string']($var);
485
+	}
451 486
 
452 487
 	// Reindex the array with slashes.
453 488
 	$new_var = array();
454 489
 
455 490
 	// Add slashes to every element, even the indexes!
456
-	foreach ($var as $k => $v)
457
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
491
+	foreach ($var as $k => $v) {
492
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
493
+	}
458 494
 
459 495
 	return $new_var;
460 496
 }
@@ -474,12 +510,14 @@  discard block
 block discarded – undo
474 510
 {
475 511
 	global $smcFunc;
476 512
 
477
-	if (!is_array($var))
478
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
513
+	if (!is_array($var)) {
514
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
515
+	}
479 516
 
480 517
 	// Add the htmlspecialchars to every element.
481
-	foreach ($var as $k => $v)
482
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
518
+	foreach ($var as $k => $v) {
519
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
520
+	}
483 521
 
484 522
 	return $var;
485 523
 }
@@ -497,15 +535,17 @@  discard block
 block discarded – undo
497 535
  */
498 536
 function urldecode__recursive($var, $level = 0)
499 537
 {
500
-	if (!is_array($var))
501
-		return urldecode($var);
538
+	if (!is_array($var)) {
539
+			return urldecode($var);
540
+	}
502 541
 
503 542
 	// Reindex the array...
504 543
 	$new_var = array();
505 544
 
506 545
 	// Add the htmlspecialchars to every element.
507
-	foreach ($var as $k => $v)
508
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
546
+	foreach ($var as $k => $v) {
547
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
548
+	}
509 549
 
510 550
 	return $new_var;
511 551
 }
@@ -523,15 +563,17 @@  discard block
 block discarded – undo
523 563
 {
524 564
 	global $smcFunc;
525 565
 
526
-	if (!is_array($var))
527
-		return $smcFunc['db_unescape_string']($var);
566
+	if (!is_array($var)) {
567
+			return $smcFunc['db_unescape_string']($var);
568
+	}
528 569
 
529 570
 	// Reindex the array without slashes, this time.
530 571
 	$new_var = array();
531 572
 
532 573
 	// Strip the slashes from every element.
533
-	foreach ($var as $k => $v)
534
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
574
+	foreach ($var as $k => $v) {
575
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
576
+	}
535 577
 
536 578
 	return $new_var;
537 579
 }
@@ -549,15 +591,17 @@  discard block
 block discarded – undo
549 591
  */
550 592
 function stripslashes__recursive($var, $level = 0)
551 593
 {
552
-	if (!is_array($var))
553
-		return stripslashes($var);
594
+	if (!is_array($var)) {
595
+			return stripslashes($var);
596
+	}
554 597
 
555 598
 	// Reindex the array without slashes, this time.
556 599
 	$new_var = array();
557 600
 
558 601
 	// Strip the slashes from every element.
559
-	foreach ($var as $k => $v)
560
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
602
+	foreach ($var as $k => $v) {
603
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
604
+	}
561 605
 
562 606
 	return $new_var;
563 607
 }
@@ -578,12 +622,14 @@  discard block
 block discarded – undo
578 622
 	global $smcFunc;
579 623
 
580 624
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
581
-	if (!is_array($var))
582
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
625
+	if (!is_array($var)) {
626
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
627
+	}
583 628
 
584 629
 	// Go through all the elements and remove the whitespace.
585
-	foreach ($var as $k => $v)
586
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
630
+	foreach ($var as $k => $v) {
631
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
632
+	}
587 633
 
588 634
 	return $var;
589 635
 }
@@ -648,30 +694,37 @@  discard block
 block discarded – undo
648 694
 	global $scripturl, $modSettings, $context;
649 695
 
650 696
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
651
-	if ($scripturl == '' || !defined('SID'))
652
-		return $buffer;
697
+	if ($scripturl == '' || !defined('SID')) {
698
+			return $buffer;
699
+	}
653 700
 
654 701
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
655 702
 	// @todo smflib
656
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
657
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
703
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
704
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
705
+	}
658 706
 	// Debugging templates, are we?
659
-	elseif (isset($_GET['debug']))
660
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
707
+	elseif (isset($_GET['debug'])) {
708
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
709
+	}
661 710
 
662 711
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
663 712
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
664 713
 	{
665 714
 		// Let's do something special for session ids!
666
-		if (defined('SID') && SID != '')
667
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
715
+		if (defined('SID') && SID != '') {
716
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
668 717
 			{
669
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
718
+				global $scripturl;
719
+		}
720
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
670 721
 			}, $buffer);
671
-		else
672
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
722
+		else {
723
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
673 724
 			{
674
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
725
+				global $scripturl;
726
+		}
727
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
675 728
 			}, $buffer);
676 729
 	}
677 730
 
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1491,7 +1491,7 @@
 block discarded – undo
1491 1491
 
1492 1492
 /**
1493 1493
  * Try to determine if the topic has already been deleted by another user.
1494
- * @return bool False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1494
+ * @return boolean|null False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1495 1495
  */
1496 1496
 function removeDeleteConcurrence()
1497 1497
 {
Please login to merge, or discard this patch.
Braces   +267 added lines, -200 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$id_topic = $smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$id_topic = $smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -821,6 +856,7 @@  discard block
 block discarded – undo
821 856
 				array('id_topic'),
822 857
 				1
823 858
 			);
859
+		}
824 860
 
825 861
 		// Capture the ID of the new topic...
826 862
 		$topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic;
@@ -858,22 +894,24 @@  discard block
 block discarded – undo
858 894
 			);
859 895
 
860 896
 			// Mark recycled topic as read.
861
-			if (!$user_info['is_guest'])
862
-				$smcFunc['db_insert']('replace',
897
+			if (!$user_info['is_guest']) {
898
+							$smcFunc['db_insert']('replace',
863 899
 					'{db_prefix}log_topics',
864 900
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
865 901
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
866 902
 					array('id_topic', 'id_member')
867 903
 				);
904
+			}
868 905
 
869 906
 			// Mark recycle board as seen, if it was marked as seen before.
870
-			if (!empty($isRead) && !$user_info['is_guest'])
871
-				$smcFunc['db_insert']('replace',
907
+			if (!empty($isRead) && !$user_info['is_guest']) {
908
+							$smcFunc['db_insert']('replace',
872 909
 					'{db_prefix}log_boards',
873 910
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
874 911
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
875 912
 					array('id_board', 'id_member')
876 913
 				);
914
+			}
877 915
 
878 916
 			// Add one topic and post to the recycle bin board.
879 917
 			$smcFunc['db_query']('', '
@@ -891,8 +929,8 @@  discard block
 block discarded – undo
891 929
 			);
892 930
 
893 931
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
894
-			if (!empty($id_recycle_topic))
895
-				$smcFunc['db_query']('', '
932
+			if (!empty($id_recycle_topic)) {
933
+							$smcFunc['db_query']('', '
896 934
 					UPDATE {db_prefix}topics
897 935
 					SET num_replies = num_replies + 1' .
898 936
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -903,6 +941,7 @@  discard block
 block discarded – undo
903 941
 						'id_merged_msg' => $message,
904 942
 					)
905 943
 				);
944
+			}
906 945
 
907 946
 			// Make sure this message isn't getting deleted later on.
908 947
 			$recycle = true;
@@ -912,8 +951,8 @@  discard block
 block discarded – undo
912 951
 		}
913 952
 
914 953
 		// If it wasn't approved don't keep it in the queue.
915
-		if (!$row['approved'])
916
-			$smcFunc['db_query']('', '
954
+		if (!$row['approved']) {
955
+					$smcFunc['db_query']('', '
917 956
 				DELETE FROM {db_prefix}approval_queue
918 957
 				WHERE id_msg = {int:id_msg}
919 958
 					AND id_attach = {int:id_attach}',
@@ -922,6 +961,7 @@  discard block
 block discarded – undo
922 961
 					'id_attach' => 0,
923 962
 				)
924 963
 			);
964
+		}
925 965
 	}
926 966
 
927 967
 	$smcFunc['db_query']('', '
@@ -939,8 +979,9 @@  discard block
 block discarded – undo
939 979
 
940 980
 	// If the poster was registered and the board this message was on incremented
941 981
 	// the member's posts when it was posted, decrease his or her post count.
942
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
943
-		updateMemberData($row['id_member'], array('posts' => '-'));
982
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
983
+			updateMemberData($row['id_member'], array('posts' => '-'));
984
+	}
944 985
 
945 986
 	// Only remove posts if they're not recycled.
946 987
 	if (!$recycle)
@@ -948,8 +989,9 @@  discard block
 block discarded – undo
948 989
 		// Callback for search APIs to do their thing
949 990
 		require_once($sourcedir . '/Search.php');
950 991
 		$searchAPI = findSearchAPI();
951
-		if ($searchAPI->supportsMethod('postRemoved'))
952
-			$searchAPI->postRemoved($message);
992
+		if ($searchAPI->supportsMethod('postRemoved')) {
993
+					$searchAPI->postRemoved($message);
994
+		}
953 995
 
954 996
 		// Remove the message!
955 997
 		$smcFunc['db_query']('', '
@@ -964,8 +1006,8 @@  discard block
 block discarded – undo
964 1006
 		{
965 1007
 			$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
966 1008
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
967
-			if (!empty($words))
968
-				$smcFunc['db_query']('', '
1009
+			if (!empty($words)) {
1010
+							$smcFunc['db_query']('', '
969 1011
 					DELETE FROM {db_prefix}log_search_words
970 1012
 					WHERE id_word IN ({array_int:word_list})
971 1013
 						AND id_msg = {int:id_msg}',
@@ -974,6 +1016,7 @@  discard block
 block discarded – undo
974 1016
 						'id_msg' => $message,
975 1017
 					)
976 1018
 				);
1019
+			}
977 1020
 		}
978 1021
 
979 1022
 		// Delete attachment(s) if they exist.
@@ -997,10 +1040,11 @@  discard block
 block discarded – undo
997 1040
 
998 1041
 	// And now to update the last message of each board we messed with.
999 1042
 	require_once($sourcedir . '/Subs-Post.php');
1000
-	if ($recycle)
1001
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1002
-	else
1003
-		updateLastMessages($row['id_board']);
1043
+	if ($recycle) {
1044
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1045
+	} else {
1046
+			updateLastMessages($row['id_board']);
1047
+	}
1004 1048
 
1005 1049
 	// Close any moderation reports for this message.
1006 1050
 	$smcFunc['db_query']('', '
@@ -1033,8 +1077,9 @@  discard block
 block discarded – undo
1033 1077
 	checkSession('get');
1034 1078
 
1035 1079
 	// Is recycled board enabled?
1036
-	if (empty($modSettings['recycle_enable']))
1037
-		fatal_lang_error('restored_disabled', 'critical');
1080
+	if (empty($modSettings['recycle_enable'])) {
1081
+			fatal_lang_error('restored_disabled', 'critical');
1082
+	}
1038 1083
 
1039 1084
 	// Can we be in here?
1040 1085
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1049,8 +1094,9 @@  discard block
 block discarded – undo
1049 1094
 	if (!empty($_REQUEST['msgs']))
1050 1095
 	{
1051 1096
 		$msgs = explode(',', $_REQUEST['msgs']);
1052
-		foreach ($msgs as $k => $msg)
1053
-			$msgs[$k] = (int) $msg;
1097
+		foreach ($msgs as $k => $msg) {
1098
+					$msgs[$k] = (int) $msg;
1099
+		}
1054 1100
 
1055 1101
 		// Get the id_previous_board and id_previous_topic.
1056 1102
 		$request = $smcFunc['db_query']('', '
@@ -1084,8 +1130,8 @@  discard block
 block discarded – undo
1084 1130
 			}
1085 1131
 
1086 1132
 			$previous_topics[] = $row['id_previous_topic'];
1087
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1088
-				$actioned_messages[$row['id_previous_topic']] = array(
1133
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1134
+							$actioned_messages[$row['id_previous_topic']] = array(
1089 1135
 					'msgs' => array(),
1090 1136
 					'count_posts' => $row['count_posts'],
1091 1137
 					'subject' => $row['subject'],
@@ -1095,17 +1141,20 @@  discard block
 block discarded – undo
1095 1141
 					'current_board' => $row['id_board'],
1096 1142
 					'members' => array(),
1097 1143
 				);
1144
+			}
1098 1145
 
1099 1146
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1100
-			if ($row['id_member'])
1101
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1147
+			if ($row['id_member']) {
1148
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1149
+			}
1102 1150
 		}
1103 1151
 		$smcFunc['db_free_result']($request);
1104 1152
 
1105 1153
 		// Check for topics we are going to fully restore.
1106
-		foreach ($actioned_messages as $topic => $data)
1107
-			if (in_array($topic, $topics_to_restore))
1154
+		foreach ($actioned_messages as $topic => $data) {
1155
+					if (in_array($topic, $topics_to_restore))
1108 1156
 				unset($actioned_messages[$topic]);
1157
+		}
1109 1158
 
1110 1159
 		// Load any previous topics to check they exist.
1111 1160
 		if (!empty($previous_topics))
@@ -1120,11 +1169,12 @@  discard block
 block discarded – undo
1120 1169
 				)
1121 1170
 			);
1122 1171
 			$previous_topics = array();
1123
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1124
-				$previous_topics[$row['id_topic']] = array(
1172
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1173
+							$previous_topics[$row['id_topic']] = array(
1125 1174
 					'board' => $row['id_board'],
1126 1175
 					'subject' => $row['subject'],
1127 1176
 				);
1177
+			}
1128 1178
 			$smcFunc['db_free_result']($request);
1129 1179
 		}
1130 1180
 
@@ -1146,11 +1196,11 @@  discard block
 block discarded – undo
1146 1196
 				// Log em.
1147 1197
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1148 1198
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1149
-			}
1150
-			else
1199
+			} else
1151 1200
 			{
1152
-				foreach ($data['msgs'] as $msg)
1153
-					$unfound_messages[$msg['id']] = $msg['subject'];
1201
+				foreach ($data['msgs'] as $msg) {
1202
+									$unfound_messages[$msg['id']] = $msg['subject'];
1203
+				}
1154 1204
 			}
1155 1205
 		}
1156 1206
 	}
@@ -1159,8 +1209,9 @@  discard block
 block discarded – undo
1159 1209
 	if (!empty($_REQUEST['topics']))
1160 1210
 	{
1161 1211
 		$topics = explode(',', $_REQUEST['topics']);
1162
-		foreach ($topics as $id)
1163
-			$topics_to_restore[] = (int) $id;
1212
+		foreach ($topics as $id) {
1213
+					$topics_to_restore[] = (int) $id;
1214
+		}
1164 1215
 	}
1165 1216
 
1166 1217
 	if (!empty($topics_to_restore))
@@ -1214,8 +1265,9 @@  discard block
 block discarded – undo
1214 1265
 					)
1215 1266
 				);
1216 1267
 
1217
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1218
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1268
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1269
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1270
+				}
1219 1271
 				$smcFunc['db_free_result']($request2);
1220 1272
 			}
1221 1273
 
@@ -1226,8 +1278,9 @@  discard block
 block discarded – undo
1226 1278
 	}
1227 1279
 
1228 1280
 	// Didn't find some things?
1229
-	if (!empty($unfound_messages))
1230
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1281
+	if (!empty($unfound_messages)) {
1282
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1283
+	}
1231 1284
 
1232 1285
 	// Just send them to the index if they get here.
1233 1286
 	redirectexit();
@@ -1247,12 +1300,14 @@  discard block
 block discarded – undo
1247 1300
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1248 1301
 
1249 1302
 	// Is it an array?
1250
-	if (!is_array($msgs))
1251
-		$msgs = array($msgs);
1303
+	if (!is_array($msgs)) {
1304
+			$msgs = array($msgs);
1305
+	}
1252 1306
 
1253 1307
 	// Lets make sure they are int.
1254
-	foreach ($msgs as $key => $msg)
1255
-		$msgs[$key] = (int) $msg;
1308
+	foreach ($msgs as $key => $msg) {
1309
+			$msgs[$key] = (int) $msg;
1310
+	}
1256 1311
 
1257 1312
 	// Get the source information.
1258 1313
 	$request = $smcFunc['db_query']('', '
@@ -1295,8 +1350,9 @@  discard block
 block discarded – undo
1295 1350
 			)
1296 1351
 		);
1297 1352
 
1298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1299
-			updateMemberData($row['id_member'], array('posts' => '+'));
1353
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1354
+					updateMemberData($row['id_member'], array('posts' => '+'));
1355
+		}
1300 1356
 	}
1301 1357
 
1302 1358
 	// Time to move the messages.
@@ -1332,13 +1388,15 @@  discard block
 block discarded – undo
1332 1388
 	);
1333 1389
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1334 1390
 	{
1335
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1336
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1391
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1392
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1393
+		}
1337 1394
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1338
-		if (!$row['approved'])
1339
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1340
-		else
1341
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1395
+		if (!$row['approved']) {
1396
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1397
+		} else {
1398
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1399
+		}
1342 1400
 	}
1343 1401
 	$smcFunc['db_free_result']($request);
1344 1402
 
@@ -1397,13 +1455,15 @@  discard block
 block discarded – undo
1397 1455
 		);
1398 1456
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1399 1457
 		{
1400
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1401
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1458
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1459
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1460
+			}
1402 1461
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1403
-			if (!$row['approved'])
1404
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1405
-			else
1406
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1462
+			if (!$row['approved']) {
1463
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1464
+			} else {
1465
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1466
+			}
1407 1467
 		}
1408 1468
 		$smcFunc['db_free_result']($request);
1409 1469
 
@@ -1467,10 +1527,12 @@  discard block
 block discarded – undo
1467 1527
 
1468 1528
 	// Subject cache?
1469 1529
 	$cache_updates = array();
1470
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1471
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1472
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1473
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1530
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1531
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1532
+	}
1533
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1534
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1535
+	}
1474 1536
 
1475 1537
 	if (!empty($cache_updates))
1476 1538
 	{
@@ -1482,8 +1544,9 @@  discard block
 block discarded – undo
1482 1544
 				'first_messages' => $cache_updates,
1483 1545
 			)
1484 1546
 		);
1485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1486
-			updateStats('subject', $row['id_topic'], $row['subject']);
1547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1548
+					updateStats('subject', $row['id_topic'], $row['subject']);
1549
+		}
1487 1550
 		$smcFunc['db_free_result']($request);
1488 1551
 	}
1489 1552
 
@@ -1499,22 +1562,26 @@  discard block
 block discarded – undo
1499 1562
 	global $modSettings, $board, $scripturl, $context;
1500 1563
 
1501 1564
 	// No recycle no need to go further
1502
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1503
-		return false;
1565
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1566
+			return false;
1567
+	}
1504 1568
 
1505 1569
 	// If it's confirmed go on and delete (from recycle)
1506
-	if (isset($_GET['confirm_delete']))
1507
-		return true;
1570
+	if (isset($_GET['confirm_delete'])) {
1571
+			return true;
1572
+	}
1508 1573
 
1509
-	if (empty($board))
1510
-		return false;
1574
+	if (empty($board)) {
1575
+			return false;
1576
+	}
1511 1577
 
1512
-	if ($modSettings['recycle_board'] != $board)
1513
-		return true;
1514
-	elseif (isset($_REQUEST['msg']))
1515
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1516
-	else
1517
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1578
+	if ($modSettings['recycle_board'] != $board) {
1579
+			return true;
1580
+	} elseif (isset($_REQUEST['msg'])) {
1581
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1582
+	} else {
1583
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1584
+	}
1518 1585
 
1519 1586
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1520 1587
 }
Please login to merge, or discard this patch.
Sources/Reports.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1013,7 +1013,7 @@
 block discarded – undo
1013 1013
  * @param string $title The title of the separator
1014 1014
  * @param null|string $custom_table The ID of the custom table
1015 1015
  *
1016
- * @return void|bool Returns false if there are no tables
1016
+ * @return null|false Returns false if there are no tables
1017 1017
  */
1018 1018
 function addSeparator($title = '', $custom_table = null)
1019 1019
 {
Please login to merge, or discard this patch.
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 4
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -451,8 +470,9 @@  discard block
 block discarded – undo
451 470
 			foreach ($member_groups as $id_group => $name)
452 471
 			{
453 472
 				// Don't overwrite the key column!
454
-				if ($id_group === 'col')
455
-					continue;
473
+				if ($id_group === 'col') {
474
+									continue;
475
+				}
456 476
 
457 477
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
458 478
 
@@ -474,16 +494,18 @@  discard block
 block discarded – undo
474 494
 				}
475 495
 
476 496
 				// Now actually make the data for the group look right.
477
-				if (empty($curData[$id_group]))
478
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
479
-				elseif ($curData[$id_group] == 1)
480
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
481
-				else
482
-					$curData[$id_group] = 'x';
497
+				if (empty($curData[$id_group])) {
498
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
499
+				} elseif ($curData[$id_group] == 1) {
500
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
501
+				} else {
502
+									$curData[$id_group] = 'x';
503
+				}
483 504
 
484 505
 				// Embolden those permissions different from global (makes it a lot easier!)
485
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
486
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
506
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
507
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
508
+				}
487 509
 			}
488 510
 
489 511
 			// Now add the data for this permission.
@@ -513,15 +535,17 @@  discard block
 block discarded – undo
513 535
 	);
514 536
 	while ($row = $smcFunc['db_fetch_assoc']($request))
515 537
 	{
516
-		if (trim($row['member_groups']) == '')
517
-			$groups = array(1);
518
-		else
519
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
538
+		if (trim($row['member_groups']) == '') {
539
+					$groups = array(1);
540
+		} else {
541
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
542
+		}
520 543
 
521
-		if (trim($row['deny_member_groups']) == '')
522
-			$denyGroups = array();
523
-		else
524
-			$denyGroups = explode(',', $row['deny_member_groups']);
544
+		if (trim($row['deny_member_groups']) == '') {
545
+					$denyGroups = array();
546
+		} else {
547
+					$denyGroups = explode(',', $row['deny_member_groups']);
548
+		}
525 549
 
526 550
 		$boards[$row['id_board']] = array(
527 551
 			'id' => $row['id_board'],
@@ -545,8 +569,9 @@  discard block
 block discarded – undo
545 569
 	);
546 570
 
547 571
 	// Add on the boards!
548
-	foreach ($boards as $board)
549
-		$mgSettings['board_' . $board['id']] = $board['name'];
572
+	foreach ($boards as $board) {
573
+			$mgSettings['board_' . $board['id']] = $board['name'];
574
+	}
550 575
 
551 576
 	// Add all the membergroup settings, plus we'll be adding in columns!
552 577
 	setKeys('cols', $mgSettings);
@@ -591,8 +616,9 @@  discard block
 block discarded – undo
591 616
 			'icons' => ''
592 617
 		),
593 618
 	);
594
-	while ($row = $smcFunc['db_fetch_assoc']($request))
595
-		$rows[] = $row;
619
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
620
+			$rows[] = $row;
621
+	}
596 622
 	$smcFunc['db_free_result']($request);
597 623
 
598 624
 	foreach ($rows as $row)
@@ -608,8 +634,9 @@  discard block
 block discarded – undo
608 634
 		);
609 635
 
610 636
 		// Board permissions.
611
-		foreach ($boards as $board)
612
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
637
+		foreach ($boards as $board) {
638
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
639
+		}
613 640
 
614 641
 		addData($group);
615 642
 	}
@@ -629,16 +656,18 @@  discard block
 block discarded – undo
629 656
 
630 657
 	if (isset($_REQUEST['groups']))
631 658
 	{
632
-		if (!is_array($_REQUEST['groups']))
633
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
634
-		foreach ($_REQUEST['groups'] as $k => $dummy)
635
-			$_REQUEST['groups'][$k] = (int) $dummy;
659
+		if (!is_array($_REQUEST['groups'])) {
660
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
661
+		}
662
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
663
+					$_REQUEST['groups'][$k] = (int) $dummy;
664
+		}
636 665
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
637 666
 
638 667
 		$clause = 'id_group IN ({array_int:groups})';
668
+	} else {
669
+			$clause = 'id_group != {int:moderator_group}';
639 670
 	}
640
-	else
641
-		$clause = 'id_group != {int:moderator_group}';
642 671
 
643 672
 	// Get all the possible membergroups, except admin!
644 673
 	$request = $smcFunc['db_query']('', '
@@ -656,12 +685,14 @@  discard block
 block discarded – undo
656 685
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
657 686
 		)
658 687
 	);
659
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
660
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
661
-	else
662
-		$groups = array('col' => '');
663
-	while ($row = $smcFunc['db_fetch_assoc']($request))
664
-		$groups[$row['id_group']] = $row['group_name'];
688
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
689
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
690
+	} else {
691
+			$groups = array('col' => '');
692
+	}
693
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
694
+			$groups[$row['id_group']] = $row['group_name'];
695
+	}
665 696
 	$smcFunc['db_free_result']($request);
666 697
 
667 698
 	// Make sure that every group is represented!
@@ -685,8 +716,9 @@  discard block
 block discarded – undo
685 716
 		$disabled_permissions[] = 'calendar_edit_own';
686 717
 		$disabled_permissions[] = 'calendar_edit_any';
687 718
 	}
688
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
689
-		$disabled_permissions[] = 'issue_warning';
719
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
720
+			$disabled_permissions[] = 'issue_warning';
721
+	}
690 722
 
691 723
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
692 724
 
@@ -707,15 +739,17 @@  discard block
 block discarded – undo
707 739
 	$curData = array();
708 740
 	while ($row = $smcFunc['db_fetch_assoc']($request))
709 741
 	{
710
-		if (in_array($row['permission'], $disabled_permissions))
711
-			continue;
742
+		if (in_array($row['permission'], $disabled_permissions)) {
743
+					continue;
744
+		}
712 745
 
713 746
 		// If this is a new permission flush the last row.
714 747
 		if ($row['permission'] != $lastPermission)
715 748
 		{
716 749
 			// Send the data!
717
-			if ($lastPermission !== null)
718
-				addData($curData);
750
+			if ($lastPermission !== null) {
751
+							addData($curData);
752
+			}
719 753
 
720 754
 			// Add the permission name in the left column.
721 755
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -724,10 +758,11 @@  discard block
 block discarded – undo
724 758
 		}
725 759
 
726 760
 		// Good stuff - add the permission to the list!
727
-		if ($row['add_deny'])
728
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
729
-		else
730
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
761
+		if ($row['add_deny']) {
762
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
763
+		} else {
764
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
765
+		}
731 766
 	}
732 767
 	$smcFunc['db_free_result']($request);
733 768
 
@@ -757,8 +792,9 @@  discard block
 block discarded – undo
757 792
 		)
758 793
 	);
759 794
 	$boards = array();
760
-	while ($row = $smcFunc['db_fetch_assoc']($request))
761
-		$boards[$row['id_board']] = $row['name'];
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+			$boards[$row['id_board']] = $row['name'];
797
+	}
762 798
 	$smcFunc['db_free_result']($request);
763 799
 
764 800
 	// Get every moderator.
@@ -790,12 +826,14 @@  discard block
 block discarded – undo
790 826
 	while ($row = $smcFunc['db_fetch_assoc']($request))
791 827
 	{
792 828
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
793
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
794
-			$moderators[$row['id_member']][] = $row['id_board'];
829
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
830
+					$moderators[$row['id_member']][] = $row['id_board'];
831
+		}
795 832
 
796 833
 		// We don't have them listed as a moderator yet
797
-		if (!array_key_exists($row['id_member'], $local_mods))
798
-			$local_mods[$row['id_member']] = $row['id_member'];
834
+		if (!array_key_exists($row['id_member'], $local_mods)) {
835
+					$local_mods[$row['id_member']] = $row['id_member'];
836
+		}
799 837
 	}
800 838
 
801 839
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -808,8 +846,9 @@  discard block
 block discarded – undo
808 846
 	$allStaff = array_unique($allStaff);
809 847
 
810 848
 	// This is a bit of a cop out - but we're protecting their forum, really!
811
-	if (count($allStaff) > 300)
812
-		fatal_lang_error('report_error_too_many_staff');
849
+	if (count($allStaff) > 300) {
850
+			fatal_lang_error('report_error_too_many_staff');
851
+	}
813 852
 
814 853
 	// Get all the possible membergroups!
815 854
 	$request = $smcFunc['db_query']('', '
@@ -819,8 +858,9 @@  discard block
 block discarded – undo
819 858
 		)
820 859
 	);
821 860
 	$groups = array(0 => $txt['full_member']);
822
-	while ($row = $smcFunc['db_fetch_assoc']($request))
823
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
861
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
862
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
863
+	}
824 864
 	$smcFunc['db_free_result']($request);
825 865
 
826 866
 	// All the fields we'll show.
@@ -861,19 +901,20 @@  discard block
 block discarded – undo
861 901
 		);
862 902
 
863 903
 		// What do they moderate?
864
-		if (in_array($row['id_member'], $global_mods))
865
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
866
-		elseif (isset($moderators[$row['id_member']]))
904
+		if (in_array($row['id_member'], $global_mods)) {
905
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
906
+		} elseif (isset($moderators[$row['id_member']]))
867 907
 		{
868 908
 			// Get the names
869
-			foreach ($moderators[$row['id_member']] as $board)
870
-				if (isset($boards[$board]))
909
+			foreach ($moderators[$row['id_member']] as $board) {
910
+							if (isset($boards[$board]))
871 911
 					$staffData['moderates'][] = $boards[$board];
912
+			}
872 913
 
873 914
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
915
+		} else {
916
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
874 917
 		}
875
-		else
876
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 918
 
878 919
 		// Next add the main data.
879 920
 		addData($staffData);
@@ -901,8 +942,9 @@  discard block
 block discarded – undo
901 942
 	global $context;
902 943
 
903 944
 	// Set the table count if needed.
904
-	if (empty($context['table_count']))
905
-		$context['table_count'] = 0;
945
+	if (empty($context['table_count'])) {
946
+			$context['table_count'] = 0;
947
+	}
906 948
 
907 949
 	// Create the table!
908 950
 	$context['tables'][$context['table_count']] = array(
@@ -952,16 +994,18 @@  discard block
 block discarded – undo
952 994
 	global $context;
953 995
 
954 996
 	// No tables? Create one even though we are probably already in a bad state!
955
-	if (empty($context['table_count']))
956
-		newTable();
997
+	if (empty($context['table_count'])) {
998
+			newTable();
999
+	}
957 1000
 
958 1001
 	// Specific table?
959
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
960
-		return false;
961
-	elseif ($custom_table !== null)
962
-		$table = $custom_table;
963
-	else
964
-		$table = $context['current_table'];
1002
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1003
+			return false;
1004
+	} elseif ($custom_table !== null) {
1005
+			$table = $custom_table;
1006
+	} else {
1007
+			$table = $context['current_table'];
1008
+	}
965 1009
 
966 1010
 	// If we have keys, sanitise the data...
967 1011
 	if (!empty($context['keys']))
@@ -973,11 +1017,11 @@  discard block
 block discarded – undo
973 1017
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
974 1018
 			);
975 1019
 			// Special "hack" the adding separators when doing data by column.
976
-			if (substr($key, 0, 5) == '#sep#')
977
-				$data[$key]['separator'] = true;
1020
+			if (substr($key, 0, 5) == '#sep#') {
1021
+							$data[$key]['separator'] = true;
1022
+			}
978 1023
 		}
979
-	}
980
-	else
1024
+	} else
981 1025
 	{
982 1026
 		$data = $inc_data;
983 1027
 		foreach ($data as $key => $value)
@@ -985,8 +1029,9 @@  discard block
 block discarded – undo
985 1029
 			$data[$key] = array(
986 1030
 				'v' => $value,
987 1031
 			);
988
-			if (substr($key, 0, 5) == '#sep#')
989
-				$data[$key]['separator'] = true;
1032
+			if (substr($key, 0, 5) == '#sep#') {
1033
+							$data[$key]['separator'] = true;
1034
+			}
990 1035
 		}
991 1036
 	}
992 1037
 
@@ -999,8 +1044,9 @@  discard block
 block discarded – undo
999 1044
 	// Otherwise, tricky!
1000 1045
 	else
1001 1046
 	{
1002
-		foreach ($data as $key => $item)
1003
-			$context['tables'][$table]['data'][$key][] = $item;
1047
+		foreach ($data as $key => $item) {
1048
+					$context['tables'][$table]['data'][$key][] = $item;
1049
+		}
1004 1050
 	}
1005 1051
 }
1006 1052
 
@@ -1017,16 +1063,18 @@  discard block
 block discarded – undo
1017 1063
 	global $context;
1018 1064
 
1019 1065
 	// No tables - return?
1020
-	if (empty($context['table_count']))
1021
-		return;
1066
+	if (empty($context['table_count'])) {
1067
+			return;
1068
+	}
1022 1069
 
1023 1070
 	// Specific table?
1024
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1025
-		return false;
1026
-	elseif ($custom_table !== null)
1027
-		$table = $custom_table;
1028
-	else
1029
-		$table = $context['current_table'];
1071
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1072
+			return false;
1073
+	} elseif ($custom_table !== null) {
1074
+			$table = $custom_table;
1075
+	} else {
1076
+			$table = $context['current_table'];
1077
+	}
1030 1078
 
1031 1079
 	// Plumb in the separator
1032 1080
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1047,8 +1095,9 @@  discard block
 block discarded – undo
1047 1095
 {
1048 1096
 	global $context;
1049 1097
 
1050
-	if (empty($context['tables']))
1051
-		return;
1098
+	if (empty($context['tables'])) {
1099
+			return;
1100
+	}
1052 1101
 
1053 1102
 	// Loop through each table counting up some basic values, to help with the templating.
1054 1103
 	foreach ($context['tables'] as $id => $table)
@@ -1059,12 +1108,13 @@  discard block
 block discarded – undo
1059 1108
 		$context['tables'][$id]['column_count'] = count($curElement);
1060 1109
 
1061 1110
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1062
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1063
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1064
-		elseif ($table['width']['normal'] != 'auto')
1065
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1066
-		else
1067
-			$context['tables'][$id]['max_width'] = 'auto';
1111
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1112
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1113
+		} elseif ($table['width']['normal'] != 'auto') {
1114
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1115
+		} else {
1116
+					$context['tables'][$id]['max_width'] = 'auto';
1117
+		}
1068 1118
 	}
1069 1119
 }
1070 1120
 
@@ -1089,10 +1139,11 @@  discard block
 block discarded – undo
1089 1139
 	global $context;
1090 1140
 
1091 1141
 	// Do we want to use the keys of the keys as the keys? :P
1092
-	if ($reverse)
1093
-		$context['keys'] = array_flip($keys);
1094
-	else
1095
-		$context['keys'] = $keys;
1142
+	if ($reverse) {
1143
+			$context['keys'] = array_flip($keys);
1144
+	} else {
1145
+			$context['keys'] = $keys;
1146
+	}
1096 1147
 
1097 1148
 	// Rows or columns?
1098 1149
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -807,7 +807,7 @@
 block discarded – undo
807 807
 /**
808 808
  * Send a group of emails from the mail queue.
809 809
  *
810
- * @param bool|int $number The number to send each loop through or false to use the standard limits
810
+ * @param integer $number The number to send each loop through or false to use the standard limits
811 811
  * @param bool $override_limit Whether to bypass the limit
812 812
  * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs)
813 813
  * @return bool Whether things were sent
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,7 +384,7 @@
 block discarded – undo
384 384
 	clean_cache();
385 385
 
386 386
 	// If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
387
-	list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
387
+	list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
388 388
 	if ($modSettings['warning_decrement'])
389 389
 	{
390 390
 		// Find every member who has a warning level...
Please login to merge, or discard this patch.
Braces   +277 added lines, -201 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
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1548,8 +1616,9 @@  discard block
 block discarded – undo
1548 1616
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1549 1617
 
1550 1618
 		// Send the actual email.
1551
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1552
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1619
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1620
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1621
+		}
1553 1622
 
1554 1623
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1555 1624
 		{
@@ -1572,18 +1641,19 @@  discard block
 block discarded – undo
1572 1641
 	}
1573 1642
 
1574 1643
 	// Insert the alerts if any
1575
-	if (!empty($alert_rows))
1576
-		$smcFunc['db_insert']('',
1644
+	if (!empty($alert_rows)) {
1645
+			$smcFunc['db_insert']('',
1577 1646
 			'{db_prefix}user_alerts',
1578 1647
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1579 1648
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1580 1649
 			$alert_rows,
1581 1650
 			array()
1582 1651
 		);
1652
+	}
1583 1653
 
1584 1654
 	// Mark the reminder as sent.
1585
-	if (!empty($subs_reminded))
1586
-		$smcFunc['db_query']('', '
1655
+	if (!empty($subs_reminded)) {
1656
+			$smcFunc['db_query']('', '
1587 1657
 			UPDATE {db_prefix}log_subscribed
1588 1658
 			SET reminder_sent = {int:reminder_sent}
1589 1659
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1592,6 +1662,7 @@  discard block
 block discarded – undo
1592 1662
 				'reminder_sent' => 1,
1593 1663
 			)
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	return true;
1597 1668
 }
@@ -1607,13 +1678,13 @@  discard block
 block discarded – undo
1607 1678
 	// We need to know where this thing is going.
1608 1679
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1609 1680
 	{
1610
-		if (!is_array($modSettings['attachmentUploadDir']))
1611
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1681
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1682
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1683
+		}
1612 1684
 
1613 1685
 		// Just use the current path for temp files.
1614 1686
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1615
-	}
1616
-	else
1687
+	} else
1617 1688
 	{
1618 1689
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1619 1690
 	}
@@ -1632,14 +1703,16 @@  discard block
 block discarded – undo
1632 1703
 
1633 1704
 		while ($file = readdir($dir))
1634 1705
 		{
1635
-			if ($file == '.' || $file == '..')
1636
-				continue;
1706
+			if ($file == '.' || $file == '..') {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (strpos($file, 'post_tmp_') !== false)
1639 1711
 			{
1640 1712
 				// Temp file is more than 5 hours old!
1641
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1642
-					@unlink($attach_dir . '/' . $file);
1713
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1714
+									@unlink($attach_dir . '/' . $file);
1715
+				}
1643 1716
 			}
1644 1717
 		}
1645 1718
 		closedir($dir);
@@ -1672,8 +1745,9 @@  discard block
 block discarded – undo
1672 1745
 		)
1673 1746
 	);
1674 1747
 
1675
-	while ($row = $smcFunc['db_fetch_row']($request))
1676
-		$topics[] = $row[0];
1748
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1749
+			$topics[] = $row[0];
1750
+	}
1677 1751
 	$smcFunc['db_free_result']($request);
1678 1752
 
1679 1753
 	// Zap, your gone
@@ -1693,8 +1767,9 @@  discard block
 block discarded – undo
1693 1767
 {
1694 1768
 	global $smcFunc, $sourcedir, $modSettings;
1695 1769
 
1696
-	if (empty($modSettings['drafts_keep_days']))
1697
-		return true;
1770
+	if (empty($modSettings['drafts_keep_days'])) {
1771
+			return true;
1772
+	}
1698 1773
 
1699 1774
 	// init
1700 1775
 	$drafts = array();
@@ -1712,8 +1787,9 @@  discard block
 block discarded – undo
1712 1787
 		)
1713 1788
 	);
1714 1789
 
1715
-	while ($row = $smcFunc['db_fetch_row']($request))
1716
-		$drafts[] = (int) $row[0];
1790
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1791
+			$drafts[] = (int) $row[0];
1792
+	}
1717 1793
 	$smcFunc['db_free_result']($request);
1718 1794
 
1719 1795
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Admin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
 /**
20 20
  * Get a list of versions that are currently installed on the server.
21
- * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
21
+ * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
22 22
  * @return array An array of versions (keys are same as what was in $checkFor, values are the versions)
23 23
  */
24 24
 function getServerVersions($checkFor)
Please login to merge, or discard this patch.
Braces   +124 added lines, -89 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Get a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_engine']();
@@ -74,24 +74,31 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	// If we're using memcache we need the server info.
77
-	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
78
-		get_memcached_server();
77
+	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
78
+			get_memcached_server();
79
+	}
79 80
 
80 81
 	// Check to see if we have any accelerators installed...
81
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
82
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
83
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
84
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
85
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
86
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
87
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
88
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
82
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
83
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
+	}
85
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
86
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
87
+	}
88
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
89
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
90
+	}
91
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
92
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
93
+	}
89 94
 
90
-	if (in_array('php', $checkFor))
91
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
95
+	if (in_array('php', $checkFor)) {
96
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
97
+	}
92 98
 
93
-	if (in_array('server', $checkFor))
94
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
99
+	if (in_array('server', $checkFor)) {
100
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
101
+	}
95 102
 
96 103
 	return $versions;
97 104
 }
@@ -131,11 +138,13 @@  discard block
 block discarded – undo
131 138
 		fclose($fp);
132 139
 
133 140
 		// The comment looks rougly like... that.
134
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
135
-			$version_info['file_versions']['SSI.php'] = $match[1];
141
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
142
+					$version_info['file_versions']['SSI.php'] = $match[1];
143
+		}
136 144
 		// Not found!  This is bad.
137
-		else
138
-			$version_info['file_versions']['SSI.php'] = '??';
145
+		else {
146
+					$version_info['file_versions']['SSI.php'] = '??';
147
+		}
139 148
 	}
140 149
 
141 150
 	// Do the paid subscriptions handler?
@@ -146,11 +155,13 @@  discard block
 block discarded – undo
146 155
 		fclose($fp);
147 156
 
148 157
 		// Found it?
149
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
150
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
158
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
159
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
160
+		}
151 161
 		// If we haven't how do we all get paid?
152
-		else
153
-			$version_info['file_versions']['subscriptions.php'] = '??';
162
+		else {
163
+					$version_info['file_versions']['subscriptions.php'] = '??';
164
+		}
154 165
 	}
155 166
 
156 167
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -165,11 +176,13 @@  discard block
 block discarded – undo
165 176
 			fclose($fp);
166 177
 
167 178
 			// Look for the version comment in the file header.
168
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
169
-				$version_info['file_versions'][$entry] = $match[1];
179
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
180
+							$version_info['file_versions'][$entry] = $match[1];
181
+			}
170 182
 			// It wasn't found, but the file was... show a '??'.
171
-			else
172
-				$version_info['file_versions'][$entry] = '??';
183
+			else {
184
+							$version_info['file_versions'][$entry] = '??';
185
+			}
173 186
 		}
174 187
 	}
175 188
 	$sources_dir->close();
@@ -188,11 +201,13 @@  discard block
 block discarded – undo
188 201
 				fclose($fp);
189 202
 
190 203
 				// Look for the version comment in the file header.
191
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
192
-					$version_info['tasks_versions'][$entry] = $match[1];
204
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
205
+									$version_info['tasks_versions'][$entry] = $match[1];
206
+				}
193 207
 				// It wasn't found, but the file was... show a '??'.
194
-				else
195
-					$version_info['tasks_versions'][$entry] = '??';
208
+				else {
209
+									$version_info['tasks_versions'][$entry] = '??';
210
+				}
196 211
 			}
197 212
 		}
198 213
 		$tasks_dir->close();
@@ -200,8 +215,9 @@  discard block
 block discarded – undo
200 215
 
201 216
 	// Load all the files in the default template directory - and the current theme if applicable.
202 217
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
203
-	if ($settings['theme_id'] != 1)
204
-		$directories += array('template_versions' => $settings['theme_dir']);
218
+	if ($settings['theme_id'] != 1) {
219
+			$directories += array('template_versions' => $settings['theme_dir']);
220
+	}
205 221
 
206 222
 	foreach ($directories as $type => $dirname)
207 223
 	{
@@ -216,11 +232,13 @@  discard block
 block discarded – undo
216 232
 				fclose($fp);
217 233
 
218 234
 				// Look for the version comment in the file header.
219
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
220
-					$version_info[$type][$entry] = $match[1];
235
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
236
+									$version_info[$type][$entry] = $match[1];
237
+				}
221 238
 				// It wasn't found, but the file was... show a '??'.
222
-				else
223
-					$version_info[$type][$entry] = '??';
239
+				else {
240
+									$version_info[$type][$entry] = '??';
241
+				}
224 242
 			}
225 243
 		}
226 244
 		$this_dir->close();
@@ -241,11 +259,13 @@  discard block
 block discarded – undo
241 259
 			list ($name, $language) = explode('.', $entry);
242 260
 
243 261
 			// Look for the version comment in the file header.
244
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
245
-				$version_info['default_language_versions'][$language][$name] = $match[1];
262
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
263
+							$version_info['default_language_versions'][$language][$name] = $match[1];
264
+			}
246 265
 			// It wasn't found, but the file was... show a '??'.
247
-			else
248
-				$version_info['default_language_versions'][$language][$name] = '??';
266
+			else {
267
+							$version_info['default_language_versions'][$language][$name] = '??';
268
+			}
249 269
 		}
250 270
 	}
251 271
 	$this_dir->close();
@@ -260,8 +280,9 @@  discard block
 block discarded – undo
260 280
 		ksort($version_info['tasks_versions']);
261 281
 
262 282
 		// For languages sort each language too.
263
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
264
-			ksort($version_info['default_language_versions'][$language]);
283
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
284
+					ksort($version_info['default_language_versions'][$language]);
285
+		}
265 286
 	}
266 287
 	return $version_info;
267 288
 }
@@ -303,27 +324,31 @@  discard block
 block discarded – undo
303 324
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
304 325
 
305 326
 	// Break it up based on \r or \n, and then clean out extra characters.
306
-	if (strpos($settingsArray, "\n") !== false)
307
-		$settingsArray = explode("\n", $settingsArray);
308
-	elseif (strpos($settingsArray, "\r") !== false)
309
-		$settingsArray = explode("\r", $settingsArray);
310
-	else
311
-		return;
327
+	if (strpos($settingsArray, "\n") !== false) {
328
+			$settingsArray = explode("\n", $settingsArray);
329
+	} elseif (strpos($settingsArray, "\r") !== false) {
330
+			$settingsArray = explode("\r", $settingsArray);
331
+	} else {
332
+			return;
333
+	}
312 334
 
313 335
 	// Presumably, the file has to have stuff in it for this function to be called :P.
314
-	if (count($settingsArray) < 10)
315
-		return;
336
+	if (count($settingsArray) < 10) {
337
+			return;
338
+	}
316 339
 
317 340
 	// remove any /r's that made there way in here
318
-	foreach ($settingsArray as $k => $dummy)
319
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
341
+	foreach ($settingsArray as $k => $dummy) {
342
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
343
+	}
320 344
 
321 345
 	// go line by line and see whats changing
322 346
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
323 347
 	{
324 348
 		// Don't trim or bother with it if it's not a variable.
325
-		if (substr($settingsArray[$i], 0, 1) != '$')
326
-			continue;
349
+		if (substr($settingsArray[$i], 0, 1) != '$') {
350
+					continue;
351
+		}
327 352
 
328 353
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
329 354
 
@@ -335,8 +360,7 @@  discard block
 block discarded – undo
335 360
 			{
336 361
 				updateDbLastError($val);
337 362
 				unset($config_vars[$var]);
338
-			}
339
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
363
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
340 364
 			{
341 365
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
342 366
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -347,34 +371,39 @@  discard block
 block discarded – undo
347 371
 		}
348 372
 
349 373
 		// End of the file ... maybe
350
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
351
-			$end = $i;
374
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
375
+					$end = $i;
376
+		}
352 377
 	}
353 378
 
354 379
 	// This should never happen, but apparently it is happening.
355
-	if (empty($end) || $end < 10)
356
-		$end = count($settingsArray) - 1;
380
+	if (empty($end) || $end < 10) {
381
+			$end = count($settingsArray) - 1;
382
+	}
357 383
 
358 384
 	// Still more variables to go?  Then lets add them at the end.
359 385
 	if (!empty($config_vars))
360 386
 	{
361
-		if (trim($settingsArray[$end]) == '?' . '>')
362
-			$settingsArray[$end++] = '';
363
-		else
364
-			$end++;
387
+		if (trim($settingsArray[$end]) == '?' . '>') {
388
+					$settingsArray[$end++] = '';
389
+		} else {
390
+					$end++;
391
+		}
365 392
 
366 393
 		// Add in any newly defined vars that were passed
367
-		foreach ($config_vars as $var => $val)
368
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
394
+		foreach ($config_vars as $var => $val) {
395
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
396
+		}
369 397
 
370 398
 		$settingsArray[$end] = '?' . '>';
399
+	} else {
400
+			$settingsArray[$end] = trim($settingsArray[$end]);
371 401
 	}
372
-	else
373
-		$settingsArray[$end] = trim($settingsArray[$end]);
374 402
 
375 403
 	// Sanity error checking: the file needs to be at least 12 lines.
376
-	if (count($settingsArray) < 12)
377
-		return;
404
+	if (count($settingsArray) < 12) {
405
+			return;
406
+	}
378 407
 
379 408
 	// Try to avoid a few pitfalls:
380 409
 	//  - like a possible race condition,
@@ -382,8 +411,9 @@  discard block
 block discarded – undo
382 411
 	//
383 412
 	// Check before you act: if cache is enabled, we can do a simple write test
384 413
 	// to validate that we even write things on this filesystem.
385
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
386
-		$cachedir = $boarddir . '/cache';
414
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
415
+			$cachedir = $boarddir . '/cache';
416
+	}
387 417
 
388 418
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
389 419
 	if ($test_fp)
@@ -418,16 +448,18 @@  discard block
 block discarded – undo
418 448
 			// Well this is not good at all, lets see if we can save this
419 449
 			$context['settings_message'] = 'settings_error';
420 450
 
421
-			if (file_exists($boarddir . '/Settings_bak.php'))
422
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
451
+			if (file_exists($boarddir . '/Settings_bak.php')) {
452
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
453
+			}
423 454
 		}
424 455
 	}
425 456
 
426 457
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
427 458
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
428
-	if (function_exists('opcache_invalidate'))
429
-		opcache_invalidate($boarddir . '/Settings.php', true);
430
-}
459
+	if (function_exists('opcache_invalidate')) {
460
+			opcache_invalidate($boarddir . '/Settings.php', true);
461
+	}
462
+	}
431 463
 
432 464
 /**
433 465
  * Saves the time of the last db error for the error log
@@ -453,8 +485,9 @@  discard block
 block discarded – undo
453 485
 	global $options, $context, $smcFunc, $settings, $user_info;
454 486
 
455 487
 	// This must exist!
456
-	if (!isset($context['admin_preferences']))
457
-		return false;
488
+	if (!isset($context['admin_preferences'])) {
489
+			return false;
490
+	}
458 491
 
459 492
 	// This is what we'll be saving.
460 493
 	$options['admin_preferences'] = json_encode($context['admin_preferences']);
@@ -518,8 +551,9 @@  discard block
 block discarded – undo
518 551
 	$emails_sent = array();
519 552
 	while ($row = $smcFunc['db_fetch_assoc']($request))
520 553
 	{
521
-		if (empty($prefs[$row['id_member']]['announcements']))
522
-			continue;
554
+		if (empty($prefs[$row['id_member']]['announcements'])) {
555
+					continue;
556
+		}
523 557
 
524 558
 		// Stick their particulars in the replacement data.
525 559
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -538,11 +572,12 @@  discard block
 block discarded – undo
538 572
 	$smcFunc['db_free_result']($request);
539 573
 
540 574
 	// Any additional users we must email this to?
541
-	if (!empty($additional_recipients))
542
-		foreach ($additional_recipients as $recipient)
575
+	if (!empty($additional_recipients)) {
576
+			foreach ($additional_recipients as $recipient)
543 577
 		{
544 578
 			if (in_array($recipient['email'], $emails_sent))
545 579
 				continue;
580
+	}
546 581
 
547 582
 			$replacements['IDMEMBER'] = $recipient['id'];
548 583
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
  *
151 151
  * @param bool $local Whether we want local cookies
152 152
  * @param bool $global Whether we want global cookies
153
- * @return array An array to set the cookie on with domain and path in it, in that order
153
+ * @return string An array to set the cookie on with domain and path in it, in that order
154 154
  */
155 155
 function url_parts($local, $global)
156 156
 {
Please login to merge, or discard this patch.
Braces   +160 added lines, -115 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 		$array = smf_json_decode($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
@@ -62,8 +64,9 @@  discard block
 block discarded – undo
62 64
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
63 65
 
64 66
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
65
-	if (empty($id) && !empty($modSettings['globalCookies']))
66
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
67
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
68
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
69
+	}
67 70
 
68 71
 	// Any alias URLs?  This is mainly for use with frames, etc.
69 72
 	if (!empty($modSettings['forum_alias_urls']))
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
81 84
 
82
-			if ($cookie_url[0] == '')
83
-				$cookie_url[0] = strtok($alias, '/');
85
+			if ($cookie_url[0] == '') {
86
+							$cookie_url[0] = strtok($alias, '/');
87
+			}
84 88
 
85 89
 			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
86 90
 		}
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
 	$identifier = $cookiename . '_tfa';
127 131
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
128 132
 
129
-	if ($preserve)
130
-		$cookie_length = 81600 * 30;
133
+	if ($preserve) {
134
+			$cookie_length = 81600 * 30;
135
+	}
131 136
 
132 137
 	// Get the data and path to set it on.
133 138
 	$data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve));
@@ -137,8 +142,9 @@  discard block
 block discarded – undo
137 142
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
138 143
 
139 144
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
140
-	if (empty($id) && !empty($modSettings['globalCookies']))
141
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
145
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
146
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
147
+	}
142 148
 
143 149
 	$_COOKIE[$identifier] = $data;
144 150
 }
@@ -160,23 +166,28 @@  discard block
 block discarded – undo
160 166
 	$parsed_url = parse_url($boardurl);
161 167
 
162 168
 	// Is local cookies off?
163
-	if (empty($parsed_url['path']) || !$local)
164
-		$parsed_url['path'] = '';
169
+	if (empty($parsed_url['path']) || !$local) {
170
+			$parsed_url['path'] = '';
171
+	}
165 172
 
166
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
167
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
173
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
174
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
175
+	}
168 176
 
169 177
 	// Globalize cookies across domains (filter out IP-addresses)?
170
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
171
-		$parsed_url['host'] = '.' . $parts[1];
178
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
179
+			$parsed_url['host'] = '.' . $parts[1];
180
+	}
172 181
 
173 182
 	// We shouldn't use a host at all if both options are off.
174
-	elseif (!$local && !$global)
175
-		$parsed_url['host'] = '';
183
+	elseif (!$local && !$global) {
184
+			$parsed_url['host'] = '';
185
+	}
176 186
 
177 187
 	// The host also shouldn't be set if there aren't any dots in it.
178
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
179
-		$parsed_url['host'] = '';
188
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
189
+			$parsed_url['host'] = '';
190
+	}
180 191
 
181 192
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
182 193
 }
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 	createToken('login');
196 207
 
197 208
 	// Never redirect to an attachment
198
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
199
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
209
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
210
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
211
+	}
200 212
 
201 213
 	$context['sub_template'] = 'kick_guest';
202 214
 	$context['page_title'] = $txt['login'];
@@ -251,10 +263,12 @@  discard block
 block discarded – undo
251 263
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
252 264
 		log_error($txt['security_wrong'], 'critical');
253 265
 
254
-		if (isset($_POST[$type . '_hash_pass']))
255
-			unset($_POST[$type . '_hash_pass']);
256
-		if (isset($_POST[$type . '_pass']))
257
-			unset($_POST[$type . '_pass']);
266
+		if (isset($_POST[$type . '_hash_pass'])) {
267
+					unset($_POST[$type . '_hash_pass']);
268
+		}
269
+		if (isset($_POST[$type . '_pass'])) {
270
+					unset($_POST[$type . '_pass']);
271
+		}
258 272
 
259 273
 		$context['incorrect_password'] = true;
260 274
 	}
@@ -267,15 +281,17 @@  discard block
 block discarded – undo
267 281
 
268 282
 	// Now go through $_POST.  Make sure the session hash is sent.
269 283
 	$_POST[$context['session_var']] = $context['session_id'];
270
-	foreach ($_POST as $k => $v)
271
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
284
+	foreach ($_POST as $k => $v) {
285
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
286
+	}
272 287
 
273 288
 	// Now we'll use the admin_login sub template of the Login template.
274 289
 	$context['sub_template'] = 'admin_login';
275 290
 
276 291
 	// And title the page something like "Login".
277
-	if (!isset($context['page_title']))
278
-		$context['page_title'] = $txt['login'];
292
+	if (!isset($context['page_title'])) {
293
+			$context['page_title'] = $txt['login'];
294
+	}
279 295
 
280 296
 	// The type of action.
281 297
 	$context['sessionCheckType'] = $type;
@@ -298,14 +314,15 @@  discard block
 block discarded – undo
298 314
 {
299 315
 	global $smcFunc;
300 316
 
301
-	if (!is_array($v))
302
-		return '
317
+	if (!is_array($v)) {
318
+			return '
303 319
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
304
-	else
320
+	} else
305 321
 	{
306 322
 		$ret = '';
307
-		foreach ($v as $k2 => $v2)
308
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
323
+		foreach ($v as $k2 => $v2) {
324
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
325
+		}
309 326
 
310 327
 		return $ret;
311 328
 	}
@@ -332,18 +349,20 @@  discard block
 block discarded – undo
332 349
 		foreach ($get as $k => $v)
333 350
 		{
334 351
 			// Only if it's not already in the $scripturl!
335
-			if (!isset($temp[$k]))
336
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
352
+			if (!isset($temp[$k])) {
353
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
354
+			}
337 355
 			// If it changed, put it out there, but with an ampersand.
338
-			elseif ($temp[$k] != $get[$k])
339
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
356
+			elseif ($temp[$k] != $get[$k]) {
357
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
358
+			}
340 359
 		}
341
-	}
342
-	else
360
+	} else
343 361
 	{
344 362
 		// Add up all the data from $_GET into get_data.
345
-		foreach ($get as $k => $v)
346
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
363
+		foreach ($get as $k => $v) {
364
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
365
+		}
347 366
 	}
348 367
 
349 368
 	$query_string = substr($query_string, 0, -1);
@@ -366,8 +385,9 @@  discard block
 block discarded – undo
366 385
 	global $scripturl, $user_info, $smcFunc;
367 386
 
368 387
 	// If it's not already an array, make it one.
369
-	if (!is_array($names))
370
-		$names = explode(',', $names);
388
+	if (!is_array($names)) {
389
+			$names = explode(',', $names);
390
+	}
371 391
 
372 392
 	$maybe_email = false;
373 393
 	foreach ($names as $i => $name)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 		$maybe_email |= strpos($name, '@') !== false;
379 399
 
380 400
 		// Make it so standard wildcards will work. (* and ?)
381
-		if ($use_wildcards)
382
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
383
-		else
384
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
401
+		if ($use_wildcards) {
402
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
403
+		} else {
404
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
405
+		}
385 406
 	}
386 407
 
387 408
 	// What are we using to compare?
@@ -391,11 +412,12 @@  discard block
 block discarded – undo
391 412
 	$results = array();
392 413
 
393 414
 	// This ensures you can't search someones email address if you can't see it.
394
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395
-		$email_condition = '
415
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
416
+			$email_condition = '
396 417
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397
-	else
398
-		$email_condition = '';
418
+	} else {
419
+			$email_condition = '';
420
+	}
399 421
 
400 422
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
401 423
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -453,10 +475,11 @@  discard block
 block discarded – undo
453 475
 	$context['template_layers'] = array();
454 476
 	$context['sub_template'] = 'find_members';
455 477
 
456
-	if (isset($_REQUEST['search']))
457
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
458
-	else
459
-		$_REQUEST['start'] = 0;
478
+	if (isset($_REQUEST['search'])) {
479
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
+	} else {
481
+			$_REQUEST['start'] = 0;
482
+	}
460 483
 
461 484
 	// Allow the user to pass the input to be added to to the box.
462 485
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -497,10 +520,10 @@  discard block
 block discarded – undo
497 520
 		);
498 521
 
499 522
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
523
+	} else {
524
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
+	}
500 526
 	}
501
-	else
502
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
503
-}
504 527
 
505 528
 /**
506 529
  * Outputs each member name on its own line.
@@ -516,8 +539,9 @@  discard block
 block discarded – undo
516 539
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
517 540
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
518 541
 
519
-	if (function_exists('iconv'))
520
-		header('Content-Type: text/plain; charset=UTF-8');
542
+	if (function_exists('iconv')) {
543
+			header('Content-Type: text/plain; charset=UTF-8');
544
+	}
521 545
 
522 546
 	$request = $smcFunc['db_query']('', '
523 547
 		SELECT real_name
@@ -537,14 +561,16 @@  discard block
 block discarded – undo
537 561
 		if (function_exists('iconv'))
538 562
 		{
539 563
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
540
-			if ($utf8)
541
-				$row['real_name'] = $utf8;
564
+			if ($utf8) {
565
+							$row['real_name'] = $utf8;
566
+			}
542 567
 		}
543 568
 
544 569
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
545 570
 
546
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
547
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
571
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
572
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
573
+		}
548 574
 
549 575
 		echo $row['real_name'], "\n";
550 576
 	}
@@ -601,9 +627,9 @@  discard block
 block discarded – undo
601 627
 
602 628
 		// Update the database...
603 629
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
630
+	} else {
631
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
604 632
 	}
605
-	else
606
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
607 633
 
608 634
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
609 635
 
@@ -634,31 +660,37 @@  discard block
 block discarded – undo
634 660
 	$errors = array();
635 661
 
636 662
 	// Don't use too long a name.
637
-	if ($smcFunc['strlen']($username) > 25)
638
-		$errors[] = array('lang', 'error_long_name');
663
+	if ($smcFunc['strlen']($username) > 25) {
664
+			$errors[] = array('lang', 'error_long_name');
665
+	}
639 666
 
640 667
 	// No name?!  How can you register with no name?
641
-	if ($username == '')
642
-		$errors[] = array('lang', 'need_username');
668
+	if ($username == '') {
669
+			$errors[] = array('lang', 'need_username');
670
+	}
643 671
 
644 672
 	// Only these characters are permitted.
645
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
646
-		$errors[] = array('lang', 'error_invalid_characters_username');
673
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
674
+			$errors[] = array('lang', 'error_invalid_characters_username');
675
+	}
647 676
 
648
-	if (stristr($username, $txt['guest_title']) !== false)
649
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
677
+	if (stristr($username, $txt['guest_title']) !== false) {
678
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
679
+	}
650 680
 
651 681
 	if ($check_reserved_name)
652 682
 	{
653 683
 		require_once($sourcedir . '/Subs-Members.php');
654
-		if (isReservedName($username, $memID, false))
655
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
684
+		if (isReservedName($username, $memID, false)) {
685
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
686
+		}
656 687
 	}
657 688
 
658
-	if ($return_error)
659
-		return $errors;
660
-	elseif (empty($errors))
661
-		return null;
689
+	if ($return_error) {
690
+			return $errors;
691
+	} elseif (empty($errors)) {
692
+			return null;
693
+	}
662 694
 
663 695
 	loadLanguage('Errors');
664 696
 	$error = $errors[0];
@@ -684,22 +716,26 @@  discard block
 block discarded – undo
684 716
 	global $modSettings, $smcFunc;
685 717
 
686 718
 	// Perform basic requirements first.
687
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
688
-		return 'short';
719
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
720
+			return 'short';
721
+	}
689 722
 
690 723
 	// Is this enough?
691
-	if (empty($modSettings['password_strength']))
692
-		return null;
724
+	if (empty($modSettings['password_strength'])) {
725
+			return null;
726
+	}
693 727
 
694 728
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
695
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
696
-		return 'restricted_words';
697
-	elseif ($smcFunc['strpos']($password, $username) !== false)
698
-		return 'restricted_words';
729
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
730
+			return 'restricted_words';
731
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
732
+			return 'restricted_words';
733
+	}
699 734
 
700 735
 	// If just medium, we're done.
701
-	if ($modSettings['password_strength'] == 1)
702
-		return null;
736
+	if ($modSettings['password_strength'] == 1) {
737
+			return null;
738
+	}
703 739
 
704 740
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
705 741
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -731,14 +767,16 @@  discard block
 block discarded – undo
731 767
 			)
732 768
 		);
733 769
 		$groups = array();
734
-		while ($row = $smcFunc['db_fetch_assoc']($request))
735
-			$groups[] = $row['id_group'];
770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
771
+					$groups[] = $row['id_group'];
772
+		}
736 773
 		$smcFunc['db_free_result']($request);
737 774
 
738
-		if (empty($groups))
739
-			$group_query = '0=1';
740
-		else
741
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
775
+		if (empty($groups)) {
776
+					$group_query = '0=1';
777
+		} else {
778
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
779
+		}
742 780
 	}
743 781
 
744 782
 	// Then, same again, just the boards this time!
@@ -748,10 +786,11 @@  discard block
 block discarded – undo
748 786
 	{
749 787
 		$boards = boardsAllowedTo('moderate_board', true);
750 788
 
751
-		if (empty($boards))
752
-			$board_query = '0=1';
753
-		else
754
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
789
+		if (empty($boards)) {
790
+					$board_query = '0=1';
791
+		} else {
792
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
793
+		}
755 794
 	}
756 795
 
757 796
 	// What boards are they the moderator of?
@@ -766,8 +805,9 @@  discard block
 block discarded – undo
766 805
 				'current_member' => $user_info['id'],
767 806
 			)
768 807
 		);
769
-		while ($row = $smcFunc['db_fetch_assoc']($request))
770
-			$boards_mod[] = $row['id_board'];
808
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
809
+					$boards_mod[] = $row['id_board'];
810
+		}
771 811
 		$smcFunc['db_free_result']($request);
772 812
 
773 813
 		// Can any of the groups they're in moderate any of the boards?
@@ -779,8 +819,9 @@  discard block
 block discarded – undo
779 819
 				'groups' => $user_info['groups'],
780 820
 			)
781 821
 		);
782
-		while ($row = $smcFunc['db_fetch_assoc']($request))
783
-			$boards_mod[] = $row['id_board'];
822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
823
+					$boards_mod[] = $row['id_board'];
824
+		}
784 825
 		$smcFunc['db_free_result']($request);
785 826
 
786 827
 		// Just in case we've got duplicates here...
@@ -825,10 +866,12 @@  discard block
 block discarded – undo
825 866
 	global $modSettings;
826 867
 
827 868
 	// In case a customization wants to override the default settings
828
-	if ($httponly === null)
829
-		$httponly = !empty($modSettings['httponlyCookies']);
830
-	if ($secure === null)
831
-		$secure = !empty($modSettings['secureCookies']);
869
+	if ($httponly === null) {
870
+			$httponly = !empty($modSettings['httponlyCookies']);
871
+	}
872
+	if ($secure === null) {
873
+			$secure = !empty($modSettings['secureCookies']);
874
+	}
832 875
 
833 876
 	// Intercept cookie?
834 877
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -848,8 +891,9 @@  discard block
 block discarded – undo
848 891
 function hash_password($username, $password, $cost = null)
849 892
 {
850 893
 	global $sourcedir, $smcFunc, $modSettings;
851
-	if (!function_exists('password_hash'))
852
-		require_once($sourcedir . '/Subs-Password.php');
894
+	if (!function_exists('password_hash')) {
895
+			require_once($sourcedir . '/Subs-Password.php');
896
+	}
853 897
 
854 898
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
855 899
 
@@ -881,8 +925,9 @@  discard block
 block discarded – undo
881 925
 function hash_verify_password($username, $password, $hash)
882 926
 {
883 927
 	global $sourcedir, $smcFunc;
884
-	if (!function_exists('password_verify'))
885
-		require_once($sourcedir . '/Subs-Password.php');
928
+	if (!function_exists('password_verify')) {
929
+			require_once($sourcedir . '/Subs-Password.php');
930
+	}
886 931
 
887 932
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
888 933
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -456,7 +456,6 @@  discard block
 block discarded – undo
456 456
 
457 457
 /**
458 458
  * affected_rows
459
- * @param resource $connection
460 459
  */
461 460
 function smf_db_affected_rows($result = null)
462 461
 {
@@ -799,7 +798,7 @@  discard block
 block discarded – undo
799 798
  *
800 799
  * @param string $db_name The database name
801 800
  * @param resource $db_connection The database connection
802
- * @return true Always returns true
801
+ * @return boolean Always returns true
803 802
  */
804 803
 function smf_db_select_db($db_name, $db_connection)
805 804
 {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 
200 200
 		case 'date':
201 201
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
202
+				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date';
203 203
 			else
204 204
 				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
205 205
 		break;
206 206
 
207 207
 		case 'time':
208 208
 			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
209
+				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time';
210 210
 			else
211 211
 				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212 212
 		break;
213 213
 		
214 214
 		case 'datetime':
215 215
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
217
-					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
216
+				return 'to_timestamp(' .
217
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
218 218
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219 219
 			else
220 220
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -763,10 +763,10 @@  discard block
 block discarded – undo
763 763
 	$returning = '';
764 764
 	$with_returning = false;
765 765
 	// lets build the returning string, mysql allow only in normal mode
766
-	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
766
+	if (!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
767 767
 	{
768 768
 		// we only take the first key
769
-		$returning = ' RETURNING '.$keys[0];
769
+		$returning = ' RETURNING ' . $keys[0];
770 770
 		$with_returning = true;
771 771
 	}
772 772
 
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 			INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
798 798
 			VALUES
799 799
 				' . implode(',
800
-				', $insertRows).$replace.$returning,
800
+				', $insertRows) . $replace . $returning,
801 801
 			array(
802 802
 				'security_override' => true,
803 803
 				'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 			if ($returnmode === 2)
811 811
 				$return_var = array();
812 812
 
813
-			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
813
+			while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
814 814
 			{
815 815
 				if (is_numeric($row[0])) // try to emulate mysql limitation
816 816
 				{
Please login to merge, or discard this patch.
Braces   +219 added lines, -163 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
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -61,11 +62,13 @@  discard block
 block discarded – undo
61 62
 			'db_mb4' => true,
62 63
 			'db_ping' => 'pg_ping',
63 64
 		);
65
+	}
64 66
 
65
-	if (!empty($db_options['persist']))
66
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
-	else
68
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	if (!empty($db_options['persist'])) {
68
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	} else {
70
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
+	}
69 72
 
70 73
 	// Something's wrong, show an error if its fatal (which we assume it is)
71 74
 	if (!$connection)
@@ -73,8 +76,7 @@  discard block
 block discarded – undo
73 76
 		if (!empty($db_options['non_fatal']))
74 77
 		{
75 78
 			return null;
76
-		}
77
-		else
79
+		} else
78 80
 		{
79 81
 			display_db_error();
80 82
 		}
@@ -125,31 +127,38 @@  discard block
 block discarded – undo
125 127
 
126 128
 	list ($values, $connection) = $db_callback;
127 129
 
128
-	if ($matches[1] === 'db_prefix')
129
-		return $db_prefix;
130
+	if ($matches[1] === 'db_prefix') {
131
+			return $db_prefix;
132
+	}
130 133
 
131
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
132
-		return $user_info[$matches[1]];
134
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
135
+			return $user_info[$matches[1]];
136
+	}
133 137
 
134
-	if ($matches[1] === 'empty')
135
-		return '\'\'';
138
+	if ($matches[1] === 'empty') {
139
+			return '\'\'';
140
+	}
136 141
 
137
-	if (!isset($matches[2]))
138
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
142
+	if (!isset($matches[2])) {
143
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	}
139 145
 
140
-	if ($matches[1] === 'literal')
141
-		return '\'' . pg_escape_string($matches[2]) . '\'';
146
+	if ($matches[1] === 'literal') {
147
+			return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	}
142 149
 
143
-	if (!isset($values[$matches[2]]))
144
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
150
+	if (!isset($values[$matches[2]])) {
151
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	}
145 153
 
146 154
 	$replacement = $values[$matches[2]];
147 155
 
148 156
 	switch ($matches[1])
149 157
 	{
150 158
 		case 'int':
151
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
152
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
159
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
160
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			}
153 162
 			return (string) (int) $replacement;
154 163
 		break;
155 164
 
@@ -161,65 +170,73 @@  discard block
 block discarded – undo
161 170
 		case 'array_int':
162 171
 			if (is_array($replacement))
163 172
 			{
164
-				if (empty($replacement))
165
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
173
+				if (empty($replacement)) {
174
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				}
166 176
 
167 177
 				foreach ($replacement as $key => $value)
168 178
 				{
169
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
170
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
180
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					}
171 182
 
172 183
 					$replacement[$key] = (string) (int) $value;
173 184
 				}
174 185
 
175 186
 				return implode(', ', $replacement);
187
+			} else {
188
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176 189
 			}
177
-			else
178
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 190
 
180 191
 		break;
181 192
 
182 193
 		case 'array_string':
183 194
 			if (is_array($replacement))
184 195
 			{
185
-				if (empty($replacement))
186
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196
+				if (empty($replacement)) {
197
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				}
187 199
 
188
-				foreach ($replacement as $key => $value)
189
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
200
+				foreach ($replacement as $key => $value) {
201
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				}
190 203
 
191 204
 				return implode(', ', $replacement);
205
+			} else {
206
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
192 207
 			}
193
-			else
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 208
 		break;
196 209
 
197 210
 		case 'date':
198
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
199
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
200
-			else
201
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
212
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
213
+			} else {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
202 216
 		break;
203 217
 
204 218
 		case 'time':
205
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
206
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
207
-			else
208
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
220
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
221
+			} else {
222
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			}
209 224
 		break;
210 225
 
211 226
 		case 'datetime':
212
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
213
-				return 'to_timestamp('.
227
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
228
+							return 'to_timestamp('.
214 229
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
215 230
 					',\'YYYY-MM-DD HH24:MI:SS\')';
216
-			else
217
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			} else {
232
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			}
218 234
 		break;
219 235
 
220 236
 		case 'float':
221
-			if (!is_numeric($replacement))
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			if (!is_numeric($replacement)) {
238
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239
+			}
223 240
 			return (string) (float) $replacement;
224 241
 		break;
225 242
 
@@ -232,31 +249,36 @@  discard block
 block discarded – undo
232 249
 		break;
233 250
 
234 251
 		case 'inet':
235
-			if ($replacement == 'null' || $replacement == '')
236
-				return 'null';
237
-			if (inet_pton($replacement) === false)
238
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+			if ($replacement == 'null' || $replacement == '') {
253
+							return 'null';
254
+			}
255
+			if (inet_pton($replacement) === false) {
256
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+			}
239 258
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
240 259
 
241 260
 		case 'array_inet':
242 261
 			if (is_array($replacement))
243 262
 			{
244
-				if (empty($replacement))
245
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+				if (empty($replacement)) {
264
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+				}
246 266
 
247 267
 				foreach ($replacement as $key => $value)
248 268
 				{
249
-					if ($replacement == 'null' || $replacement == '')
250
-						$replacement[$key] = 'null';
251
-					if (!isValidIP($value))
252
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+					if ($replacement == 'null' || $replacement == '') {
270
+											$replacement[$key] = 'null';
271
+					}
272
+					if (!isValidIP($value)) {
273
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+					}
253 275
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
254 276
 				}
255 277
 
256 278
 				return implode(', ', $replacement);
279
+			} else {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257 281
 			}
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 282
 		break;
261 283
 
262 284
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -399,8 +424,9 @@  discard block
 block discarded – undo
399 424
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
400 425
 
401 426
 		// Initialize $db_cache if not already initialized.
402
-		if (!isset($db_cache))
403
-			$db_cache = array();
427
+		if (!isset($db_cache)) {
428
+					$db_cache = array();
429
+		}
404 430
 
405 431
 		if (!empty($_SESSION['debug_redirect']))
406 432
 		{
@@ -426,17 +452,18 @@  discard block
 block discarded – undo
426 452
 		while (true)
427 453
 		{
428 454
 			$pos = strpos($db_string, '\'', $pos + 1);
429
-			if ($pos === false)
430
-				break;
455
+			if ($pos === false) {
456
+							break;
457
+			}
431 458
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
432 459
 
433 460
 			while (true)
434 461
 			{
435 462
 				$pos1 = strpos($db_string, '\'', $pos + 1);
436 463
 				$pos2 = strpos($db_string, '\\', $pos + 1);
437
-				if ($pos1 === false)
438
-					break;
439
-				elseif ($pos2 === false || $pos2 > $pos1)
464
+				if ($pos1 === false) {
465
+									break;
466
+				} elseif ($pos2 === false || $pos2 > $pos1)
440 467
 				{
441 468
 					$pos = $pos1;
442 469
 					break;
@@ -452,16 +479,19 @@  discard block
 block discarded – undo
452 479
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
453 480
 
454 481
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
455
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
456
-			$fail = true;
482
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
483
+					$fail = true;
484
+		}
457 485
 		// Trying to change passwords, slow us down, or something?
458
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
459
-			$fail = true;
460
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
461
-			$fail = true;
486
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
487
+					$fail = true;
488
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
489
+					$fail = true;
490
+		}
462 491
 
463
-		if (!empty($fail) && function_exists('log_error'))
464
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
492
+		if (!empty($fail) && function_exists('log_error')) {
493
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
494
+		}
465 495
 	}
466 496
 
467 497
 	// Set optimize stuff
@@ -480,18 +510,21 @@  discard block
 block discarded – undo
480 510
 
481 511
 		$db_string = $query_hints_set . $db_string;
482 512
 		
483
-		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...')
484
-			$db_cache[$db_count]['q'] = "\t\t" . $db_string;
513
+		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') {
514
+					$db_cache[$db_count]['q'] = "\t\t" . $db_string;
515
+		}
485 516
 	}
486 517
 
487 518
 	$db_last_result = @pg_query($connection, $db_string);
488 519
 
489
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
490
-		$db_last_result = smf_db_error($db_string, $connection);
520
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
521
+			$db_last_result = smf_db_error($db_string, $connection);
522
+	}
491 523
 
492 524
 	// Debugging.
493
-	if (isset($db_show_debug) && $db_show_debug === true)
494
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
525
+	if (isset($db_show_debug) && $db_show_debug === true) {
526
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
527
+	}
495 528
 
496 529
 	return $db_last_result;
497 530
 }
@@ -504,10 +537,11 @@  discard block
 block discarded – undo
504 537
 {
505 538
 	global $db_last_result, $db_replace_result;
506 539
 
507
-	if ($db_replace_result)
508
-		return $db_replace_result;
509
-	elseif ($result === null && !$db_last_result)
510
-		return 0;
540
+	if ($db_replace_result) {
541
+			return $db_replace_result;
542
+	} elseif ($result === null && !$db_last_result) {
543
+			return 0;
544
+	}
511 545
 
512 546
 	return pg_affected_rows($result === null ? $db_last_result : $result);
513 547
 }
@@ -531,8 +565,9 @@  discard block
 block discarded – undo
531 565
 		array(
532 566
 		)
533 567
 	);
534
-	if (!$request)
535
-		return false;
568
+	if (!$request) {
569
+			return false;
570
+	}
536 571
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
537 572
 	$smcFunc['db_free_result']($request);
538 573
 
@@ -553,12 +588,13 @@  discard block
 block discarded – undo
553 588
 	// Decide which connection to use
554 589
 	$connection = $connection === null ? $db_connection : $connection;
555 590
 
556
-	if ($type == 'begin')
557
-		return @pg_query($connection, 'BEGIN');
558
-	elseif ($type == 'rollback')
559
-		return @pg_query($connection, 'ROLLBACK');
560
-	elseif ($type == 'commit')
561
-		return @pg_query($connection, 'COMMIT');
591
+	if ($type == 'begin') {
592
+			return @pg_query($connection, 'BEGIN');
593
+	} elseif ($type == 'rollback') {
594
+			return @pg_query($connection, 'ROLLBACK');
595
+	} elseif ($type == 'commit') {
596
+			return @pg_query($connection, 'COMMIT');
597
+	}
562 598
 
563 599
 	return false;
564 600
 }
@@ -586,19 +622,22 @@  discard block
 block discarded – undo
586 622
 	$query_error = @pg_last_error($connection);
587 623
 
588 624
 	// Log the error.
589
-	if (function_exists('log_error'))
590
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
625
+	if (function_exists('log_error')) {
626
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
627
+	}
591 628
 
592 629
 	// Nothing's defined yet... just die with it.
593
-	if (empty($context) || empty($txt))
594
-		die($query_error);
630
+	if (empty($context) || empty($txt)) {
631
+			die($query_error);
632
+	}
595 633
 
596 634
 	// Show an error message, if possible.
597 635
 	$context['error_title'] = $txt['database_error'];
598
-	if (allowedTo('admin_forum'))
599
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
600
-	else
601
-		$context['error_message'] = $txt['try_again'];
636
+	if (allowedTo('admin_forum')) {
637
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
638
+	} else {
639
+			$context['error_message'] = $txt['try_again'];
640
+	}
602 641
 
603 642
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
604 643
 	{
@@ -620,12 +659,14 @@  discard block
 block discarded – undo
620 659
 {
621 660
 	global $db_row_count;
622 661
 
623
-	if ($counter !== false)
624
-		return pg_fetch_row($request, $counter);
662
+	if ($counter !== false) {
663
+			return pg_fetch_row($request, $counter);
664
+	}
625 665
 
626 666
 	// Reset the row counter...
627
-	if (!isset($db_row_count[(int) $request]))
628
-		$db_row_count[(int) $request] = 0;
667
+	if (!isset($db_row_count[(int) $request])) {
668
+			$db_row_count[(int) $request] = 0;
669
+	}
629 670
 
630 671
 	// Return the right row.
631 672
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -642,12 +683,14 @@  discard block
 block discarded – undo
642 683
 {
643 684
 	global $db_row_count;
644 685
 
645
-	if ($counter !== false)
646
-		return pg_fetch_assoc($request, $counter);
686
+	if ($counter !== false) {
687
+			return pg_fetch_assoc($request, $counter);
688
+	}
647 689
 
648 690
 	// Reset the row counter...
649
-	if (!isset($db_row_count[(int) $request]))
650
-		$db_row_count[(int) $request] = 0;
691
+	if (!isset($db_row_count[(int) $request])) {
692
+			$db_row_count[(int) $request] = 0;
693
+	}
651 694
 
652 695
 	// Return the right row.
653 696
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -700,11 +743,13 @@  discard block
 block discarded – undo
700 743
 
701 744
 	$replace = '';
702 745
 
703
-	if (empty($data))
704
-		return;
746
+	if (empty($data)) {
747
+			return;
748
+	}
705 749
 
706
-	if (!is_array($data[array_rand($data)]))
707
-		$data = array($data);
750
+	if (!is_array($data[array_rand($data)])) {
751
+			$data = array($data);
752
+	}
708 753
 
709 754
 	// Replace the prefix holder with the actual prefix.
710 755
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -723,11 +768,13 @@  discard block
 block discarded – undo
723 768
 			//pg 9.5 got replace support
724 769
 			$pg_version = $smcFunc['db_get_version']();
725 770
 			// if we got a Beta Version
726
-			if (stripos($pg_version, 'beta') !== false)
727
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
771
+			if (stripos($pg_version, 'beta') !== false) {
772
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
773
+			}
728 774
 			// or RC
729
-			if (stripos($pg_version, 'rc') !== false)
730
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
775
+			if (stripos($pg_version, 'rc') !== false) {
776
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
777
+			}
731 778
 
732 779
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
733 780
 		}
@@ -746,8 +793,7 @@  discard block
 block discarded – undo
746 793
 					$key_str .= ($count_pk > 0 ? ',' : '');
747 794
 					$key_str .= $columnName;
748 795
 					$count_pk++;
749
-				}
750
-				else //normal field
796
+				} else //normal field
751 797
 				{
752 798
 					$col_str .= ($count > 0 ? ',' : '');
753 799
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -755,20 +801,21 @@  discard block
 block discarded – undo
755 801
 				}
756 802
 			}
757 803
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
758
-		}
759
-		else
804
+		} else
760 805
 		{
761 806
 			foreach ($columns as $columnName => $type)
762 807
 			{
763 808
 				// Are we restricting the length?
764
-				if (strpos($type, 'string-') !== false)
765
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
766
-				else
767
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
809
+				if (strpos($type, 'string-') !== false) {
810
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
811
+				} else {
812
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
813
+				}
768 814
 
769 815
 				// A key? That's what we were looking for.
770
-				if (in_array($columnName, $keys))
771
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
816
+				if (in_array($columnName, $keys)) {
817
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
818
+				}
772 819
 				$count++;
773 820
 			}
774 821
 
@@ -804,10 +851,11 @@  discard block
 block discarded – undo
804 851
 		foreach ($columns as $columnName => $type)
805 852
 		{
806 853
 			// Are we restricting the length?
807
-			if (strpos($type, 'string-') !== false)
808
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
809
-			else
810
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+			if (strpos($type, 'string-') !== false) {
855
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
856
+			} else {
857
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+			}
811 859
 		}
812 860
 		$insertData = substr($insertData, 0, -2) . ')';
813 861
 
@@ -816,8 +864,9 @@  discard block
 block discarded – undo
816 864
 
817 865
 		// Here's where the variables are injected to the query.
818 866
 		$insertRows = array();
819
-		foreach ($data as $dataRow)
820
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
867
+		foreach ($data as $dataRow) {
868
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+		}
821 870
 
822 871
 		// Do the insert.
823 872
 		$request = $smcFunc['db_query']('', '
@@ -834,19 +883,21 @@  discard block
 block discarded – undo
834 883
 
835 884
 		if ($with_returning && $request !== false)
836 885
 		{
837
-			if ($returnmode === 2)
838
-				$return_var = array();
886
+			if ($returnmode === 2) {
887
+							$return_var = array();
888
+			}
839 889
 
840 890
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
841 891
 			{
842
-				if (is_numeric($row[0])) // try to emulate mysql limitation
892
+				if (is_numeric($row[0])) {
893
+					// try to emulate mysql limitation
843 894
 				{
844 895
 					if ($returnmode === 1)
845 896
 						$return_var = $row[0];
846
-					elseif ($returnmode === 2)
847
-						$return_var[] = $row[0];
848
-				}
849
-				else
897
+				} elseif ($returnmode === 2) {
898
+											$return_var[] = $row[0];
899
+					}
900
+				} else
850 901
 				{
851 902
 					$with_returning = false;
852 903
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -855,9 +906,10 @@  discard block
 block discarded – undo
855 906
 		}
856 907
 	}
857 908
 
858
-	if ($with_returning && !empty($return_var))
859
-		return $return_var;
860
-}
909
+	if ($with_returning && !empty($return_var)) {
910
+			return $return_var;
911
+	}
912
+	}
861 913
 
862 914
 /**
863 915
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -894,8 +946,9 @@  discard block
 block discarded – undo
894 946
  */
895 947
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
896 948
 {
897
-	if (empty($log_message))
898
-		$log_message = $error_message;
949
+	if (empty($log_message)) {
950
+			$log_message = $error_message;
951
+	}
899 952
 
900 953
 	foreach (debug_backtrace() as $step)
901 954
 	{
@@ -914,12 +967,14 @@  discard block
 block discarded – undo
914 967
 	}
915 968
 
916 969
 	// A special case - we want the file and line numbers for debugging.
917
-	if ($error_type == 'return')
918
-		return array($file, $line);
970
+	if ($error_type == 'return') {
971
+			return array($file, $line);
972
+	}
919 973
 
920 974
 	// Is always a critical error.
921
-	if (function_exists('log_error'))
922
-		log_error($log_message, 'critical', $file, $line);
975
+	if (function_exists('log_error')) {
976
+			log_error($log_message, 'critical', $file, $line);
977
+	}
923 978
 
924 979
 	if (function_exists('fatal_error'))
925 980
 	{
@@ -927,12 +982,12 @@  discard block
 block discarded – undo
927 982
 
928 983
 		// Cannot continue...
929 984
 		exit;
985
+	} elseif ($error_type) {
986
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
987
+	} else {
988
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
989
+	}
930 990
 	}
931
-	elseif ($error_type)
932
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
933
-	else
934
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
935
-}
936 991
 
937 992
 /**
938 993
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -949,10 +1004,11 @@  discard block
 block discarded – undo
949 1004
 		'\\' => '\\\\',
950 1005
 	);
951 1006
 
952
-	if ($translate_human_wildcards)
953
-		$replacements += array(
1007
+	if ($translate_human_wildcards) {
1008
+			$replacements += array(
954 1009
 			'*' => '%',
955 1010
 		);
1011
+	}
956 1012
 
957 1013
 	return strtr($string, $replacements);
958 1014
 }
Please login to merge, or discard this patch.
Sources/Subs-Graphics.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@
 block discarded – undo
170 170
  *
171 171
  * @param string $fileName The path to the file
172 172
  * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp
173
- * @return boolean Whether the reencoding was successful
173
+ * @return false|null Whether the reencoding was successful
174 174
  */
175 175
 function reencodeImage($fileName, $preferred_format = 0)
176 176
 {
Please login to merge, or discard this patch.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -523,7 +523,6 @@  discard block
 block discarded – undo
523 523
 /**
524 524
  * Copy image.
525 525
  * Used when imagecopyresample() is not available.
526
-
527 526
  * @param resource $dst_img The destination image - a GD image resource
528 527
  * @param resource $src_img The source image - a GD image resource
529 528
  * @param int $dst_x The "x" coordinate of the destination image
@@ -754,7 +753,6 @@  discard block
 block discarded – undo
754 753
 
755 754
 /**
756 755
  * Writes a gif file to disk as a png file.
757
-
758 756
  * @param resource $gif A gif image resource
759 757
  * @param string $lpszFileName The name of the file
760 758
  * @param int $background_color The background color
Please login to merge, or discard this patch.
Braces   +240 added lines, -195 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 4
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -218,8 +225,7 @@  discard block
 block discarded – undo
218 225
 				fclose($fp);
219 226
 				return false;
220 227
 			}
221
-		}
222
-		else
228
+		} else
223 229
 		{
224 230
 			// Check for potential infection - focus on clues for inline php & flash.
225 231
 			// Will result in significantly fewer false positives than the paranoid check.
@@ -247,8 +253,9 @@  discard block
 block discarded – undo
247 253
 	global $gd2;
248 254
 
249 255
 	// Check to see if GD is installed and what version.
250
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
251
-		return false;
256
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
257
+			return false;
258
+	}
252 259
 
253 260
 	// Also determine if GD2 is installed and store it in a global.
254 261
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -320,8 +327,9 @@  discard block
 block discarded – undo
320 327
 	global $sourcedir;
321 328
 
322 329
 	// Nothing to do without GD or IM/MW
323
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
324
-		return false;
330
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
331
+			return false;
332
+	}
325 333
 
326 334
 	static $default_formats = array(
327 335
 		'1' => 'gif',
@@ -343,38 +351,39 @@  discard block
 block discarded – undo
343 351
 		fclose($fp_destination);
344 352
 
345 353
 		$sizes = @getimagesize($destination);
346
-	}
347
-	elseif ($fp_destination)
354
+	} elseif ($fp_destination)
348 355
 	{
349 356
 		$sizes = @getimagesize($source);
350 357
 
351 358
 		$fp_source = fopen($source, 'rb');
352 359
 		if ($fp_source !== false)
353 360
 		{
354
-			while (!feof($fp_source))
355
-				fwrite($fp_destination, fread($fp_source, 8192));
361
+			while (!feof($fp_source)) {
362
+							fwrite($fp_destination, fread($fp_source, 8192));
363
+			}
356 364
 			fclose($fp_source);
365
+		} else {
366
+					$sizes = array(-1, -1, -1);
357 367
 		}
358
-		else
359
-			$sizes = array(-1, -1, -1);
360 368
 		fclose($fp_destination);
361 369
 	}
362 370
 	// We can't get to the file.
363
-	else
364
-		$sizes = array(-1, -1, -1);
371
+	else {
372
+			$sizes = array(-1, -1, -1);
373
+	}
365 374
 
366 375
 	// See if we have -or- can get the needed memory for this operation
367 376
 	// ImageMagick isn't subject to PHP's memory limits :)
368
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
369
-		return false;
377
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
378
+			return false;
379
+	}
370 380
 
371 381
 	// A known and supported format?
372 382
 	// @todo test PSD and gif.
373 383
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
374 384
 	{
375 385
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
376
-	}
377
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
386
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
378 387
 	{
379 388
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
380 389
 		if ($src_img = @$imagecreatefrom($destination))
@@ -427,14 +436,14 @@  discard block
 block discarded – undo
427 436
 			$dest_width = empty($max_width) ? $src_width : $max_width;
428 437
 			$dest_height = empty($max_height) ? $src_height : $max_height;
429 438
 
430
-			if ($default_formats[$preferred_format] == 'jpeg')
431
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			if ($default_formats[$preferred_format] == 'jpeg') {
440
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
441
+			}
432 442
 
433 443
 			$imagick->setImageFormat($default_formats[$preferred_format]);
434 444
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
435 445
 			$success = $imagick->writeImage($destName);
436
-		}
437
-		else
446
+		} else
438 447
 		{
439 448
 			$magick_wand = newMagickWand();
440 449
 			MagickReadImage($magick_wand, $destName);
@@ -443,8 +452,9 @@  discard block
 block discarded – undo
443 452
 			$dest_width = empty($max_width) ? $src_width : $max_width;
444 453
 			$dest_height = empty($max_height) ? $src_height : $max_height;
445 454
 
446
-			if ($default_formats[$preferred_format] == 'jpeg')
447
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			if ($default_formats[$preferred_format] == 'jpeg') {
456
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
457
+			}
448 458
 
449 459
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
450 460
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -452,8 +462,7 @@  discard block
 block discarded – undo
452 462
 		}
453 463
 
454 464
 		return !empty($success);
455
-	}
456
-	elseif (checkGD())
465
+	} elseif (checkGD())
457 466
 	{
458 467
 		$success = false;
459 468
 
@@ -464,8 +473,7 @@  discard block
 block discarded – undo
464 473
 			{
465 474
 				$dst_width = $max_width;
466 475
 				$dst_height = round($src_height * $max_width / $src_width);
467
-			}
468
-			elseif (!empty($max_height))
476
+			} elseif (!empty($max_height))
469 477
 			{
470 478
 				$dst_width = round($src_width * $max_height / $src_height);
471 479
 				$dst_height = $max_height;
@@ -483,44 +491,48 @@  discard block
 block discarded – undo
483 491
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
484 492
 					{
485 493
 						imagealphablending($dst_img, false);
486
-						if (function_exists('imagesavealpha'))
487
-							imagesavealpha($dst_img, true);
494
+						if (function_exists('imagesavealpha')) {
495
+													imagesavealpha($dst_img, true);
496
+						}
488 497
 					}
498
+				} else {
499
+									$dst_img = imagecreate($dst_width, $dst_height);
489 500
 				}
490
-				else
491
-					$dst_img = imagecreate($dst_width, $dst_height);
492 501
 
493 502
 				// Resize it!
494
-				if ($gd2)
495
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
496
-				else
497
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				if ($gd2) {
504
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				} else {
506
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
507
+				}
508
+			} else {
509
+							$dst_img = $src_img;
498 510
 			}
499
-			else
500
-				$dst_img = $src_img;
511
+		} else {
512
+					$dst_img = $src_img;
501 513
 		}
502
-		else
503
-			$dst_img = $src_img;
504 514
 
505 515
 		// Save the image as ...
506
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
507
-			$success = imagepng($dst_img, $destName);
508
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
509
-			$success = imagegif($dst_img, $destName);
510
-		elseif (function_exists('imagejpeg'))
511
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
516
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
517
+					$success = imagepng($dst_img, $destName);
518
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
519
+					$success = imagegif($dst_img, $destName);
520
+		} elseif (function_exists('imagejpeg')) {
521
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
522
+		}
512 523
 
513 524
 		// Free the memory.
514 525
 		imagedestroy($src_img);
515
-		if ($dst_img != $src_img)
516
-			imagedestroy($dst_img);
526
+		if ($dst_img != $src_img) {
527
+					imagedestroy($dst_img);
528
+		}
517 529
 
518 530
 		return $success;
519
-	}
520
-	else
521
-		// Without GD, no image resizing at all.
531
+	} else {
532
+			// Without GD, no image resizing at all.
522 533
 		return false;
523
-}
534
+	}
535
+	}
524 536
 
525 537
 /**
526 538
  * Copy image.
@@ -574,8 +586,9 @@  discard block
 block discarded – undo
574 586
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
575 587
 			if ($color == -1)
576 588
 			{
577
-				if ($palsize++ < 256)
578
-					imagecolorallocate($dst_img, $red, $green, $blue);
589
+				if ($palsize++ < 256) {
590
+									imagecolorallocate($dst_img, $red, $green, $blue);
591
+				}
579 592
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
580 593
 			}
581 594
 
@@ -605,13 +618,15 @@  discard block
 block discarded – undo
605 618
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
606 619
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
607 620
 
608
-		if ($header['type'] != 0x4D42)
609
-			return false;
621
+		if ($header['type'] != 0x4D42) {
622
+					return false;
623
+		}
610 624
 
611
-		if ($gd2)
612
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
613
-		else
614
-			$dst_img = imagecreate($info['width'], $info['height']);
625
+		if ($gd2) {
626
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
627
+		} else {
628
+					$dst_img = imagecreate($info['width'], $info['height']);
629
+		}
615 630
 
616 631
 		$palette_size = $header['offset'] - 54;
617 632
 		$info['ncolor'] = $palette_size / 4;
@@ -637,8 +652,9 @@  discard block
 block discarded – undo
637 652
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
638 653
 			$scan_line = fread($fp, $scan_line_size);
639 654
 
640
-			if (strlen($scan_line) < $scan_line_size)
641
-				continue;
655
+			if (strlen($scan_line) < $scan_line_size) {
656
+							continue;
657
+			}
642 658
 
643 659
 			if ($info['bits'] == 32)
644 660
 			{
@@ -656,14 +672,14 @@  discard block
 block discarded – undo
656 672
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
657 673
 
658 674
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
659
-						if ($color == -1)
660
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						if ($color == -1) {
676
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
677
+						}
661 678
 					}
662 679
 
663 680
 					imagesetpixel($dst_img, $x, $y, $color);
664 681
 				}
665
-			}
666
-			elseif ($info['bits'] == 24)
682
+			} elseif ($info['bits'] == 24)
667 683
 			{
668 684
 				$x = 0;
669 685
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -678,14 +694,14 @@  discard block
 block discarded – undo
678 694
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
679 695
 
680 696
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
681
-						if ($color == -1)
682
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						if ($color == -1) {
698
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
699
+						}
683 700
 					}
684 701
 
685 702
 					imagesetpixel($dst_img, $x, $y, $color);
686 703
 				}
687
-			}
688
-			elseif ($info['bits'] == 16)
704
+			} elseif ($info['bits'] == 16)
689 705
 			{
690 706
 				$x = 0;
691 707
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -706,20 +722,20 @@  discard block
 block discarded – undo
706 722
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
707 723
 
708 724
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
709
-						if ($color == -1)
710
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						if ($color == -1) {
726
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
727
+						}
711 728
 					}
712 729
 
713 730
 					imagesetpixel($dst_img, $x, $y, $color);
714 731
 				}
715
-			}
716
-			elseif ($info['bits'] == 8)
732
+			} elseif ($info['bits'] == 8)
717 733
 			{
718 734
 				$x = 0;
719
-				for ($j = 0; $j < $scan_line_size; $x++)
720
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
721
-			}
722
-			elseif ($info['bits'] == 4)
735
+				for ($j = 0; $j < $scan_line_size; $x++) {
736
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
737
+				}
738
+			} elseif ($info['bits'] == 4)
723 739
 			{
724 740
 				$x = 0;
725 741
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -727,11 +743,11 @@  discard block
 block discarded – undo
727 743
 					$byte = ord($scan_line{$j++});
728 744
 
729 745
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
730
-					if (++$x < $info['width'])
731
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
746
+					if (++$x < $info['width']) {
747
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
748
+					}
732 749
 				}
733
-			}
734
-			elseif ($info['bits'] == 1)
750
+			} elseif ($info['bits'] == 1)
735 751
 			{
736 752
 				$x = 0;
737 753
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -740,7 +756,9 @@  discard block
 block discarded – undo
740 756
 
741 757
 					imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]);
742 758
 					for ($shift = 1; $shift < 8; $shift++) {
743
-						if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
759
+						if (++$x < $info['width']) {
760
+							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
761
+						}
744 762
 					}
745 763
 				}
746 764
 			}
@@ -764,15 +782,18 @@  discard block
 block discarded – undo
764 782
  */
765 783
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
766 784
 {
767
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
768
-		return false;
785
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
786
+			return false;
787
+	}
769 788
 
770 789
 	$fd = $gif->get_png_data($background_color);
771
-	if (strlen($fd) <= 0)
772
-		return false;
790
+	if (strlen($fd) <= 0) {
791
+			return false;
792
+	}
773 793
 
774
-	if (!($fh = @fopen($lpszFileName, 'wb')))
775
-		return false;
794
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
795
+			return false;
796
+	}
776 797
 
777 798
 	@fwrite($fh, $fd, strlen($fd));
778 799
 	@fflush($fh);
@@ -799,8 +820,9 @@  discard block
 block discarded – undo
799 820
 	// What type are we going to be doing?
800 821
 	$imageType = $modSettings['visual_verification_type'];
801 822
 	// Special case to allow the admin center to show samples.
802
-	if ($user_info['is_admin'] && isset($_GET['type']))
803
-		$imageType = (int) $_GET['type'];
823
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
824
+			$imageType = (int) $_GET['type'];
825
+	}
804 826
 
805 827
 	// Some quick references for what we do.
806 828
 	// Do we show no, low or high noise?
@@ -834,25 +856,28 @@  discard block
 block discarded – undo
834 856
 	$character_spacing = 1;
835 857
 
836 858
 	// What color is the background - generally white unless we're on "hard".
837
-	if ($simpleBGColor)
838
-		$background_color = array(255, 255, 255);
839
-	else
840
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
859
+	if ($simpleBGColor) {
860
+			$background_color = array(255, 255, 255);
861
+	} else {
862
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
863
+	}
841 864
 
842 865
 	// The color of the characters shown (red, green, blue).
843
-	if ($simpleFGColor)
844
-		$foreground_color = array(0, 0, 0);
845
-	else
866
+	if ($simpleFGColor) {
867
+			$foreground_color = array(0, 0, 0);
868
+	} else
846 869
 	{
847 870
 		$foreground_color = array(64, 101, 136);
848 871
 
849 872
 		// Has the theme author requested a custom color?
850
-		if (isset($settings['verification_foreground']))
851
-			$foreground_color = $settings['verification_foreground'];
873
+		if (isset($settings['verification_foreground'])) {
874
+					$foreground_color = $settings['verification_foreground'];
875
+		}
852 876
 	}
853 877
 
854
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
855
-		return false;
878
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
879
+			return false;
880
+	}
856 881
 
857 882
 	// Get a list of the available fonts.
858 883
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -863,25 +888,28 @@  discard block
 block discarded – undo
863 888
 	{
864 889
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
865 890
 		{
866
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
867
-				$font_list[] = $entry;
891
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
892
+							$font_list[] = $entry;
893
+			}
894
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
895
+					$ttfont_list[] = $entry;
868 896
 		}
869
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
870
-			$ttfont_list[] = $entry;
871 897
 	}
872 898
 
873
-	if (empty($font_list))
874
-		return false;
899
+	if (empty($font_list)) {
900
+			return false;
901
+	}
875 902
 
876 903
 	// For non-hard things don't even change fonts.
877 904
 	if (!$varyFonts)
878 905
 	{
879 906
 		$font_list = array($font_list[0]);
880 907
 		// Try use Screenge if we can - it looks good!
881
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
882
-			$ttfont_list = array('AnonymousPro.ttf');
883
-		else
884
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
908
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
909
+					$ttfont_list = array('AnonymousPro.ttf');
910
+		} else {
911
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
912
+		}
885 913
 
886 914
 	}
887 915
 
@@ -899,14 +927,16 @@  discard block
 block discarded – undo
899 927
 	}
900 928
 
901 929
 	// Load all fonts and determine the maximum font height.
902
-	foreach ($loaded_fonts as $font_index => $dummy)
903
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	foreach ($loaded_fonts as $font_index => $dummy) {
931
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
932
+	}
904 933
 
905 934
 	// Determine the dimensions of each character.
906
-	if ($imageType == 4 || $imageType == 5)
907
-		$extra = 80;
908
-	else
909
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
910 940
 
911 941
 	$total_width = $character_spacing * strlen($code) + $extra;
912 942
 	$max_height = 0;
@@ -927,13 +957,15 @@  discard block
 block discarded – undo
927 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
928 958
 
929 959
 	// Randomize the foreground color a little.
930
-	for ($i = 0; $i < 3; $i++)
931
-		$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	for ($i = 0; $i < 3; $i++) {
961
+			$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
962
+	}
932 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
933 964
 
934 965
 	// Color for the dots.
935
-	for ($i = 0; $i < 3; $i++)
936
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
966
+	for ($i = 0; $i < 3; $i++) {
967
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
968
+	}
937 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
938 970
 
939 971
 	// Some squares/rectanges for new extreme level
@@ -959,10 +991,11 @@  discard block
 block discarded – undo
959 991
 			$can_do_ttf = function_exists('imagettftext');
960 992
 
961 993
 			// How much rotation will we give?
962
-			if ($rotationType == 'none')
963
-				$angle = 0;
964
-			else
965
-				$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
994
+			if ($rotationType == 'none') {
995
+							$angle = 0;
996
+			} else {
997
+							$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
998
+			}
966 999
 
967 1000
 			// What color shall we do it?
968 1001
 			if ($fontColorType == 'cyclic')
@@ -976,51 +1009,56 @@  discard block
 block discarded – undo
976 1009
 					array(0, 0, 0),
977 1010
 					array(143, 39, 31),
978 1011
 				);
979
-				if (!isset($last_index))
980
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
981 1015
 				$new_index = $last_index;
982
-				while ($last_index == $new_index)
983
-					$new_index = mt_rand(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = mt_rand(0, count($colors) - 1);
1018
+				}
984 1019
 				$char_fg_color = $colors[$new_index];
985 1020
 				$last_index = $new_index;
1021
+			} elseif ($fontColorType == 'random') {
1022
+							$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1023
+			} else {
1024
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
986 1025
 			}
987
-			elseif ($fontColorType == 'random')
988
-				$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
989
-			else
990
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
991 1026
 
992 1027
 			if (!empty($can_do_ttf))
993 1028
 			{
994 1029
 				// GD2 handles font size differently.
995
-				if ($fontSizeRandom)
996
-					$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
997
-				else
998
-					$font_size = $gd2 ? 18 : 24;
1030
+				if ($fontSizeRandom) {
1031
+									$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
1032
+				} else {
1033
+									$font_size = $gd2 ? 18 : 24;
1034
+				}
999 1035
 
1000 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1001 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1002 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5));
1003 1039
 
1004 1040
 				// What font face?
1005
-				if (!empty($ttfont_list))
1006
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1041
+				if (!empty($ttfont_list)) {
1042
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1043
+				}
1007 1044
 
1008 1045
 				// What color are we to do it in?
1009 1046
 				$is_reverse = $showReverseChars ? mt_rand(0, 1) : false;
1010 1047
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1011 1048
 
1012 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1013
-				if (empty($fontcord))
1014
-					$can_do_ttf = false;
1015
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1016 1053
 				{
1017 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1018 1055
 					// Put the character back!
1019 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1020 1057
 				}
1021 1058
 
1022
-				if ($can_do_ttf)
1023
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				if ($can_do_ttf) {
1060
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1061
+				}
1024 1062
 			}
1025 1063
 
1026 1064
 			if (!$can_do_ttf)
@@ -1039,8 +1077,9 @@  discard block
 block discarded – undo
1039 1077
 				}
1040 1078
 
1041 1079
 				// Sorry, no rotation available.
1042
-				else
1043
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				else {
1081
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1082
+				}
1044 1083
 				$cur_x += $character['width'] + $character_spacing;
1045 1084
 			}
1046 1085
 		}
@@ -1053,17 +1092,22 @@  discard block
 block discarded – undo
1053 1092
 	}
1054 1093
 
1055 1094
 	// Make the background color transparent on the hard image.
1056
-	if (!$simpleBGColor)
1057
-		imagecolortransparent($code_image, $bg_color);
1058
-	if ($hasBorder)
1059
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1095
+	if (!$simpleBGColor) {
1096
+			imagecolortransparent($code_image, $bg_color);
1097
+	}
1098
+	if ($hasBorder) {
1099
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1100
+	}
1060 1101
 
1061 1102
 	// Add some noise to the background?
1062 1103
 	if ($noiseType != 'none')
1063 1104
 	{
1064
-		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2))
1065
-			for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10))
1066
-				imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1105
+		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) {
1106
+					for ($j = mt_rand(0, 10);
1107
+		}
1108
+		$j < $total_width; $j += mt_rand(1, 10)) {
1109
+							imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1110
+			}
1067 1111
 
1068 1112
 		// Put in some lines too?
1069 1113
 		if ($noiseType != 'extreme')
@@ -1076,8 +1120,7 @@  discard block
 block discarded – undo
1076 1120
 					$x1 = mt_rand(0, $total_width);
1077 1121
 					$x2 = mt_rand(0, $total_width);
1078 1122
 					$y1 = 0; $y2 = $max_height;
1079
-				}
1080
-				else
1123
+				} else
1081 1124
 				{
1082 1125
 					$y1 = mt_rand(0, $max_height);
1083 1126
 					$y2 = mt_rand(0, $max_height);
@@ -1086,8 +1129,7 @@  discard block
 block discarded – undo
1086 1129
 				imagesetthickness($code_image, mt_rand(1, 2));
1087 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color);
1088 1131
 			}
1089
-		}
1090
-		else
1132
+		} else
1091 1133
 		{
1092 1134
 			// Put in some ellipse
1093 1135
 			$num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6);
@@ -1107,8 +1149,7 @@  discard block
 block discarded – undo
1107 1149
 	{
1108 1150
 		header('Content-type: image/gif');
1109 1151
 		imagegif($code_image);
1110
-	}
1111
-	else
1152
+	} else
1112 1153
 	{
1113 1154
 		header('Content-type: image/png');
1114 1155
 		imagepng($code_image);
@@ -1131,25 +1172,29 @@  discard block
 block discarded – undo
1131 1172
 {
1132 1173
 	global $settings;
1133 1174
 
1134
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1135
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1136 1178
 
1137 1179
 	// Get a list of the available font directories.
1138 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1139 1181
 	$font_list = array();
1140
-	while ($entry = $font_dir->read())
1141
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1182
+	while ($entry = $font_dir->read()) {
1183
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1142 1184
 			$font_list[] = $entry;
1185
+	}
1143 1186
 
1144
-	if (empty($font_list))
1145
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1146 1190
 
1147 1191
 	// Pick a random font.
1148 1192
 	$random_font = $font_list[array_rand($font_list)];
1149 1193
 
1150 1194
 	// Check if the given letter exists.
1151
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1152
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1153 1198
 
1154 1199
 	// Include it!
1155 1200
 	header('Content-type: image/png');
Please login to merge, or discard this patch.