Completed
Push — release-2.1 ( 306c59...efe294 )
by
unknown
08:30
created
Sources/MoveTopic.php 1 patch
Braces   +101 added lines, -72 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
  * This function allows to move a topic, making sure to ask the moderator
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 {
33 34
 	global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir;
34 35
 
35
-	if (empty($topic))
36
-		fatal_lang_error('no_access', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	$request = $smcFunc['db_query']('', '
39 41
 		SELECT t.id_member_started, ms.subject, t.approved
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 	$smcFunc['db_free_result']($request);
50 52
 
51 53
 	// Can they see it - if not approved?
52
-	if ($modSettings['postmod_active'] && !$context['is_approved'])
53
-		isAllowedTo('approve_posts');
54
+	if ($modSettings['postmod_active'] && !$context['is_approved']) {
55
+			isAllowedTo('approve_posts');
56
+	}
54 57
 
55 58
 	// Permission check!
56 59
 	// @todo
@@ -59,9 +62,9 @@  discard block
 block discarded – undo
59 62
 		if ($id_member_started == $user_info['id'])
60 63
 		{
61 64
 			isAllowedTo('move_own');
65
+		} else {
66
+					isAllowedTo('move_any');
62 67
 		}
63
-		else
64
-			isAllowedTo('move_any');
65 68
 	}
66 69
 
67 70
 	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
@@ -83,11 +86,13 @@  discard block
 block discarded – undo
83 86
 		'not_redirection' => true,
84 87
 	);
85 88
 
86
-	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board)
87
-		$options['selected_board'] = $_SESSION['move_to_topic'];
89
+	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) {
90
+			$options['selected_board'] = $_SESSION['move_to_topic'];
91
+	}
88 92
 
89
-	if (!$context['move_any'])
90
-		$options['included_boards'] = $boards;
93
+	if (!$context['move_any']) {
94
+			$options['included_boards'] = $boards;
95
+	}
91 96
 
92 97
 	require_once($sourcedir . '/Subs-MessageIndex.php');
93 98
 	$context['categories'] = getBoardList($options);
@@ -138,12 +143,14 @@  discard block
 block discarded – undo
138 143
 	global $txt, $topic, $scripturl, $sourcedir, $context;
139 144
 	global $board, $language, $user_info, $smcFunc;
140 145
 
141
-	if (empty($topic))
142
-		fatal_lang_error('no_access', false);
146
+	if (empty($topic)) {
147
+			fatal_lang_error('no_access', false);
148
+	}
143 149
 
144 150
 	// You can't choose to have a redirection topic and use an empty reason.
145
-	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
146
-		fatal_lang_error('movetopic_no_reason', false);
151
+	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
152
+			fatal_lang_error('movetopic_no_reason', false);
153
+	}
147 154
 
148 155
 	moveTopicConcurrence();
149 156
 
@@ -163,16 +170,18 @@  discard block
 block discarded – undo
163 170
 	$smcFunc['db_free_result']($request);
164 171
 
165 172
 	// Can they see it?
166
-	if (!$context['is_approved'])
167
-		isAllowedTo('approve_posts');
173
+	if (!$context['is_approved']) {
174
+			isAllowedTo('approve_posts');
175
+	}
168 176
 
169 177
 	// Can they move topics on this board?
170 178
 	if (!allowedTo('move_any'))
171 179
 	{
172
-		if ($id_member_started == $user_info['id'])
173
-			isAllowedTo('move_own');
174
-		else
175
-			isAllowedTo('move_any');
180
+		if ($id_member_started == $user_info['id']) {
181
+					isAllowedTo('move_own');
182
+		} else {
183
+					isAllowedTo('move_any');
184
+		}
176 185
 	}
177 186
 
178 187
 	checkSession();
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 			'blank_redirect' => '',
198 207
 		)
199 208
 	);
200
-	if ($smcFunc['db_num_rows']($request) == 0)
201
-		fatal_lang_error('no_board');
209
+	if ($smcFunc['db_num_rows']($request) == 0) {
210
+			fatal_lang_error('no_board');
211
+	}
202 212
 	list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
203 213
 	$smcFunc['db_free_result']($request);
204 214
 
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 	{
211 221
 		$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
212 222
 		// Keep checking the length.
213
-		if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
214
-			$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
223
+		if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
224
+					$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
225
+		}
215 226
 
216 227
 		// If it's still valid move onwards and upwards.
217 228
 		if ($_POST['custom_subject'] != '')
@@ -221,9 +232,9 @@  discard block
 block discarded – undo
221 232
 				// Get a response prefix, but in the forum's default language.
222 233
 				if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
223 234
 				{
224
-					if ($language === $user_info['language'])
225
-						$context['response_prefix'] = $txt['response_prefix'];
226
-					else
235
+					if ($language === $user_info['language']) {
236
+											$context['response_prefix'] = $txt['response_prefix'];
237
+					} else
227 238
 					{
228 239
 						loadLanguage('index', $language, false);
229 240
 						$context['response_prefix'] = $txt['response_prefix'];
@@ -263,8 +274,9 @@  discard block
 block discarded – undo
263 274
 	if (isset($_POST['postRedirect']))
264 275
 	{
265 276
 		// Should be in the boardwide language.
266
-		if ($user_info['language'] != $language)
267
-			loadLanguage('index', $language);
277
+		if ($user_info['language'] != $language) {
278
+					loadLanguage('index', $language);
279
+		}
268 280
 
269 281
 		$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
270 282
 		preparsecode($_POST['reason']);
@@ -328,8 +340,9 @@  discard block
 block discarded – undo
328 340
 		$posters = array();
329 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
330 342
 		{
331
-			if (!isset($posters[$row['id_member']]))
332
-				$posters[$row['id_member']] = 0;
343
+			if (!isset($posters[$row['id_member']])) {
344
+							$posters[$row['id_member']] = 0;
345
+			}
333 346
 
334 347
 			$posters[$row['id_member']]++;
335 348
 		}
@@ -338,11 +351,13 @@  discard block
 block discarded – undo
338 351
 		foreach ($posters as $id_member => $posts)
339 352
 		{
340 353
 			// The board we're moving from counted posts, but not to.
341
-			if (empty($pcounter_from))
342
-				updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
354
+			if (empty($pcounter_from)) {
355
+							updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
356
+			}
343 357
 			// The reverse: from didn't, to did.
344
-			else
345
-				updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
358
+			else {
359
+							updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
360
+			}
346 361
 		}
347 362
 	}
348 363
 
@@ -350,19 +365,21 @@  discard block
 block discarded – undo
350 365
 	moveTopics($topic, $_POST['toboard']);
351 366
 
352 367
 	// Log that they moved this topic.
353
-	if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
354
-		logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
368
+	if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
369
+			logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
370
+	}
355 371
 	// Notify people that this topic has been moved?
356 372
 	sendNotifications($topic, 'move');
357 373
 	
358 374
 	call_integration_hook('integrate_movetopic2_end');
359 375
 
360 376
 	// Why not go back to the original board in case they want to keep moving?
361
-	if (!isset($_REQUEST['goback']))
362
-		redirectexit('board=' . $board . '.0');
363
-	else
364
-		redirectexit('topic=' . $topic . '.0');
365
-}
377
+	if (!isset($_REQUEST['goback'])) {
378
+			redirectexit('board=' . $board . '.0');
379
+	} else {
380
+			redirectexit('topic=' . $topic . '.0');
381
+	}
382
+	}
366 383
 
367 384
 /**
368 385
  * Moves one or more topics to a specific board. (doesn't check permissions.)
@@ -378,18 +395,21 @@  discard block
 block discarded – undo
378 395
 	global $sourcedir, $user_info, $modSettings, $smcFunc;
379 396
 
380 397
 	// Empty array?
381
-	if (empty($topics))
382
-		return;
398
+	if (empty($topics)) {
399
+			return;
400
+	}
383 401
 
384 402
 	// Only a single topic.
385
-	if (is_numeric($topics))
386
-		$topics = array($topics);
403
+	if (is_numeric($topics)) {
404
+			$topics = array($topics);
405
+	}
387 406
 
388 407
 	$fromBoards = array();
389 408
 
390 409
 	// Destination board empty or equal to 0?
391
-	if (empty($toBoard))
392
-		return;
410
+	if (empty($toBoard)) {
411
+			return;
412
+	}
393 413
 
394 414
 	// Are we moving to the recycle board?
395 415
 	$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
@@ -397,8 +417,9 @@  discard block
 block discarded – undo
397 417
 	// Callback for search APIs to do their thing
398 418
 	require_once($sourcedir . '/Search.php');
399 419
 	$searchAPI = findSearchAPI();
400
-	if ($searchAPI->supportsMethod('topicsMoved'))
401
-		$searchAPI->topicsMoved($topics, $toBoard);
420
+	if ($searchAPI->supportsMethod('topicsMoved')) {
421
+			$searchAPI->topicsMoved($topics, $toBoard);
422
+	}
402 423
 
403 424
 	// Determine the source boards...
404 425
 	$request = $smcFunc['db_query']('', '
@@ -412,8 +433,9 @@  discard block
 block discarded – undo
412 433
 		)
413 434
 	);
414 435
 	// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
415
-	if ($smcFunc['db_num_rows']($request) == 0)
416
-		return;
436
+	if ($smcFunc['db_num_rows']($request) == 0) {
437
+			return;
438
+	}
417 439
 	while ($row = $smcFunc['db_fetch_assoc']($request))
418 440
 	{
419 441
 		if (!isset($fromBoards[$row['id_board']]['num_posts']))
@@ -431,10 +453,11 @@  discard block
 block discarded – undo
431 453
 		$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
432 454
 
433 455
 		// Add the topics to the right type.
434
-		if ($row['approved'])
435
-			$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
436
-		else
437
-			$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
456
+		if ($row['approved']) {
457
+					$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
458
+		} else {
459
+					$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
460
+		}
438 461
 	}
439 462
 	$smcFunc['db_free_result']($request);
440 463
 
@@ -560,13 +583,14 @@  discard block
 block discarded – undo
560 583
 			)
561 584
 		);
562 585
 		$approval_msgs = array();
563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
564
-			$approval_msgs[] = $row['id_msg'];
586
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
587
+					$approval_msgs[] = $row['id_msg'];
588
+		}
565 589
 		$smcFunc['db_free_result']($request);
566 590
 
567 591
 		// Empty the approval queue for these, as we're going to approve them next.
568
-		if (!empty($approval_msgs))
569
-			$smcFunc['db_query']('', '
592
+		if (!empty($approval_msgs)) {
593
+					$smcFunc['db_query']('', '
570 594
 				DELETE FROM {db_prefix}approval_queue
571 595
 				WHERE id_msg IN ({array_int:message_list})
572 596
 					AND id_attach = {int:id_attach}',
@@ -575,6 +599,7 @@  discard block
 block discarded – undo
575 599
 					'id_attach' => 0,
576 600
 				)
577 601
 			);
602
+		}
578 603
 
579 604
 		// Get all the current max and mins.
580 605
 		$request = $smcFunc['db_query']('', '
@@ -608,8 +633,8 @@  discard block
 block discarded – undo
608 633
 		while ($row = $smcFunc['db_fetch_assoc']($request))
609 634
 		{
610 635
 			// If not, update.
611
-			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
612
-				$smcFunc['db_query']('', '
636
+			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
637
+							$smcFunc['db_query']('', '
613 638
 					UPDATE {db_prefix}topics
614 639
 					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
615 640
 					WHERE id_topic = {int:selected_topic}',
@@ -619,6 +644,7 @@  discard block
 block discarded – undo
619 644
 						'selected_topic' => $row['id_topic'],
620 645
 					)
621 646
 				);
647
+			}
622 648
 		}
623 649
 		$smcFunc['db_free_result']($request);
624 650
 	}
@@ -677,9 +703,10 @@  discard block
 block discarded – undo
677 703
 	}
678 704
 
679 705
 	// Update the cache?
680
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
681
-		foreach ($topics as $topic_id)
706
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
707
+			foreach ($topics as $topic_id)
682 708
 			cache_put_data('topic_board-' . $topic_id, null, 120);
709
+	}
683 710
 
684 711
 	require_once($sourcedir . '/Subs-Post.php');
685 712
 
@@ -703,15 +730,17 @@  discard block
 block discarded – undo
703 730
 {
704 731
 	global $board, $topic, $smcFunc, $scripturl;
705 732
 
706
-	if (isset($_GET['current_board']))
707
-		$move_from = (int) $_GET['current_board'];
733
+	if (isset($_GET['current_board'])) {
734
+			$move_from = (int) $_GET['current_board'];
735
+	}
708 736
 
709
-	if (empty($move_from) || empty($board) || empty($topic))
710
-		return true;
737
+	if (empty($move_from) || empty($board) || empty($topic)) {
738
+			return true;
739
+	}
711 740
 
712
-	if ($move_from == $board)
713
-		return true;
714
-	else
741
+	if ($move_from == $board) {
742
+			return true;
743
+	} else
715 744
 	{
716 745
 		$request = $smcFunc['db_query']('', '
717 746
 			SELECT m.subject, b.name
Please login to merge, or discard this patch.
Sources/ManageErrors.php 1 patch
Braces   +52 added lines, -40 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
  * View the forum's error log.
@@ -30,12 +31,14 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 	
36 38
 	// Viewing contents of a backtrace?
37
-	if (isset($_GET['backtrace']))
38
-		return ViewBacktrace();
39
+	if (isset($_GET['backtrace'])) {
40
+			return ViewBacktrace();
41
+	}
39 42
 
40 43
 	// Check for the administrative permission to do this.
41 44
 	isAllowedTo('admin_forum');
@@ -89,8 +92,8 @@  discard block
 block discarded – undo
89 92
 	);
90 93
 
91 94
 	// Set up the filtering...
92
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
93
-		$filter = array(
95
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
96
+			$filter = array(
94 97
 			'variable' => $_GET['filter'],
95 98
 			'value' => array(
96 99
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -98,10 +101,12 @@  discard block
 block discarded – undo
98 101
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
99 102
 			'entity' => $filters[$_GET['filter']]['txt']
100 103
 		);
104
+	}
101 105
 
102 106
 	// Deleting, are we?
103
-	if (isset($_POST['delall']) || isset($_POST['delete']))
104
-		deleteErrors();
107
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
108
+			deleteErrors();
109
+	}
105 110
 
106 111
 	// Just how many errors are there?
107 112
 	$result = $smcFunc['db_query']('', '
@@ -116,12 +121,14 @@  discard block
 block discarded – undo
116 121
 	$smcFunc['db_free_result']($result);
117 122
 
118 123
 	// If this filter is empty...
119
-	if ($num_errors == 0 && isset($filter))
120
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
124
+	if ($num_errors == 0 && isset($filter)) {
125
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
126
+	}
121 127
 
122 128
 	// Clean up start.
123
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
124
-		$_GET['start'] = 0;
129
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
130
+			$_GET['start'] = 0;
131
+	}
125 132
 
126 133
 	// Do we want to reverse error listing?
127 134
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -131,9 +138,9 @@  discard block
 block discarded – undo
131 138
 	$context['start'] = $_GET['start'];
132 139
 
133 140
 	// Update the error count
134
-	if (!isset($filter))
135
-		$context['num_errors'] = $num_errors;
136
-	else
141
+	if (!isset($filter)) {
142
+			$context['num_errors'] = $num_errors;
143
+	} else
137 144
 	{
138 145
 		// We want all errors, not just the number of filtered messages...
139 146
 		$query = $smcFunc['db_query']('', '
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
166 173
 	{
167 174
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
168
-		if ($search_message == $filter['value']['sql'])
169
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
175
+		if ($search_message == $filter['value']['sql']) {
176
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
177
+		}
170 178
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
171 179
 
172 180
 		$context['errors'][$row['id_error']] = array(
@@ -225,8 +233,9 @@  discard block
 block discarded – undo
225 233
 				'members' => count($members),
226 234
 			)
227 235
 		);
228
-		while ($row = $smcFunc['db_fetch_assoc']($request))
229
-			$members[$row['id_member']] = $row;
236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+					$members[$row['id_member']] = $row;
238
+		}
230 239
 		$smcFunc['db_free_result']($request);
231 240
 
232 241
 		// This is a guest...
@@ -258,20 +267,18 @@  discard block
 block discarded – undo
258 267
 			$id = $filter['value']['sql'];
259 268
 			loadMemberData($id, false, 'minimal');
260 269
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
261
-		}
262
-		elseif ($filter['variable'] == 'url')
263
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
264
-		elseif ($filter['variable'] == 'message')
270
+		} elseif ($filter['variable'] == 'url') {
271
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
272
+		} elseif ($filter['variable'] == 'message')
265 273
 		{
266 274
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
267 275
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
268
-		}
269
-		elseif ($filter['variable'] == 'error_type')
276
+		} elseif ($filter['variable'] == 'error_type')
270 277
 		{
271 278
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
279
+		} else {
280
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
272 281
 		}
273
-		else
274
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
275 282
 	}
276 283
 
277 284
 	$context['error_types'] = array();
@@ -312,10 +319,11 @@  discard block
 block discarded – undo
312 319
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
313 320
 
314 321
 	// Finally, work out what is the last tab!
315
-	if (isset($context['error_types'][$sum]))
316
-		$context['error_types'][$sum]['is_last'] = true;
317
-	else
318
-		$context['error_types']['all']['is_last'] = true;
322
+	if (isset($context['error_types'][$sum])) {
323
+			$context['error_types'][$sum]['is_last'] = true;
324
+	} else {
325
+			$context['error_types']['all']['is_last'] = true;
326
+	}
319 327
 
320 328
 	// And this is pretty basic ;).
321 329
 	$context['page_title'] = $txt['errlog'];
@@ -341,21 +349,23 @@  discard block
 block discarded – undo
341 349
 	validateToken('admin-el');
342 350
 
343 351
 	// Delete all or just some?
344
-	if (isset($_POST['delall']) && !isset($filter))
345
-		$smcFunc['db_query']('truncate_table', '
352
+	if (isset($_POST['delall']) && !isset($filter)) {
353
+			$smcFunc['db_query']('truncate_table', '
346 354
 			TRUNCATE {db_prefix}log_errors',
347 355
 			array(
348 356
 			)
349 357
 		);
358
+	}
350 359
 	// Deleting all with a filter?
351
-	elseif (isset($_POST['delall']) && isset($filter))
352
-		$smcFunc['db_query']('', '
360
+	elseif (isset($_POST['delall']) && isset($filter)) {
361
+			$smcFunc['db_query']('', '
353 362
 			DELETE FROM {db_prefix}log_errors
354 363
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
355 364
 			array(
356 365
 				'filter' => $filter['value']['sql'],
357 366
 			)
358 367
 		);
368
+	}
359 369
 	// Just specific errors?
360 370
 	elseif (!empty($_POST['delete']))
361 371
 	{
@@ -401,15 +411,17 @@  discard block
 block discarded – undo
401 411
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
402 412
 
403 413
 	// Make sure the file we are looking for is one they are allowed to look at
404
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
405
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
414
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
415
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
416
+	}
406 417
 
407 418
 	// get the min and max lines
408 419
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
409 420
 	$max = $line + 21; // One additional line to make everything work out correctly
410 421
 
411
-	if ($max <= 0 || $min >= $max)
412
-		fatal_lang_error('error_bad_line');
422
+	if ($max <= 0 || $min >= $max) {
423
+			fatal_lang_error('error_bad_line');
424
+	}
413 425
 
414 426
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
415 427
 
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 
255 255
 		case 'datetime':
256 256
 			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)
257
-				return 'str_to_date('.
258
-					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]).
257
+				return 'str_to_date(' .
258
+					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]) .
259 259
 					',\'%Y-%m-%d %h:%i:%s\')';
260 260
 			else
261 261
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 		$old_pos = 0;
407 407
 		$pos = -1;
408 408
 		// Remove the string escape for better runtime
409
-		$db_string_1 = str_replace('\\\'','',$db_string);
409
+		$db_string_1 = str_replace('\\\'', '', $db_string);
410 410
 		while (true)
411 411
 		{
412 412
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	{
788 788
 		$count = count($insertRows);
789 789
 		$ai = 0;
790
-		for($i = 0; $i < $count; $i++)
790
+		for ($i = 0; $i < $count; $i++)
791 791
 		{
792 792
 			$old_id = $smcFunc['db_insert_id']();
793 793
 
@@ -813,13 +813,13 @@  discard block
 block discarded – undo
813 813
 				$count2 = count($indexed_columns);
814 814
 				for ($x = 0; $x < $count2; $x++)
815 815
 				{
816
-					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
816
+					$where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x];
817 817
 					if (($x + 1) < $count2)
818 818
 						$where_string += ' AND ';
819 819
 				}
820 820
 
821
-				$request = $smcFunc['db_query']('','
822
-					SELECT `'. $keys[0] . '` FROM ' . $table .'
821
+				$request = $smcFunc['db_query']('', '
822
+					SELECT `'. $keys[0] . '` FROM ' . $table . '
823 823
 					WHERE ' . $where_string . ' LIMIT 1',
824 824
 					array()
825 825
 				);
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 			$return_var = array();
849 849
 			$count = count($insertRows);
850 850
 			$start = smf_db_insert_id($table, $keys[0]);
851
-			for ($i = 0; $i < $count; $i++ )
851
+			for ($i = 0; $i < $count; $i++)
852 852
 				$return_var[] = $start + $i;
853 853
 		}
854 854
 		return $return_var;
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
986 986
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
987 987
 		$error_array[7], $error_array[8], $error_array[9]);
988
-	mysqli_stmt_execute ($mysql_error_data_prep);
988
+	mysqli_stmt_execute($mysql_error_data_prep);
989 989
 }
990 990
 
991 991
 /**
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
  */
1000 1000
 function smf_db_custom_order($field, $array_values, $desc = false)
1001 1001
 {
1002
-	$return = 'CASE '. $field . ' ';
1002
+	$return = 'CASE ' . $field . ' ';
1003 1003
 	$count = count($array_values);
1004 1004
 	$then = ($desc ? ' THEN -' : ' THEN ');
1005 1005
 
Please login to merge, or discard this patch.
Braces   +257 added lines, -189 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)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -64,13 +65,16 @@  discard block
 block discarded – undo
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 			'db_native_replace'			=> 'smf_db_native_replace',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$db_server = 'p:' . $db_server;
70
+	if (!empty($db_options['persist'])) {
71
+			$db_server = 'p:' . $db_server;
72
+	}
70 73
 
71 74
 	// We are not going to make it very far without these.
72
-	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect'))
73
-		display_db_error();
75
+	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) {
76
+			display_db_error();
77
+	}
74 78
 
75 79
 	$connection = mysqli_init();
76 80
 
@@ -80,24 +84,27 @@  discard block
 block discarded – undo
80 84
 
81 85
 	if ($connection)
82 86
 	{
83
-		if (!empty($db_options['port']))
84
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
85
-		else
86
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
87
+		if (!empty($db_options['port'])) {
88
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
89
+		} else {
90
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
91
+		}
87 92
 	}
88 93
 
89 94
 	// Something's wrong, show an error if its fatal (which we assume it is)
90 95
 	if ($success === false)
91 96
 	{
92
-		if (!empty($db_options['non_fatal']))
93
-			return null;
94
-		else
95
-			display_db_error();
97
+		if (!empty($db_options['non_fatal'])) {
98
+					return null;
99
+		} else {
100
+					display_db_error();
101
+		}
96 102
 	}
97 103
 
98 104
 	// Select the database, unless told not to
99
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
100
-		display_db_error();
105
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
106
+			display_db_error();
107
+	}
101 108
 
102 109
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
103 110
 
@@ -170,34 +177,42 @@  discard block
 block discarded – undo
170 177
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
171 178
 
172 179
 	list ($values, $connection) = $db_callback;
173
-	if (!is_object($connection))
174
-		display_db_error();
180
+	if (!is_object($connection)) {
181
+			display_db_error();
182
+	}
175 183
 
176
-	if ($matches[1] === 'db_prefix')
177
-		return $db_prefix;
184
+	if ($matches[1] === 'db_prefix') {
185
+			return $db_prefix;
186
+	}
178 187
 
179
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
180
-		return $user_info[$matches[1]];
188
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
189
+			return $user_info[$matches[1]];
190
+	}
181 191
 
182
-	if ($matches[1] === 'empty')
183
-		return '\'\'';
192
+	if ($matches[1] === 'empty') {
193
+			return '\'\'';
194
+	}
184 195
 
185
-	if (!isset($matches[2]))
186
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	if (!isset($matches[2])) {
197
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
198
+	}
187 199
 
188
-	if ($matches[1] === 'literal')
189
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	if ($matches[1] === 'literal') {
201
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
202
+	}
190 203
 
191
-	if (!isset($values[$matches[2]]))
192
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	if (!isset($values[$matches[2]])) {
205
+			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__);
206
+	}
193 207
 
194 208
 	$replacement = $values[$matches[2]];
195 209
 
196 210
 	switch ($matches[1])
197 211
 	{
198 212
 		case 'int':
199
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
200
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
201 216
 			return (string) (int) $replacement;
202 217
 		break;
203 218
 
@@ -209,65 +224,73 @@  discard block
 block discarded – undo
209 224
 		case 'array_int':
210 225
 			if (is_array($replacement))
211 226
 			{
212
-				if (empty($replacement))
213
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				if (empty($replacement)) {
228
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+				}
214 230
 
215 231
 				foreach ($replacement as $key => $value)
216 232
 				{
217
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
218
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
234
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+					}
219 236
 
220 237
 					$replacement[$key] = (string) (int) $value;
221 238
 				}
222 239
 
223 240
 				return implode(', ', $replacement);
241
+			} else {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 243
 			}
225
-			else
226
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227 244
 
228 245
 		break;
229 246
 
230 247
 		case 'array_string':
231 248
 			if (is_array($replacement))
232 249
 			{
233
-				if (empty($replacement))
234
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				if (empty($replacement)) {
251
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+				}
235 253
 
236
-				foreach ($replacement as $key => $value)
237
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				foreach ($replacement as $key => $value) {
255
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
256
+				}
238 257
 
239 258
 				return implode(', ', $replacement);
259
+			} else {
260
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 261
 			}
241
-			else
242
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243 262
 		break;
244 263
 
245 264
 		case 'date':
246
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
247
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
248
-			else
249
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
266
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
267
+			} else {
268
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+			}
250 270
 		break;
251 271
 
252 272
 		case 'time':
253
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
254
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
255
-			else
256
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
274
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
275
+			} else {
276
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+			}
257 278
 		break;
258 279
 
259 280
 		case 'datetime':
260
-			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)
261
-				return 'str_to_date('.
281
+			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) {
282
+							return 'str_to_date('.
262 283
 					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]).
263 284
 					',\'%Y-%m-%d %h:%i:%s\')';
264
-			else
265
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
285
+			} else {
286
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			}
266 288
 		break;
267 289
 
268 290
 		case 'float':
269
-			if (!is_numeric($replacement))
270
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
291
+			if (!is_numeric($replacement)) {
292
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
293
+			}
271 294
 			return (string) (float) $replacement;
272 295
 		break;
273 296
 
@@ -281,32 +304,37 @@  discard block
 block discarded – undo
281 304
 		break;
282 305
 
283 306
 		case 'inet':
284
-			if ($replacement == 'null' || $replacement == '')
285
-				return 'null';
286
-			if (!isValidIP($replacement))
287
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			if ($replacement == 'null' || $replacement == '') {
308
+							return 'null';
309
+			}
310
+			if (!isValidIP($replacement)) {
311
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+			}
288 313
 			//we don't use the native support of mysql > 5.6.2
289 314
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
290 315
 
291 316
 		case 'array_inet':
292 317
 			if (is_array($replacement))
293 318
 			{
294
-				if (empty($replacement))
295
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
319
+				if (empty($replacement)) {
320
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
321
+				}
296 322
 
297 323
 				foreach ($replacement as $key => $value)
298 324
 				{
299
-					if ($replacement == 'null' || $replacement == '')
300
-						$replacement[$key] = 'null';
301
-					if (!isValidIP($value))
302
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					if ($replacement == 'null' || $replacement == '') {
326
+											$replacement[$key] = 'null';
327
+					}
328
+					if (!isValidIP($value)) {
329
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
330
+					}
303 331
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
304 332
 				}
305 333
 
306 334
 				return implode(', ', $replacement);
335
+			} else {
336
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307 337
 			}
308
-			else
309
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
310 338
 		break;
311 339
 
312 340
 		default:
@@ -377,18 +405,20 @@  discard block
 block discarded – undo
377 405
 	// One more query....
378 406
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
379 407
 
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__);
408
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
409
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
410
+	}
382 411
 
383 412
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
384 413
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
385 414
 	{
386 415
 		// Add before LIMIT
387
-		if ($pos = strpos($db_string, 'LIMIT '))
388
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
389
-		else
390
-			// Append it.
416
+		if ($pos = strpos($db_string, 'LIMIT ')) {
417
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
418
+		} else {
419
+					// Append it.
391 420
 			$db_string .= "\n\t\t\tORDER BY null";
421
+		}
392 422
 	}
393 423
 
394 424
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -414,17 +444,18 @@  discard block
 block discarded – undo
414 444
 		while (true)
415 445
 		{
416 446
 			$pos = strpos($db_string_1, '\'', $pos + 1);
417
-			if ($pos === false)
418
-				break;
447
+			if ($pos === false) {
448
+							break;
449
+			}
419 450
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
420 451
 
421 452
 			while (true)
422 453
 			{
423 454
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
424 455
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
425
-				if ($pos1 === false)
426
-					break;
427
-				elseif ($pos2 === false || $pos2 > $pos1)
456
+				if ($pos1 === false) {
457
+									break;
458
+				} elseif ($pos2 === false || $pos2 > $pos1)
428 459
 				{
429 460
 					$pos = $pos1;
430 461
 					break;
@@ -440,16 +471,19 @@  discard block
 block discarded – undo
440 471
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
441 472
 
442 473
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
443
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
444
-			$fail = true;
474
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
475
+					$fail = true;
476
+		}
445 477
 		// Trying to change passwords, slow us down, or something?
446
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
447
-			$fail = true;
448
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
449
-			$fail = true;
478
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
479
+					$fail = true;
480
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
481
+					$fail = true;
482
+		}
450 483
 
451
-		if (!empty($fail) && function_exists('log_error'))
452
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
484
+		if (!empty($fail) && function_exists('log_error')) {
485
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
486
+		}
453 487
 	}
454 488
 
455 489
 	// Debugging.
@@ -459,8 +493,9 @@  discard block
 block discarded – undo
459 493
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
460 494
 
461 495
 		// Initialize $db_cache if not already initialized.
462
-		if (!isset($db_cache))
463
-			$db_cache = array();
496
+		if (!isset($db_cache)) {
497
+					$db_cache = array();
498
+		}
464 499
 
465 500
 		if (!empty($_SESSION['debug_redirect']))
466 501
 		{
@@ -476,17 +511,20 @@  discard block
 block discarded – undo
476 511
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
477 512
 	}
478 513
 
479
-	if (empty($db_unbuffered))
480
-		$ret = @mysqli_query($connection, $db_string);
481
-	else
482
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
514
+	if (empty($db_unbuffered)) {
515
+			$ret = @mysqli_query($connection, $db_string);
516
+	} else {
517
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
518
+	}
483 519
 
484
-	if ($ret === false && empty($db_values['db_error_skip']))
485
-		$ret = smf_db_error($db_string, $connection);
520
+	if ($ret === false && empty($db_values['db_error_skip'])) {
521
+			$ret = smf_db_error($db_string, $connection);
522
+	}
486 523
 
487 524
 	// Debugging.
488
-	if (isset($db_show_debug) && $db_show_debug === true)
489
-		$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
+	}
490 528
 
491 529
 	return $ret;
492 530
 }
@@ -533,12 +571,13 @@  discard block
 block discarded – undo
533 571
 	// Decide which connection to use
534 572
 	$connection = $connection === null ? $db_connection : $connection;
535 573
 
536
-	if ($type == 'begin')
537
-		return @mysqli_query($connection, 'BEGIN');
538
-	elseif ($type == 'rollback')
539
-		return @mysqli_query($connection, 'ROLLBACK');
540
-	elseif ($type == 'commit')
541
-		return @mysqli_query($connection, 'COMMIT');
574
+	if ($type == 'begin') {
575
+			return @mysqli_query($connection, 'BEGIN');
576
+	} elseif ($type == 'rollback') {
577
+			return @mysqli_query($connection, 'ROLLBACK');
578
+	} elseif ($type == 'commit') {
579
+			return @mysqli_query($connection, 'COMMIT');
580
+	}
542 581
 
543 582
 	return false;
544 583
 }
@@ -576,8 +615,9 @@  discard block
 block discarded – undo
576 615
 	//    1213: Deadlock found.
577 616
 
578 617
 	// Log the error.
579
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
580
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
618
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
619
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
620
+	}
581 621
 
582 622
 	// Database error auto fixing ;).
583 623
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -586,8 +626,9 @@  discard block
 block discarded – undo
586 626
 		$old_cache = @$modSettings['cache_enable'];
587 627
 		$modSettings['cache_enable'] = '1';
588 628
 
589
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
590
-			$db_last_error = max(@$db_last_error, $temp);
629
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
630
+					$db_last_error = max(@$db_last_error, $temp);
631
+		}
591 632
 
592 633
 		if (@$db_last_error < time() - 3600 * 24 * 3)
593 634
 		{
@@ -603,8 +644,9 @@  discard block
 block discarded – undo
603 644
 					foreach ($tables as $table)
604 645
 					{
605 646
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
606
-						if (trim($table) != '')
607
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
647
+						if (trim($table) != '') {
648
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
649
+						}
608 650
 					}
609 651
 				}
610 652
 
@@ -613,8 +655,9 @@  discard block
 block discarded – undo
613 655
 			// Table crashed.  Let's try to fix it.
614 656
 			elseif ($query_errno == 1016)
615 657
 			{
616
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
617
-					$fix_tables = array('`' . $match[1] . '`');
658
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
659
+									$fix_tables = array('`' . $match[1] . '`');
660
+				}
618 661
 			}
619 662
 			// Indexes crashed.  Should be easy to fix!
620 663
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -633,13 +676,15 @@  discard block
 block discarded – undo
633 676
 
634 677
 			// Make a note of the REPAIR...
635 678
 			cache_put_data('db_last_error', time(), 600);
636
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
637
-				updateSettingsFile(array('db_last_error' => time()));
679
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
680
+							updateSettingsFile(array('db_last_error' => time()));
681
+			}
638 682
 
639 683
 			// Attempt to find and repair the broken table.
640
-			foreach ($fix_tables as $table)
641
-				$smcFunc['db_query']('', "
684
+			foreach ($fix_tables as $table) {
685
+							$smcFunc['db_query']('', "
642 686
 					REPAIR TABLE $table", false, false);
687
+			}
643 688
 
644 689
 			// And send off an email!
645 690
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -648,11 +693,12 @@  discard block
 block discarded – undo
648 693
 
649 694
 			// Try the query again...?
650 695
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
651
-			if ($ret !== false)
652
-				return $ret;
696
+			if ($ret !== false) {
697
+							return $ret;
698
+			}
699
+		} else {
700
+					$modSettings['cache_enable'] = $old_cache;
653 701
 		}
654
-		else
655
-			$modSettings['cache_enable'] = $old_cache;
656 702
 
657 703
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
658 704
 		if (in_array($query_errno, array(1205, 1213)))
@@ -665,24 +711,27 @@  discard block
 block discarded – undo
665 711
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
666 712
 
667 713
 					$new_errno = mysqli_errno($db_connection);
668
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
669
-						break;
714
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
715
+											break;
716
+					}
670 717
 				}
671 718
 
672 719
 				// If it failed again, shucks to be you... we're not trying it over and over.
673
-				if ($ret !== false)
674
-					return $ret;
720
+				if ($ret !== false) {
721
+									return $ret;
722
+				}
675 723
 			}
676 724
 		}
677 725
 		// Are they out of space, perhaps?
678 726
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
679 727
 		{
680
-			if (!isset($txt))
681
-				$query_error .= ' - check database storage space.';
682
-			else
728
+			if (!isset($txt)) {
729
+							$query_error .= ' - check database storage space.';
730
+			} else
683 731
 			{
684
-				if (!isset($txt['mysql_error_space']))
685
-					loadLanguage('Errors');
732
+				if (!isset($txt['mysql_error_space'])) {
733
+									loadLanguage('Errors');
734
+				}
686 735
 
687 736
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
688 737
 			}
@@ -690,15 +739,17 @@  discard block
 block discarded – undo
690 739
 	}
691 740
 
692 741
 	// Nothing's defined yet... just die with it.
693
-	if (empty($context) || empty($txt))
694
-		die($query_error);
742
+	if (empty($context) || empty($txt)) {
743
+			die($query_error);
744
+	}
695 745
 
696 746
 	// Show an error message, if possible.
697 747
 	$context['error_title'] = $txt['database_error'];
698
-	if (allowedTo('admin_forum'))
699
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
700
-	else
701
-		$context['error_message'] = $txt['try_again'];
748
+	if (allowedTo('admin_forum')) {
749
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
750
+	} else {
751
+			$context['error_message'] = $txt['try_again'];
752
+	}
702 753
 
703 754
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
704 755
 	{
@@ -730,8 +781,9 @@  discard block
 block discarded – undo
730 781
 	$return_var = null;
731 782
 
732 783
 	// With nothing to insert, simply return.
733
-	if (empty($data))
734
-		return;
784
+	if (empty($data)) {
785
+			return;
786
+	}
735 787
 
736 788
 	// Replace the prefix holder with the actual prefix.
737 789
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -741,23 +793,26 @@  discard block
 block discarded – undo
741 793
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
742 794
 	{
743 795
 		$with_returning = true;
744
-		if ($returnmode == 2)
745
-			$return_var = array();
796
+		if ($returnmode == 2) {
797
+					$return_var = array();
798
+		}
746 799
 	}
747 800
 
748 801
 	// Inserting data as a single row can be done as a single array.
749
-	if (!is_array($data[array_rand($data)]))
750
-		$data = array($data);
802
+	if (!is_array($data[array_rand($data)])) {
803
+			$data = array($data);
804
+	}
751 805
 
752 806
 	// Create the mold for a single row insert.
753 807
 	$insertData = '(';
754 808
 	foreach ($columns as $columnName => $type)
755 809
 	{
756 810
 		// Are we restricting the length?
757
-		if (strpos($type, 'string-') !== false)
758
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
759
-		else
760
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
811
+		if (strpos($type, 'string-') !== false) {
812
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
813
+		} else {
814
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
815
+		}
761 816
 	}
762 817
 	$insertData = substr($insertData, 0, -2) . ')';
763 818
 
@@ -766,8 +821,9 @@  discard block
 block discarded – undo
766 821
 
767 822
 	// Here's where the variables are injected to the query.
768 823
 	$insertRows = array();
769
-	foreach ($data as $dataRow)
770
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
824
+	foreach ($data as $dataRow) {
825
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
826
+	}
771 827
 
772 828
 	// Determine the method of insertion.
773 829
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -786,8 +842,7 @@  discard block
 block discarded – undo
786 842
 			),
787 843
 			$connection
788 844
 		);
789
-	}
790
-	else //special way for ignore method with returning
845
+	} else //special way for ignore method with returning
791 846
 	{
792 847
 		$count = count($insertRows);
793 848
 		$ai = 0;
@@ -807,19 +862,21 @@  discard block
 block discarded – undo
807 862
 			);
808 863
 			$new_id = $smcFunc['db_insert_id']();
809 864
 
810
-			if ($last_id != $new_id) //the inserted value was new
865
+			if ($last_id != $new_id) {
866
+				//the inserted value was new
811 867
 			{
812 868
 				$ai = $new_id;
813 869
 			}
814
-			else	// the inserted value already exists we need to find the pk
870
+			} else	// the inserted value already exists we need to find the pk
815 871
 			{
816 872
 				$where_string = '';
817 873
 				$count2 = count($indexed_columns);
818 874
 				for ($x = 0; $x < $count2; $x++)
819 875
 				{
820 876
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
821
-					if (($x + 1) < $count2)
822
-						$where_string += ' AND ';
877
+					if (($x + 1) < $count2) {
878
+											$where_string += ' AND ';
879
+					}
823 880
 				}
824 881
 
825 882
 				$request = $smcFunc['db_query']('','
@@ -835,25 +892,27 @@  discard block
 block discarded – undo
835 892
 				}
836 893
 			}
837 894
 
838
-			if ($returnmode == 1)
839
-				$return_var = $ai;
840
-			else if ($returnmode == 2)
841
-				$return_var[] = $ai;
895
+			if ($returnmode == 1) {
896
+							$return_var = $ai;
897
+			} else if ($returnmode == 2) {
898
+							$return_var[] = $ai;
899
+			}
842 900
 		}
843 901
 	}
844 902
 
845 903
 
846 904
 	if ($with_returning)
847 905
 	{
848
-		if ($returnmode == 1 && empty($return_var))
849
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
850
-		else if ($returnmode == 2 && empty($return_var))
906
+		if ($returnmode == 1 && empty($return_var)) {
907
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
908
+		} else if ($returnmode == 2 && empty($return_var))
851 909
 		{
852 910
 			$return_var = array();
853 911
 			$count = count($insertRows);
854 912
 			$start = smf_db_insert_id($table, $keys[0]);
855
-			for ($i = 0; $i < $count; $i++ )
856
-				$return_var[] = $start + $i;
913
+			for ($i = 0; $i < $count; $i++ ) {
914
+							$return_var[] = $start + $i;
915
+			}
857 916
 		}
858 917
 		return $return_var;
859 918
 	}
@@ -871,8 +930,9 @@  discard block
 block discarded – undo
871 930
  */
872 931
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
873 932
 {
874
-	if (empty($log_message))
875
-		$log_message = $error_message;
933
+	if (empty($log_message)) {
934
+			$log_message = $error_message;
935
+	}
876 936
 
877 937
 	foreach (debug_backtrace() as $step)
878 938
 	{
@@ -891,12 +951,14 @@  discard block
 block discarded – undo
891 951
 	}
892 952
 
893 953
 	// A special case - we want the file and line numbers for debugging.
894
-	if ($error_type == 'return')
895
-		return array($file, $line);
954
+	if ($error_type == 'return') {
955
+			return array($file, $line);
956
+	}
896 957
 
897 958
 	// Is always a critical error.
898
-	if (function_exists('log_error'))
899
-		log_error($log_message, 'critical', $file, $line);
959
+	if (function_exists('log_error')) {
960
+			log_error($log_message, 'critical', $file, $line);
961
+	}
900 962
 
901 963
 	if (function_exists('fatal_error'))
902 964
 	{
@@ -904,12 +966,12 @@  discard block
 block discarded – undo
904 966
 
905 967
 		// Cannot continue...
906 968
 		exit;
969
+	} elseif ($error_type) {
970
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
971
+	} else {
972
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
973
+	}
907 974
 	}
908
-	elseif ($error_type)
909
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
910
-	else
911
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
912
-}
913 975
 
914 976
 /**
915 977
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -926,10 +988,11 @@  discard block
 block discarded – undo
926 988
 		'\\' => '\\\\',
927 989
 	);
928 990
 
929
-	if ($translate_human_wildcards)
930
-		$replacements += array(
991
+	if ($translate_human_wildcards) {
992
+			$replacements += array(
931 993
 			'*' => '%',
932 994
 		);
995
+	}
933 996
 
934 997
 	return strtr($string, $replacements);
935 998
 }
@@ -943,8 +1006,9 @@  discard block
 block discarded – undo
943 1006
  */
944 1007
 function smf_is_resource($result)
945 1008
 {
946
-	if ($result instanceof mysqli_result)
947
-		return true;
1009
+	if ($result instanceof mysqli_result) {
1010
+			return true;
1011
+	}
948 1012
 
949 1013
 	return false;
950 1014
 }
@@ -973,19 +1037,22 @@  discard block
 block discarded – undo
973 1037
 	static $mysql_error_data_prep;
974 1038
 
975 1039
 	// without database we can't do anything
976
-	if (empty($db_connection))
977
-		return;
1040
+	if (empty($db_connection)) {
1041
+			return;
1042
+	}
978 1043
 
979
-	if (empty($mysql_error_data_prep))
980
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1044
+	if (empty($mysql_error_data_prep)) {
1045
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
981 1046
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
982 1047
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?, ?)'
983 1048
 			);
1049
+	}
984 1050
 
985
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
986
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
987
-	else
988
-		$error_array[2] = null;
1051
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1052
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1053
+	} else {
1054
+			$error_array[2] = null;
1055
+	}
989 1056
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
990 1057
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
991 1058
 		$error_array[7], $error_array[8], $error_array[9]);
@@ -1007,8 +1074,9 @@  discard block
 block discarded – undo
1007 1074
 	$count = count($array_values);
1008 1075
 	$then = ($desc ? ' THEN -' : ' THEN ');
1009 1076
 
1010
-	for ($i = 0; $i < $count; $i++)
1011
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1077
+	for ($i = 0; $i < $count; $i++) {
1078
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1079
+	}
1012 1080
 
1013 1081
 	$return .= 'END';
1014 1082
 	return $return;
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +39 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -283,25 +290,30 @@  discard block
 block discarded – undo
283 290
 			<div class="windowbg noup">
284 291
 				<ul class="padding">';
285 292
 
286
-		if (!empty($context['error_info']['error_type']))
287
-			echo '
293
+		if (!empty($context['error_info']['error_type'])) {
294
+					echo '
288 295
 					<li>', $txt['error_type'], ': ', ucfirst($context['error_info']['error_type']), '</li>';
296
+		}
289 297
 
290
-		if (!empty($context['error_info']['message']))
291
-			echo '
298
+		if (!empty($context['error_info']['message'])) {
299
+					echo '
292 300
 					<li>', $txt['error_message'], ': ', $context['error_info']['message'], '</li>';
301
+		}
293 302
 
294
-		if (!empty($context['error_info']['file']))
295
-			echo '
303
+		if (!empty($context['error_info']['file'])) {
304
+					echo '
296 305
 					<li>', $txt['error_file'], ': ', $context['error_info']['file'], '</li>';
306
+		}
297 307
 
298
-		if (!empty($context['error_info']['line']))
299
-			echo '
308
+		if (!empty($context['error_info']['line'])) {
309
+					echo '
300 310
 					<li>', $txt['error_line'], ': ', $context['error_info']['line'], '</li>';
311
+		}
301 312
 
302
-		if (!empty($context['error_info']['url']))
303
-			echo '
313
+		if (!empty($context['error_info']['url'])) {
314
+					echo '
304 315
 					<li>', $txt['error_url'], ': ', $context['error_info']['url'], '</li>';
316
+		}
305 317
 
306 318
 
307 319
 		echo '
Please login to merge, or discard this patch.
Sources/ManageMembergroups.php 1 patch
Braces   +125 added lines, -86 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
 /**
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
45 46
 
46 47
 	// Is it elsewhere?
47
-	if (isset($subActions[$_REQUEST['sa']][2]))
48
-		require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
48
+	if (isset($subActions[$_REQUEST['sa']][2])) {
49
+			require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
50
+	}
49 51
 
50 52
 	// Do the permission check, you might not be allowed her.
51 53
 	isAllowedTo($subActions[$_REQUEST['sa']][1]);
@@ -104,19 +106,20 @@  discard block
 block discarded – undo
104 106
 					'function' => function($rowData) use ($scripturl)
105 107
 					{
106 108
 						// Since the moderator group has no explicit members, no link is needed.
107
-						if ($rowData['id_group'] == 3)
108
-							$group_name = $rowData['group_name'];
109
-						else
109
+						if ($rowData['id_group'] == 3) {
110
+													$group_name = $rowData['group_name'];
111
+						} else
110 112
 						{
111 113
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
112 114
 							$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
113 115
 						}
114 116
 
115 117
 						// Add a help option for moderator and administrator.
116
-						if ($rowData['id_group'] == 1)
117
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
-						elseif ($rowData['id_group'] == 3)
119
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
+						if ($rowData['id_group'] == 1) {
119
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
120
+						} elseif ($rowData['id_group'] == 3) {
121
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
122
+						}
120 123
 
121 124
 						return $group_name;
122 125
 					},
@@ -329,12 +332,14 @@  discard block
 block discarded – undo
329 332
 		call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
330 333
 
331 334
 		// Update the post groups now, if this is a post group!
332
-		if (isset($_POST['min_posts']))
333
-			updateStats('postgroups');
335
+		if (isset($_POST['min_posts'])) {
336
+					updateStats('postgroups');
337
+		}
334 338
 
335 339
 		// You cannot set permissions for post groups if they are disabled.
336
-		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
337
-			$_POST['perm_type'] = '';
340
+		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
341
+					$_POST['perm_type'] = '';
342
+		}
338 343
 
339 344
 		if ($_POST['perm_type'] == 'predefined')
340 345
 		{
@@ -364,8 +369,9 @@  discard block
 block discarded – undo
364 369
 				$smcFunc['db_free_result']($request);
365 370
 
366 371
 				// Protected groups are... well, protected!
367
-				if ($copy_type == 1)
368
-					fatal_lang_error('membergroup_does_not_exist');
372
+				if ($copy_type == 1) {
373
+									fatal_lang_error('membergroup_does_not_exist');
374
+				}
369 375
 			}
370 376
 
371 377
 			// Don't allow copying of a real priviledged person!
@@ -383,18 +389,20 @@  discard block
 block discarded – undo
383 389
 			$inserts = array();
384 390
 			while ($row = $smcFunc['db_fetch_assoc']($request))
385 391
 			{
386
-				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
387
-					$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
392
+				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) {
393
+									$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
394
+				}
388 395
 			}
389 396
 			$smcFunc['db_free_result']($request);
390 397
 
391
-			if (!empty($inserts))
392
-				$smcFunc['db_insert']('insert',
398
+			if (!empty($inserts)) {
399
+							$smcFunc['db_insert']('insert',
393 400
 					'{db_prefix}permissions',
394 401
 					array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
395 402
 					$inserts,
396 403
 					array('id_group', 'permission')
397 404
 				);
405
+			}
398 406
 
399 407
 			$request = $smcFunc['db_query']('', '
400 408
 				SELECT id_profile, permission, add_deny
@@ -405,17 +413,19 @@  discard block
 block discarded – undo
405 413
 				)
406 414
 			);
407 415
 			$inserts = array();
408
-			while ($row = $smcFunc['db_fetch_assoc']($request))
409
-				$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
416
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
417
+							$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
418
+			}
410 419
 			$smcFunc['db_free_result']($request);
411 420
 
412
-			if (!empty($inserts))
413
-				$smcFunc['db_insert']('insert',
421
+			if (!empty($inserts)) {
422
+							$smcFunc['db_insert']('insert',
414 423
 					'{db_prefix}board_permissions',
415 424
 					array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
416 425
 					$inserts,
417 426
 					array('id_group', 'id_profile', 'permission')
418 427
 				);
428
+			}
419 429
 
420 430
 			// Also get some membergroup information if we're copying and not copying from guests...
421 431
 			if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
@@ -468,14 +478,15 @@  discard block
 block discarded – undo
468 478
 		$changed_boards['allow'] = array();
469 479
 		$changed_boards['deny'] = array();
470 480
 		$changed_boards['ignore'] = array();
471
-		foreach ($accesses as $group_id => $action)
472
-			$changed_boards[$action][] = (int) $group_id;
481
+		foreach ($accesses as $group_id => $action) {
482
+					$changed_boards[$action][] = (int) $group_id;
483
+		}
473 484
 
474 485
 		foreach (array('allow', 'deny') as $board_action)
475 486
 		{
476 487
 			// Only do this if they have special access requirements.
477
-			if (!empty($changed_boards[$board_action]))
478
-				$smcFunc['db_query']('', '
488
+			if (!empty($changed_boards[$board_action])) {
489
+							$smcFunc['db_query']('', '
479 490
 					UPDATE {db_prefix}boards
480 491
 					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
481 492
 					WHERE id_board IN ({array_int:board_list})',
@@ -487,11 +498,13 @@  discard block
 block discarded – undo
487 498
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
488 499
 					)
489 500
 				);
501
+			}
490 502
 		}
491 503
 
492 504
 		// If this is joinable then set it to show group membership in people's profiles.
493
-		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
494
-			updateSettings(array('show_group_membership' => 1));
505
+		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
506
+					updateSettings(array('show_group_membership' => 1));
507
+		}
495 508
 
496 509
 		// Rebuild the group cache.
497 510
 		updateSettings(array(
@@ -512,8 +525,9 @@  discard block
 block discarded – undo
512 525
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
513 526
 	$context['allow_protected'] = allowedTo('admin_forum');
514 527
 
515
-	if (!empty($modSettings['deny_boards_access']))
516
-		loadLanguage('ManagePermissions');
528
+	if (!empty($modSettings['deny_boards_access'])) {
529
+			loadLanguage('ManagePermissions');
530
+	}
517 531
 
518 532
 	$result = $smcFunc['db_query']('', '
519 533
 		SELECT id_group, group_name
@@ -530,11 +544,12 @@  discard block
 block discarded – undo
530 544
 		)
531 545
 	);
532 546
 	$context['groups'] = array();
533
-	while ($row = $smcFunc['db_fetch_assoc']($result))
534
-		$context['groups'][] = array(
547
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
548
+			$context['groups'][] = array(
535 549
 			'id' => $row['id_group'],
536 550
 			'name' => $row['group_name']
537 551
 		);
552
+	}
538 553
 	$smcFunc['db_free_result']($result);
539 554
 
540 555
 	$request = $smcFunc['db_query']('', '
@@ -551,12 +566,13 @@  discard block
 block discarded – undo
551 566
 	while ($row = $smcFunc['db_fetch_assoc']($request))
552 567
 	{
553 568
 		// This category hasn't been set up yet..
554
-		if (!isset($context['categories'][$row['id_cat']]))
555
-			$context['categories'][$row['id_cat']] = array(
569
+		if (!isset($context['categories'][$row['id_cat']])) {
570
+					$context['categories'][$row['id_cat']] = array(
556 571
 				'id' => $row['id_cat'],
557 572
 				'name' => $row['cat_name'],
558 573
 				'boards' => array()
559 574
 			);
575
+		}
560 576
 
561 577
 		// Set this board up, and let the template know when it's a child.  (indent them..)
562 578
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -603,8 +619,9 @@  discard block
 block discarded – undo
603 619
 	require_once($sourcedir . '/Subs-Membergroups.php');
604 620
 	$result = deleteMembergroups((int) $_REQUEST['group']);
605 621
 	// Need to throw a warning if it went wrong, but this is the only one we have a message for...
606
-	if ($result === 'group_cannot_delete_sub')
607
-		fatal_lang_error('membergroups_cannot_delete_paid', false);
622
+	if ($result === 'group_cannot_delete_sub') {
623
+			fatal_lang_error('membergroups_cannot_delete_paid', false);
624
+	}
608 625
 
609 626
 	// Go back to the membergroup index.
610 627
 	redirectexit('action=admin;area=membergroups;');
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 
627 644
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
628 645
 
629
-	if (!empty($modSettings['deny_boards_access']))
630
-		loadLanguage('ManagePermissions');
646
+	if (!empty($modSettings['deny_boards_access'])) {
647
+			loadLanguage('ManagePermissions');
648
+	}
631 649
 
632 650
 	// Make sure this group is editable.
633 651
 	if (!empty($_REQUEST['group']))
@@ -649,8 +667,9 @@  discard block
 block discarded – undo
649 667
 	}
650 668
 
651 669
 	// Now, do we have a valid id?
652
-	if (empty($_REQUEST['group']))
653
-		fatal_lang_error('membergroup_does_not_exist', false);
670
+	if (empty($_REQUEST['group'])) {
671
+			fatal_lang_error('membergroup_does_not_exist', false);
672
+	}
654 673
 
655 674
 	// People who can manage boards are a bit special.
656 675
 	require_once($sourcedir . '/Subs-Members.php');
@@ -681,8 +700,9 @@  discard block
 block discarded – undo
681 700
 		require_once($sourcedir . '/Subs-Membergroups.php');
682 701
 		$result = deleteMembergroups($_REQUEST['group']);
683 702
 		// Need to throw a warning if it went wrong, but this is the only one we have a message for...
684
-		if ($result === 'group_cannot_delete_sub')
685
-			fatal_lang_error('membergroups_cannot_delete_paid', false);
703
+		if ($result === 'group_cannot_delete_sub') {
704
+					fatal_lang_error('membergroups_cannot_delete_paid', false);
705
+		}
686 706
 
687 707
 		redirectexit('action=admin;area=membergroups;');
688 708
 	}
@@ -759,16 +779,18 @@  discard block
 block discarded – undo
759 779
 				$request = $smcFunc['db_query']('', '
760 780
 					SELECT id_board
761 781
 					FROM {db_prefix}boards');
762
-				while ($row = $smcFunc['db_fetch_assoc']($request))
763
-					$accesses[(int) $row['id_board']] = 'allow';
782
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
783
+									$accesses[(int) $row['id_board']] = 'allow';
784
+				}
764 785
 				$smcFunc['db_free_result']($request);
765 786
 			}
766 787
 
767 788
 			$changed_boards['allow'] = array();
768 789
 			$changed_boards['deny'] = array();
769 790
 			$changed_boards['ignore'] = array();
770
-			foreach ($accesses as $group_id => $action)
771
-				$changed_boards[$action][] = (int) $group_id;
791
+			foreach ($accesses as $group_id => $action) {
792
+							$changed_boards[$action][] = (int) $group_id;
793
+			}
772 794
 
773 795
 			foreach (array('allow', 'deny') as $board_action)
774 796
 			{
@@ -784,8 +806,8 @@  discard block
 block discarded – undo
784 806
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
785 807
 					)
786 808
 				);
787
-				while ($row = $smcFunc['db_fetch_assoc']($request))
788
-					$smcFunc['db_query']('', '
809
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
810
+									$smcFunc['db_query']('', '
789 811
 						UPDATE {db_prefix}boards
790 812
 						SET {raw:column} = {string:member_group_access}
791 813
 						WHERE id_board = {int:current_board}',
@@ -795,11 +817,12 @@  discard block
 block discarded – undo
795 817
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
796 818
 						)
797 819
 					);
820
+				}
798 821
 				$smcFunc['db_free_result']($request);
799 822
 
800 823
 				// Add the membergroup to all boards that hadn't been set yet.
801
-				if (!empty($changed_boards[$board_action]))
802
-					$smcFunc['db_query']('', '
824
+				if (!empty($changed_boards[$board_action])) {
825
+									$smcFunc['db_query']('', '
803 826
 						UPDATE {db_prefix}boards
804 827
 						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
805 828
 						WHERE id_board IN ({array_int:board_list})
@@ -813,6 +836,7 @@  discard block
 block discarded – undo
813 836
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
814 837
 						)
815 838
 					);
839
+				}
816 840
 			}
817 841
 		}
818 842
 
@@ -838,12 +862,14 @@  discard block
 block discarded – undo
838 862
 				)
839 863
 			);
840 864
 			$updates = array();
841
-			while ($row = $smcFunc['db_fetch_assoc']($request))
842
-				$updates[$row['additional_groups']][] = $row['id_member'];
865
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
866
+							$updates[$row['additional_groups']][] = $row['id_member'];
867
+			}
843 868
 			$smcFunc['db_free_result']($request);
844 869
 
845
-			foreach ($updates as $additional_groups => $memberArray)
846
-				updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
870
+			foreach ($updates as $additional_groups => $memberArray) {
871
+							updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
872
+			}
847 873
 
848 874
 			// Sorry, but post groups can't moderate boards
849 875
 			$smcFunc['db_query']('', '
@@ -853,8 +879,7 @@  discard block
 block discarded – undo
853 879
 					'current_group' => (int) $_REQUEST['group'],
854 880
 				)
855 881
 			);
856
-		}
857
-		elseif ($_REQUEST['group'] != 3)
882
+		} elseif ($_REQUEST['group'] != 3)
858 883
 		{
859 884
 			// Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
860 885
 			if ($_POST['group_hidden'] == 2)
@@ -869,8 +894,9 @@  discard block
 block discarded – undo
869 894
 					)
870 895
 				);
871 896
 				$updates = array();
872
-				while ($row = $smcFunc['db_fetch_assoc']($request))
873
-					$updates[$row['additional_groups']][] = $row['id_member'];
897
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
898
+									$updates[$row['additional_groups']][] = $row['id_member'];
899
+				}
874 900
 				$smcFunc['db_free_result']($request);
875 901
 
876 902
 				foreach ($updates as $additional_groups => $memberArray)
@@ -912,8 +938,9 @@  discard block
 block discarded – undo
912 938
 			$smcFunc['db_free_result']($request);
913 939
 
914 940
 			// Do we need to update the setting?
915
-			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
916
-				updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
941
+			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) {
942
+							updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
943
+			}
917 944
 		}
918 945
 
919 946
 		// Do we need to set inherited permissions?
@@ -946,8 +973,9 @@  discard block
 block discarded – undo
946 973
 				{
947 974
 					$moderators[$k] = trim($moderators[$k]);
948 975
 
949
-					if (strlen($moderators[$k]) == 0)
950
-						unset($moderators[$k]);
976
+					if (strlen($moderators[$k]) == 0) {
977
+											unset($moderators[$k]);
978
+					}
951 979
 				}
952 980
 
953 981
 				// Find all the id_member's for the member_name's in the list.
@@ -963,8 +991,9 @@  discard block
 block discarded – undo
963 991
 							'count' => count($moderators),
964 992
 						)
965 993
 					);
966
-					while ($row = $smcFunc['db_fetch_assoc']($request))
967
-						$group_moderators[] = $row['id_member'];
994
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
995
+											$group_moderators[] = $row['id_member'];
996
+					}
968 997
 					$smcFunc['db_free_result']($request);
969 998
 				}
970 999
 			}
@@ -972,8 +1001,9 @@  discard block
 block discarded – undo
972 1001
 			if (!empty($_POST['moderator_list']))
973 1002
 			{
974 1003
 				$moderators = array();
975
-				foreach ($_POST['moderator_list'] as $moderator)
976
-					$moderators[] = (int) $moderator;
1004
+				foreach ($_POST['moderator_list'] as $moderator) {
1005
+									$moderators[] = (int) $moderator;
1006
+				}
977 1007
 
978 1008
 				if (!empty($moderators))
979 1009
 				{
@@ -987,8 +1017,9 @@  discard block
 block discarded – undo
987 1017
 							'num_moderators' => count($moderators),
988 1018
 						)
989 1019
 					);
990
-					while ($row = $smcFunc['db_fetch_assoc']($request))
991
-						$group_moderators[] = $row['id_member'];
1020
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
1021
+											$group_moderators[] = $row['id_member'];
1022
+					}
992 1023
 					$smcFunc['db_free_result']($request);
993 1024
 				}
994 1025
 			}
@@ -1000,8 +1031,9 @@  discard block
 block discarded – undo
1000 1031
 			if (!empty($group_moderators))
1001 1032
 			{
1002 1033
 				$mod_insert = array();
1003
-				foreach ($group_moderators as $moderator)
1004
-					$mod_insert[] = array($_REQUEST['group'], $moderator);
1034
+				foreach ($group_moderators as $moderator) {
1035
+									$mod_insert[] = array($_REQUEST['group'], $moderator);
1036
+				}
1005 1037
 
1006 1038
 				$smcFunc['db_insert']('insert',
1007 1039
 					'{db_prefix}group_moderators',
@@ -1035,8 +1067,9 @@  discard block
 block discarded – undo
1035 1067
 			'current_group' => (int) $_REQUEST['group'],
1036 1068
 		)
1037 1069
 	);
1038
-	if ($smcFunc['db_num_rows']($request) == 0)
1039
-		fatal_lang_error('membergroup_does_not_exist', false);
1070
+	if ($smcFunc['db_num_rows']($request) == 0) {
1071
+			fatal_lang_error('membergroup_does_not_exist', false);
1072
+	}
1040 1073
 	$row = $smcFunc['db_fetch_assoc']($request);
1041 1074
 	$smcFunc['db_free_result']($request);
1042 1075
 
@@ -1073,14 +1106,16 @@  discard block
 block discarded – undo
1073 1106
 		)
1074 1107
 	);
1075 1108
 	$context['group']['moderators'] = array();
1076
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1077
-		$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1110
+			$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1111
+	}
1078 1112
 	$smcFunc['db_free_result']($request);
1079 1113
 
1080 1114
 	$context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
1081 1115
 
1082
-	if (!empty($context['group']['moderators']))
1083
-		list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1116
+	if (!empty($context['group']['moderators'])) {
1117
+			list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1118
+	}
1084 1119
 
1085 1120
 	// Get a list of boards this membergroup is allowed to see.
1086 1121
 	$context['boards'] = array();
@@ -1100,12 +1135,13 @@  discard block
 block discarded – undo
1100 1135
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1101 1136
 		{
1102 1137
 			// This category hasn't been set up yet..
1103
-			if (!isset($context['categories'][$row['id_cat']]))
1104
-				$context['categories'][$row['id_cat']] = array(
1138
+			if (!isset($context['categories'][$row['id_cat']])) {
1139
+							$context['categories'][$row['id_cat']] = array(
1105 1140
 					'id' => $row['id_cat'],
1106 1141
 					'name' => $row['cat_name'],
1107 1142
 					'boards' => array()
1108 1143
 				);
1144
+			}
1109 1145
 
1110 1146
 			// Set this board up, and let the template know when it's a child.  (indent them..)
1111 1147
 			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -1147,14 +1183,16 @@  discard block
 block discarded – undo
1147 1183
 			$ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION);
1148 1184
 
1149 1185
 			// If the extension is not empty, and it is valid
1150
-			if (!empty($ext) && in_array($ext, $imageExts))
1151
-				$context['possible_icons'][] = $value;
1186
+			if (!empty($ext) && in_array($ext, $imageExts)) {
1187
+							$context['possible_icons'][] = $value;
1188
+			}
1152 1189
 		}
1153 1190
 	}
1154 1191
 
1155 1192
 	// Insert our JS, if we have possible icons.
1156
-	if (!empty($context['possible_icons']))
1157
-		loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown');
1193
+	if (!empty($context['possible_icons'])) {
1194
+			loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown');
1195
+	}
1158 1196
 
1159 1197
 	loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
1160 1198
 
@@ -1176,8 +1214,9 @@  discard block
 block discarded – undo
1176 1214
 		)
1177 1215
 	);
1178 1216
 	$context['inheritable_groups'] = array();
1179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1180
-		$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1217
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1218
+			$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1219
+	}
1181 1220
 	$smcFunc['db_free_result']($request);
1182 1221
 
1183 1222
 	call_integration_hook('integrate_view_membergroup');
Please login to merge, or discard this patch.