Completed
Pull Request — release-2.1 (#4490)
by 01
08:01
created
Sources/MessageIndex.php 2 patches
Braces   +266 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -260,8 +273,9 @@  discard block
 block discarded – undo
260 273
 	// Bring in any changes we want to make before the query.
261 274
 	call_integration_hook('integrate_pre_messageindex', array(&$sort_methods));
262 275
 
263
-	foreach ($sort_methods as $key => $val)
264
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
276
+	foreach ($sort_methods as $key => $val) {
277
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
278
+	}
265 279
 
266 280
 	// Calculate the fastest way to get the topics.
267 281
 	$start = (int) $_REQUEST['start'];
@@ -271,14 +285,15 @@  discard block
 block discarded – undo
271 285
 		$fake_ascending = true;
272 286
 		$context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex'];
273 287
 		$start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex'];
288
+	} else {
289
+			$fake_ascending = false;
274 290
 	}
275
-	else
276
-		$fake_ascending = false;
277 291
 
278 292
 	// Setup the default topic icons...
279 293
 	$context['icon_sources'] = array();
280
-	foreach ($context['stable_icons'] as $icon)
281
-		$context['icon_sources'][$icon] = 'images_url';
294
+	foreach ($context['stable_icons'] as $icon) {
295
+			$context['icon_sources'][$icon] = 'images_url';
296
+	}
282 297
 
283 298
 	$topic_ids = array();
284 299
 	$context['topics'] = array();
@@ -316,8 +331,9 @@  discard block
 block discarded – undo
316 331
 			$message_pre_index_parameters
317 332
 		);
318 333
 		$topic_ids = array();
319
-		while ($row = $smcFunc['db_fetch_assoc']($request))
320
-			$topic_ids[] = $row['id_topic'];
334
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
335
+					$topic_ids[] = $row['id_topic'];
336
+		}
321 337
 	}
322 338
 
323 339
 	// Grab the appropriate topic information...
@@ -340,10 +356,11 @@  discard block
 block discarded – undo
340 356
 		$message_index_wheres = array();
341 357
 		call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids));
342 358
 		
343
-		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
344
-			$enableParticipation = true;
345
-		else
346
-			$enableParticipation = false;
359
+		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) {
360
+					$enableParticipation = true;
361
+		} else {
362
+					$enableParticipation = false;
363
+		}
347 364
 
348 365
 		$result = $smcFunc['db_query']('substring', '
349 366
 			SELECT
@@ -382,11 +399,13 @@  discard block
 block discarded – undo
382 399
 		// Begin 'printing' the message index for current board.
383 400
 		while ($row = $smcFunc['db_fetch_assoc']($result))
384 401
 		{
385
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
386
-				continue;
402
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
403
+							continue;
404
+			}
387 405
 
388
-			if (!$pre_query)
389
-				$topic_ids[] = $row['id_topic'];
406
+			if (!$pre_query) {
407
+							$topic_ids[] = $row['id_topic'];
408
+			}
390 409
 
391 410
 			// Reference the main color class.
392 411
 			$colorClass = 'windowbg';
@@ -396,8 +415,9 @@  discard block
 block discarded – undo
396 415
 			{
397 416
 				// Limit them to $modSettings['preview_characters'] characters
398 417
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
399
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
400
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
418
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
419
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
420
+				}
401 421
 
402 422
 				// Censor the subject and message preview.
403 423
 				censorText($row['first_subject']);
@@ -408,27 +428,27 @@  discard block
 block discarded – undo
408 428
 				{
409 429
 					$row['last_subject'] = $row['first_subject'];
410 430
 					$row['last_body'] = $row['first_body'];
411
-				}
412
-				else
431
+				} else
413 432
 				{
414 433
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
415
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
416
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
434
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
435
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
436
+					}
417 437
 
418 438
 					censorText($row['last_subject']);
419 439
 					censorText($row['last_body']);
420 440
 				}
421
-			}
422
-			else
441
+			} else
423 442
 			{
424 443
 				$row['first_body'] = '';
425 444
 				$row['last_body'] = '';
426 445
 				censorText($row['first_subject']);
427 446
 
428
-				if ($row['id_first_msg'] == $row['id_last_msg'])
429
-					$row['last_subject'] = $row['first_subject'];
430
-				else
431
-					censorText($row['last_subject']);
447
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
448
+									$row['last_subject'] = $row['first_subject'];
449
+				} else {
450
+									censorText($row['last_subject']);
451
+				}
432 452
 			}
433 453
 
434 454
 			// Decide how many pages the topic should have.
@@ -439,42 +459,50 @@  discard block
 block discarded – undo
439 459
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
440 460
 
441 461
 				// If we can use all, show all.
442
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
443
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
462
+				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
463
+									$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
464
+				}
465
+			} else {
466
+							$pages = '';
444 467
 			}
445
-			else
446
-				$pages = '';
447 468
 
448 469
 			// We need to check the topic icons exist...
449 470
 			if (!empty($modSettings['messageIconChecks_enable']))
450 471
 			{
451
-				if (!isset($context['icon_sources'][$row['first_icon']]))
452
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
453
-				if (!isset($context['icon_sources'][$row['last_icon']]))
454
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
455
-			}
456
-			else
472
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
473
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
474
+				}
475
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
476
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
477
+				}
478
+			} else
457 479
 			{
458
-				if (!isset($context['icon_sources'][$row['first_icon']]))
459
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
460
-				if (!isset($context['icon_sources'][$row['last_icon']]))
461
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
480
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
481
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
482
+				}
483
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
484
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
485
+				}
462 486
 			}
463 487
 
464
-			if (!empty($board_info['recycle']))
465
-				$row['first_icon'] = 'recycled';
488
+			if (!empty($board_info['recycle'])) {
489
+							$row['first_icon'] = 'recycled';
490
+			}
466 491
 
467 492
 			// Is this topic pending approval, or does it have any posts pending approval?
468
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
469
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
493
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
494
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
495
+			}
470 496
 
471 497
 			// Sticky topics should get a different color, too.
472
-			if ($row['is_sticky'])
473
-				$colorClass .= ' sticky';
498
+			if ($row['is_sticky']) {
499
+							$colorClass .= ' sticky';
500
+			}
474 501
 
475 502
 			// Locked topics get special treatment as well.
476
-			if ($row['locked'])
477
-				$colorClass .= ' locked';
503
+			if ($row['locked']) {
504
+							$colorClass .= ' locked';
505
+			}
478 506
 
479 507
 			// 'Print' the topic info.
480 508
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -555,8 +583,9 @@  discard block
 block discarded – undo
555 583
 		$smcFunc['db_free_result']($result);
556 584
 
557 585
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
558
-		if ($fake_ascending)
559
-			$context['topics'] = array_reverse($context['topics'], true);
586
+		if ($fake_ascending) {
587
+					$context['topics'] = array_reverse($context['topics'], true);
588
+		}
560 589
 	}
561 590
 
562 591
 	$context['jump_to'] = array(
@@ -579,9 +608,9 @@  discard block
 block discarded – undo
579 608
 		// Can we restore topics?
580 609
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
581 610
 
582
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
583
-			$context['can_move_any'] = true;
584
-		else
611
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
612
+					$context['can_move_any'] = true;
613
+		} else
585 614
 		{
586 615
 			// We'll use this in a minute
587 616
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -608,11 +637,13 @@  discard block
 block discarded – undo
608 637
 		}
609 638
 
610 639
 		// Can we use quick moderation checkboxes?
611
-		if ($options['display_quick_mod'] == 1)
612
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
640
+		if ($options['display_quick_mod'] == 1) {
641
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
642
+		}
613 643
 		// Or the icons?
614
-		else
615
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
644
+		else {
645
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
646
+		}
616 647
 	}
617 648
 
618 649
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -646,13 +677,15 @@  discard block
 block discarded – undo
646 677
 			);
647 678
 
648 679
 			// We've seen all these boards now!
649
-			foreach ($board_info['parent_boards'] as $k => $dummy)
650
-				if (isset($_SESSION['topicseen_cache'][$k]))
680
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
681
+							if (isset($_SESSION['topicseen_cache'][$k]))
651 682
 					unset($_SESSION['topicseen_cache'][$k]);
683
+			}
652 684
 		}
653 685
 
654
-		if (isset($_SESSION['topicseen_cache'][$board]))
655
-			unset($_SESSION['topicseen_cache'][$board]);
686
+		if (isset($_SESSION['topicseen_cache'][$board])) {
687
+					unset($_SESSION['topicseen_cache'][$board]);
688
+		}
656 689
 
657 690
 		$request = $smcFunc['db_query']('', '
658 691
 			SELECT id_topic, id_board, sent
@@ -673,8 +706,9 @@  discard block
 block discarded – undo
673 706
 				$context['is_marked_notify'] = true;
674 707
 				$board_sent = $row['sent'];
675 708
 			}
676
-			if (!empty($row['id_topic']))
677
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
709
+			if (!empty($row['id_topic'])) {
710
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
711
+			}
678 712
 		}
679 713
 		$smcFunc['db_free_result']($request);
680 714
 
@@ -698,8 +732,7 @@  discard block
 block discarded – undo
698 732
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
699 733
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
700 734
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
701
-	}
702
-	else
735
+	} else
703 736
 	{
704 737
 		$context['is_marked_notify'] = false;
705 738
 		$context['board_notification_mode'] = 1;
@@ -712,23 +745,27 @@  discard block
 block discarded – undo
712 745
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
713 746
 
714 747
 	// Don't want to show this forever...
715
-	if ($context['becomesUnapproved'])
716
-		unset($_SESSION['becomesUnapproved']);
748
+	if ($context['becomesUnapproved']) {
749
+			unset($_SESSION['becomesUnapproved']);
750
+	}
717 751
 
718 752
 	// Build the message index button array.
719 753
 	$context['normal_buttons'] = array();
720 754
 
721
-	if ($context['can_post_new'])
722
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
755
+	if ($context['can_post_new']) {
756
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
757
+	}
723 758
 
724
-	if ($context['can_post_poll'])
725
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
759
+	if ($context['can_post_poll']) {
760
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
761
+	}
726 762
 
727
-	if (!$context['user']['is_logged'])
728
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
763
+	if (!$context['user']['is_logged']) {
764
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
765
+	}
729 766
 
730
-	if ($context['can_mark_notify'])
731
-		$context['normal_buttons']['notify'] = array(
767
+	if ($context['can_mark_notify']) {
768
+			$context['normal_buttons']['notify'] = array(
732 769
 			'lang' => true,
733 770
 			'text' => 'notify_board_' . $context['board_notification_mode'],
734 771
 			'sub_buttons' => array(
@@ -746,6 +783,7 @@  discard block
 block discarded – undo
746 783
 				),
747 784
 			),
748 785
 		);
786
+	}
749 787
 
750 788
 	// Javascript for inline editing.
751 789
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -767,18 +805,21 @@  discard block
 block discarded – undo
767 805
 	checkSession('request');
768 806
 
769 807
 	// Lets go straight to the restore area.
770
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
771
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
808
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
809
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
810
+	}
772 811
 
773
-	if (isset($_SESSION['topicseen_cache']))
774
-		$_SESSION['topicseen_cache'] = array();
812
+	if (isset($_SESSION['topicseen_cache'])) {
813
+			$_SESSION['topicseen_cache'] = array();
814
+	}
775 815
 
776 816
 	// This is going to be needed to send off the notifications and for updateLastMessages().
777 817
 	require_once($sourcedir . '/Subs-Post.php');
778 818
 
779 819
 	// Remember the last board they moved things to.
780
-	if (isset($_REQUEST['move_to']))
781
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
820
+	if (isset($_REQUEST['move_to'])) {
821
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
822
+	}
782 823
 
783 824
 	// Only a few possible actions.
784 825
 	$possibleActions = array();
@@ -798,8 +839,7 @@  discard block
 block discarded – undo
798 839
 		);
799 840
 
800 841
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
801
-	}
802
-	else
842
+	} else
803 843
 	{
804 844
 		/**
805 845
 		 * @todo Ugly. There's no getting around this, is there?
@@ -817,8 +857,7 @@  discard block
 block discarded – undo
817 857
 		if (!empty($board))
818 858
 		{
819 859
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
820
-		}
821
-		else
860
+		} else
822 861
 		{
823 862
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
824 863
 		}
@@ -829,55 +868,67 @@  discard block
 block discarded – undo
829 868
 		}
830 869
 	}
831 870
 
832
-	if (!$user_info['is_guest'])
833
-		$possibleActions[] = 'markread';
834
-	if (!empty($boards_can['make_sticky']))
835
-		$possibleActions[] = 'sticky';
836
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
837
-		$possibleActions[] = 'move';
838
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
839
-		$possibleActions[] = 'remove';
840
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
841
-		$possibleActions[] = 'lock';
842
-	if (!empty($boards_can['merge_any']))
843
-		$possibleActions[] = 'merge';
844
-	if (!empty($boards_can['approve_posts']))
845
-		$possibleActions[] = 'approve';
871
+	if (!$user_info['is_guest']) {
872
+			$possibleActions[] = 'markread';
873
+	}
874
+	if (!empty($boards_can['make_sticky'])) {
875
+			$possibleActions[] = 'sticky';
876
+	}
877
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
878
+			$possibleActions[] = 'move';
879
+	}
880
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
881
+			$possibleActions[] = 'remove';
882
+	}
883
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
884
+			$possibleActions[] = 'lock';
885
+	}
886
+	if (!empty($boards_can['merge_any'])) {
887
+			$possibleActions[] = 'merge';
888
+	}
889
+	if (!empty($boards_can['approve_posts'])) {
890
+			$possibleActions[] = 'approve';
891
+	}
846 892
 
847 893
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
848 894
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
849 895
 	if (!empty($_REQUEST['topics']))
850 896
 	{
851 897
 		// If the action isn't valid, just quit now.
852
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
853
-			redirectexit($redirect_url);
898
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
899
+					redirectexit($redirect_url);
900
+		}
854 901
 
855 902
 		// Merge requires all topics as one parameter and can be done at once.
856 903
 		if ($_REQUEST['qaction'] == 'merge')
857 904
 		{
858 905
 			// Merge requires at least two topics.
859
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
860
-				redirectexit($redirect_url);
906
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
907
+							redirectexit($redirect_url);
908
+			}
861 909
 
862 910
 			require_once($sourcedir . '/SplitTopics.php');
863 911
 			return MergeExecute($_REQUEST['topics']);
864 912
 		}
865 913
 
866 914
 		// Just convert to the other method, to make it easier.
867
-		foreach ($_REQUEST['topics'] as $topic)
868
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
915
+		foreach ($_REQUEST['topics'] as $topic) {
916
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
917
+		}
869 918
 	}
870 919
 
871 920
 	// Weird... how'd you get here?
872
-	if (empty($_REQUEST['actions']))
873
-		redirectexit($redirect_url);
921
+	if (empty($_REQUEST['actions'])) {
922
+			redirectexit($redirect_url);
923
+	}
874 924
 
875 925
 	// Validate each action.
876 926
 	$temp = array();
877 927
 	foreach ($_REQUEST['actions'] as $topic => $action)
878 928
 	{
879
-		if (in_array($action, $possibleActions))
880
-			$temp[(int) $topic] = $action;
929
+		if (in_array($action, $possibleActions)) {
930
+					$temp[(int) $topic] = $action;
931
+		}
881 932
 	}
882 933
 	$_REQUEST['actions'] = $temp;
883 934
 
@@ -898,27 +949,31 @@  discard block
 block discarded – undo
898 949
 		{
899 950
 			if (!empty($board))
900 951
 			{
901
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
902
-					unset($_REQUEST['actions'][$row['id_topic']]);
903
-			}
904
-			else
952
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
953
+									unset($_REQUEST['actions'][$row['id_topic']]);
954
+				}
955
+			} else
905 956
 			{
906 957
 				// Don't allow them to act on unapproved posts they can't see...
907
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
908
-					unset($_REQUEST['actions'][$row['id_topic']]);
958
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
959
+									unset($_REQUEST['actions'][$row['id_topic']]);
960
+				}
909 961
 				// Goodness, this is fun.  We need to validate the action.
910
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
911
-					unset($_REQUEST['actions'][$row['id_topic']]);
912
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
913
-					unset($_REQUEST['actions'][$row['id_topic']]);
914
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
915
-					unset($_REQUEST['actions'][$row['id_topic']]);
962
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
963
+									unset($_REQUEST['actions'][$row['id_topic']]);
964
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
965
+									unset($_REQUEST['actions'][$row['id_topic']]);
966
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
967
+									unset($_REQUEST['actions'][$row['id_topic']]);
968
+				}
916 969
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
917
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
918
-					unset($_REQUEST['actions'][$row['id_topic']]);
970
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
971
+									unset($_REQUEST['actions'][$row['id_topic']]);
972
+				}
919 973
 				// If the topic is approved then you need permission to approve the posts within.
920
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
921
-					unset($_REQUEST['actions'][$row['id_topic']]);
974
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
975
+									unset($_REQUEST['actions'][$row['id_topic']]);
976
+				}
922 977
 			}
923 978
 		}
924 979
 		$smcFunc['db_free_result']($request);
@@ -936,11 +991,11 @@  discard block
 block discarded – undo
936 991
 	{
937 992
 		$topic = (int) $topic;
938 993
 
939
-		if ($action == 'markread')
940
-			$markCache[] = $topic;
941
-		elseif ($action == 'sticky')
942
-			$stickyCache[] = $topic;
943
-		elseif ($action == 'move')
994
+		if ($action == 'markread') {
995
+					$markCache[] = $topic;
996
+		} elseif ($action == 'sticky') {
997
+					$stickyCache[] = $topic;
998
+		} elseif ($action == 'move')
944 999
 		{
945 1000
 			require_once($sourcedir . '/MoveTopic.php');
946 1001
 			moveTopicConcurrence();
@@ -948,23 +1003,25 @@  discard block
 block discarded – undo
948 1003
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
949 1004
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
950 1005
 
951
-			if (empty($moveCache[1][$topic]))
952
-				continue;
1006
+			if (empty($moveCache[1][$topic])) {
1007
+							continue;
1008
+			}
953 1009
 
954 1010
 			$moveCache[0][] = $topic;
1011
+		} elseif ($action == 'remove') {
1012
+					$removeCache[] = $topic;
1013
+		} elseif ($action == 'lock') {
1014
+					$lockCache[] = $topic;
1015
+		} elseif ($action == 'approve') {
1016
+					$approveCache[] = $topic;
955 1017
 		}
956
-		elseif ($action == 'remove')
957
-			$removeCache[] = $topic;
958
-		elseif ($action == 'lock')
959
-			$lockCache[] = $topic;
960
-		elseif ($action == 'approve')
961
-			$approveCache[] = $topic;
962 1018
 	}
963 1019
 
964
-	if (empty($board))
965
-		$affectedBoards = array();
966
-	else
967
-		$affectedBoards = array($board => array(0, 0));
1020
+	if (empty($board)) {
1021
+			$affectedBoards = array();
1022
+	} else {
1023
+			$affectedBoards = array($board => array(0, 0));
1024
+	}
968 1025
 
969 1026
 	// Do all the stickies...
970 1027
 	if (!empty($stickyCache))
@@ -1024,14 +1081,16 @@  discard block
 block discarded – undo
1024 1081
 		{
1025 1082
 			$to = $moveCache[1][$row['id_topic']];
1026 1083
 
1027
-			if (empty($to))
1028
-				continue;
1084
+			if (empty($to)) {
1085
+							continue;
1086
+			}
1029 1087
 
1030 1088
 			// Does this topic's board count the posts or not?
1031 1089
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1032 1090
 
1033
-			if (!isset($moveTos[$to]))
1034
-				$moveTos[$to] = array();
1091
+			if (!isset($moveTos[$to])) {
1092
+							$moveTos[$to] = array();
1093
+			}
1035 1094
 
1036 1095
 			$moveTos[$to][] = $row['id_topic'];
1037 1096
 
@@ -1045,8 +1104,9 @@  discard block
 block discarded – undo
1045 1104
 		require_once($sourcedir . '/MoveTopic.php');
1046 1105
 
1047 1106
 		// Do the actual moves...
1048
-		foreach ($moveTos as $to => $topics)
1049
-			moveTopics($topics, $to);
1107
+		foreach ($moveTos as $to => $topics) {
1108
+					moveTopics($topics, $to);
1109
+		}
1050 1110
 
1051 1111
 		// Does the post counts need to be updated?
1052 1112
 		if (!empty($moveTos))
@@ -1095,20 +1155,23 @@  discard block
 block discarded – undo
1095 1155
 
1096 1156
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1097 1157
 				{
1098
-					if (!isset($members[$row['id_member']]))
1099
-						$members[$row['id_member']] = 0;
1158
+					if (!isset($members[$row['id_member']])) {
1159
+											$members[$row['id_member']] = 0;
1160
+					}
1100 1161
 
1101
-					if ($topicRecounts[$row['id_topic']] === '+')
1102
-						$members[$row['id_member']] += 1;
1103
-					else
1104
-						$members[$row['id_member']] -= 1;
1162
+					if ($topicRecounts[$row['id_topic']] === '+') {
1163
+											$members[$row['id_member']] += 1;
1164
+					} else {
1165
+											$members[$row['id_member']] -= 1;
1166
+					}
1105 1167
 				}
1106 1168
 
1107 1169
 				$smcFunc['db_free_result']($request);
1108 1170
 
1109 1171
 				// And now update them member's post counts
1110
-				foreach ($members as $id_member => $post_adj)
1111
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1172
+				foreach ($members as $id_member => $post_adj) {
1173
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1174
+				}
1112 1175
 
1113 1176
 			}
1114 1177
 		}
@@ -1188,8 +1251,9 @@  discard block
 block discarded – undo
1188 1251
 			approveTopics($approveCache);
1189 1252
 
1190 1253
 			// Time for some logging!
1191
-			foreach ($approveCache as $topic)
1192
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1254
+			foreach ($approveCache as $topic) {
1255
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1256
+			}
1193 1257
 		}
1194 1258
 	}
1195 1259
 
@@ -1224,8 +1288,7 @@  discard block
 block discarded – undo
1224 1288
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1225 1289
 			}
1226 1290
 			$smcFunc['db_free_result']($result);
1227
-		}
1228
-		else
1291
+		} else
1229 1292
 		{
1230 1293
 			$result = $smcFunc['db_query']('', '
1231 1294
 				SELECT id_topic, locked, id_board
@@ -1275,13 +1338,15 @@  discard block
 block discarded – undo
1275 1338
 			)
1276 1339
 		);
1277 1340
 		$logged_topics = array();
1278
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1279
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1341
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1342
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1343
+		}
1280 1344
 		$smcFunc['db_free_result']($request);
1281 1345
 
1282 1346
 		$markArray = array();
1283
-		foreach ($markCache as $topic)
1284
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1347
+		foreach ($markCache as $topic) {
1348
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1349
+		}
1285 1350
 
1286 1351
 		$smcFunc['db_insert']('replace',
1287 1352
 			'{db_prefix}log_topics',
@@ -1294,8 +1359,9 @@  discard block
 block discarded – undo
1294 1359
 	foreach ($moveCache as $topic)
1295 1360
 	{
1296 1361
 		// Didn't actually move anything!
1297
-		if (!isset($topic[0]))
1298
-			break;
1362
+		if (!isset($topic[0])) {
1363
+					break;
1364
+		}
1299 1365
 
1300 1366
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1301 1367
 		sendNotifications($topic[0], 'move');
@@ -1317,8 +1383,9 @@  discard block
 block discarded – undo
1317 1383
 		'calendar_updated' => time(),
1318 1384
 	));
1319 1385
 
1320
-	if (!empty($affectedBoards))
1321
-		updateLastMessages(array_keys($affectedBoards));
1386
+	if (!empty($affectedBoards)) {
1387
+			updateLastMessages(array_keys($affectedBoards));
1388
+	}
1322 1389
 
1323 1390
 	redirectexit($redirect_url);
1324 1391
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -349,7 +349,7 @@
 block discarded – undo
349 349
 			SELECT
350 350
 				t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
351 351
 				' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from,
352
-				' . ( $enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
352
+				' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
353 353
 				'	: '') . '
354 354
 				t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic,
355 355
 				ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -155,12 +158,13 @@  discard block
 block discarded – undo
155 158
 				'data' => array(
156 159
 					'function' => function($news)
157 160
 					{
158
-						if (is_numeric($news['id']))
159
-							return '
161
+						if (is_numeric($news['id'])) {
162
+													return '
160 163
 								<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
161 164
 								<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
162
-						else
163
-							return $news['unparsed'];
165
+						} else {
166
+													return $news['unparsed'];
167
+						}
164 168
 					},
165 169
 					'class' => 'half_table',
166 170
 				),
@@ -186,10 +190,11 @@  discard block
 block discarded – undo
186 190
 				'data' => array(
187 191
 					'function' => function($news)
188 192
 					{
189
-						if (is_numeric($news['id']))
190
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
191
-						else
192
-							return '';
193
+						if (is_numeric($news['id'])) {
194
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
195
+						} else {
196
+													return '';
197
+						}
193 198
 					},
194 199
 					'class' => 'centercol icon',
195 200
 				),
@@ -283,12 +288,13 @@  discard block
 block discarded – undo
283 288
 
284 289
 	$admin_current_news = array();
285 290
 	// Ready the current news.
286
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
287
-		$admin_current_news[$id] = array(
291
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
292
+			$admin_current_news[$id] = array(
288 293
 			'id' => $id,
289 294
 			'unparsed' => un_preparsecode($line),
290 295
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
291 296
 		);
297
+	}
292 298
 
293 299
 	$admin_current_news['last'] = array(
294 300
 		'id' => 'last',
@@ -355,10 +361,11 @@  discard block
 block discarded – undo
355 361
 			'member_count' => 0,
356 362
 		);
357 363
 
358
-		if ($row['min_posts'] == -1)
359
-			$normalGroups[$row['id_group']] = $row['id_group'];
360
-		else
361
-			$postGroups[$row['id_group']] = $row['id_group'];
364
+		if ($row['min_posts'] == -1) {
365
+					$normalGroups[$row['id_group']] = $row['id_group'];
366
+		} else {
367
+					$postGroups[$row['id_group']] = $row['id_group'];
368
+		}
362 369
 	}
363 370
 	$smcFunc['db_free_result']($request);
364 371
 
@@ -374,8 +381,9 @@  discard block
 block discarded – undo
374 381
 				'post_group_list' => $postGroups,
375 382
 			)
376 383
 		);
377
-		while ($row = $smcFunc['db_fetch_assoc']($query))
378
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
384
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
385
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
386
+		}
379 387
 		$smcFunc['db_free_result']($query);
380 388
 	}
381 389
 
@@ -391,8 +399,9 @@  discard block
 block discarded – undo
391 399
 				'normal_group_list' => $normalGroups,
392 400
 			)
393 401
 		);
394
-		while ($row = $smcFunc['db_fetch_assoc']($query))
395
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
402
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
403
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
404
+		}
396 405
 		$smcFunc['db_free_result']($query);
397 406
 
398 407
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -409,8 +418,9 @@  discard block
 block discarded – undo
409 418
 				'blank_string' => '',
410 419
 			)
411 420
 		);
412
-		while ($row = $smcFunc['db_fetch_assoc']($query))
413
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
421
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
422
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
423
+		}
414 424
 		$smcFunc['db_free_result']($query);
415 425
 	}
416 426
 
@@ -461,10 +471,11 @@  discard block
 block discarded – undo
461 471
 	{
462 472
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
463 473
 
464
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
465
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
466
-		elseif (!empty($_REQUEST['xml']))
467
-			continue;
474
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
475
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
476
+		} elseif (!empty($_REQUEST['xml'])) {
477
+					continue;
478
+		}
468 479
 
469 480
 		preparsecode($context[$key]);
470 481
 		if ($html)
@@ -543,10 +554,12 @@  discard block
 block discarded – undo
543 554
 
544 555
 	// Start by finding any members!
545 556
 	$toClean = array();
546
-	if (!empty($_POST['members']))
547
-		$toClean[] = 'members';
548
-	if (!empty($_POST['exclude_members']))
549
-		$toClean[] = 'exclude_members';
557
+	if (!empty($_POST['members'])) {
558
+			$toClean[] = 'members';
559
+	}
560
+	if (!empty($_POST['exclude_members'])) {
561
+			$toClean[] = 'exclude_members';
562
+	}
550 563
 	if (!empty($toClean))
551 564
 	{
552 565
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -558,11 +571,13 @@  discard block
 block discarded – undo
558 571
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
559 572
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
560 573
 
561
-			foreach ($_POST[$type] as $index => $member)
562
-				if (strlen(trim($member)) > 0)
574
+			foreach ($_POST[$type] as $index => $member) {
575
+							if (strlen(trim($member)) > 0)
563 576
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
564
-				else
565
-					unset($_POST[$type][$index]);
577
+			}
578
+				else {
579
+									unset($_POST[$type][$index]);
580
+				}
566 581
 
567 582
 			// Find the members
568 583
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -572,16 +587,18 @@  discard block
 block discarded – undo
572 587
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
573 588
 	{
574 589
 		$members = array();
575
-		foreach ($_POST['member_list'] as $member_id)
576
-			$members[] = (int) $member_id;
590
+		foreach ($_POST['member_list'] as $member_id) {
591
+					$members[] = (int) $member_id;
592
+		}
577 593
 		$_POST['members'] = implode(',', $members);
578 594
 	}
579 595
 
580 596
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
581 597
 	{
582 598
 		$members = array();
583
-		foreach ($_POST['exclude_member_list'] as $member_id)
584
-			$members[] = (int) $member_id;
599
+		foreach ($_POST['exclude_member_list'] as $member_id) {
600
+					$members[] = (int) $member_id;
601
+		}
585 602
 		$_POST['exclude_members'] = implode(',', $members);
586 603
 	}
587 604
 
@@ -605,8 +622,9 @@  discard block
 block discarded – undo
605 622
 			'current_time' => time(),
606 623
 		)
607 624
 	);
608
-	while ($row = $smcFunc['db_fetch_assoc']($request))
609
-		$context['recipients']['exclude_members'][] = $row['id_member'];
625
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
626
+			$context['recipients']['exclude_members'][] = $row['id_member'];
627
+	}
610 628
 	$smcFunc['db_free_result']($request);
611 629
 
612 630
 	$request = $smcFunc['db_query']('', '
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
642 660
 			$condition_array_params
643 661
 		);
644
-		while ($row = $smcFunc['db_fetch_assoc']($request))
645
-			$context['recipients']['exclude_members'][] = $row['id_member'];
662
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
663
+					$context['recipients']['exclude_members'][] = $row['id_member'];
664
+		}
646 665
 		$smcFunc['db_free_result']($request);
647 666
 	}
648 667
 
@@ -660,10 +679,11 @@  discard block
 block discarded – undo
660 679
 		);
661 680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
662 681
 		{
663
-			if (in_array(3, $context['recipients']))
664
-				$context['recipients']['exclude_members'][] = $row['identifier'];
665
-			else
666
-				$context['recipients']['members'][] = $row['identifier'];
682
+			if (in_array(3, $context['recipients'])) {
683
+							$context['recipients']['exclude_members'][] = $row['identifier'];
684
+			} else {
685
+							$context['recipients']['members'][] = $row['identifier'];
686
+			}
667 687
 		}
668 688
 		$smcFunc['db_free_result']($request);
669 689
 	}
@@ -710,8 +730,9 @@  discard block
 block discarded – undo
710 730
 	$num_at_once = 1000;
711 731
 
712 732
 	// If by PM's I suggest we half the above number.
713
-	if (!empty($_POST['send_pm']))
714
-		$num_at_once /= 2;
733
+	if (!empty($_POST['send_pm'])) {
734
+			$num_at_once /= 2;
735
+	}
715 736
 
716 737
 	checkSession();
717 738
 
@@ -734,8 +755,7 @@  discard block
 block discarded – undo
734 755
 		);
735 756
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
736 757
 		$smcFunc['db_free_result']($request);
737
-	}
738
-	else
758
+	} else
739 759
 	{
740 760
 		$context['total_members'] = (int) $_REQUEST['total_members'];
741 761
 	}
@@ -753,32 +773,35 @@  discard block
 block discarded – undo
753 773
 	if (!empty($_POST['exclude_members']))
754 774
 	{
755 775
 		$members = explode(',', $_POST['exclude_members']);
756
-		foreach ($members as $member)
757
-			if ($member >= $context['start'])
776
+		foreach ($members as $member) {
777
+					if ($member >= $context['start'])
758 778
 				$context['recipients']['exclude_members'][] = (int) $member;
779
+		}
759 780
 	}
760 781
 
761 782
 	// What about members we *must* do?
762 783
 	if (!empty($_POST['members']))
763 784
 	{
764 785
 		$members = explode(',', $_POST['members']);
765
-		foreach ($members as $member)
766
-			if ($member >= $context['start'])
786
+		foreach ($members as $member) {
787
+					if ($member >= $context['start'])
767 788
 				$context['recipients']['members'][] = (int) $member;
789
+		}
768 790
 	}
769 791
 	// Cleaning groups is simple - although deal with both checkbox and commas.
770 792
 	if (isset($_POST['groups']))
771 793
 	{
772 794
 		if (is_array($_POST['groups']))
773 795
 		{
774
-			foreach ($_POST['groups'] as $group => $dummy)
775
-				$context['recipients']['groups'][] = (int) $group;
776
-		}
777
-		else
796
+			foreach ($_POST['groups'] as $group => $dummy) {
797
+							$context['recipients']['groups'][] = (int) $group;
798
+			}
799
+		} else
778 800
 		{
779 801
 			$groups = explode(',', $_POST['groups']);
780
-			foreach ($groups as $group)
781
-				$context['recipients']['groups'][] = (int) $group;
802
+			foreach ($groups as $group) {
803
+							$context['recipients']['groups'][] = (int) $group;
804
+			}
782 805
 		}
783 806
 	}
784 807
 	// Same for excluded groups
@@ -786,15 +809,17 @@  discard block
 block discarded – undo
786 809
 	{
787 810
 		if (is_array($_POST['exclude_groups']))
788 811
 		{
789
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
790
-				$context['recipients']['exclude_groups'][] = (int) $group;
812
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
813
+							$context['recipients']['exclude_groups'][] = (int) $group;
814
+			}
791 815
 		}
792 816
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
793 817
 		elseif ($_POST['exclude_groups'] != '')
794 818
 		{
795 819
 			$groups = explode(',', $_POST['exclude_groups']);
796
-			foreach ($groups as $group)
797
-				$context['recipients']['exclude_groups'][] = (int) $group;
820
+			foreach ($groups as $group) {
821
+							$context['recipients']['exclude_groups'][] = (int) $group;
822
+			}
798 823
 		}
799 824
 	}
800 825
 	// Finally - emails!
@@ -804,14 +829,16 @@  discard block
 block discarded – undo
804 829
 		foreach ($addressed as $curmem)
805 830
 		{
806 831
 			$curmem = trim($curmem);
807
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
808
-				$context['recipients']['emails'][$curmem] = $curmem;
832
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
833
+							$context['recipients']['emails'][$curmem] = $curmem;
834
+			}
809 835
 		}
810 836
 	}
811 837
 
812 838
 	// If we're only cleaning drop out here.
813
-	if ($clean_only)
814
-		return;
839
+	if ($clean_only) {
840
+			return;
841
+	}
815 842
 
816 843
 	require_once($sourcedir . '/Subs-Post.php');
817 844
 
@@ -827,16 +854,18 @@  discard block
 block discarded – undo
827 854
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
828 855
 	{
829 856
 		// Prepare the message for HTML.
830
-		if (!empty($_POST['parse_html']))
831
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
857
+		if (!empty($_POST['parse_html'])) {
858
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
859
+		}
832 860
 
833 861
 		// This is here to prevent spam filters from tagging this as spam.
834 862
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
835 863
 		{
836
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
837
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
838
-			else
839
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
864
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
865
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
866
+			} else {
867
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
868
+			}
840 869
 		}
841 870
 	}
842 871
 
@@ -890,15 +919,17 @@  discard block
 block discarded – undo
890 919
 	foreach ($context['recipients']['emails'] as $k => $email)
891 920
 	{
892 921
 		// Done as many as we can?
893
-		if ($i >= $num_at_once)
894
-			break;
922
+		if ($i >= $num_at_once) {
923
+					break;
924
+		}
895 925
 
896 926
 		// Don't sent it twice!
897 927
 		unset($context['recipients']['emails'][$k]);
898 928
 
899 929
 		// Dammit - can't PM emails!
900
-		if ($context['send_pm'])
901
-			continue;
930
+		if ($context['send_pm']) {
931
+					continue;
932
+		}
902 933
 
903 934
 		$to_member = array(
904 935
 			$email,
@@ -932,8 +963,9 @@  discard block
 block discarded – undo
932 963
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
933 964
 				}
934 965
 			}
935
-			if (!empty($queryBuild))
936
-			$sendQuery .= implode(' OR ', $queryBuild);
966
+			if (!empty($queryBuild)) {
967
+						$sendQuery .= implode(' OR ', $queryBuild);
968
+			}
937 969
 		}
938 970
 		if (!empty($context['recipients']['members']))
939 971
 		{
@@ -952,8 +984,9 @@  discard block
 block discarded – undo
952 984
 		}
953 985
 
954 986
 		// Anything to exclude?
955
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
956
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
987
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
988
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
989
+		}
957 990
 		if (!empty($context['recipients']['exclude_members']))
958 991
 		{
959 992
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -989,21 +1022,24 @@  discard block
 block discarded – undo
989 1022
 		foreach ($rows as $row)
990 1023
 		{
991 1024
 			// Force them to have it?
992
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
993
-				continue;
1025
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1026
+							continue;
1027
+			}
994 1028
 
995 1029
 			// What groups are we looking at here?
996
-			if (empty($row['additional_groups']))
997
-				$groups = array($row['id_group'], $row['id_post_group']);
998
-			else
999
-				$groups = array_merge(
1030
+			if (empty($row['additional_groups'])) {
1031
+							$groups = array($row['id_group'], $row['id_post_group']);
1032
+			} else {
1033
+							$groups = array_merge(
1000 1034
 					array($row['id_group'], $row['id_post_group']),
1001 1035
 					explode(',', $row['additional_groups'])
1002 1036
 				);
1037
+			}
1003 1038
 
1004 1039
 			// Excluded groups?
1005
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1006
-				continue;
1040
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1041
+							continue;
1042
+			}
1007 1043
 
1008 1044
 			// We might need this
1009 1045
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1026,10 +1062,11 @@  discard block
 block discarded – undo
1026 1062
 				), $_POST['subject']);
1027 1063
 
1028 1064
 			// Send the actual email - or a PM!
1029
-			if (!$context['send_pm'])
1030
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1031
-			else
1032
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1065
+			if (!$context['send_pm']) {
1066
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1067
+			} else {
1068
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1069
+			}
1033 1070
 		}
1034 1071
 	}
1035 1072
 
@@ -1079,8 +1116,9 @@  discard block
 block discarded – undo
1079 1116
 
1080 1117
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1081 1118
 
1082
-	if ($return_config)
1083
-		return $config_vars;
1119
+	if ($return_config) {
1120
+			return $config_vars;
1121
+	}
1084 1122
 
1085 1123
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1086 1124
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Themes/default/Register.template.php 1 patch
Braces   +90 added lines, -65 removed lines patch added patch discarded remove patch
@@ -28,14 +28,15 @@  discard block
 block discarded – undo
28 28
 			<div id="confirm_buttons">';
29 29
 
30 30
 	// Age restriction in effect?
31
-	if ($context['show_coppa'])
32
-		echo '
31
+	if ($context['show_coppa']) {
32
+			echo '
33 33
 				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button"><br>
34 34
 				<br>
35 35
 				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button">';
36
-	else
37
-		echo '
36
+	} else {
37
+			echo '
38 38
 				<input type="submit" name="accept_agreement" value="', $txt['agreement_agree'], '" class="button">';
39
+	}
39 40
 
40 41
 	echo '
41 42
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -78,9 +79,10 @@  discard block
 block discarded – undo
78 79
 			<ul>';
79 80
 
80 81
 		// Cycle through each error and display an error message.
81
-		foreach ($context['registration_errors'] as $error)
82
-			echo '
82
+		foreach ($context['registration_errors'] as $error) {
83
+					echo '
83 84
 				<li>', $error, '</li>';
85
+		}
84 86
 
85 87
 		echo '
86 88
 			</ul>
@@ -149,14 +151,15 @@  discard block
 block discarded – undo
149 151
 		echo '
150 152
 					<dl class="register_form">';
151 153
 
152
-		foreach ($context['custom_fields'] as $field)
153
-			if ($field['show_reg'] > 1)
154
+		foreach ($context['custom_fields'] as $field) {
155
+					if ($field['show_reg'] > 1)
154 156
 				echo '
155 157
 						<dt>
156 158
 							<strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong>
157 159
 							<span class="smalltext">', $field['desc'], '</span>
158 160
 						</dt>
159 161
 						<dd>', str_replace('name="', 'tabindex="' . $context['tabindex']++ . '" name="', $field['input_html']), '</dd>';
162
+		}
160 163
 
161 164
 		echo '
162 165
 					</dl>';
@@ -167,14 +170,15 @@  discard block
 block discarded – undo
167 170
 			</div><!-- .roundframe -->';
168 171
 
169 172
 	// If we have either of these, show the extra group.
170
-	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
171
-		echo '
173
+	if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) {
174
+			echo '
172 175
 			<div class="title_bar title_top">
173 176
 				<h3 class="titlebg">', $txt['additional_information'], '</h3>
174 177
 			</div>
175 178
 			<div class="roundframe noup">
176 179
 				<fieldset>
177 180
 					<dl class="register_form" id="custom_group">';
181
+	}
178 182
 
179 183
 	if (!empty($context['profile_fields']))
180 184
 	{
@@ -188,41 +192,45 @@  discard block
 block discarded – undo
188 192
 					$callback_func = 'template_profile_' . $field['callback_func'];
189 193
 					$callback_func();
190 194
 				}
191
-			}
192
-			else
195
+			} else
193 196
 			{
194 197
 				echo '
195 198
 						<dt>
196 199
 							<strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['label'], ':</strong>';
197 200
 
198 201
 				// Does it have any subtext to show?
199
-				if (!empty($field['subtext']))
200
-					echo '
202
+				if (!empty($field['subtext'])) {
203
+									echo '
201 204
 							<span class="smalltext">', $field['subtext'], '</span>';
205
+				}
202 206
 
203 207
 				echo '
204 208
 						</dt>
205 209
 						<dd>';
206 210
 
207 211
 				// Want to put something infront of the box?
208
-				if (!empty($field['preinput']))
209
-					echo '
212
+				if (!empty($field['preinput'])) {
213
+									echo '
210 214
 							', $field['preinput'];
215
+				}
211 216
 
212 217
 				// What type of data are we showing?
213
-				if ($field['type'] == 'label')
214
-					echo '
218
+				if ($field['type'] == 'label') {
219
+									echo '
215 220
 							', $field['value'];
221
+				}
216 222
 
217 223
 				// Maybe it's a text box - very likely!
218
-				elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'url')))
219
-					echo '
224
+				elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'url'))) {
225
+									echo '
220 226
 							<input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>';
227
+				}
221 228
 
222 229
 				// You "checking" me out? ;)
223
-				elseif ($field['type'] == 'check')
224
-					echo '
230
+				elseif ($field['type'] == 'check') {
231
+									echo '
225 232
 							<input type="hidden" name="', $key, '" value="0"><input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>';
233
+				}
226 234
 
227 235
 				// Always fun - select boxes!
228 236
 				elseif ($field['type'] == 'select')
@@ -233,14 +241,16 @@  discard block
 block discarded – undo
233 241
 					if (isset($field['options']))
234 242
 					{
235 243
 						// Is this some code to generate the options?
236
-						if (!is_array($field['options']))
237
-							$field['options'] = eval($field['options']);
244
+						if (!is_array($field['options'])) {
245
+													$field['options'] = eval($field['options']);
246
+						}
238 247
 
239 248
 						// Assuming we now have some!
240
-						if (is_array($field['options']))
241
-							foreach ($field['options'] as $value => $name)
249
+						if (is_array($field['options'])) {
250
+													foreach ($field['options'] as $value => $name)
242 251
 								echo '
243 252
 								<option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>';
253
+						}
244 254
 					}
245 255
 
246 256
 					echo '
@@ -248,9 +258,10 @@  discard block
 block discarded – undo
248 258
 				}
249 259
 
250 260
 				// Something to end with?
251
-				if (!empty($field['postinput']))
252
-					echo '
261
+				if (!empty($field['postinput'])) {
262
+									echo '
253 263
 							', $field['postinput'];
264
+				}
254 265
 
255 266
 				echo '
256 267
 						</dd>';
@@ -261,25 +272,27 @@  discard block
 block discarded – undo
261 272
 	// Are there any custom fields?
262 273
 	if (!empty($context['custom_fields']))
263 274
 	{
264
-		foreach ($context['custom_fields'] as $field)
265
-			if ($field['show_reg'] < 2)
275
+		foreach ($context['custom_fields'] as $field) {
276
+					if ($field['show_reg'] < 2)
266 277
 				echo '
267 278
 						<dt>
268 279
 							<strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong>
269 280
 							<span class="smalltext">', $field['desc'], '</span>
270 281
 						</dt>
271 282
 						<dd>', $field['input_html'], '</dd>';
283
+		}
272 284
 	}
273 285
 
274 286
 	// If we have either of these, close the list like a proper gent.
275
-	if (!empty($context['profile_fields']) || !empty($context['custom_fields']))
276
-		echo '
287
+	if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) {
288
+			echo '
277 289
 					</dl>
278 290
 				</fieldset>
279 291
 			</div><!-- .roundframe -->';
292
+	}
280 293
 
281
-	if ($context['visual_verification'])
282
-		echo '
294
+	if ($context['visual_verification']) {
295
+			echo '
283 296
 			<div class="title_bar title_top">
284 297
 				<h3 class="titlebg">', $txt['verification'], '</h3>
285 298
 			</div>
@@ -288,19 +301,21 @@  discard block
 block discarded – undo
288 301
 					', template_control_verification($context['visual_verification_id'], 'all'), '
289 302
 				</fieldset>
290 303
 			</div>';
304
+	}
291 305
 
292 306
 	echo '
293 307
 			<div id="confirm_buttons" class="flow_auto">';
294 308
 
295 309
 	// Age restriction in effect?
296
-	if (!$context['require_agreement'] && $context['show_coppa'])
297
-		echo '
310
+	if (!$context['require_agreement'] && $context['show_coppa']) {
311
+			echo '
298 312
 				<input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button"><br>
299 313
 				<br>
300 314
 				<input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button">';
301
-	else
302
-		echo '
315
+	} else {
316
+			echo '
303 317
 				<input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button">';
318
+	}
304 319
 
305 320
 	echo '
306 321
 			</div>
@@ -362,25 +377,28 @@  discard block
 block discarded – undo
362 377
 				<p>', $context['coppa']['many_options'] ? $txt['coppa_send_to_two_options'] : $txt['coppa_send_to_one_option'], '</p>';
363 378
 
364 379
 	// Can they send by post?
365
-	if (!empty($context['coppa']['post']))
366
-		echo '
380
+	if (!empty($context['coppa']['post'])) {
381
+			echo '
367 382
 				<h4>1) ', $txt['coppa_send_by_post'], '</h4>
368 383
 				<div class="coppa_contact">
369 384
 					', $context['coppa']['post'], '
370 385
 				</div>';
386
+	}
371 387
 
372 388
 	// Can they send by fax??
373
-	if (!empty($context['coppa']['fax']))
374
-		echo '
389
+	if (!empty($context['coppa']['fax'])) {
390
+			echo '
375 391
 				<h4>', !empty($context['coppa']['post']) ? '2' : '1', ') ', $txt['coppa_send_by_fax'], '</h4>
376 392
 				<div class="coppa_contact">
377 393
 					', $context['coppa']['fax'], '
378 394
 				</div>';
395
+	}
379 396
 
380 397
 	// Offer an alternative Phone Number?
381
-	if ($context['coppa']['phone'])
382
-		echo '
398
+	if ($context['coppa']['phone']) {
399
+			echo '
383 400
 				<p>', $context['coppa']['phone'], '</p>';
401
+	}
384 402
 
385 403
 	echo '
386 404
 			</div><!-- #coppa -->';
@@ -445,19 +463,20 @@  discard block
 block discarded – undo
445 463
 	<body style="margin: 1ex;">
446 464
 		<div class="windowbg description" style="text-align: center;">';
447 465
 
448
-	if (isBrowser('is_ie') || isBrowser('is_ie11'))
449
-		echo '
466
+	if (isBrowser('is_ie') || isBrowser('is_ie11')) {
467
+			echo '
450 468
 			<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="audio/x-wav">
451 469
 				<param name="AutoStart" value="1">
452 470
 				<param name="FileName" value="', $context['verification_sound_href'], '">
453 471
 			</object>';
454
-	else
455
-		echo '
472
+	} else {
473
+			echo '
456 474
 			<audio src="', $context['verification_sound_href'], '" controls>
457 475
 				<object type="audio/x-wav" data="', $context['verification_sound_href'], '">
458 476
 					<a href="', $context['verification_sound_href'], '" rel="nofollow">', $context['verification_sound_href'], '</a>
459 477
 				</object>
460 478
 			</audio>';
479
+	}
461 480
 
462 481
 	echo '
463 482
 			<br>
@@ -485,11 +504,12 @@  discard block
 block discarded – undo
485 504
 				</div>
486 505
 				<div id="register_screen" class="windowbg2 noup">';
487 506
 
488
-	if (!empty($context['registration_done']))
489
-		echo '
507
+	if (!empty($context['registration_done'])) {
508
+			echo '
490 509
 					<div class="infobox">
491 510
 						', $context['registration_done'], '
492 511
 					</div>';
512
+	}
493 513
 
494 514
 	echo '
495 515
 					<dl class="register_form" id="admin_register_form">
@@ -525,9 +545,10 @@  discard block
 block discarded – undo
525 545
 						<dd>
526 546
 							<select name="group" id="group_select" tabindex="', $context['tabindex']++, '">';
527 547
 
528
-		foreach ($context['member_groups'] as $id => $name)
529
-			echo '
548
+		foreach ($context['member_groups'] as $id => $name) {
549
+					echo '
530 550
 								<option value="', $id, '">', $name, '</option>';
551
+		}
531 552
 
532 553
 		echo '
533 554
 							</select>
@@ -535,8 +556,8 @@  discard block
 block discarded – undo
535 556
 	}
536 557
 
537 558
 	// If there is any field marked as required, show it here!
538
-	if (!empty($context['custom_fields_required']) && !empty($context['custom_fields']))
539
-		foreach ($context['custom_fields'] as $field)
559
+	if (!empty($context['custom_fields_required']) && !empty($context['custom_fields'])) {
560
+			foreach ($context['custom_fields'] as $field)
540 561
 			if ($field['show_reg'] > 1)
541 562
 				echo '
542 563
 						<dt>
@@ -546,6 +567,7 @@  discard block
 block discarded – undo
546 567
 						<dd>
547 568
 							', str_replace('name="', 'tabindex="' . $context['tabindex']++ . '" name="', $field['input_html']), '
548 569
 						</dd>';
570
+	}
549 571
 
550 572
 	echo '
551 573
 						<dt>
@@ -582,13 +604,13 @@  discard block
 block discarded – undo
582 604
 {
583 605
 	global $context, $scripturl, $txt;
584 606
 
585
-	if (!empty($context['saved_successful']))
586
-		echo '
607
+	if (!empty($context['saved_successful'])) {
608
+			echo '
587 609
 		<div class="infobox">', $txt['settings_saved'], '</div>';
588
-
589
-	elseif (!empty($context['could_not_save']))
590
-		echo '
610
+	} elseif (!empty($context['could_not_save'])) {
611
+			echo '
591 612
 		<div class="errorbox">', $txt['admin_agreement_not_saved'], '</div>';
613
+	}
592 614
 
593 615
 	// Just a big box to edit the text file ;)
594 616
 	echo '
@@ -598,9 +620,10 @@  discard block
 block discarded – undo
598 620
 			</div>';
599 621
 
600 622
 	// Warning for if the file isn't writable.
601
-	if (!empty($context['warning']))
602
-		echo '
623
+	if (!empty($context['warning'])) {
624
+			echo '
603 625
 			<p class="error">', $context['warning'], '</p>';
626
+	}
604 627
 
605 628
 	echo '
606 629
 			<div class="windowbg2 noup" id="registration_agreement">';
@@ -617,9 +640,10 @@  discard block
 block discarded – undo
617 640
 						<strong>', $txt['admin_agreement_select_language'], ':</strong>
618 641
 						<select name="agree_lang" onchange="document.getElementById(\'change_reg\').submit();" tabindex="', $context['tabindex']++, '">';
619 642
 
620
-		foreach ($context['editable_agreements'] as $file => $name)
621
-			echo '
643
+		foreach ($context['editable_agreements'] as $file => $name) {
644
+					echo '
622 645
 							<option value="', $file, '"', $context['current_agreement'] == $file ? ' selected' : '', '>', $name, '</option>';
646
+		}
623 647
 
624 648
 		echo '
625 649
 						</select>
@@ -659,9 +683,10 @@  discard block
 block discarded – undo
659 683
 {
660 684
 	global $context, $scripturl, $txt;
661 685
 
662
-	if (!empty($context['saved_successful']))
663
-		echo '
686
+	if (!empty($context['saved_successful'])) {
687
+			echo '
664 688
 	<div class="infobox">', $txt['settings_saved'], '</div>';
689
+	}
665 690
 
666 691
 	echo '
667 692
 	<form id="admin_form_wrapper" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">
Please login to merge, or discard this patch.
Themes/default/Search.template.php 1 patch
Braces   +90 added lines, -65 removed lines patch added patch discarded remove patch
@@ -20,17 +20,19 @@  discard block
 block discarded – undo
20 20
 	echo '
21 21
 	<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">';
22 22
 
23
-	if (!empty($context['search_errors']))
24
-		echo '
23
+	if (!empty($context['search_errors'])) {
24
+			echo '
25 25
 		<div class="errorbox">
26 26
 			', implode('<br>', $context['search_errors']['messages']), '
27 27
 		</div>';
28
+	}
28 29
 
29
-	if (!empty($context['search_ignored']))
30
-		echo '
30
+	if (!empty($context['search_ignored'])) {
31
+			echo '
31 32
 		<div class="noticebox">
32 33
 			', $txt['search_warning_ignored_word' . (count($context['search_ignored']) == 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '
33 34
 		</div>';
35
+	}
34 36
 
35 37
 	echo '
36 38
 		<div class="cat_bar">
@@ -48,9 +50,10 @@  discard block
 block discarded – undo
48 50
 				<dd>
49 51
 					<input type="search" name="search" id="searchfor" ', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40">';
50 52
 
51
-	if (empty($modSettings['search_simple_fulltext']))
52
-		echo '
53
+	if (empty($modSettings['search_simple_fulltext'])) {
54
+			echo '
53 55
 					<br><em class="smalltext">', $txt['search_example'], '</em>';
56
+	}
54 57
 
55 58
 	echo '
56 59
 				</dd>
@@ -114,21 +117,23 @@  discard block
 block discarded – undo
114 117
 			<input type="hidden" name="advanced" value="1">';
115 118
 
116 119
 	// Require an image to be typed to save spamming?
117
-	if ($context['require_verification'])
118
-		echo '
120
+	if ($context['require_verification']) {
121
+			echo '
119 122
 			<p>
120 123
 				<strong>', $txt['verification'], ':</strong>
121 124
 				', template_control_verification($context['visual_verification_id'], 'all'), '
122 125
 			</p>';
126
+	}
123 127
 
124 128
 	// If $context['search_params']['topic'] is set, that means we're searching just one topic.
125
-	if (!empty($context['search_params']['topic']))
126
-		echo '
129
+	if (!empty($context['search_params']['topic'])) {
130
+			echo '
127 131
 			<p>
128 132
 				', $txt['search_specific_topic'], ' &quot;', $context['search_topic']['link'], '&quot;.
129 133
 			</p>
130 134
 			<input type="hidden" name="topic" value="', $context['search_topic']['id'], '">
131 135
 			<input type="submit" name="b_search" value="', $txt['search'], '" class="button">';
136
+	}
132 137
 
133 138
 	echo '
134 139
 		</div>';
@@ -158,14 +163,15 @@  discard block
 block discarded – undo
158 163
 
159 164
 			foreach ($category['boards'] as $board)
160 165
 			{
161
-				if ($i == $limit)
162
-					echo '
166
+				if ($i == $limit) {
167
+									echo '
163 168
 							</ul>
164 169
 						</li>
165 170
 					</ul>
166 171
 					<ul class="ignoreboards floatright">
167 172
 						<li class="category">
168 173
 							<ul>';
174
+				}
169 175
 
170 176
 				echo '
171 177
 								<li class="board">
@@ -253,17 +259,19 @@  discard block
 block discarded – undo
253 259
 		<div class="roundframe noup">';
254 260
 
255 261
 		// Did they make any typos or mistakes, perhaps?
256
-		if (isset($context['did_you_mean']))
257
-			echo '
262
+		if (isset($context['did_you_mean'])) {
263
+					echo '
258 264
 			<p>
259 265
 				', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.
260 266
 			</p>';
267
+		}
261 268
 
262
-		if (!empty($context['search_ignored']))
263
-			echo '
269
+		if (!empty($context['search_ignored'])) {
270
+					echo '
264 271
 			<p>
265 272
 				', $txt['search_warning_ignored_word' . (count($context['search_ignored']) == 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '
266 273
 			</p>';
274
+		}
267 275
 
268 276
 		echo '
269 277
 			<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -286,10 +294,11 @@  discard block
 block discarded – undo
286 294
 					<input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '">
287 295
 				</div>';
288 296
 
289
-		if (!empty($context['search_params']['brd']))
290
-			foreach ($context['search_params']['brd'] as $board_id)
297
+		if (!empty($context['search_params']['brd'])) {
298
+					foreach ($context['search_params']['brd'] as $board_id)
291 299
 				echo '
292 300
 				<input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '">';
301
+		}
293 302
 
294 303
 		echo '
295 304
 			</form>
@@ -300,18 +309,20 @@  discard block
 block discarded – undo
300 309
 	if ($context['compact'])
301 310
 	{
302 311
 		// Quick moderation set to checkboxes? Oh, how fun :/
303
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
304
-			echo '
312
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
313
+					echo '
305 314
 	<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="topicForm">';
315
+		}
306 316
 
307 317
 		echo '
308 318
 		<div class="cat_bar">
309 319
 			<h3 class="catbg">
310 320
 				<span class="floatright">';
311 321
 
312
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
313
-			echo '
322
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
323
+					echo '
314 324
 					<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">';
325
+		}
315 326
 		echo '
316 327
 				</span>
317 328
 				<span class="generic_icons filter"></span> ', $txt['mlist_search_results'], ': ', $context['search_params']['search'], '
@@ -319,15 +330,15 @@  discard block
 block discarded – undo
319 330
 		</div>';
320 331
 
321 332
 		// Was anything even found?
322
-		if (!empty($context['topics']))
323
-			echo '
333
+		if (!empty($context['topics'])) {
334
+					echo '
324 335
 		<div class="pagesection">
325 336
 			<span>', $context['page_index'], '</span>
326 337
 		</div>';
327
-
328
-		else
329
-			echo '
338
+		} else {
339
+					echo '
330 340
 		<div class="roundframe noup">', $txt['find_no_results'], '</div>';
341
+		}
331 342
 
332 343
 		// While we have results to show ...
333 344
 		while ($topic = $context['get_topics']())
@@ -350,31 +361,35 @@  discard block
 block discarded – undo
350 361
 					echo '
351 362
 				<span class="floatright">';
352 363
 
353
-					if ($options['display_quick_mod'] == 1)
354
-						echo '
364
+					if ($options['display_quick_mod'] == 1) {
365
+											echo '
355 366
 					<input type="checkbox" name="topics[]" value="', $topic['id'], '">';
356
-
357
-					else
367
+					} else
358 368
 					{
359
-						if ($topic['quick_mod']['remove'])
360
-							echo '
369
+						if ($topic['quick_mod']['remove']) {
370
+													echo '
361 371
 					<a href="', $scripturl, '?action=quickmod;board=' . $topic['board']['id'] . '.0;actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
372
+						}
362 373
 
363
-						if ($topic['quick_mod']['lock'])
364
-							echo '
374
+						if ($topic['quick_mod']['lock']) {
375
+													echo '
365 376
 					<a href="', $scripturl, '?action=quickmod;board=' . $topic['board']['id'] . '.0;actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
377
+						}
366 378
 
367
-						if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
368
-							echo '
379
+						if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) {
380
+													echo '
369 381
 					<br>';
382
+						}
370 383
 
371
-						if ($topic['quick_mod']['sticky'])
372
-							echo '
384
+						if ($topic['quick_mod']['sticky']) {
385
+													echo '
373 386
 					<a href="', $scripturl, '?action=quickmod;board=' . $topic['board']['id'] . '.0;actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
387
+						}
374 388
 
375
-						if ($topic['quick_mod']['move'])
376
-							echo '
389
+						if ($topic['quick_mod']['move']) {
390
+													echo '
377 391
 					<a href="', $scripturl, '?action=movetopic;topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
392
+						}
378 393
 					}
379 394
 
380 395
 					echo '
@@ -384,20 +399,22 @@  discard block
 block discarded – undo
384 399
 			echo '
385 400
 			</div><!-- .block -->';
386 401
 
387
-				if ($message['body_highlighted'] != '')
388
-					echo '
402
+				if ($message['body_highlighted'] != '') {
403
+									echo '
389 404
 				<div class="list_posts double_height">', $message['body_highlighted'], '</div>';
405
+				}
390 406
 			}
391 407
 
392 408
 			echo '
393 409
 		</div><!-- $topic[css_class] -->';
394 410
 
395 411
 		}
396
-		if (!empty($context['topics']))
397
-			echo '
412
+		if (!empty($context['topics'])) {
413
+					echo '
398 414
 		<div class="pagesection">
399 415
 			<span>', $context['page_index'], '</span>
400 416
 		</div>';
417
+		}
401 418
 
402 419
 		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
403 420
 		{
@@ -406,17 +423,19 @@  discard block
 block discarded – undo
406 423
 			<select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
407 424
 				<option value="">--------</option>';
408 425
 
409
-			foreach ($context['qmod_actions'] as $qmod_action)
410
-				if ($context['can_' . $qmod_action])
426
+			foreach ($context['qmod_actions'] as $qmod_action) {
427
+							if ($context['can_' . $qmod_action])
411 428
 					echo '
412 429
 				<option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
430
+			}
413 431
 
414 432
 			echo '
415 433
 			</select>';
416 434
 
417
-			if ($context['can_move'])
418
-				echo '
435
+			if ($context['can_move']) {
436
+							echo '
419 437
 			<span id="quick_mod_jump_to"></span>';
438
+			}
420 439
 
421 440
 			echo '
422 441
 			<input type="hidden" name="redirect_url" value="', $scripturl . '?action=search2;params=' . $context['params'], '">
@@ -425,13 +444,13 @@  discard block
 block discarded – undo
425 444
 		}
426 445
 
427 446
 
428
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
429
-			echo '
447
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics'])) {
448
+					echo '
430 449
 		<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
431 450
 	</form>';
451
+		}
432 452
 
433
-	}
434
-	else
453
+	} else
435 454
 	{
436 455
 		echo '
437 456
 	<div class="cat_bar">
@@ -443,9 +462,10 @@  discard block
 block discarded – undo
443 462
 		<span>', $context['page_index'], '</span>
444 463
 	</div>';
445 464
 
446
-		if (empty($context['topics']))
447
-			echo '
465
+		if (empty($context['topics'])) {
466
+					echo '
448 467
 	<div class="information">(', $txt['search_no_results'], ')</div>';
468
+		}
449 469
 
450 470
 		while ($topic = $context['get_topics']())
451 471
 		{
@@ -462,23 +482,27 @@  discard block
 block discarded – undo
462 482
 		</div>
463 483
 		<div class="list_posts">', $message['body_highlighted'], '</div>';
464 484
 
465
-			if ($topic['can_reply'])
466
-				echo '
485
+			if ($topic['can_reply']) {
486
+							echo '
467 487
 		<ul class="quickbuttons">';
488
+			}
468 489
 
469 490
 			// If they *can* reply?
470
-			if ($topic['can_reply'])
471
-				echo '
491
+			if ($topic['can_reply']) {
492
+							echo '
472 493
 			<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
494
+			}
473 495
 
474 496
 			// If they *can* quote?
475
-			if ($topic['can_quote'])
476
-				echo '
497
+			if ($topic['can_quote']) {
498
+							echo '
477 499
 			<li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'] . ';quote=' . $message['id'] . '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
500
+			}
478 501
 
479
-			if ($topic['can_reply'])
480
-				echo '
502
+			if ($topic['can_reply']) {
503
+							echo '
481 504
 		</ul>';
505
+			}
482 506
 			echo '
483 507
 		<br class="clear">
484 508
 	</div><!-- $topic[css_class] -->';
@@ -497,8 +521,8 @@  discard block
 block discarded – undo
497 521
 	<div class="smalltext righttext" id="search_jump_to"></div>
498 522
 	<script>';
499 523
 
500
-	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move'])
501
-		echo '
524
+	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) {
525
+			echo '
502 526
 		if (typeof(window.XMLHttpRequest) != "undefined")
503 527
 			aJumpTo[aJumpTo.length] = new JumpTo({
504 528
 				sContainerId: "quick_mod_jump_to",
@@ -513,6 +537,7 @@  discard block
 block discarded – undo
513 537
 				bDisabled: true,
514 538
 				sCustomName: "move_to"
515 539
 			});';
540
+	}
516 541
 
517 542
 	echo '
518 543
 		if (typeof(window.XMLHttpRequest) != "undefined")
Please login to merge, or discard this patch.
Themes/default/ModerationCenter.template.php 1 patch
Braces   +59 added lines, -41 removed lines patch added patch discarded remove patch
@@ -54,18 +54,20 @@  discard block
 block discarded – undo
54 54
 		<div class="windowbg2 noup" id="group_requests_panel">
55 55
 			<ul>';
56 56
 
57
-	foreach ($context['group_requests'] as $request)
58
-		echo '
57
+	foreach ($context['group_requests'] as $request) {
58
+			echo '
59 59
 				<li class="smalltext">
60 60
 					<a href="', $request['request_href'], '">', $request['group']['name'], '</a> ', $txt['mc_groupr_by'], ' ', $request['member']['link'], '
61 61
 				</li>';
62
+	}
62 63
 
63 64
 	// Don't have any watched users right now?
64
-	if (empty($context['group_requests']))
65
-		echo '
65
+	if (empty($context['group_requests'])) {
66
+			echo '
66 67
 				<li>
67 68
 					<strong class="smalltext">', $txt['mc_group_requests_none'], '</strong>
68 69
 				</li>';
70
+	}
69 71
 
70 72
 	echo '
71 73
 			</ul>
@@ -121,18 +123,20 @@  discard block
 block discarded – undo
121 123
 		<div class="windowbg2 noup" id="watched_users_panel">
122 124
 			<ul>';
123 125
 
124
-	foreach ($context['watched_users'] as $user)
125
-		echo '
126
+	foreach ($context['watched_users'] as $user) {
127
+			echo '
126 128
 				<li>
127 129
 					<span class="smalltext">', sprintf(!empty($user['last_login']) ? $txt['mc_seen'] : $txt['mc_seen_never'], $user['link'], $user['last_login']), '</span>
128 130
 				</li>';
131
+	}
129 132
 
130 133
 	// Don't have any watched users right now?
131
-	if (empty($context['watched_users']))
132
-		echo '
134
+	if (empty($context['watched_users'])) {
135
+			echo '
133 136
 				<li>
134 137
 					<strong class="smalltext">', $txt['mc_watched_users_none'], '</strong>
135 138
 				</li>';
139
+	}
136 140
 
137 141
 	echo '
138 142
 			</ul>
@@ -188,18 +192,20 @@  discard block
 block discarded – undo
188 192
 		<div class="windowbg2 noup" id="reported_posts_panel">
189 193
 			<ul>';
190 194
 
191
-	foreach ($context['reported_posts'] as $post)
192
-		echo '
195
+	foreach ($context['reported_posts'] as $post) {
196
+			echo '
193 197
 				<li>
194 198
 					<span class="smalltext">', sprintf($txt['mc_post_report'], $post['report_link'], $post['author']['link']), '</span>
195 199
 				</li>';
200
+	}
196 201
 
197 202
 	// Don't have any watched users right now?
198
-	if (empty($context['reported_posts']))
199
-		echo '
203
+	if (empty($context['reported_posts'])) {
204
+			echo '
200 205
 				<li>
201 206
 					<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
202 207
 				</li>';
208
+	}
203 209
 
204 210
 	echo '
205 211
 			</ul>
@@ -255,18 +261,20 @@  discard block
 block discarded – undo
255 261
 		<div class="windowbg2 noup" id="reported_users_panel">
256 262
 			<ul>';
257 263
 
258
-	foreach ($context['reported_users'] as $user)
259
-		echo '
264
+	foreach ($context['reported_users'] as $user) {
265
+			echo '
260 266
 				<li>
261 267
 					<span class="smalltext">', $user['user']['link'], '</span>
262 268
 				</li>';
269
+	}
263 270
 
264 271
 	// Don't have any watched users right now?
265
-	if (empty($context['reported_users']))
266
-		echo '
272
+	if (empty($context['reported_users'])) {
273
+			echo '
267 274
 				<li>
268 275
 					<strong class="smalltext">', $txt['mc_reported_users_none'], '</strong>
269 276
 				</li>';
277
+	}
270 278
 
271 279
 	echo '
272 280
 			</ul>
@@ -313,11 +321,12 @@  discard block
 block discarded – undo
313 321
 	global $context, $txt, $scripturl;
314 322
 
315 323
 	// Let them know the action was a success.
316
-	if (!empty($context['report_post_action']))
317
-		echo '
324
+	if (!empty($context['report_post_action'])) {
325
+			echo '
318 326
 		<div class="infobox">
319 327
 			', $txt['report_action_' . $context['report_post_action']], '
320 328
 		</div>';
329
+	}
321 330
 
322 331
 	echo '
323 332
 		<div id="modnotes">
@@ -333,11 +342,12 @@  discard block
 block discarded – undo
333 342
 					<ul class="moderation_notes">';
334 343
 
335 344
 		// Cycle through the notes.
336
-		foreach ($context['notes'] as $note)
337
-			echo '
345
+		foreach ($context['notes'] as $note) {
346
+					echo '
338 347
 						<li class="smalltext">
339 348
 							', ($note['can_delete'] ? '<a href="' . $note['delete_href'] . ';' . $context['mod-modnote-del_token_var'] . '=' . $context['mod-modnote-del_token'] . '" data-confirm="' . $txt['mc_reportedp_delete_confirm'] . '" class="you_sure"><span class="generic_icons delete"></span></a>' : ''), $note['time'], ' <strong>', $note['author']['link'], ':</strong> ', $note['text'], '
340 349
 						</li>';
350
+		}
341 351
 
342 352
 		echo '
343 353
 					</ul>
@@ -378,18 +388,19 @@  discard block
 block discarded – undo
378 388
 	$remove_button = create_button('delete', 'remove_message', 'remove');
379 389
 
380 390
 	// No posts?
381
-	if (empty($context['unapproved_items']))
382
-		echo '
391
+	if (empty($context['unapproved_items'])) {
392
+			echo '
383 393
 			<div class="windowbg2">
384 394
 				<p class="centertext">
385 395
 					', $txt['mc_unapproved_' . $context['current_view'] . '_none_found'], '
386 396
 				</p>
387 397
 			</div>';
388
-	else
389
-		echo '
398
+	} else {
399
+			echo '
390 400
 			<div class="pagesection floatleft">
391 401
 				', $context['page_index'], '
392 402
 			</div>';
403
+	}
393 404
 
394 405
 	foreach ($context['unapproved_items'] as $item)
395 406
 	{
@@ -408,14 +419,16 @@  discard block
 block discarded – undo
408 419
 				<span class="floatright">
409 420
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';approve=', $item['id'], '">', $approve_button, '</a>';
410 421
 
411
-		if ($item['can_delete'])
412
-			echo '
422
+		if ($item['can_delete']) {
423
+					echo '
413 424
 					', $context['menu_separator'], '
414 425
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';delete=', $item['id'], '">', $remove_button, '</a>';
426
+		}
415 427
 
416
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
417
-			echo '
428
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
429
+					echo '
418 430
 					<input type="checkbox" name="item[]" value="', $item['id'], '" checked> ';
431
+		}
419 432
 
420 433
 		echo '
421 434
 				</span>
@@ -425,8 +438,8 @@  discard block
 block discarded – undo
425 438
 	echo '
426 439
 			<div class="pagesection">';
427 440
 
428
-	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
429
-		echo '
441
+	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
442
+			echo '
430 443
 				<div class="floatright">
431 444
 					<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
432 445
 						<option value="0">', $txt['with_selected'], ':</option>
@@ -438,12 +451,14 @@  discard block
 block discarded – undo
438 451
 						<input type="submit" name="mc_go" value="', $txt['go'], '" class="button">
439 452
 					</noscript>
440 453
 				</div>';
454
+	}
441 455
 
442
-	if (!empty($context['unapproved_items']))
443
-		echo '
456
+	if (!empty($context['unapproved_items'])) {
457
+			echo '
444 458
 				<div class="floatleft">
445 459
 					<div class="pagelinks">', $context['page_index'], '</div>
446 460
 				</div>';
461
+	}
447 462
 
448 463
 	echo '
449 464
 			</div><!-- .pagesection -->
@@ -464,8 +479,9 @@  discard block
 block discarded – undo
464 479
 
465 480
 	// We'll have a delete please bob.
466 481
 	// @todo Discuss this with the team and rewrite if required.
467
-	if (empty($delete_button))
468
-		$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
482
+	if (empty($delete_button)) {
483
+			$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
484
+	}
469 485
 
470 486
 	$output_html = '
471 487
 					<div>
@@ -474,10 +490,11 @@  discard block
 block discarded – undo
474 490
 						</div>
475 491
 						<div class="floatright">';
476 492
 
477
-	if ($post['can_delete'])
478
-		$output_html .= '
493
+	if ($post['can_delete']) {
494
+			$output_html .= '
479 495
 							<a href="' . $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['mc_watched_users_delete_post'] . '" class="you_sure">' . $delete_button . '</a>
480 496
 							<input type="checkbox" name="delete[]" value="' . $post['id'] . '">';
497
+	}
481 498
 
482 499
 	$output_html .= '
483 500
 						</div>
@@ -521,12 +538,12 @@  discard block
 block discarded – undo
521 538
 				<input type="submit" name="save" value="', $txt['save'], '" class="button">
522 539
 			</div>
523 540
 		</form>';
524
-	}
525
-	else
526
-		echo '
541
+	} else {
542
+			echo '
527 543
 		<div class="windowbg">
528 544
 			<div class="centertext">', $txt['mc_no_settings'], '</div>
529 545
 		</div>';
546
+	}
530 547
 
531 548
 	echo '
532 549
 	</div><!-- #modcenter -->';
@@ -622,13 +639,14 @@  discard block
 block discarded – undo
622 639
 					</dd>
623 640
 				</dl>';
624 641
 
625
-	if ($context['template_data']['can_edit_personal'])
626
-		echo '
642
+	if ($context['template_data']['can_edit_personal']) {
643
+			echo '
627 644
 				<input type="checkbox" name="make_personal" id="make_personal"', $context['template_data']['personal'] ? ' checked' : '', '>
628 645
 					<label for="make_personal">
629 646
 						<strong>', $txt['mc_warning_template_personal'], '</strong>
630 647
 					</label>
631 648
 					<p class="smalltext">', $txt['mc_warning_template_personal_desc'], '</p>';
649
+	}
632 650
 
633 651
 	echo '
634 652
 				<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button">
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 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
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +34 added lines, -23 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -63,23 +66,26 @@  discard block
 block discarded – undo
63 66
 		if (!empty($modSettings['databaseSession_enable']))
64 67
 		{
65 68
 			@ini_set('session.serialize_handler', 'php_serialize');
66
-			if (ini_get('session.serialize_handler') != 'php_serialize')
67
-				@ini_set('session.serialize_handler', 'php');
69
+			if (ini_get('session.serialize_handler') != 'php_serialize') {
70
+							@ini_set('session.serialize_handler', 'php');
71
+			}
68 72
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
69 73
 			@ini_set('session.gc_probability', '1');
74
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
75
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
70 76
 		}
71
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
72
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
73 77
 
74 78
 		// Use cache setting sessions?
75
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
76
-			call_integration_hook('integrate_session_handlers');
79
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
80
+					call_integration_hook('integrate_session_handlers');
81
+		}
77 82
 
78 83
 		session_start();
79 84
 
80 85
 		// Change it so the cache settings are a little looser than default.
81
-		if (!empty($modSettings['databaseSession_loose']))
82
-			header('Cache-Control: private');
86
+		if (!empty($modSettings['databaseSession_loose'])) {
87
+					header('Cache-Control: private');
88
+		}
83 89
 	}
84 90
 
85 91
 	// Set the randomly generated code.
@@ -125,8 +131,9 @@  discard block
 block discarded – undo
125 131
 {
126 132
 	global $smcFunc;
127 133
 
128
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
129
-		return '';
134
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
135
+			return '';
136
+	}
130 137
 
131 138
 	// Look for it in the database.
132 139
 	$result = $smcFunc['db_query']('', '
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 {
156 163
 	global $smcFunc;
157 164
 
158
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
159
-		return false;
165
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
166
+			return false;
167
+	}
160 168
 
161 169
 	// First try to update an existing row...
162 170
 	$smcFunc['db_query']('', '
@@ -171,13 +179,14 @@  discard block
 block discarded – undo
171 179
 	);
172 180
 
173 181
 	// If that didn't work, try inserting a new one.
174
-	if ($smcFunc['db_affected_rows']() == 0)
175
-		$smcFunc['db_insert']('ignore',
182
+	if ($smcFunc['db_affected_rows']() == 0) {
183
+			$smcFunc['db_insert']('ignore',
176 184
 			'{db_prefix}sessions',
177 185
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
178 186
 			array($session_id, $data, time()),
179 187
 			array('session_id')
180 188
 		);
189
+	}
181 190
 
182 191
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
183 192
 }
@@ -192,8 +201,9 @@  discard block
 block discarded – undo
192 201
 {
193 202
 	global $smcFunc;
194 203
 
195
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
196
-		return false;
204
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
205
+			return false;
206
+	}
197 207
 
198 208
 	// Just delete the row...
199 209
 	$smcFunc['db_query']('', '
@@ -219,8 +229,9 @@  discard block
 block discarded – undo
219 229
 	global $modSettings, $smcFunc;
220 230
 
221 231
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
222
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
223
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
232
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
233
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
234
+	}
224 235
 
225 236
 	// Clean up after yerself ;).
226 237
 	$smcFunc['db_query']('', '
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
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 
256 256
 		case 'datetime':
257 257
 			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)
258
-				return 'str_to_date('.
259
-					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]).
258
+				return 'str_to_date(' .
259
+					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]) .
260 260
 					',\'%Y-%m-%d %h:%i:%s\')';
261 261
 			else
262 262
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		$old_pos = 0;
461 461
 		$pos = -1;
462 462
 		// Remove the string escape for better runtime
463
-		$db_string_1 = str_replace('\\\'','',$db_string);
463
+		$db_string_1 = str_replace('\\\'', '', $db_string);
464 464
 		while (true)
465 465
 		{
466 466
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 	{
843 843
 		$count = count($insertRows);
844 844
 		$ai = 0;
845
-		for($i = 0; $i < $count; $i++)
845
+		for ($i = 0; $i < $count; $i++)
846 846
 		{
847 847
 			$old_id = $smcFunc['db_insert_id']();
848 848
 			
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 				$count2 = count($indexed_columns);
869 869
 				for ($x = 0; $x < $count2; $x++)
870 870
 				{
871
-					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
871
+					$where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x];
872 872
 					if (($x + 1) < $count2)
873 873
 						$where_string += ' AND ';
874 874
 				}
875 875
 
876
-				$request = $smcFunc['db_query']('','
877
-					SELECT `'. $keys[0] . '` FROM ' . $table .'
876
+				$request = $smcFunc['db_query']('', '
877
+					SELECT `'. $keys[0] . '` FROM ' . $table . '
878 878
 					WHERE ' . $where_string . ' LIMIT 1',
879 879
 					array()
880 880
 				);
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 			$return_var = array();
904 904
 			$count = count($insertRows);
905 905
 			$start = smf_db_insert_id($table, $keys[0]);
906
-			for ($i = 0; $i < $count; $i++ )
906
+			for ($i = 0; $i < $count; $i++)
907 907
 				$return_var[] = $start + $i;
908 908
 		}
909 909
 		return $return_var;
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', 
1037 1037
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1038 1038
 		$error_array[7], $error_array[8]);
1039
-	mysqli_stmt_execute ($mysql_error_data_prep);
1039
+	mysqli_stmt_execute($mysql_error_data_prep);
1040 1040
 }
1041 1041
 
1042 1042
 /**
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
  */
1051 1051
 function smf_db_custom_order($field, $array_values, $desc = false)
1052 1052
 {
1053
-	$return = 'CASE '. $field . ' ';
1053
+	$return = 'CASE ' . $field . ' ';
1054 1054
 	$count = count($array_values);
1055 1055
 	$then = ($desc ? ' THEN -' : ' THEN ');
1056 1056
 
Please login to merge, or discard this patch.
Braces   +277 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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',
@@ -63,9 +64,11 @@  discard block
 block discarded – undo
63 64
 			'db_error_insert'			=> 'smf_db_error_insert',
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 		);
67
+	}
66 68
 
67
-	if (!empty($db_options['persist']))
68
-		$db_server = 'p:' . $db_server;
69
+	if (!empty($db_options['persist'])) {
70
+			$db_server = 'p:' . $db_server;
71
+	}
69 72
 
70 73
 	$connection = mysqli_init();
71 74
 
@@ -74,24 +77,27 @@  discard block
 block discarded – undo
74 77
 	$success = false;
75 78
 
76 79
 	if ($connection) {
77
-		if (!empty($db_options['port']))
78
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
-		else
80
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
80
+		if (!empty($db_options['port'])) {
81
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
82
+		} else {
83
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
84
+		}
81 85
 	}
82 86
 
83 87
 	// Something's wrong, show an error if its fatal (which we assume it is)
84 88
 	if ($success === false)
85 89
 	{
86
-		if (!empty($db_options['non_fatal']))
87
-			return null;
88
-		else
89
-			display_db_error();
90
+		if (!empty($db_options['non_fatal'])) {
91
+					return null;
92
+		} else {
93
+					display_db_error();
94
+		}
90 95
 	}
91 96
 
92 97
 	// Select the database, unless told not to
93
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
94
-		display_db_error();
98
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
99
+			display_db_error();
100
+	}
95 101
 
96 102
 	$smcFunc['db_query']('', '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\'',
97 103
 		array(),
@@ -167,34 +173,42 @@  discard block
 block discarded – undo
167 173
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
168 174
 
169 175
 	list ($values, $connection) = $db_callback;
170
-	if (!is_object($connection))
171
-		display_db_error();
176
+	if (!is_object($connection)) {
177
+			display_db_error();
178
+	}
172 179
 
173
-	if ($matches[1] === 'db_prefix')
174
-		return $db_prefix;
180
+	if ($matches[1] === 'db_prefix') {
181
+			return $db_prefix;
182
+	}
175 183
 
176
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
177
-		return $user_info[$matches[1]];
184
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
185
+			return $user_info[$matches[1]];
186
+	}
178 187
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
188
+	if ($matches[1] === 'empty') {
189
+			return '\'\'';
190
+	}
181 191
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
192
+	if (!isset($matches[2])) {
193
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	}
184 195
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
196
+	if ($matches[1] === 'literal') {
197
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	}
187 199
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
200
+	if (!isset($values[$matches[2]])) {
201
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	}
190 203
 
191 204
 	$replacement = $values[$matches[2]];
192 205
 
193 206
 	switch ($matches[1])
194 207
 	{
195 208
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
209
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			}
198 212
 			return (string) (int) $replacement;
199 213
 		break;
200 214
 
@@ -206,65 +220,73 @@  discard block
 block discarded – undo
206 220
 		case 'array_int':
207 221
 			if (is_array($replacement))
208 222
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+				if (empty($replacement)) {
224
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				}
211 226
 
212 227
 				foreach ($replacement as $key => $value)
213 228
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
230
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					}
216 232
 
217 233
 					$replacement[$key] = (string) (int) $value;
218 234
 				}
219 235
 
220 236
 				return implode(', ', $replacement);
237
+			} else {
238
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 239
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 240
 
225 241
 		break;
226 242
 
227 243
 		case 'array_string':
228 244
 			if (is_array($replacement))
229 245
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
246
+				if (empty($replacement)) {
247
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				}
232 249
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
250
+				foreach ($replacement as $key => $value) {
251
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				}
235 253
 
236 254
 				return implode(', ', $replacement);
255
+			} else {
256
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 257
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 258
 		break;
241 259
 
242 260
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
262
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
263
+			} else {
264
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			}
247 266
 		break;
248 267
 
249 268
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
270
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			}
254 274
 		break;
255 275
 
256 276
 		case 'datetime':
257
-			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)
258
-				return 'str_to_date('.
277
+			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) {
278
+							return 'str_to_date('.
259 279
 					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]).
260 280
 					',\'%Y-%m-%d %h:%i:%s\')';
261
-			else
262
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			} else {
282
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+			}
263 284
 		break;
264 285
 
265 286
 		case 'float':
266
-			if (!is_numeric($replacement))
267
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			if (!is_numeric($replacement)) {
288
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
289
+			}
268 290
 			return (string) (float) $replacement;
269 291
 		break;
270 292
 
@@ -278,32 +300,37 @@  discard block
 block discarded – undo
278 300
 		break;
279 301
 
280 302
 		case 'inet':
281
-			if ($replacement == 'null' || $replacement == '')
282
-				return 'null';
283
-			if (!isValidIP($replacement))
284
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
303
+			if ($replacement == 'null' || $replacement == '') {
304
+							return 'null';
305
+			}
306
+			if (!isValidIP($replacement)) {
307
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
308
+			}
285 309
 			//we don't use the native support of mysql > 5.6.2
286 310
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
287 311
 
288 312
 		case 'array_inet':
289 313
 			if (is_array($replacement))
290 314
 			{
291
-				if (empty($replacement))
292
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
315
+				if (empty($replacement)) {
316
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
317
+				}
293 318
 
294 319
 				foreach ($replacement as $key => $value)
295 320
 				{
296
-					if ($replacement == 'null' || $replacement == '')
297
-						$replacement[$key] = 'null';
298
-					if (!isValidIP($value))
299
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
321
+					if ($replacement == 'null' || $replacement == '') {
322
+											$replacement[$key] = 'null';
323
+					}
324
+					if (!isValidIP($value)) {
325
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
326
+					}
300 327
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
301 328
 				}
302 329
 
303 330
 				return implode(', ', $replacement);
331
+			} else {
332
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 333
 			}
305
-			else
306
-				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 334
 		break;
308 335
 
309 336
 		default:
@@ -379,22 +406,25 @@  discard block
 block discarded – undo
379 406
 		// Are we in SSI mode?  If so try that username and password first
380 407
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
381 408
 		{
382
-			if (empty($db_persist))
383
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
384
-			else
385
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
409
+			if (empty($db_persist)) {
410
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
411
+			} else {
412
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
413
+			}
386 414
 		}
387 415
 		// Fall back to the regular username and password if need be
388 416
 		if (!$db_connection)
389 417
 		{
390
-			if (empty($db_persist))
391
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
392
-			else
393
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
418
+			if (empty($db_persist)) {
419
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
420
+			} else {
421
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
422
+			}
394 423
 		}
395 424
 
396
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
397
-			$db_connection = false;
425
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
426
+					$db_connection = false;
427
+		}
398 428
 
399 429
 		$connection = $db_connection;
400 430
 	}
@@ -402,18 +432,20 @@  discard block
 block discarded – undo
402 432
 	// One more query....
403 433
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
404 434
 
405
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
406
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
435
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
436
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
437
+	}
407 438
 
408 439
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
409 440
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
410 441
 	{
411 442
 		// Add before LIMIT
412
-		if ($pos = strpos($db_string, 'LIMIT '))
413
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
414
-		else
415
-			// Append it.
443
+		if ($pos = strpos($db_string, 'LIMIT ')) {
444
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
445
+		} else {
446
+					// Append it.
416 447
 			$db_string .= "\n\t\t\tORDER BY null";
448
+		}
417 449
 	}
418 450
 
419 451
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -435,8 +467,9 @@  discard block
 block discarded – undo
435 467
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
436 468
 
437 469
 		// Initialize $db_cache if not already initialized.
438
-		if (!isset($db_cache))
439
-			$db_cache = array();
470
+		if (!isset($db_cache)) {
471
+					$db_cache = array();
472
+		}
440 473
 
441 474
 		if (!empty($_SESSION['debug_redirect']))
442 475
 		{
@@ -464,17 +497,18 @@  discard block
 block discarded – undo
464 497
 		while (true)
465 498
 		{
466 499
 			$pos = strpos($db_string_1, '\'', $pos + 1);
467
-			if ($pos === false)
468
-				break;
500
+			if ($pos === false) {
501
+							break;
502
+			}
469 503
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
470 504
 
471 505
 			while (true)
472 506
 			{
473 507
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
474 508
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
475
-				if ($pos1 === false)
476
-					break;
477
-				elseif ($pos2 === false || $pos2 > $pos1)
509
+				if ($pos1 === false) {
510
+									break;
511
+				} elseif ($pos2 === false || $pos2 > $pos1)
478 512
 				{
479 513
 					$pos = $pos1;
480 514
 					break;
@@ -490,29 +524,35 @@  discard block
 block discarded – undo
490 524
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
491 525
 
492 526
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
493
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
494
-			$fail = true;
527
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
528
+					$fail = true;
529
+		}
495 530
 		// Trying to change passwords, slow us down, or something?
496
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
497
-			$fail = true;
498
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
499
-			$fail = true;
531
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
532
+					$fail = true;
533
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
534
+					$fail = true;
535
+		}
500 536
 
501
-		if (!empty($fail) && function_exists('log_error'))
502
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
537
+		if (!empty($fail) && function_exists('log_error')) {
538
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
539
+		}
503 540
 	}
504 541
 
505
-	if (empty($db_unbuffered))
506
-		$ret = @mysqli_query($connection, $db_string);
507
-	else
508
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
542
+	if (empty($db_unbuffered)) {
543
+			$ret = @mysqli_query($connection, $db_string);
544
+	} else {
545
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
546
+	}
509 547
 
510
-	if ($ret === false && empty($db_values['db_error_skip']))
511
-		$ret = smf_db_error($db_string, $connection);
548
+	if ($ret === false && empty($db_values['db_error_skip'])) {
549
+			$ret = smf_db_error($db_string, $connection);
550
+	}
512 551
 
513 552
 	// Debugging.
514
-	if (isset($db_show_debug) && $db_show_debug === true)
515
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
553
+	if (isset($db_show_debug) && $db_show_debug === true) {
554
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
555
+	}
516 556
 
517 557
 	return $ret;
518 558
 }
@@ -559,12 +599,13 @@  discard block
 block discarded – undo
559 599
 	// Decide which connection to use
560 600
 	$connection = $connection === null ? $db_connection : $connection;
561 601
 
562
-	if ($type == 'begin')
563
-		return @mysqli_query($connection, 'BEGIN');
564
-	elseif ($type == 'rollback')
565
-		return @mysqli_query($connection, 'ROLLBACK');
566
-	elseif ($type == 'commit')
567
-		return @mysqli_query($connection, 'COMMIT');
602
+	if ($type == 'begin') {
603
+			return @mysqli_query($connection, 'BEGIN');
604
+	} elseif ($type == 'rollback') {
605
+			return @mysqli_query($connection, 'ROLLBACK');
606
+	} elseif ($type == 'commit') {
607
+			return @mysqli_query($connection, 'COMMIT');
608
+	}
568 609
 
569 610
 	return false;
570 611
 }
@@ -604,8 +645,9 @@  discard block
 block discarded – undo
604 645
 	//    2013: Lost connection to server during query.
605 646
 
606 647
 	// Log the error.
607
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
608
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
648
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
649
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
650
+	}
609 651
 
610 652
 	// Database error auto fixing ;).
611 653
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -614,8 +656,9 @@  discard block
 block discarded – undo
614 656
 		$old_cache = @$modSettings['cache_enable'];
615 657
 		$modSettings['cache_enable'] = '1';
616 658
 
617
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
618
-			$db_last_error = max(@$db_last_error, $temp);
659
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
660
+					$db_last_error = max(@$db_last_error, $temp);
661
+		}
619 662
 
620 663
 		if (@$db_last_error < time() - 3600 * 24 * 3)
621 664
 		{
@@ -631,8 +674,9 @@  discard block
 block discarded – undo
631 674
 					foreach ($tables as $table)
632 675
 					{
633 676
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
634
-						if (trim($table) != '')
635
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
677
+						if (trim($table) != '') {
678
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
679
+						}
636 680
 					}
637 681
 				}
638 682
 
@@ -641,8 +685,9 @@  discard block
 block discarded – undo
641 685
 			// Table crashed.  Let's try to fix it.
642 686
 			elseif ($query_errno == 1016)
643 687
 			{
644
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
645
-					$fix_tables = array('`' . $match[1] . '`');
688
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
689
+									$fix_tables = array('`' . $match[1] . '`');
690
+				}
646 691
 			}
647 692
 			// Indexes crashed.  Should be easy to fix!
648 693
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -661,13 +706,15 @@  discard block
 block discarded – undo
661 706
 
662 707
 			// Make a note of the REPAIR...
663 708
 			cache_put_data('db_last_error', time(), 600);
664
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
665
-				updateSettingsFile(array('db_last_error' => time()));
709
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
710
+							updateSettingsFile(array('db_last_error' => time()));
711
+			}
666 712
 
667 713
 			// Attempt to find and repair the broken table.
668
-			foreach ($fix_tables as $table)
669
-				$smcFunc['db_query']('', "
714
+			foreach ($fix_tables as $table) {
715
+							$smcFunc['db_query']('', "
670 716
 					REPAIR TABLE $table", false, false);
717
+			}
671 718
 
672 719
 			// And send off an email!
673 720
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -676,11 +723,12 @@  discard block
 block discarded – undo
676 723
 
677 724
 			// Try the query again...?
678 725
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
679
-			if ($ret !== false)
680
-				return $ret;
726
+			if ($ret !== false) {
727
+							return $ret;
728
+			}
729
+		} else {
730
+					$modSettings['cache_enable'] = $old_cache;
681 731
 		}
682
-		else
683
-			$modSettings['cache_enable'] = $old_cache;
684 732
 
685 733
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
686 734
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -690,22 +738,25 @@  discard block
 block discarded – undo
690 738
 				// Are we in SSI mode?  If so try that username and password first
691 739
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
692 740
 				{
693
-					if (empty($db_persist))
694
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
695
-					else
696
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
741
+					if (empty($db_persist)) {
742
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
743
+					} else {
744
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
745
+					}
697 746
 				}
698 747
 				// Fall back to the regular username and password if need be
699 748
 				if (!$db_connection)
700 749
 				{
701
-					if (empty($db_persist))
702
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
703
-					else
704
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
750
+					if (empty($db_persist)) {
751
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
752
+					} else {
753
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
754
+					}
705 755
 				}
706 756
 
707
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
708
-					$db_connection = false;
757
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
758
+									$db_connection = false;
759
+				}
709 760
 			}
710 761
 
711 762
 			if ($db_connection)
@@ -716,24 +767,27 @@  discard block
 block discarded – undo
716 767
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
717 768
 
718 769
 					$new_errno = mysqli_errno($db_connection);
719
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
720
-						break;
770
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
771
+											break;
772
+					}
721 773
 				}
722 774
 
723 775
 				// If it failed again, shucks to be you... we're not trying it over and over.
724
-				if ($ret !== false)
725
-					return $ret;
776
+				if ($ret !== false) {
777
+									return $ret;
778
+				}
726 779
 			}
727 780
 		}
728 781
 		// Are they out of space, perhaps?
729 782
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
730 783
 		{
731
-			if (!isset($txt))
732
-				$query_error .= ' - check database storage space.';
733
-			else
784
+			if (!isset($txt)) {
785
+							$query_error .= ' - check database storage space.';
786
+			} else
734 787
 			{
735
-				if (!isset($txt['mysql_error_space']))
736
-					loadLanguage('Errors');
788
+				if (!isset($txt['mysql_error_space'])) {
789
+									loadLanguage('Errors');
790
+				}
737 791
 
738 792
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
739 793
 			}
@@ -741,15 +795,17 @@  discard block
 block discarded – undo
741 795
 	}
742 796
 
743 797
 	// Nothing's defined yet... just die with it.
744
-	if (empty($context) || empty($txt))
745
-		die($query_error);
798
+	if (empty($context) || empty($txt)) {
799
+			die($query_error);
800
+	}
746 801
 
747 802
 	// Show an error message, if possible.
748 803
 	$context['error_title'] = $txt['database_error'];
749
-	if (allowedTo('admin_forum'))
750
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
751
-	else
752
-		$context['error_message'] = $txt['try_again'];
804
+	if (allowedTo('admin_forum')) {
805
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
806
+	} else {
807
+			$context['error_message'] = $txt['try_again'];
808
+	}
753 809
 
754 810
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
755 811
 	{
@@ -781,8 +837,9 @@  discard block
 block discarded – undo
781 837
 	$return_var = null;
782 838
 
783 839
 	// With nothing to insert, simply return.
784
-	if (empty($data))
785
-		return;
840
+	if (empty($data)) {
841
+			return;
842
+	}
786 843
 
787 844
 	// Replace the prefix holder with the actual prefix.
788 845
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -792,23 +849,26 @@  discard block
 block discarded – undo
792 849
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
793 850
 	{
794 851
 		$with_returning = true;
795
-		if ($returnmode == 2)
796
-			$return_var = array();
852
+		if ($returnmode == 2) {
853
+					$return_var = array();
854
+		}
797 855
 	}
798 856
 
799 857
 	// Inserting data as a single row can be done as a single array.
800
-	if (!is_array($data[array_rand($data)]))
801
-		$data = array($data);
858
+	if (!is_array($data[array_rand($data)])) {
859
+			$data = array($data);
860
+	}
802 861
 
803 862
 	// Create the mold for a single row insert.
804 863
 	$insertData = '(';
805 864
 	foreach ($columns as $columnName => $type)
806 865
 	{
807 866
 		// Are we restricting the length?
808
-		if (strpos($type, 'string-') !== false)
809
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
810
-		else
811
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
867
+		if (strpos($type, 'string-') !== false) {
868
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
869
+		} else {
870
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
871
+		}
812 872
 	}
813 873
 	$insertData = substr($insertData, 0, -2) . ')';
814 874
 
@@ -817,8 +877,9 @@  discard block
 block discarded – undo
817 877
 
818 878
 	// Here's where the variables are injected to the query.
819 879
 	$insertRows = array();
820
-	foreach ($data as $dataRow)
821
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
880
+	foreach ($data as $dataRow) {
881
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
882
+	}
822 883
 
823 884
 	// Determine the method of insertion.
824 885
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -837,8 +898,7 @@  discard block
 block discarded – undo
837 898
 			),
838 899
 			$connection
839 900
 		);
840
-	}
841
-	else //special way for ignore method with returning
901
+	} else //special way for ignore method with returning
842 902
 	{
843 903
 		$count = count($insertRows);
844 904
 		$ai = 0;
@@ -858,19 +918,21 @@  discard block
 block discarded – undo
858 918
 			);
859 919
 			$new_id = $smcFunc['db_insert_id']();
860 920
 			
861
-			if ($last_id != $new_id) //the inserted value was new
921
+			if ($last_id != $new_id) {
922
+				//the inserted value was new
862 923
 			{
863 924
 				$ai = $new_id;
864 925
 			}
865
-			else	// the inserted value already exists we need to find the pk
926
+			} else	// the inserted value already exists we need to find the pk
866 927
 			{
867 928
 				$where_string = '';
868 929
 				$count2 = count($indexed_columns);
869 930
 				for ($x = 0; $x < $count2; $x++)
870 931
 				{
871 932
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
872
-					if (($x + 1) < $count2)
873
-						$where_string += ' AND ';
933
+					if (($x + 1) < $count2) {
934
+											$where_string += ' AND ';
935
+					}
874 936
 				}
875 937
 
876 938
 				$request = $smcFunc['db_query']('','
@@ -886,25 +948,27 @@  discard block
 block discarded – undo
886 948
 				}
887 949
 			}
888 950
 			
889
-			if ($returnmode == 1)
890
-				$return_var = $ai;
891
-			else if ($returnmode == 2)
892
-				$return_var[] = $ai;
951
+			if ($returnmode == 1) {
952
+							$return_var = $ai;
953
+			} else if ($returnmode == 2) {
954
+							$return_var[] = $ai;
955
+			}
893 956
 		}
894 957
 	}
895 958
 	
896 959
 
897 960
 	if ($with_returning)
898 961
 	{
899
-		if ($returnmode == 1 && empty($return_var))
900
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
901
-		else if ($returnmode == 2 && empty($return_var))
962
+		if ($returnmode == 1 && empty($return_var)) {
963
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
964
+		} else if ($returnmode == 2 && empty($return_var))
902 965
 		{
903 966
 			$return_var = array();
904 967
 			$count = count($insertRows);
905 968
 			$start = smf_db_insert_id($table, $keys[0]);
906
-			for ($i = 0; $i < $count; $i++ )
907
-				$return_var[] = $start + $i;
969
+			for ($i = 0; $i < $count; $i++ ) {
970
+							$return_var[] = $start + $i;
971
+			}
908 972
 		}
909 973
 		return $return_var;
910 974
 	}
@@ -922,8 +986,9 @@  discard block
 block discarded – undo
922 986
  */
923 987
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
924 988
 {
925
-	if (empty($log_message))
926
-		$log_message = $error_message;
989
+	if (empty($log_message)) {
990
+			$log_message = $error_message;
991
+	}
927 992
 
928 993
 	foreach (debug_backtrace() as $step)
929 994
 	{
@@ -942,12 +1007,14 @@  discard block
 block discarded – undo
942 1007
 	}
943 1008
 
944 1009
 	// A special case - we want the file and line numbers for debugging.
945
-	if ($error_type == 'return')
946
-		return array($file, $line);
1010
+	if ($error_type == 'return') {
1011
+			return array($file, $line);
1012
+	}
947 1013
 
948 1014
 	// Is always a critical error.
949
-	if (function_exists('log_error'))
950
-		log_error($log_message, 'critical', $file, $line);
1015
+	if (function_exists('log_error')) {
1016
+			log_error($log_message, 'critical', $file, $line);
1017
+	}
951 1018
 
952 1019
 	if (function_exists('fatal_error'))
953 1020
 	{
@@ -955,12 +1022,12 @@  discard block
 block discarded – undo
955 1022
 
956 1023
 		// Cannot continue...
957 1024
 		exit;
1025
+	} elseif ($error_type) {
1026
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
1027
+	} else {
1028
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
1029
+	}
958 1030
 	}
959
-	elseif ($error_type)
960
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
961
-	else
962
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
963
-}
964 1031
 
965 1032
 /**
966 1033
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -977,10 +1044,11 @@  discard block
 block discarded – undo
977 1044
 		'\\' => '\\\\',
978 1045
 	);
979 1046
 
980
-	if ($translate_human_wildcards)
981
-		$replacements += array(
1047
+	if ($translate_human_wildcards) {
1048
+			$replacements += array(
982 1049
 			'*' => '%',
983 1050
 		);
1051
+	}
984 1052
 
985 1053
 	return strtr($string, $replacements);
986 1054
 }
@@ -994,8 +1062,9 @@  discard block
 block discarded – undo
994 1062
  */
995 1063
 function smf_is_resource($result)
996 1064
 {
997
-	if ($result instanceof mysqli_result)
998
-		return true;
1065
+	if ($result instanceof mysqli_result) {
1066
+			return true;
1067
+	}
999 1068
 
1000 1069
 	return false;
1001 1070
 }
@@ -1023,16 +1092,18 @@  discard block
 block discarded – undo
1023 1092
 	global  $db_prefix, $db_connection;
1024 1093
 	static $mysql_error_data_prep;
1025 1094
 
1026
-	if (empty($mysql_error_data_prep))
1027
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1095
+	if (empty($mysql_error_data_prep)) {
1096
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
1028 1097
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
1029 1098
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
1030 1099
 			);
1100
+	}
1031 1101
 
1032
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
1033
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
1034
-	else
1035
-		$error_array[2] = null;
1102
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1103
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1104
+	} else {
1105
+			$error_array[2] = null;
1106
+	}
1036 1107
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', 
1037 1108
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1038 1109
 		$error_array[7], $error_array[8]);
@@ -1054,8 +1125,9 @@  discard block
 block discarded – undo
1054 1125
 	$count = count($array_values);
1055 1126
 	$then = ($desc ? ' THEN -' : ' THEN ');
1056 1127
 
1057
-	for ($i = 0; $i < $count; $i++)
1058
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1128
+	for ($i = 0; $i < $count; $i++) {
1129
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1130
+	}
1059 1131
 
1060 1132
 	$return .= 'END';
1061 1133
 	return $return;
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,19 +466,20 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
@@ -469,14 +490,12 @@  discard block
 block discarded – undo
469 490
 	{
470 491
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
471 492
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
472
-	}
473
-	elseif ($_SESSION['mc']['bq'] != '0=1')
493
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
474 494
 	{
475 495
 		require_once($sourcedir . '/Subs-ReportedContent.php');
476 496
 		$context['open_mod_reports'] = recountOpenReports('posts');
477 497
 		$context['open_member_reports'] = recountOpenReports('members');
478
-	}
479
-	else
498
+	} else
480 499
 	{
481 500
 		$context['open_mod_reports'] = 0;
482 501
 		$context['open_member_reports'] = 0;
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	global $user_info, $smcFunc;
497 516
 
498 517
 	// Don't log web accelerators, it's very confusing...
499
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
500
-		return;
518
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
519
+			return;
520
+	}
501 521
 
502 522
 	$smcFunc['db_insert']('',
503 523
 		'{db_prefix}log_banned',
@@ -507,8 +527,8 @@  discard block
 block discarded – undo
507 527
 	);
508 528
 
509 529
 	// One extra point for these bans.
510
-	if (!empty($ban_ids))
511
-		$smcFunc['db_query']('', '
530
+	if (!empty($ban_ids)) {
531
+			$smcFunc['db_query']('', '
512 532
 			UPDATE {db_prefix}ban_items
513 533
 			SET hits = hits + 1
514 534
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -516,7 +536,8 @@  discard block
 block discarded – undo
516 536
 				'ban_ids' => $ban_ids,
517 537
 			)
518 538
 		);
519
-}
539
+	}
540
+	}
520 541
 
521 542
 /**
522 543
  * Checks if a given email address might be banned.
@@ -532,8 +553,9 @@  discard block
 block discarded – undo
532 553
 	global $txt, $smcFunc;
533 554
 
534 555
 	// Can't ban an empty email
535
-	if (empty($email) || trim($email) == '')
536
-		return;
556
+	if (empty($email) || trim($email) == '') {
557
+			return;
558
+	}
537 559
 
538 560
 	// Let's start with the bans based on your IP/hostname/memberID...
539 561
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -606,16 +628,18 @@  discard block
 block discarded – undo
606 628
 	if ($type == 'post')
607 629
 	{
608 630
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
609
-		if ($check !== $sc)
610
-			$error = 'session_timeout';
631
+		if ($check !== $sc) {
632
+					$error = 'session_timeout';
633
+		}
611 634
 	}
612 635
 
613 636
 	// How about $_GET['sesc']?
614 637
 	elseif ($type == 'get')
615 638
 	{
616 639
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
617
-		if ($check !== $sc)
618
-			$error = 'session_verify_fail';
640
+		if ($check !== $sc) {
641
+					$error = 'session_verify_fail';
642
+		}
619 643
 	}
620 644
 
621 645
 	// Or can it be in either?
@@ -623,13 +647,15 @@  discard block
 block discarded – undo
623 647
 	{
624 648
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
625 649
 
626
-		if ($check !== $sc)
627
-			$error = 'session_verify_fail';
650
+		if ($check !== $sc) {
651
+					$error = 'session_verify_fail';
652
+		}
628 653
 	}
629 654
 
630 655
 	// Verify that they aren't changing user agents on us - that could be bad.
631
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
632
-		$error = 'session_verify_fail';
656
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
657
+			$error = 'session_verify_fail';
658
+	}
633 659
 
634 660
 	// Make sure a page with session check requirement is not being prefetched.
635 661
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -640,30 +666,35 @@  discard block
 block discarded – undo
640 666
 	}
641 667
 
642 668
 	// Check the referring site - it should be the same server at least!
643
-	if (isset($_SESSION['request_referer']))
644
-		$referrer = $_SESSION['request_referer'];
645
-	else
646
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
669
+	if (isset($_SESSION['request_referer'])) {
670
+			$referrer = $_SESSION['request_referer'];
671
+	} else {
672
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
673
+	}
647 674
 	if (!empty($referrer['host']))
648 675
 	{
649
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
650
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
651
-		else
652
-			$real_host = $_SERVER['HTTP_HOST'];
676
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
677
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
678
+		} else {
679
+					$real_host = $_SERVER['HTTP_HOST'];
680
+		}
653 681
 
654 682
 		$parsed_url = parse_url($boardurl);
655 683
 
656 684
 		// Are global cookies on?  If so, let's check them ;).
657 685
 		if (!empty($modSettings['globalCookies']))
658 686
 		{
659
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
660
-				$parsed_url['host'] = $parts[1];
687
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
688
+							$parsed_url['host'] = $parts[1];
689
+			}
661 690
 
662
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
663
-				$referrer['host'] = $parts[1];
691
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
692
+							$referrer['host'] = $parts[1];
693
+			}
664 694
 
665
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
666
-				$real_host = $parts[1];
695
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
696
+							$real_host = $parts[1];
697
+			}
667 698
 		}
668 699
 
669 700
 		// Okay: referrer must either match parsed_url or real_host.
@@ -681,12 +712,14 @@  discard block
 block discarded – undo
681 712
 		$log_error = true;
682 713
 	}
683 714
 
684
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
685
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
715
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
716
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
717
+	}
686 718
 
687 719
 	// Everything is ok, return an empty string.
688
-	if (!isset($error))
689
-		return '';
720
+	if (!isset($error)) {
721
+			return '';
722
+	}
690 723
 	// A session error occurred, show the error.
691 724
 	elseif ($is_fatal)
692 725
 	{
@@ -695,13 +728,14 @@  discard block
 block discarded – undo
695 728
 			ob_end_clean();
696 729
 			header('HTTP/1.1 403 Forbidden - Session timeout');
697 730
 			die;
731
+		} else {
732
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
698 733
 		}
699
-		else
700
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
701 734
 	}
702 735
 	// A session error occurred, return the error to the calling function.
703
-	else
704
-		return $error;
736
+	else {
737
+			return $error;
738
+	}
705 739
 
706 740
 	// We really should never fall through here, for very important reasons.  Let's make sure.
707 741
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -717,10 +751,9 @@  discard block
 block discarded – undo
717 751
 {
718 752
 	global $modSettings;
719 753
 
720
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
721
-		return true;
722
-
723
-	else
754
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
755
+			return true;
756
+	} else
724 757
 	{
725 758
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
726 759
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -771,9 +804,9 @@  discard block
 block discarded – undo
771 804
 			$return = $_SESSION['token'][$type . '-' . $action][3];
772 805
 			unset($_SESSION['token'][$type . '-' . $action]);
773 806
 			return $return;
807
+		} else {
808
+					return '';
774 809
 		}
775
-		else
776
-			return '';
777 810
 	}
778 811
 
779 812
 	// This nasty piece of code validates a token.
@@ -804,12 +837,14 @@  discard block
 block discarded – undo
804 837
 		fatal_lang_error('token_verify_fail', false);
805 838
 	}
806 839
 	// Remove this token as its useless
807
-	else
808
-		unset($_SESSION['token'][$type . '-' . $action]);
840
+	else {
841
+			unset($_SESSION['token'][$type . '-' . $action]);
842
+	}
809 843
 
810 844
 	// Randomly check if we should remove some older tokens.
811
-	if (mt_rand(0, 138) == 23)
812
-		cleanTokens();
845
+	if (mt_rand(0, 138) == 23) {
846
+			cleanTokens();
847
+	}
813 848
 
814 849
 	return false;
815 850
 }
@@ -824,14 +859,16 @@  discard block
 block discarded – undo
824 859
 function cleanTokens($complete = false)
825 860
 {
826 861
 	// We appreciate cleaning up after yourselves.
827
-	if (!isset($_SESSION['token']))
828
-		return;
862
+	if (!isset($_SESSION['token'])) {
863
+			return;
864
+	}
829 865
 
830 866
 	// Clean up tokens, trying to give enough time still.
831
-	foreach ($_SESSION['token'] as $key => $data)
832
-		if ($data[2] + 10800 < time() || $complete)
867
+	foreach ($_SESSION['token'] as $key => $data) {
868
+			if ($data[2] + 10800 < time() || $complete)
833 869
 			unset($_SESSION['token'][$key]);
834
-}
870
+	}
871
+	}
835 872
 
836 873
 /**
837 874
  * Check whether a form has been submitted twice.
@@ -849,37 +886,40 @@  discard block
 block discarded – undo
849 886
 {
850 887
 	global $context;
851 888
 
852
-	if (!isset($_SESSION['forms']))
853
-		$_SESSION['forms'] = array();
889
+	if (!isset($_SESSION['forms'])) {
890
+			$_SESSION['forms'] = array();
891
+	}
854 892
 
855 893
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
856 894
 	if ($action == 'register')
857 895
 	{
858 896
 		$context['form_sequence_number'] = 0;
859
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
860
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
897
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
898
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
899
+		}
861 900
 	}
862 901
 	// Check whether the submitted number can be found in the session.
863 902
 	elseif ($action == 'check')
864 903
 	{
865
-		if (!isset($_REQUEST['seqnum']))
866
-			return true;
867
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
904
+		if (!isset($_REQUEST['seqnum'])) {
905
+					return true;
906
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
868 907
 		{
869 908
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
870 909
 			return true;
910
+		} elseif ($is_fatal) {
911
+					fatal_lang_error('error_form_already_submitted', false);
912
+		} else {
913
+					return false;
871 914
 		}
872
-		elseif ($is_fatal)
873
-			fatal_lang_error('error_form_already_submitted', false);
874
-		else
875
-			return false;
876 915
 	}
877 916
 	// Don't check, just free the stack number.
878
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
879
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
880
-	elseif ($action != 'free')
881
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
882
-}
917
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
918
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
919
+	} elseif ($action != 'free') {
920
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
921
+	}
922
+	}
883 923
 
884 924
 /**
885 925
  * Check the user's permissions.
@@ -896,16 +936,19 @@  discard block
 block discarded – undo
896 936
 	global $user_info, $smcFunc;
897 937
 
898 938
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
899
-	if (empty($permission))
900
-		return true;
939
+	if (empty($permission)) {
940
+			return true;
941
+	}
901 942
 
902 943
 	// You're never allowed to do something if your data hasn't been loaded yet!
903
-	if (empty($user_info))
904
-		return false;
944
+	if (empty($user_info)) {
945
+			return false;
946
+	}
905 947
 
906 948
 	// Administrators are supermen :P.
907
-	if ($user_info['is_admin'])
908
-		return true;
949
+	if ($user_info['is_admin']) {
950
+			return true;
951
+	}
909 952
 
910 953
 	// Let's ensure this is an array.
911 954
 	$permission = (array) $permission;
@@ -913,14 +956,16 @@  discard block
 block discarded – undo
913 956
 	// Are we checking the _current_ board, or some other boards?
914 957
 	if ($boards === null)
915 958
 	{
916
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
917
-			return true;
959
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
960
+					return true;
961
+		}
918 962
 		// You aren't allowed, by default.
919
-		else
920
-			return false;
963
+		else {
964
+					return false;
965
+		}
966
+	} elseif (!is_array($boards)) {
967
+			$boards = array($boards);
921 968
 	}
922
-	elseif (!is_array($boards))
923
-		$boards = array($boards);
924 969
 
925 970
 	$request = $smcFunc['db_query']('', '
926 971
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -943,12 +988,14 @@  discard block
 block discarded – undo
943 988
 	);
944 989
 
945 990
 	// Make sure they can do it on all of the boards.
946
-	if ($smcFunc['db_num_rows']($request) != count($boards))
947
-		return false;
991
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
992
+			return false;
993
+	}
948 994
 
949 995
 	$result = true;
950
-	while ($row = $smcFunc['db_fetch_assoc']($request))
951
-		$result &= !empty($row['add_deny']);
996
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
997
+			$result &= !empty($row['add_deny']);
998
+	}
952 999
 	$smcFunc['db_free_result']($request);
953 1000
 
954 1001
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1013,9 +1060,10 @@  discard block
 block discarded – undo
1013 1060
 
1014 1061
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1015 1062
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1016
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1017
-		validateSession();
1018
-}
1063
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1064
+			validateSession();
1065
+	}
1066
+	}
1019 1067
 
1020 1068
 /**
1021 1069
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1034,8 +1082,9 @@  discard block
 block discarded – undo
1034 1082
 	global $user_info, $smcFunc;
1035 1083
 
1036 1084
 	// Arrays are nice, most of the time.
1037
-	if (!is_array($permissions))
1038
-		$permissions = array($permissions);
1085
+	if (!is_array($permissions)) {
1086
+			$permissions = array($permissions);
1087
+	}
1039 1088
 
1040 1089
 	/*
1041 1090
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1047,13 +1096,14 @@  discard block
 block discarded – undo
1047 1096
 	// Administrators are all powerful, sorry.
1048 1097
 	if ($user_info['is_admin'])
1049 1098
 	{
1050
-		if ($simple)
1051
-			return array(0);
1052
-		else
1099
+		if ($simple) {
1100
+					return array(0);
1101
+		} else
1053 1102
 		{
1054 1103
 			$boards = array();
1055
-			foreach ($permissions as $permission)
1056
-				$boards[$permission] = array(0);
1104
+			foreach ($permissions as $permission) {
1105
+							$boards[$permission] = array(0);
1106
+			}
1057 1107
 
1058 1108
 			return $boards;
1059 1109
 		}
@@ -1085,31 +1135,32 @@  discard block
 block discarded – undo
1085 1135
 	{
1086 1136
 		if ($simple)
1087 1137
 		{
1088
-			if (empty($row['add_deny']))
1089
-				$deny_boards[] = $row['id_board'];
1090
-			else
1091
-				$boards[] = $row['id_board'];
1092
-		}
1093
-		else
1138
+			if (empty($row['add_deny'])) {
1139
+							$deny_boards[] = $row['id_board'];
1140
+			} else {
1141
+							$boards[] = $row['id_board'];
1142
+			}
1143
+		} else
1094 1144
 		{
1095
-			if (empty($row['add_deny']))
1096
-				$deny_boards[$row['permission']][] = $row['id_board'];
1097
-			else
1098
-				$boards[$row['permission']][] = $row['id_board'];
1145
+			if (empty($row['add_deny'])) {
1146
+							$deny_boards[$row['permission']][] = $row['id_board'];
1147
+			} else {
1148
+							$boards[$row['permission']][] = $row['id_board'];
1149
+			}
1099 1150
 		}
1100 1151
 	}
1101 1152
 	$smcFunc['db_free_result']($request);
1102 1153
 
1103
-	if ($simple)
1104
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1105
-	else
1154
+	if ($simple) {
1155
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1156
+	} else
1106 1157
 	{
1107 1158
 		foreach ($permissions as $permission)
1108 1159
 		{
1109 1160
 			// never had it to start with
1110
-			if (empty($boards[$permission]))
1111
-				$boards[$permission] = array();
1112
-			else
1161
+			if (empty($boards[$permission])) {
1162
+							$boards[$permission] = array();
1163
+			} else
1113 1164
 			{
1114 1165
 				// Or it may have been removed
1115 1166
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1145,10 +1196,11 @@  discard block
 block discarded – undo
1145 1196
 
1146 1197
 
1147 1198
 	// Moderators are free...
1148
-	if (!allowedTo('moderate_board'))
1149
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1150
-	else
1151
-		$timeLimit = 2;
1199
+	if (!allowedTo('moderate_board')) {
1200
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1201
+	} else {
1202
+			$timeLimit = 2;
1203
+	}
1152 1204
 
1153 1205
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1154 1206
 
@@ -1175,8 +1227,9 @@  discard block
 block discarded – undo
1175 1227
 	if ($smcFunc['db_affected_rows']() != 1)
1176 1228
 	{
1177 1229
 		// Spammer!  You only have to wait a *few* seconds!
1178
-		if (!$only_return_result)
1179
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1230
+		if (!$only_return_result) {
1231
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1232
+		}
1180 1233
 
1181 1234
 		return true;
1182 1235
 	}
@@ -1194,11 +1247,13 @@  discard block
 block discarded – undo
1194 1247
  */
1195 1248
 function secureDirectory($path, $attachments = false)
1196 1249
 {
1197
-	if (empty($path))
1198
-		return 'empty_path';
1250
+	if (empty($path)) {
1251
+			return 'empty_path';
1252
+	}
1199 1253
 
1200
-	if (!is_writable($path))
1201
-		return 'path_not_writable';
1254
+	if (!is_writable($path)) {
1255
+			return 'path_not_writable';
1256
+	}
1202 1257
 
1203 1258
 	$directoryname = basename($path);
1204 1259
 
@@ -1210,9 +1265,9 @@  discard block
 block discarded – undo
1210 1265
 
1211 1266
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1212 1267
 
1213
-	if (file_exists($path . '/.htaccess'))
1214
-		$errors[] = 'htaccess_exists';
1215
-	else
1268
+	if (file_exists($path . '/.htaccess')) {
1269
+			$errors[] = 'htaccess_exists';
1270
+	} else
1216 1271
 	{
1217 1272
 		$fh = @fopen($path . '/.htaccess', 'w');
1218 1273
 		if ($fh) {
@@ -1224,9 +1279,9 @@  discard block
 block discarded – undo
1224 1279
 		$errors[] = 'htaccess_cannot_create_file';
1225 1280
 	}
1226 1281
 
1227
-	if (file_exists($path . '/index.php'))
1228
-		$errors[] = 'index-php_exists';
1229
-	else
1282
+	if (file_exists($path . '/index.php')) {
1283
+			$errors[] = 'index-php_exists';
1284
+	} else
1230 1285
 	{
1231 1286
 		$fh = @fopen($path . '/index.php', 'w');
1232 1287
 		if ($fh) {
@@ -1253,11 +1308,12 @@  discard block
 block discarded – undo
1253 1308
 		$errors[] = 'index-php_cannot_create_file';
1254 1309
 	}
1255 1310
 
1256
-	if (!empty($errors))
1257
-		return $errors;
1258
-	else
1259
-		return true;
1260
-}
1311
+	if (!empty($errors)) {
1312
+			return $errors;
1313
+	} else {
1314
+			return true;
1315
+	}
1316
+	}
1261 1317
 
1262 1318
 /**
1263 1319
 * This sets the X-Frame-Options header.
@@ -1270,14 +1326,16 @@  discard block
 block discarded – undo
1270 1326
 	global $modSettings;
1271 1327
 
1272 1328
 	$option = 'SAMEORIGIN';
1273
-	if (is_null($override) && !empty($modSettings['frame_security']))
1274
-		$option = $modSettings['frame_security'];
1275
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1276
-		$option = $override;
1329
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1330
+			$option = $modSettings['frame_security'];
1331
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1332
+			$option = $override;
1333
+	}
1277 1334
 
1278 1335
 	// Don't bother setting the header if we have disabled it.
1279
-	if ($option == 'DISABLE')
1280
-		return;
1336
+	if ($option == 'DISABLE') {
1337
+			return;
1338
+	}
1281 1339
 
1282 1340
 	// Finally set it.
1283 1341
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.