Completed
Push — release-2.1 ( aa21c4...a79db9 )
by Colin
19:42 queued 09:42
created
Sources/Search.php 1 patch
Braces   +414 added lines, -307 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
 // This defines two version types for checking the API's are compatible with this version of SMF.
20 21
 $GLOBALS['search_versions'] = array(
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir;
40 41
 
41 42
 	// Is the load average too high to allow searching just now?
42
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
43
-		fatal_lang_error('loadavg_search_disabled', false);
43
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
44
+			fatal_lang_error('loadavg_search_disabled', false);
45
+	}
44 46
 
45 47
 	loadLanguage('Search');
46 48
 	// Don't load this in XML mode.
@@ -88,23 +90,30 @@  discard block
 block discarded – undo
88 90
 			@list ($k, $v) = explode('|\'|', $data);
89 91
 			$context['search_params'][$k] = $v;
90 92
 		}
91
-		if (isset($context['search_params']['brd']))
92
-			$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
93
+		if (isset($context['search_params']['brd'])) {
94
+					$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
95
+		}
93 96
 	}
94 97
 
95
-	if (isset($_REQUEST['search']))
96
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
98
+	if (isset($_REQUEST['search'])) {
99
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
100
+	}
97 101
 
98
-	if (isset($context['search_params']['search']))
99
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
100
-	if (isset($context['search_params']['userspec']))
101
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
102
-	if (!empty($context['search_params']['searchtype']))
103
-		$context['search_params']['searchtype'] = 2;
104
-	if (!empty($context['search_params']['minage']))
105
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
106
-	if (!empty($context['search_params']['maxage']))
107
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
102
+	if (isset($context['search_params']['search'])) {
103
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
104
+	}
105
+	if (isset($context['search_params']['userspec'])) {
106
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
107
+	}
108
+	if (!empty($context['search_params']['searchtype'])) {
109
+			$context['search_params']['searchtype'] = 2;
110
+	}
111
+	if (!empty($context['search_params']['minage'])) {
112
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
113
+	}
114
+	if (!empty($context['search_params']['maxage'])) {
115
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
116
+	}
108 117
 
109 118
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
110 119
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
@@ -116,11 +125,13 @@  discard block
 block discarded – undo
116 125
 		$context['search_errors']['messages'] = array();
117 126
 		foreach ($context['search_errors'] as $search_error => $dummy)
118 127
 		{
119
-			if ($search_error === 'messages')
120
-				continue;
128
+			if ($search_error === 'messages') {
129
+							continue;
130
+			}
121 131
 
122
-			if ($search_error == 'string_too_long')
123
-				$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
132
+			if ($search_error == 'string_too_long') {
133
+							$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
134
+			}
124 135
 
125 136
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
126 137
 		}
@@ -143,12 +154,13 @@  discard block
 block discarded – undo
143 154
 	while ($row = $smcFunc['db_fetch_assoc']($request))
144 155
 	{
145 156
 		// This category hasn't been set up yet..
146
-		if (!isset($context['categories'][$row['id_cat']]))
147
-			$context['categories'][$row['id_cat']] = array(
157
+		if (!isset($context['categories'][$row['id_cat']])) {
158
+					$context['categories'][$row['id_cat']] = array(
148 159
 				'id' => $row['id_cat'],
149 160
 				'name' => $row['cat_name'],
150 161
 				'boards' => array()
151 162
 			);
163
+		}
152 164
 
153 165
 		// Set this board up, and let the template know when it's a child.  (indent them..)
154 166
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -159,8 +171,9 @@  discard block
 block discarded – undo
159 171
 		);
160 172
 
161 173
 		// If a board wasn't checked that probably should have been ensure the board selection is selected, yo!
162
-		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board']))
163
-			$context['boards_check_all'] = false;
174
+		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) {
175
+					$context['boards_check_all'] = false;
176
+		}
164 177
 	}
165 178
 	$smcFunc['db_free_result']($request);
166 179
 
@@ -182,18 +195,20 @@  discard block
 block discarded – undo
182 195
 	}
183 196
 
184 197
 	$max_boards = ceil(count($temp_boards) / 2);
185
-	if ($max_boards == 1)
186
-		$max_boards = 2;
198
+	if ($max_boards == 1) {
199
+			$max_boards = 2;
200
+	}
187 201
 
188 202
 	// Now, alternate them so they can be shown left and right ;).
189 203
 	$context['board_columns'] = array();
190 204
 	for ($i = 0; $i < $max_boards; $i++)
191 205
 	{
192 206
 		$context['board_columns'][] = $temp_boards[$i];
193
-		if (isset($temp_boards[$i + $max_boards]))
194
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
195
-		else
196
-			$context['board_columns'][] = array();
207
+		if (isset($temp_boards[$i + $max_boards])) {
208
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
209
+		} else {
210
+					$context['board_columns'][] = array();
211
+		}
197 212
 	}
198 213
 
199 214
 	if (!empty($_REQUEST['topic']))
@@ -225,8 +240,9 @@  discard block
 block discarded – undo
225 240
 			)
226 241
 		);
227 242
 
228
-		if ($smcFunc['db_num_rows']($request) == 0)
229
-			fatal_lang_error('topic_gone', false);
243
+		if ($smcFunc['db_num_rows']($request) == 0) {
244
+					fatal_lang_error('topic_gone', false);
245
+		}
230 246
 
231 247
 		list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request);
232 248
 		$smcFunc['db_free_result']($request);
@@ -256,11 +272,13 @@  discard block
 block discarded – undo
256 272
 	global $excludedWords, $participants, $smcFunc;
257 273
 
258 274
 	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
259
-	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
260
-		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
275
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') {
276
+			redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
277
+	}
261 278
 
262
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
263
-		fatal_lang_error('loadavg_search_disabled', false);
279
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
280
+			fatal_lang_error('loadavg_search_disabled', false);
281
+	}
264 282
 
265 283
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
266 284
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -307,8 +325,9 @@  discard block
 block discarded – undo
307 325
 	}
308 326
 
309 327
 	// Zero weight.  Weightless :P.
310
-	if (empty($weight_total))
311
-		fatal_lang_error('search_invalid_weights');
328
+	if (empty($weight_total)) {
329
+			fatal_lang_error('search_invalid_weights');
330
+	}
312 331
 
313 332
 	// These vars don't require an interface, they're just here for tweaking.
314 333
 	$recentPercentage = 0.30;
@@ -326,11 +345,13 @@  discard block
 block discarded – undo
326 345
 	$context['search_string_limit'] = 100;
327 346
 
328 347
 	loadLanguage('Search');
329
-	if (!isset($_REQUEST['xml']))
330
-		loadTemplate('Search');
348
+	if (!isset($_REQUEST['xml'])) {
349
+			loadTemplate('Search');
350
+	}
331 351
 	//If we're doing XML we need to use the results template regardless really.
332
-	else
333
-		$context['sub_template'] = 'results';
352
+	else {
353
+			$context['sub_template'] = 'results';
354
+	}
334 355
 
335 356
 	// Are you allowed?
336 357
 	isAllowedTo('search_posts');
@@ -363,34 +384,39 @@  discard block
 block discarded – undo
363 384
 			$search_params[$k] = $v;
364 385
 		}
365 386
 
366
-		if (isset($search_params['brd']))
367
-			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
387
+		if (isset($search_params['brd'])) {
388
+					$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
389
+		}
368 390
 	}
369 391
 
370 392
 	// Store whether simple search was used (needed if the user wants to do another query).
371
-	if (!isset($search_params['advanced']))
372
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
393
+	if (!isset($search_params['advanced'])) {
394
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
395
+	}
373 396
 
374 397
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
375
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
376
-		$search_params['searchtype'] = 2;
398
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
399
+			$search_params['searchtype'] = 2;
400
+	}
377 401
 
378 402
 	// Minimum age of messages. Default to zero (don't set param in that case).
379
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
380
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
403
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
404
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
405
+	}
381 406
 
382 407
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
383
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999))
384
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
408
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) {
409
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
410
+	}
385 411
 
386 412
 	// Searching a specific topic?
387 413
 	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
388 414
 	{
389 415
 		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
390 416
 		$search_params['show_complete'] = true;
417
+	} elseif (!empty($search_params['topic'])) {
418
+			$search_params['topic'] = (int) $search_params['topic'];
391 419
 	}
392
-	elseif (!empty($search_params['topic']))
393
-		$search_params['topic'] = (int) $search_params['topic'];
394 420
 
395 421
 	if (!empty($search_params['minage']) || !empty($search_params['maxage']))
396 422
 	{
@@ -408,19 +434,21 @@  discard block
 block discarded – undo
408 434
 			)
409 435
 		);
410 436
 		list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request);
411
-		if ($minMsgID < 0 || $maxMsgID < 0)
412
-			$context['search_errors']['no_messages_in_time_frame'] = true;
437
+		if ($minMsgID < 0 || $maxMsgID < 0) {
438
+					$context['search_errors']['no_messages_in_time_frame'] = true;
439
+		}
413 440
 		$smcFunc['db_free_result']($request);
414 441
 	}
415 442
 
416 443
 	// Default the user name to a wildcard matching every user (*).
417
-	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
418
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
444
+	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
445
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
446
+	}
419 447
 
420 448
 	// If there's no specific user, then don't mention it in the main query.
421
-	if (empty($search_params['userspec']))
422
-		$userQuery = '';
423
-	else
449
+	if (empty($search_params['userspec'])) {
450
+			$userQuery = '';
451
+	} else
424 452
 	{
425 453
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
426 454
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -432,19 +460,21 @@  discard block
 block discarded – undo
432 460
 		{
433 461
 			$possible_users[$k] = trim($possible_users[$k]);
434 462
 
435
-			if (strlen($possible_users[$k]) == 0)
436
-				unset($possible_users[$k]);
463
+			if (strlen($possible_users[$k]) == 0) {
464
+							unset($possible_users[$k]);
465
+			}
437 466
 		}
438 467
 
439 468
 		// Create a list of database-escaped search names.
440 469
 		$realNameMatches = array();
441
-		foreach ($possible_users as $possible_user)
442
-			$realNameMatches[] = $smcFunc['db_quote'](
470
+		foreach ($possible_users as $possible_user) {
471
+					$realNameMatches[] = $smcFunc['db_quote'](
443 472
 				'{string:possible_user}',
444 473
 				array(
445 474
 					'possible_user' => $possible_user
446 475
 				)
447 476
 			);
477
+		}
448 478
 
449 479
 		// Retrieve a list of possible members.
450 480
 		$request = $smcFunc['db_query']('', '
@@ -456,9 +486,9 @@  discard block
 block discarded – undo
456 486
 			)
457 487
 		);
458 488
 		// Simply do nothing if there're too many members matching the criteria.
459
-		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
460
-			$userQuery = '';
461
-		elseif ($smcFunc['db_num_rows']($request) == 0)
489
+		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
490
+					$userQuery = '';
491
+		} elseif ($smcFunc['db_num_rows']($request) == 0)
462 492
 		{
463 493
 			$userQuery = $smcFunc['db_quote'](
464 494
 				'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})',
@@ -467,12 +497,12 @@  discard block
 block discarded – undo
467 497
 					'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches),
468 498
 				)
469 499
 			);
470
-		}
471
-		else
500
+		} else
472 501
 		{
473 502
 			$memberlist = array();
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$memberlist[] = $row['id_member'];
503
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
504
+							$memberlist[] = $row['id_member'];
505
+			}
476 506
 			$userQuery = $smcFunc['db_quote'](
477 507
 				'(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))',
478 508
 				array(
@@ -486,22 +516,25 @@  discard block
 block discarded – undo
486 516
 	}
487 517
 
488 518
 	// If the boards were passed by URL (params=), temporarily put them back in $_REQUEST.
489
-	if (!empty($search_params['brd']) && is_array($search_params['brd']))
490
-		$_REQUEST['brd'] = $search_params['brd'];
519
+	if (!empty($search_params['brd']) && is_array($search_params['brd'])) {
520
+			$_REQUEST['brd'] = $search_params['brd'];
521
+	}
491 522
 
492 523
 	// Ensure that brd is an array.
493 524
 	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
494 525
 	{
495
-		if (!empty($_REQUEST['brd']))
496
-			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
497
-		else
498
-			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
526
+		if (!empty($_REQUEST['brd'])) {
527
+					$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
528
+		} else {
529
+					$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
530
+		}
499 531
 	}
500 532
 
501 533
 	// Make sure all boards are integers.
502
-	if (!empty($_REQUEST['brd']))
503
-		foreach ($_REQUEST['brd'] as $id => $brd)
534
+	if (!empty($_REQUEST['brd'])) {
535
+			foreach ($_REQUEST['brd'] as $id => $brd)
504 536
 			$_REQUEST['brd'][$id] = (int) $brd;
537
+	}
505 538
 
506 539
 	// Special case for boards: searching just one topic?
507 540
 	if (!empty($search_params['topic']))
@@ -520,17 +553,18 @@  discard block
 block discarded – undo
520 553
 			)
521 554
 		);
522 555
 
523
-		if ($smcFunc['db_num_rows']($request) == 0)
524
-			fatal_lang_error('topic_gone', false);
556
+		if ($smcFunc['db_num_rows']($request) == 0) {
557
+					fatal_lang_error('topic_gone', false);
558
+		}
525 559
 
526 560
 		$search_params['brd'] = array();
527 561
 		list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request);
528 562
 		$smcFunc['db_free_result']($request);
529 563
 	}
530 564
 	// Select all boards you've selected AND are allowed to see.
531
-	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
532
-		$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
533
-	else
565
+	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) {
566
+			$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
567
+	} else
534 568
 	{
535 569
 		$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
536 570
 		$request = $smcFunc['db_query']('', '
@@ -548,19 +582,22 @@  discard block
 block discarded – undo
548 582
 			)
549 583
 		);
550 584
 		$search_params['brd'] = array();
551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
552
-			$search_params['brd'][] = $row['id_board'];
585
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
586
+					$search_params['brd'][] = $row['id_board'];
587
+		}
553 588
 		$smcFunc['db_free_result']($request);
554 589
 
555 590
 		// This error should pro'bly only happen for hackers.
556
-		if (empty($search_params['brd']))
557
-			$context['search_errors']['no_boards_selected'] = true;
591
+		if (empty($search_params['brd'])) {
592
+					$context['search_errors']['no_boards_selected'] = true;
593
+		}
558 594
 	}
559 595
 
560 596
 	if (count($search_params['brd']) != 0)
561 597
 	{
562
-		foreach ($search_params['brd'] as $k => $v)
563
-			$search_params['brd'][$k] = (int) $v;
598
+		foreach ($search_params['brd'] as $k => $v) {
599
+					$search_params['brd'][$k] = (int) $v;
600
+		}
564 601
 
565 602
 		// If we've selected all boards, this parameter can be left empty.
566 603
 		$request = $smcFunc['db_query']('', '
@@ -574,15 +611,16 @@  discard block
 block discarded – undo
574 611
 		list ($num_boards) = $smcFunc['db_fetch_row']($request);
575 612
 		$smcFunc['db_free_result']($request);
576 613
 
577
-		if (count($search_params['brd']) == $num_boards)
614
+		if (count($search_params['brd']) == $num_boards) {
615
+					$boardQuery = '';
616
+		} elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) {
617
+					$boardQuery = '!= ' . $modSettings['recycle_board'];
618
+		} else {
619
+					$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
620
+		}
621
+	} else {
578 622
 			$boardQuery = '';
579
-		elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd']))
580
-			$boardQuery = '!= ' . $modSettings['recycle_board'];
581
-		else
582
-			$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
583 623
 	}
584
-	else
585
-		$boardQuery = '';
586 624
 
587 625
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
588 626
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
@@ -596,11 +634,13 @@  discard block
 block discarded – undo
596 634
 		'id_msg',
597 635
 	);
598 636
 	call_integration_hook('integrate_search_sort_columns', array(&$sort_columns));
599
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
600
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
637
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
638
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
639
+	}
601 640
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance';
602
-	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies')
603
-		$search_params['sort'] = 'id_msg';
641
+	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') {
642
+			$search_params['sort'] = 'id_msg';
643
+	}
604 644
 
605 645
 	// Sorting direction: descending unless stated otherwise.
606 646
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
@@ -624,17 +664,19 @@  discard block
 block discarded – undo
624 664
 	// What are we searching for?
625 665
 	if (empty($search_params['search']))
626 666
 	{
627
-		if (isset($_GET['search']))
628
-			$search_params['search'] = un_htmlspecialchars($_GET['search']);
629
-		elseif (isset($_POST['search']))
630
-			$search_params['search'] = $_POST['search'];
631
-		else
632
-			$search_params['search'] = '';
667
+		if (isset($_GET['search'])) {
668
+					$search_params['search'] = un_htmlspecialchars($_GET['search']);
669
+		} elseif (isset($_POST['search'])) {
670
+					$search_params['search'] = $_POST['search'];
671
+		} else {
672
+					$search_params['search'] = '';
673
+		}
633 674
 	}
634 675
 
635 676
 	// Nothing??
636
-	if (!isset($search_params['search']) || $search_params['search'] == '')
637
-		$context['search_errors']['invalid_search_string'] = true;
677
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
678
+			$context['search_errors']['invalid_search_string'] = true;
679
+	}
638 680
 	// Too long?
639 681
 	elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit'])
640 682
 	{
@@ -648,8 +690,9 @@  discard block
 block discarded – undo
648 690
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));
649 691
 
650 692
 	// This (hidden) setting will do fulltext searching in the most basic way.
651
-	if (!empty($modSettings['search_simple_fulltext']))
652
-		$stripped_query = strtr($stripped_query, array('"' => ''));
693
+	if (!empty($modSettings['search_simple_fulltext'])) {
694
+			$stripped_query = strtr($stripped_query, array('"' => ''));
695
+	}
653 696
 
654 697
 	$no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1;
655 698
 
@@ -672,8 +715,9 @@  discard block
 block discarded – undo
672 715
 	{
673 716
 		if ($word === '-')
674 717
 		{
675
-			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
676
-				$excludedWords[] = $word;
718
+			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
719
+							$excludedWords[] = $word;
720
+			}
677 721
 			unset($phraseArray[$index]);
678 722
 		}
679 723
 	}
@@ -683,8 +727,9 @@  discard block
 block discarded – undo
683 727
 	{
684 728
 		if (strpos(trim($word), '-') === 0)
685 729
 		{
686
-			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
687
-				$excludedWords[] = $word;
730
+			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
731
+							$excludedWords[] = $word;
732
+			}
688 733
 			unset($wordArray[$index]);
689 734
 		}
690 735
 	}
@@ -697,8 +742,9 @@  discard block
 block discarded – undo
697 742
 	foreach ($searchArray as $index => $value)
698 743
 	{
699 744
 		// Skip anything practically empty.
700
-		if (($searchArray[$index] = trim($value, '-_\' ')) === '')
701
-			unset($searchArray[$index]);
745
+		if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
746
+					unset($searchArray[$index]);
747
+		}
702 748
 		// Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing.
703 749
 		elseif (in_array($searchArray[$index], $blacklisted_words))
704 750
 		{
@@ -716,31 +762,37 @@  discard block
 block discarded – undo
716 762
 
717 763
 	// Create an array of replacements for highlighting.
718 764
 	$context['mark'] = array();
719
-	foreach ($searchArray as $word)
720
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
765
+	foreach ($searchArray as $word) {
766
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
767
+	}
721 768
 
722 769
 	// Initialize two arrays storing the words that have to be searched for.
723 770
 	$orParts = array();
724 771
 	$searchWords = array();
725 772
 
726 773
 	// Make sure at least one word is being searched for.
727
-	if (empty($searchArray))
728
-		$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
774
+	if (empty($searchArray)) {
775
+			$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
776
+	}
729 777
 	// All words/sentences must match.
730
-	elseif (empty($search_params['searchtype']))
731
-		$orParts[0] = $searchArray;
778
+	elseif (empty($search_params['searchtype'])) {
779
+			$orParts[0] = $searchArray;
780
+	}
732 781
 	// Any word/sentence must match.
733
-	else
734
-		foreach ($searchArray as $index => $value)
782
+	else {
783
+			foreach ($searchArray as $index => $value)
735 784
 			$orParts[$index] = array($value);
785
+	}
736 786
 
737 787
 	// Don't allow duplicate error messages if one string is too short.
738
-	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string']))
739
-		unset($context['search_errors']['invalid_search_string']);
788
+	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) {
789
+			unset($context['search_errors']['invalid_search_string']);
790
+	}
740 791
 	// Make sure the excluded words are in all or-branches.
741
-	foreach ($orParts as $orIndex => $andParts)
742
-		foreach ($excludedWords as $word)
792
+	foreach ($orParts as $orIndex => $andParts) {
793
+			foreach ($excludedWords as $word)
743 794
 			$orParts[$orIndex][] = $word;
795
+	}
744 796
 
745 797
 	// Determine the or-branches and the fulltext search words.
746 798
 	foreach ($orParts as $orIndex => $andParts)
@@ -754,8 +806,9 @@  discard block
 block discarded – undo
754 806
 		);
755 807
 
756 808
 		// Sort the indexed words (large words -> small words -> excluded words).
757
-		if ($searchAPI->supportsMethod('searchSort'))
758
-			usort($orParts[$orIndex], 'searchSort');
809
+		if ($searchAPI->supportsMethod('searchSort')) {
810
+					usort($orParts[$orIndex], 'searchSort');
811
+		}
759 812
 
760 813
 		foreach ($orParts[$orIndex] as $word)
761 814
 		{
@@ -767,15 +820,17 @@  discard block
 block discarded – undo
767 820
 			if (!$is_excluded || count($subjectWords) === 1)
768 821
 			{
769 822
 				$searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords);
770
-				if ($is_excluded)
771
-					$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
823
+				if ($is_excluded) {
824
+									$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
825
+				}
826
+			} else {
827
+							$excludedPhrases[] = $word;
772 828
 			}
773
-			else
774
-				$excludedPhrases[] = $word;
775 829
 
776 830
 			// Have we got indexes to prepare?
777
-			if ($searchAPI->supportsMethod('prepareIndexes'))
778
-				$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
831
+			if ($searchAPI->supportsMethod('prepareIndexes')) {
832
+							$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
833
+			}
779 834
 		}
780 835
 
781 836
 		// Search_force_index requires all AND parts to have at least one fulltext word.
@@ -783,8 +838,7 @@  discard block
 block discarded – undo
783 838
 		{
784 839
 			$context['search_errors']['query_not_specific_enough'] = true;
785 840
 			break;
786
-		}
787
-		elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
841
+		} elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
788 842
 		{
789 843
 			$context['search_errors']['query_not_specific_enough'] = true;
790 844
 			break;
@@ -812,8 +866,9 @@  discard block
 block discarded – undo
812 866
 		$found_misspelling = false;
813 867
 		foreach ($searchArray as $word)
814 868
 		{
815
-			if (empty($link))
816
-				continue;
869
+			if (empty($link)) {
870
+							continue;
871
+			}
817 872
 
818 873
 			// Don't check phrases.
819 874
 			if (preg_match('~^\w+$~', $word) === 0)
@@ -828,8 +883,7 @@  discard block
 block discarded – undo
828 883
 				$did_you_mean['search'][] = $word;
829 884
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
830 885
 				continue;
831
-			}
832
-			elseif (spell_check($link, $word))
886
+			} elseif (spell_check($link, $word))
833 887
 			{
834 888
 				$did_you_mean['search'][] = $word;
835 889
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -840,11 +894,13 @@  discard block
 block discarded – undo
840 894
 			foreach ($suggestions as $i => $s)
841 895
 			{
842 896
 				// Search is case insensitive.
843
-				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
844
-					unset($suggestions[$i]);
897
+				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) {
898
+									unset($suggestions[$i]);
899
+				}
845 900
 				// Plus, don't suggest something the user thinks is rude!
846
-				elseif ($suggestions[$i] != censorText($s))
847
-					unset($suggestions[$i]);
901
+				elseif ($suggestions[$i] != censorText($s)) {
902
+									unset($suggestions[$i]);
903
+				}
848 904
 			}
849 905
 
850 906
 			// Anything found?  If so, correct it!
@@ -854,8 +910,7 @@  discard block
 block discarded – undo
854 910
 				$did_you_mean['search'][] = $suggestions[0];
855 911
 				$did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
856 912
 				$found_misspelling = true;
857
-			}
858
-			else
913
+			} else
859 914
 			{
860 915
 				$did_you_mean['search'][] = $word;
861 916
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -872,8 +927,7 @@  discard block
 block discarded – undo
872 927
 				{
873 928
 					$temp_excluded['search'][] = '-"' . $word . '"';
874 929
 					$temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
875
-				}
876
-				else
930
+				} else
877 931
 				{
878 932
 					$temp_excluded['search'][] = '-' . $word;
879 933
 					$temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
@@ -885,11 +939,13 @@  discard block
 block discarded – undo
885 939
 
886 940
 			$temp_params = $search_params;
887 941
 			$temp_params['search'] = implode(' ', $did_you_mean['search']);
888
-			if (isset($temp_params['brd']))
889
-				$temp_params['brd'] = implode(',', $temp_params['brd']);
942
+			if (isset($temp_params['brd'])) {
943
+							$temp_params['brd'] = implode(',', $temp_params['brd']);
944
+			}
890 945
 			$context['params'] = array();
891
-			foreach ($temp_params as $k => $v)
892
-				$context['did_you_mean_params'][] = $k . '|\'|' . $v;
946
+			foreach ($temp_params as $k => $v) {
947
+							$context['did_you_mean_params'][] = $k . '|\'|' . $v;
948
+			}
893 949
 			$context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
894 950
 			$context['did_you_mean'] = implode(' ', $did_you_mean['display']);
895 951
 		}
@@ -897,18 +953,20 @@  discard block
 block discarded – undo
897 953
 
898 954
 	// Let the user adjust the search query, should they wish?
899 955
 	$context['search_params'] = $search_params;
900
-	if (isset($context['search_params']['search']))
901
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
902
-	if (isset($context['search_params']['userspec']))
903
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
956
+	if (isset($context['search_params']['search'])) {
957
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
958
+	}
959
+	if (isset($context['search_params']['userspec'])) {
960
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
961
+	}
904 962
 
905 963
 	// Do we have captcha enabled?
906 964
 	if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']))
907 965
 	{
908 966
 		// If we come from another search box tone down the error...
909
-		if (!isset($_REQUEST['search_vv']))
910
-			$context['search_errors']['need_verification_code'] = true;
911
-		else
967
+		if (!isset($_REQUEST['search_vv'])) {
968
+					$context['search_errors']['need_verification_code'] = true;
969
+		} else
912 970
 		{
913 971
 			require_once($sourcedir . '/Subs-Editor.php');
914 972
 			$verificationOptions = array(
@@ -918,12 +976,14 @@  discard block
 block discarded – undo
918 976
 
919 977
 			if (is_array($context['require_verification']))
920 978
 			{
921
-				foreach ($context['require_verification'] as $error)
922
-					$context['search_errors'][$error] = true;
979
+				foreach ($context['require_verification'] as $error) {
980
+									$context['search_errors'][$error] = true;
981
+				}
923 982
 			}
924 983
 			// Don't keep asking for it - they've proven themselves worthy.
925
-			else
926
-				$_SESSION['ss_vv_passed'] = true;
984
+			else {
985
+							$_SESSION['ss_vv_passed'] = true;
986
+			}
927 987
 		}
928 988
 	}
929 989
 
@@ -931,19 +991,22 @@  discard block
 block discarded – undo
931 991
 
932 992
 	// All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below.
933 993
 	$temp_params = $search_params;
934
-	if (isset($temp_params['brd']))
935
-		$temp_params['brd'] = implode(',', $temp_params['brd']);
994
+	if (isset($temp_params['brd'])) {
995
+			$temp_params['brd'] = implode(',', $temp_params['brd']);
996
+	}
936 997
 	$context['params'] = array();
937
-	foreach ($temp_params as $k => $v)
938
-		$context['params'][] = $k . '|\'|' . $v;
998
+	foreach ($temp_params as $k => $v) {
999
+			$context['params'][] = $k . '|\'|' . $v;
1000
+	}
939 1001
 
940 1002
 	if (!empty($context['params']))
941 1003
 	{
942 1004
 		// Due to old IE's 2083 character limit, we have to compress long search strings
943 1005
 		$params = @gzcompress(implode('|"|', $context['params']));
944 1006
 		// Gzcompress failed, use try non-gz
945
-		if (empty($params))
946
-			$params = implode('|"|', $context['params']);
1007
+		if (empty($params)) {
1008
+					$params = implode('|"|', $context['params']);
1009
+		}
947 1010
 		// Base64 encode, then replace +/= with uri safe ones that can be reverted
948 1011
 		$context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params));
949 1012
 	}
@@ -969,8 +1032,9 @@  discard block
 block discarded – undo
969 1032
 	}
970 1033
 
971 1034
 	// Spam me not, Spam-a-lot?
972
-	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])
973
-		spamProtection('search');
1035
+	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) {
1036
+			spamProtection('search');
1037
+	}
974 1038
 	// Store the last search string to allow pages of results to be browsed.
975 1039
 	$_SESSION['last_ss'] = $search_params['search'];
976 1040
 
@@ -1030,8 +1094,9 @@  discard block
 block discarded – undo
1030 1094
 						'where' => array(),
1031 1095
 					);
1032 1096
 
1033
-					if ($modSettings['postmod_active'])
1034
-						$subject_query['where'][] = 't.approved = {int:is_approved}';
1097
+					if ($modSettings['postmod_active']) {
1098
+											$subject_query['where'][] = 't.approved = {int:is_approved}';
1099
+					}
1035 1100
 
1036 1101
 					$numTables = 0;
1037 1102
 					$prev_join = 0;
@@ -1043,8 +1108,7 @@  discard block
 block discarded – undo
1043 1108
 						{
1044 1109
 							$subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)';
1045 1110
 							$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1046
-						}
1047
-						else
1111
+						} else
1048 1112
 						{
1049 1113
 							$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1050 1114
 							$subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}');
@@ -1062,14 +1126,18 @@  discard block
 block discarded – undo
1062 1126
 						}
1063 1127
 						$subject_query['where'][] = $userQuery;
1064 1128
 					}
1065
-					if (!empty($search_params['topic']))
1066
-						$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1067
-					if (!empty($minMsgID))
1068
-						$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1069
-					if (!empty($maxMsgID))
1070
-						$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1071
-					if (!empty($boardQuery))
1072
-						$subject_query['where'][] = 't.id_board ' . $boardQuery;
1129
+					if (!empty($search_params['topic'])) {
1130
+											$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1131
+					}
1132
+					if (!empty($minMsgID)) {
1133
+											$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1134
+					}
1135
+					if (!empty($maxMsgID)) {
1136
+											$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1137
+					}
1138
+					if (!empty($boardQuery)) {
1139
+											$subject_query['where'][] = 't.id_board ' . $boardQuery;
1140
+					}
1073 1141
 					if (!empty($excludedPhrases))
1074 1142
 					{
1075 1143
 						if ($subject_query['from'] != '{db_prefix}messages AS m')
@@ -1089,8 +1157,9 @@  discard block
 block discarded – undo
1089 1157
 					foreach ($weight_factors as $type => $value)
1090 1158
 					{
1091 1159
 						$relevance .= $weight[$type];
1092
-						if (!empty($value['results']))
1093
-							$relevance .= ' * ' . $value['results'];
1160
+						if (!empty($value['results'])) {
1161
+													$relevance .= ' * ' . $value['results'];
1162
+						}
1094 1163
 						$relevance .= ' + ';
1095 1164
 					}
1096 1165
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1128,20 +1197,23 @@  discard block
 block discarded – undo
1128 1197
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1129 1198
 						{
1130 1199
 							// No duplicates!
1131
-							if (isset($inserts[$row[1]]))
1132
-								continue;
1200
+							if (isset($inserts[$row[1]])) {
1201
+															continue;
1202
+							}
1133 1203
 
1134
-							foreach ($row as $key => $value)
1135
-								$inserts[$row[1]][] = (int) $row[$key];
1204
+							foreach ($row as $key => $value) {
1205
+															$inserts[$row[1]][] = (int) $row[$key];
1206
+							}
1136 1207
 						}
1137 1208
 						$smcFunc['db_free_result']($ignoreRequest);
1138 1209
 						$numSubjectResults = count($inserts);
1210
+					} else {
1211
+											$numSubjectResults += $smcFunc['db_affected_rows']();
1139 1212
 					}
1140
-					else
1141
-						$numSubjectResults += $smcFunc['db_affected_rows']();
1142 1213
 
1143
-					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1144
-						break;
1214
+					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1215
+											break;
1216
+					}
1145 1217
 				}
1146 1218
 
1147 1219
 				// If there's data to be inserted for non-IGNORE databases do it here!
@@ -1156,8 +1228,7 @@  discard block
 block discarded – undo
1156 1228
 				}
1157 1229
 
1158 1230
 				$_SESSION['search_cache']['num_results'] = $numSubjectResults;
1159
-			}
1160
-			else
1231
+			} else
1161 1232
 			{
1162 1233
 				$main_query = array(
1163 1234
 					'select' => array(
@@ -1189,8 +1260,7 @@  discard block
 block discarded – undo
1189 1260
 					$main_query['weights'] = $weight_factors;
1190 1261
 
1191 1262
 					$main_query['group_by'][] = 't.id_topic';
1192
-				}
1193
-				else
1263
+				} else
1194 1264
 				{
1195 1265
 					// This is outrageous!
1196 1266
 					$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
@@ -1211,8 +1281,9 @@  discard block
 block discarded – undo
1211 1281
 						$main_query['where'][] = 't.id_topic = {int:topic}';
1212 1282
 						$main_query['parameters']['topic'] = $search_params['topic'];
1213 1283
 					}
1214
-					if (!empty($search_params['show_complete']))
1215
-						$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1284
+					if (!empty($search_params['show_complete'])) {
1285
+											$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1286
+					}
1216 1287
 				}
1217 1288
 
1218 1289
 				// *** Get the subject results.
@@ -1239,14 +1310,15 @@  discard block
 block discarded – undo
1239 1310
 					) !== false;
1240 1311
 
1241 1312
 					// Clean up some previous cache.
1242
-					if (!$createTemporary)
1243
-						$smcFunc['db_search_query']('delete_log_search_topics', '
1313
+					if (!$createTemporary) {
1314
+											$smcFunc['db_search_query']('delete_log_search_topics', '
1244 1315
 							DELETE FROM {db_prefix}log_search_topics
1245 1316
 							WHERE id_search = {int:search_id}',
1246 1317
 							array(
1247 1318
 								'search_id' => $_SESSION['search_cache']['id_search'],
1248 1319
 							)
1249 1320
 						);
1321
+					}
1250 1322
 
1251 1323
 					foreach ($searchWords as $orIndex => $words)
1252 1324
 					{
@@ -1278,8 +1350,7 @@  discard block
 block discarded – undo
1278 1350
 								$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1279 1351
 								$subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}';
1280 1352
 								$subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]';
1281
-							}
1282
-							else
1353
+							} else
1283 1354
 							{
1284 1355
 								$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1285 1356
 								$subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}';
@@ -1334,8 +1405,9 @@  discard block
 block discarded – undo
1334 1405
 						call_integration_hook('integrate_subject_search_query', array(&$subject_query));
1335 1406
 
1336 1407
 						// Nothing to search for?
1337
-						if (empty($subject_query['where']))
1338
-							continue;
1408
+						if (empty($subject_query['where'])) {
1409
+													continue;
1410
+						}
1339 1411
 
1340 1412
 						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1341 1413
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
@@ -1358,19 +1430,21 @@  discard block
 block discarded – undo
1358 1430
 							{
1359 1431
 								$ind = $createTemporary ? 0 : 1;
1360 1432
 								// No duplicates!
1361
-								if (isset($inserts[$row[$ind]]))
1362
-									continue;
1433
+								if (isset($inserts[$row[$ind]])) {
1434
+																	continue;
1435
+								}
1363 1436
 
1364 1437
 								$inserts[$row[$ind]] = $row;
1365 1438
 							}
1366 1439
 							$smcFunc['db_free_result']($ignoreRequest);
1367 1440
 							$numSubjectResults = count($inserts);
1441
+						} else {
1442
+													$numSubjectResults += $smcFunc['db_affected_rows']();
1368 1443
 						}
1369
-						else
1370
-							$numSubjectResults += $smcFunc['db_affected_rows']();
1371 1444
 
1372
-						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1373
-							break;
1445
+						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1446
+													break;
1447
+						}
1374 1448
 					}
1375 1449
 
1376 1450
 					// Got some non-MySQL data to plonk in?
@@ -1388,8 +1462,9 @@  discard block
 block discarded – undo
1388 1462
 					{
1389 1463
 						$main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END';
1390 1464
 						$main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)';
1391
-						if (!$createTemporary)
1392
-							$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1465
+						if (!$createTemporary) {
1466
+													$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1467
+						}
1393 1468
 					}
1394 1469
 				}
1395 1470
 
@@ -1417,14 +1492,15 @@  discard block
 block discarded – undo
1417 1492
 					) !== false;
1418 1493
 
1419 1494
 					// Clear, all clear!
1420
-					if (!$createTemporary)
1421
-						$smcFunc['db_search_query']('delete_log_search_messages', '
1495
+					if (!$createTemporary) {
1496
+											$smcFunc['db_search_query']('delete_log_search_messages', '
1422 1497
 							DELETE FROM {db_prefix}log_search_messages
1423 1498
 							WHERE id_search = {int:id_search}',
1424 1499
 							array(
1425 1500
 								'id_search' => $_SESSION['search_cache']['id_search'],
1426 1501
 							)
1427 1502
 						);
1503
+					}
1428 1504
 
1429 1505
 					foreach ($searchWords as $orIndex => $words)
1430 1506
 					{
@@ -1458,19 +1534,21 @@  discard block
 block discarded – undo
1458 1534
 								while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1459 1535
 								{
1460 1536
 									// No duplicates!
1461
-									if (isset($inserts[$row[0]]))
1462
-										continue;
1537
+									if (isset($inserts[$row[0]])) {
1538
+																			continue;
1539
+									}
1463 1540
 
1464 1541
 									$inserts[$row[0]] = $row;
1465 1542
 								}
1466 1543
 								$smcFunc['db_free_result']($ignoreRequest);
1467 1544
 								$indexedResults = count($inserts);
1545
+							} else {
1546
+															$indexedResults += $smcFunc['db_affected_rows']();
1468 1547
 							}
1469
-							else
1470
-								$indexedResults += $smcFunc['db_affected_rows']();
1471 1548
 
1472
-							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults)
1473
-								break;
1549
+							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) {
1550
+															break;
1551
+							}
1474 1552
 						}
1475 1553
 					}
1476 1554
 
@@ -1490,8 +1568,7 @@  discard block
 block discarded – undo
1490 1568
 						$context['search_errors']['query_not_specific_enough'] = true;
1491 1569
 						$_REQUEST['params'] = $context['params'];
1492 1570
 						return PlushSearch1();
1493
-					}
1494
-					elseif (!empty($indexedResults))
1571
+					} elseif (!empty($indexedResults))
1495 1572
 					{
1496 1573
 						$main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)';
1497 1574
 						if (!$createTemporary)
@@ -1513,15 +1590,18 @@  discard block
 block discarded – undo
1513 1590
 						foreach ($words['all_words'] as $regularWord)
1514 1591
 						{
1515 1592
 							$where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1516
-							if (in_array($regularWord, $excludedWords))
1517
-								$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1593
+							if (in_array($regularWord, $excludedWords)) {
1594
+															$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1595
+							}
1518 1596
 							$main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
1519 1597
 						}
1520
-						if (!empty($where))
1521
-							$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1598
+						if (!empty($where)) {
1599
+													$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1600
+						}
1601
+					}
1602
+					if (!empty($orWhere)) {
1603
+											$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1522 1604
 					}
1523
-					if (!empty($orWhere))
1524
-						$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1525 1605
 
1526 1606
 					if (!empty($userQuery))
1527 1607
 					{
@@ -1559,8 +1639,9 @@  discard block
 block discarded – undo
1559 1639
 					foreach ($main_query['weights'] as $type => $value)
1560 1640
 					{
1561 1641
 						$relevance .= $weight[$type];
1562
-						if (!empty($value['search']))
1563
-							$relevance .= ' * ' . $value['search'];
1642
+						if (!empty($value['search'])) {
1643
+													$relevance .= ' * ' . $value['search'];
1644
+						}
1564 1645
 						$relevance .= ' + ';
1565 1646
 						$new_weight_total += $weight[$type];
1566 1647
 					}
@@ -1591,11 +1672,13 @@  discard block
 block discarded – undo
1591 1672
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1592 1673
 						{
1593 1674
 							// No duplicates!
1594
-							if (isset($inserts[$row[2]]))
1595
-								continue;
1675
+							if (isset($inserts[$row[2]])) {
1676
+															continue;
1677
+							}
1596 1678
 
1597
-							foreach ($row as $key => $value)
1598
-								$inserts[$row[2]][] = (int) $row[$key];
1679
+							foreach ($row as $key => $value) {
1680
+															$inserts[$row[2]][] = (int) $row[$key];
1681
+							}
1599 1682
 						}
1600 1683
 						$smcFunc['db_free_result']($ignoreRequest);
1601 1684
 
@@ -1603,8 +1686,9 @@  discard block
 block discarded – undo
1603 1686
 						if (!empty($inserts))
1604 1687
 						{
1605 1688
 							$query_columns = array();
1606
-							foreach ($main_query['select'] as $k => $v)
1607
-								$query_columns[$k] = 'int';
1689
+							foreach ($main_query['select'] as $k => $v) {
1690
+															$query_columns[$k] = 'int';
1691
+							}
1608 1692
 
1609 1693
 							$smcFunc['db_insert']('',
1610 1694
 								'{db_prefix}log_search_results',
@@ -1614,21 +1698,23 @@  discard block
 block discarded – undo
1614 1698
 							);
1615 1699
 						}
1616 1700
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1701
+					} else {
1702
+											$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1617 1703
 					}
1618
-					else
1619
-						$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1620 1704
 				}
1621 1705
 
1622 1706
 				// Insert subject-only matches.
1623 1707
 				if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0)
1624 1708
 				{
1625 1709
 					$relevance = '1000 * (';
1626
-					foreach ($weight_factors as $type => $value)
1627
-						if (isset($value['results']))
1710
+					foreach ($weight_factors as $type => $value) {
1711
+											if (isset($value['results']))
1628 1712
 						{
1629 1713
 							$relevance .= $weight[$type];
1630
-							if (!empty($value['results']))
1631
-								$relevance .= ' * ' . $value['results'];
1714
+					}
1715
+							if (!empty($value['results'])) {
1716
+															$relevance .= ' * ' . $value['results'];
1717
+							}
1632 1718
 							$relevance .= ' + ';
1633 1719
 						}
1634 1720
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1662,8 +1748,9 @@  discard block
 block discarded – undo
1662 1748
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1663 1749
 						{
1664 1750
 							// No duplicates!
1665
-							if (isset($usedIDs[$row[1]]))
1666
-								continue;
1751
+							if (isset($usedIDs[$row[1]])) {
1752
+															continue;
1753
+							}
1667 1754
 
1668 1755
 							$usedIDs[$row[1]] = true;
1669 1756
 							$inserts[] = $row;
@@ -1681,12 +1768,12 @@  discard block
 block discarded – undo
1681 1768
 							);
1682 1769
 						}
1683 1770
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1771
+					} else {
1772
+											$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1684 1773
 					}
1685
-					else
1686
-						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1774
+				} elseif ($_SESSION['search_cache']['num_results'] == -1) {
1775
+									$_SESSION['search_cache']['num_results'] = 0;
1687 1776
 				}
1688
-				elseif ($_SESSION['search_cache']['num_results'] == -1)
1689
-					$_SESSION['search_cache']['num_results'] = 0;
1690 1777
 			}
1691 1778
 		}
1692 1779
 
@@ -1756,14 +1843,16 @@  discard block
 block discarded – undo
1756 1843
 			)
1757 1844
 		);
1758 1845
 		$posters = array();
1759
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1760
-			$posters[] = $row['id_member'];
1846
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1847
+					$posters[] = $row['id_member'];
1848
+		}
1761 1849
 		$smcFunc['db_free_result']($request);
1762 1850
 
1763 1851
 		call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters));
1764 1852
 
1765
-		if (!empty($posters))
1766
-			loadMemberData(array_unique($posters));
1853
+		if (!empty($posters)) {
1854
+					loadMemberData(array_unique($posters));
1855
+		}
1767 1856
 
1768 1857
 		// Get the messages out for the callback - select enough that it can be made to look just like Display.
1769 1858
 		$messages_request = $smcFunc['db_query']('', '
@@ -1797,8 +1886,9 @@  discard block
 block discarded – undo
1797 1886
 		);
1798 1887
 
1799 1888
 		// If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore.
1800
-		if ($smcFunc['db_num_rows']($messages_request) == 0)
1801
-			$context['topics'] = array();
1889
+		if ($smcFunc['db_num_rows']($messages_request) == 0) {
1890
+					$context['topics'] = array();
1891
+		}
1802 1892
 
1803 1893
 		// If we want to know who participated in what then load this now.
1804 1894
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
@@ -1816,8 +1906,9 @@  discard block
 block discarded – undo
1816 1906
 					'limit' => count($participants),
1817 1907
 				)
1818 1908
 			);
1819
-			while ($row = $smcFunc['db_fetch_assoc']($result))
1820
-				$participants[$row['id_topic']] = true;
1909
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
1910
+							$participants[$row['id_topic']] = true;
1911
+			}
1821 1912
 			$smcFunc['db_free_result']($result);
1822 1913
 		}
1823 1914
 	}
@@ -1826,15 +1917,17 @@  discard block
 block discarded – undo
1826 1917
 	$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false);
1827 1918
 
1828 1919
 	// Consider the search complete!
1829
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1830
-		cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1920
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1921
+			cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1922
+	}
1831 1923
 
1832 1924
 	$context['key_words'] = &$searchArray;
1833 1925
 
1834 1926
 	// Setup the default topic icons... for checking they exist and the like!
1835 1927
 	$context['icon_sources'] = array();
1836
-	foreach ($context['stable_icons'] as $icon)
1837
-		$context['icon_sources'][$icon] = 'images_url';
1928
+	foreach ($context['stable_icons'] as $icon) {
1929
+			$context['icon_sources'][$icon] = 'images_url';
1930
+	}
1838 1931
 
1839 1932
 	$context['sub_template'] = 'results';
1840 1933
 	$context['page_title'] = $txt['search_results'];
@@ -1865,26 +1958,31 @@  discard block
 block discarded – undo
1865 1958
 	global $boards_can, $participants, $smcFunc;
1866 1959
 	static $recycle_board = null;
1867 1960
 
1868
-	if ($recycle_board === null)
1869
-		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1961
+	if ($recycle_board === null) {
1962
+			$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1963
+	}
1870 1964
 
1871 1965
 	// Remember which message this is.  (ie. reply #83)
1872 1966
 	static $counter = null;
1873
-	if ($counter == null || $reset)
1874
-		$counter = $_REQUEST['start'] + 1;
1967
+	if ($counter == null || $reset) {
1968
+			$counter = $_REQUEST['start'] + 1;
1969
+	}
1875 1970
 
1876 1971
 	// If the query returned false, bail.
1877
-	if ($messages_request == false)
1878
-		return false;
1972
+	if ($messages_request == false) {
1973
+			return false;
1974
+	}
1879 1975
 
1880 1976
 	// Start from the beginning...
1881
-	if ($reset)
1882
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1977
+	if ($reset) {
1978
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1979
+	}
1883 1980
 
1884 1981
 	// Attempt to get the next message.
1885 1982
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1886
-	if (!$message)
1887
-		return false;
1983
+	if (!$message) {
1984
+			return false;
1985
+	}
1888 1986
 
1889 1987
 	// Can't have an empty subject can we?
1890 1988
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1923,9 +2021,9 @@  discard block
 block discarded – undo
1923 2021
 
1924 2022
 		if ($smcFunc['strlen']($message['body']) > $charLimit)
1925 2023
 		{
1926
-			if (empty($context['key_words']))
1927
-				$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
1928
-			else
2024
+			if (empty($context['key_words'])) {
2025
+							$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
2026
+			} else
1929 2027
 			{
1930 2028
 				$matchString = '';
1931 2029
 				$force_partial_word = false;
@@ -1934,18 +2032,20 @@  discard block
 block discarded – undo
1934 2032
 					$keyword = un_htmlspecialchars($keyword);
1935 2033
 					$keyword = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
1936 2034
 
1937
-					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
1938
-						$force_partial_word = true;
2035
+					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) {
2036
+											$force_partial_word = true;
2037
+					}
1939 2038
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
1940 2039
 				}
1941 2040
 				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
1942 2041
 
1943 2042
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br>' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
1944 2043
 
1945
-				if (empty($modSettings['search_method']) || $force_partial_word)
1946
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
1947
-				else
1948
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2044
+				if (empty($modSettings['search_method']) || $force_partial_word) {
2045
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2046
+				} else {
2047
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2048
+				}
1949 2049
 
1950 2050
 				$message['body'] = '';
1951 2051
 				foreach ($matches[0] as $index => $match)
@@ -1958,8 +2058,7 @@  discard block
 block discarded – undo
1958 2058
 			// Re-fix the international characters.
1959 2059
 			$message['body'] = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
1960 2060
 		}
1961
-	}
1962
-	else
2061
+	} else
1963 2062
 	{
1964 2063
 		// Run BBC interpreter on the message.
1965 2064
 		$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
@@ -1978,21 +2077,26 @@  discard block
 block discarded – undo
1978 2077
 	// Sadly, we need to check the icon ain't broke.
1979 2078
 	if (!empty($modSettings['messageIconChecks_enable']))
1980 2079
 	{
1981
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1982
-			$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1983
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1984
-			$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1985
-		if (!isset($context['icon_sources'][$message['icon']]))
1986
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1987
-	}
1988
-	else
2080
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2081
+					$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
2082
+		}
2083
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2084
+					$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
2085
+		}
2086
+		if (!isset($context['icon_sources'][$message['icon']])) {
2087
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
2088
+		}
2089
+	} else
1989 2090
 	{
1990
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1991
-			$context['icon_sources'][$message['first_icon']] = 'images_url';
1992
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1993
-			$context['icon_sources'][$message['last_icon']] = 'images_url';
1994
-		if (!isset($context['icon_sources'][$message['icon']]))
1995
-			$context['icon_sources'][$message['icon']] = 'images_url';
2091
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2092
+					$context['icon_sources'][$message['first_icon']] = 'images_url';
2093
+		}
2094
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2095
+					$context['icon_sources'][$message['last_icon']] = 'images_url';
2096
+		}
2097
+		if (!isset($context['icon_sources'][$message['icon']])) {
2098
+					$context['icon_sources'][$message['icon']] = 'images_url';
2099
+		}
1996 2100
 	}
1997 2101
 
1998 2102
 	// Do we have quote tag enabled?
@@ -2002,12 +2106,14 @@  discard block
 block discarded – undo
2002 2106
 	$colorClass = 'windowbg';
2003 2107
 
2004 2108
 	// Sticky topics should get a different color, too.
2005
-	if ($message['is_sticky'])
2006
-		$colorClass .= ' sticky';
2109
+	if ($message['is_sticky']) {
2110
+			$colorClass .= ' sticky';
2111
+	}
2007 2112
 
2008 2113
 	// Locked topics get special treatment as well.
2009
-	if ($message['locked'])
2010
-		$colorClass .= ' locked';
2114
+	if ($message['locked']) {
2115
+			$colorClass .= ' locked';
2116
+	}
2011 2117
 
2012 2118
 	$output = array_merge($context['topics'][$message['id_msg']], array(
2013 2119
 		'id' => $message['id_topic'],
@@ -2151,8 +2257,9 @@  discard block
 block discarded – undo
2151 2257
 
2152 2258
 	// Load up the search API we are going to use.
2153 2259
 	$modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
2154
-	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'))
2155
-		fatal_lang_error('search_api_missing');
2260
+	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) {
2261
+			fatal_lang_error('search_api_missing');
2262
+	}
2156 2263
 	require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php');
2157 2264
 
2158 2265
 	// Create an instance of the search API and check it is valid for this version of SMF.
Please login to merge, or discard this patch.
Sources/ManageMail.php 1 patch
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Main dispatcher. This function checks permissions and passes control through to the relevant section.
@@ -245,8 +246,9 @@  discard block
 block discarded – undo
245 246
 	while ($row = $smcFunc['db_fetch_assoc']($request))
246 247
 	{
247 248
 		// Private PM/email subjects and similar shouldn't be shown in the mailbox area.
248
-		if (!empty($row['private']))
249
-			$row['subject'] = $txt['personal_message'];
249
+		if (!empty($row['private'])) {
250
+					$row['subject'] = $txt['personal_message'];
251
+		}
250 252
 
251 253
 		$mails[] = $row;
252 254
 	}
@@ -300,8 +302,9 @@  discard block
 block discarded – undo
300 302
 		$element = substr($key, strrpos($key, '_') + 1);
301 303
 		$processedBirthdayEmails[$index][$element] = $value;
302 304
 	}
303
-	foreach ($processedBirthdayEmails as $index => $dummy)
304
-		$emails[$index] = $index;
305
+	foreach ($processedBirthdayEmails as $index => $dummy) {
306
+			$emails[$index] = $index;
307
+	}
305 308
 
306 309
 	$config_vars = array(
307 310
 			// Mail queue stuff, this rocks ;)
@@ -322,8 +325,9 @@  discard block
 block discarded – undo
322 325
 
323 326
 	call_integration_hook('integrate_modify_mail_settings', array(&$config_vars));
324 327
 
325
-	if ($return_config)
326
-		return $config_vars;
328
+	if ($return_config) {
329
+			return $config_vars;
330
+	}
327 331
 
328 332
 	// Saving?
329 333
 	if (isset($_GET['save']))
@@ -398,9 +402,9 @@  discard block
 block discarded – undo
398 402
 		);
399 403
 		list ($_GET['te']) = $smcFunc['db_fetch_row']($request);
400 404
 		$smcFunc['db_free_result']($request);
405
+	} else {
406
+			$_GET['te'] = (int) $_GET['te'];
401 407
 	}
402
-	else
403
-		$_GET['te'] = (int) $_GET['te'];
404 408
 
405 409
 	$_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0;
406 410
 
@@ -424,12 +428,14 @@  discard block
 block discarded – undo
424 428
 
425 429
 	// Try get more time...
426 430
 	@set_time_limit(600);
427
-	if (function_exists('apache_reset_timeout'))
428
-		@apache_reset_timeout();
431
+	if (function_exists('apache_reset_timeout')) {
432
+			@apache_reset_timeout();
433
+	}
429 434
 
430 435
 	// Have we already used our maximum time?
431
-	if (time() - array_sum(explode(' ', $time_start)) < 5)
432
-		return;
436
+	if (time() - array_sum(explode(' ', $time_start)) < 5) {
437
+			return;
438
+	}
433 439
 
434 440
 	$context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id'];
435 441
 	$context['page_title'] = $txt['not_done_title'];
@@ -459,8 +465,9 @@  discard block
 block discarded – undo
459 465
 {
460 466
 	global $txt;
461 467
 
462
-	if ($time_diff < 0)
463
-		$time_diff = 0;
468
+	if ($time_diff < 0) {
469
+			$time_diff = 0;
470
+	}
464 471
 
465 472
 	// Just do a bit of an if fest...
466 473
 	if ($time_diff > 86400)
@@ -481,8 +488,9 @@  discard block
 block discarded – undo
481 488
 		return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes);
482 489
 	}
483 490
 	// Otherwise must be second
484
-	else
485
-		return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
486
-}
491
+	else {
492
+			return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
493
+	}
494
+	}
487 495
 
488 496
 ?>
489 497
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/DbPackages-postgresql.php 1 patch
Braces   +110 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
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
103 105
 
104 106
 	// First - no way do we touch SMF tables.
105
-	if (in_array(strtolower($table_name), $reservedTables))
106
-		return false;
107
+	if (in_array(strtolower($table_name), $reservedTables)) {
108
+			return false;
109
+	}
107 110
 
108 111
 	// Log that we'll want to remove this on uninstall.
109 112
 	$db_package_log[] = array('remove_table', $table_name);
@@ -113,10 +116,11 @@  discard block
 block discarded – undo
113 116
 	if (in_array($full_table_name, $tables))
114 117
 	{
115 118
 		// This is a sad day... drop the table? If not, return false (error) by default.
116
-		if ($if_exists == 'overwrite')
117
-			$smcFunc['db_drop_table']($table_name);
118
-		else
119
-			return $if_exists == 'ignore';
119
+		if ($if_exists == 'overwrite') {
120
+					$smcFunc['db_drop_table']($table_name);
121
+		} else {
122
+					return $if_exists == 'ignore';
123
+		}
120 124
 	}
121 125
 
122 126
 	// If we've got this far - good news - no table exists. We can build our own!
@@ -134,17 +138,18 @@  discard block
 block discarded – undo
134 138
 				)
135 139
 			);
136 140
 			$default = 'default nextval(\'' . $table_name . '_seq\')';
141
+		} elseif (isset($column['default']) && $column['default'] !== null) {
142
+					$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
143
+		} else {
144
+					$default = '';
137 145
 		}
138
-		elseif (isset($column['default']) && $column['default'] !== null)
139
-			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
140
-		else
141
-			$default = '';
142 146
 
143 147
 		// Sort out the size...
144 148
 		$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
145 149
 		list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']);
146
-		if ($size !== null)
147
-			$type = $type . '(' . $size . ')';
150
+		if ($size !== null) {
151
+					$type = $type . '(' . $size . ')';
152
+		}
148 153
 
149 154
 		// Now just put it together!
150 155
 		$table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ',';
@@ -157,19 +162,21 @@  discard block
 block discarded – undo
157 162
 		$columns = implode(',', $index['columns']);
158 163
 
159 164
 		// Primary goes in the table...
160
-		if (isset($index['type']) && $index['type'] == 'primary')
161
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
162
-		else
165
+		if (isset($index['type']) && $index['type'] == 'primary') {
166
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
167
+		} else
163 168
 		{
164
-			if (empty($index['name']))
165
-				$index['name'] = implode('_', $index['columns']);
169
+			if (empty($index['name'])) {
170
+							$index['name'] = implode('_', $index['columns']);
171
+			}
166 172
 			$index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')';
167 173
 		}
168 174
 	}
169 175
 
170 176
 	// No trailing commas!
171
-	if (substr($table_query, -1) == ',')
172
-		$table_query = substr($table_query, 0, -1);
177
+	if (substr($table_query, -1) == ',') {
178
+			$table_query = substr($table_query, 0, -1);
179
+	}
173 180
 
174 181
 	$table_query .= ')';
175 182
 
@@ -180,12 +187,13 @@  discard block
 block discarded – undo
180 187
 		)
181 188
 	);
182 189
 	// And the indexes...
183
-	foreach ($index_queries as $query)
184
-		$smcFunc['db_query']('', $query,
190
+	foreach ($index_queries as $query) {
191
+			$smcFunc['db_query']('', $query,
185 192
 		array(
186 193
 			'security_override' => true,
187 194
 		)
188 195
 	);
196
+	}
189 197
 
190 198
 	// Go, go power rangers!
191 199
 	$smcFunc['db_transaction']('commit');
@@ -213,8 +221,9 @@  discard block
 block discarded – undo
213 221
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
214 222
 
215 223
 	// God no - dropping one of these = bad.
216
-	if (in_array(strtolower($table_name), $reservedTables))
217
-		return false;
224
+	if (in_array(strtolower($table_name), $reservedTables)) {
225
+			return false;
226
+	}
218 227
 
219 228
 	// Does it exist?
220 229
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -272,21 +281,24 @@  discard block
 block discarded – undo
272 281
 
273 282
 	// Does it exist - if so don't add it again!
274 283
 	$columns = $smcFunc['db_list_columns']($table_name, false);
275
-	foreach ($columns as $column)
276
-		if ($column == $column_info['name'])
284
+	foreach ($columns as $column) {
285
+			if ($column == $column_info['name'])
277 286
 		{
278 287
 			// If we're going to overwrite then use change column.
279 288
 			if ($if_exists == 'update')
280 289
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
281
-			else
282
-				return false;
290
+	}
291
+			else {
292
+							return false;
293
+			}
283 294
 		}
284 295
 
285 296
 	// Get the specifics...
286 297
 	$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
287 298
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
288
-	if ($size !== null)
289
-		$type = $type . '(' . $size . ')';
299
+	if ($size !== null) {
300
+			$type = $type . '(' . $size . ')';
301
+	}
290 302
 
291 303
 	// Now add the thing!
292 304
 	$query = '
@@ -301,11 +313,12 @@  discard block
 block discarded – undo
301 313
 	// If there's more attributes they need to be done via a change on PostgreSQL.
302 314
 	unset($column_info['type'], $column_info['size']);
303 315
 
304
-	if (count($column_info) != 1)
305
-		return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
306
-	else
307
-		return true;
308
-}
316
+	if (count($column_info) != 1) {
317
+			return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
318
+	} else {
319
+			return true;
320
+	}
321
+	}
309 322
 
310 323
 /**
311 324
  * Removes a column.
@@ -324,8 +337,8 @@  discard block
 block discarded – undo
324 337
 
325 338
 	// Does it exist?
326 339
 	$columns = $smcFunc['db_list_columns']($table_name, true);
327
-	foreach ($columns as $column)
328
-		if ($column['name'] == $column_name)
340
+	foreach ($columns as $column) {
341
+			if ($column['name'] == $column_name)
329 342
 		{
330 343
 			// If there is an auto we need remove it!
331 344
 			if ($column['auto'])
@@ -335,6 +348,7 @@  discard block
 block discarded – undo
335 348
 						'security_override' => true,
336 349
 					)
337 350
 				);
351
+	}
338 352
 
339 353
 			$smcFunc['db_query']('', '
340 354
 				ALTER TABLE ' . $table_name . '
@@ -368,13 +382,15 @@  discard block
 block discarded – undo
368 382
 	// Check it does exist!
369 383
 	$columns = $smcFunc['db_list_columns']($table_name, true);
370 384
 	$old_info = null;
371
-	foreach ($columns as $column)
372
-		if ($column['name'] == $old_column)
385
+	foreach ($columns as $column) {
386
+			if ($column['name'] == $old_column)
373 387
 			$old_info = $column;
388
+	}
374 389
 
375 390
 	// Nothing?
376
-	if ($old_info == null)
377
-		return false;
391
+	if ($old_info == null) {
392
+			return false;
393
+	}
378 394
 
379 395
 	// Now we check each bit individually and ALTER as required.
380 396
 	if (isset($column_info['name']) && $column_info['name'] != $old_column)
@@ -431,8 +447,9 @@  discard block
 block discarded – undo
431 447
 	{
432 448
 		$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
433 449
 		list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
434
-		if ($size !== null)
435
-			$type = $type . '(' . $size . ')';
450
+		if ($size !== null) {
451
+					$type = $type . '(' . $size . ')';
452
+		}
436 453
 
437 454
 		// The alter is a pain.
438 455
 		$smcFunc['db_transaction']('begin');
@@ -526,21 +543,23 @@  discard block
 block discarded – undo
526 543
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
527 544
 
528 545
 	// No columns = no index.
529
-	if (empty($index_info['columns']))
530
-		return false;
546
+	if (empty($index_info['columns'])) {
547
+			return false;
548
+	}
531 549
 	$columns = implode(',', $index_info['columns']);
532 550
 
533 551
 	// No name - make it up!
534 552
 	if (empty($index_info['name']))
535 553
 	{
536 554
 		// No need for primary.
537
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
538
-			$index_info['name'] = '';
539
-		else
540
-			$index_info['name'] = $table_name . implode('_', $index_info['columns']);
555
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
556
+					$index_info['name'] = '';
557
+		} else {
558
+					$index_info['name'] = $table_name . implode('_', $index_info['columns']);
559
+		}
560
+	} else {
561
+			$index_info['name'] = $table_name . $index_info['name'];
541 562
 	}
542
-	else
543
-		$index_info['name'] = $table_name . $index_info['name'];
544 563
 
545 564
 	// Log that we are going to want to remove this!
546 565
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -553,10 +572,11 @@  discard block
 block discarded – undo
553 572
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
554 573
 		{
555 574
 			// If we want to overwrite simply remove the current one then continue.
556
-			if ($if_exists != 'update' || $index['type'] == 'primary')
557
-				return false;
558
-			else
559
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
575
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
576
+							return false;
577
+			} else {
578
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
579
+			}
560 580
 		}
561 581
 	}
562 582
 
@@ -570,8 +590,7 @@  discard block
 block discarded – undo
570 590
 				'security_override' => true,
571 591
 			)
572 592
 		);
573
-	}
574
-	else
593
+	} else
575 594
 	{
576 595
 		$smcFunc['db_query']('', '
577 596
 			CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')',
@@ -599,8 +618,9 @@  discard block
 block discarded – undo
599 618
 
600 619
 	// Better exist!
601 620
 	$indexes = $smcFunc['db_list_indexes']($table_name, true);
602
-	if ($index_name != 'primary')
603
-		$index_name = $table_name . '_' . $index_name;
621
+	if ($index_name != 'primary') {
622
+			$index_name = $table_name . '_' . $index_name;
623
+	}
604 624
 
605 625
 	foreach ($indexes as $index)
606 626
 	{
@@ -664,8 +684,7 @@  discard block
 block discarded – undo
664 684
 			'datetime' => 'timestamp without time zone',
665 685
 			'timestamp' => 'timestamp without time zone',
666 686
 		);
667
-	}
668
-	else
687
+	} else
669 688
 	{
670 689
 		$types = array(
671 690
 			'character varying' => 'varchar',
@@ -681,14 +700,16 @@  discard block
 block discarded – undo
681 700
 	// Got it? Change it!
682 701
 	if (isset($types[$type_name]))
683 702
 	{
684
-		if ($type_name == 'tinytext')
685
-			$type_size = 255;
703
+		if ($type_name == 'tinytext') {
704
+					$type_size = 255;
705
+		}
686 706
 		$type_name = $types[$type_name];
687 707
 	}
688 708
 
689 709
 	// Only char fields got size
690
-	if (strpos($type_name, 'char') === false)
691
-			$type_size = null;
710
+	if (strpos($type_name, 'char') === false) {
711
+				$type_size = null;
712
+	}
692 713
 
693 714
 
694 715
 	return array($type_name, $type_size);
@@ -742,8 +763,7 @@  discard block
 block discarded – undo
742 763
 		if (!$detail)
743 764
 		{
744 765
 			$columns[] = $row['column_name'];
745
-		}
746
-		else
766
+		} else
747 767
 		{
748 768
 			$auto = false;
749 769
 			// What is the default?
@@ -751,11 +771,11 @@  discard block
 block discarded – undo
751 771
 			{
752 772
 				$default = null;
753 773
 				$auto = true;
774
+			} elseif (trim($row['column_default']) != '') {
775
+							$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
776
+			} else {
777
+							$default = null;
754 778
 			}
755
-			elseif (trim($row['column_default']) != '')
756
-				$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
757
-			else
758
-				$default = null;
759 779
 
760 780
 			// Make the type generic.
761 781
 			list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true);
@@ -806,26 +826,30 @@  discard block
 block discarded – undo
806 826
 	while ($row = $smcFunc['db_fetch_assoc']($result))
807 827
 	{
808 828
 		// Try get the columns that make it up.
809
-		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
810
-			continue;
829
+		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
830
+					continue;
831
+		}
811 832
 
812 833
 		$columns = explode(',', $matches[1]);
813 834
 
814
-		if (empty($columns))
815
-			continue;
835
+		if (empty($columns)) {
836
+					continue;
837
+		}
816 838
 
817
-		foreach ($columns as $k => $v)
818
-			$columns[$k] = trim($v);
839
+		foreach ($columns as $k => $v) {
840
+					$columns[$k] = trim($v);
841
+		}
819 842
 
820 843
 		// Fix up the name to be consistent cross databases
821
-		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1)
822
-			$row['name'] = 'PRIMARY';
823
-		else
824
-			$row['name'] = str_replace($table_name . '_', '', $row['name']);
844
+		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) {
845
+					$row['name'] = 'PRIMARY';
846
+		} else {
847
+					$row['name'] = str_replace($table_name . '_', '', $row['name']);
848
+		}
825 849
 
826
-		if (!$detail)
827
-			$indexes[] = $row['name'];
828
-		else
850
+		if (!$detail) {
851
+					$indexes[] = $row['name'];
852
+		} else
829 853
 		{
830 854
 			$indexes[$row['name']] = array(
831 855
 				'name' => $row['name'],
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 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
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
88 98
 	{
89
-		if (!$utf8 || $smcFunc['db_mb4'])
90
-			return $string;
99
+		if (!$utf8 || $smcFunc['db_mb4']) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i + 1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1283,13 +1340,16 @@  discard block
 block discarded – undo
1283 1340
 			$row['avatar_original'] = $row['avatar'];
1284 1341
 
1285 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1287
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1288 1346
 
1289
-			if (isset($row['member_ip']))
1290
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1291
-			if (isset($row['member_ip2']))
1292
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1293 1353
 			$new_loaded_ids[] = $row['id_member'];
1294 1354
 			$loaded_ids[] = $row['id_member'];
1295 1355
 			$row['options'] = array();
@@ -1308,8 +1368,9 @@  discard block
 block discarded – undo
1308 1368
 				'loaded_ids' => $new_loaded_ids,
1309 1369
 			)
1310 1370
 		);
1311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1312
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1313 1374
 		$smcFunc['db_free_result']($request);
1314 1375
 	}
1315 1376
 
@@ -1320,10 +1381,11 @@  discard block
 block discarded – undo
1320 1381
 	{
1321 1382
 		foreach ($loaded_ids as $a_member)
1322 1383
 		{
1323
-			if (!empty($user_profile[$a_member]['additional_groups']))
1324
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1325
-			else
1326
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1327 1389
 
1328 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1329 1391
 
@@ -1336,8 +1398,9 @@  discard block
 block discarded – undo
1336 1398
 
1337 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1338 1400
 	{
1339
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1340
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1341 1404
 	}
1342 1405
 
1343 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1363,14 +1426,17 @@  discard block
 block discarded – undo
1363 1426
 		foreach ($temp_mods as $id)
1364 1427
 		{
1365 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1366
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1367
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1368 1432
 
1369 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1370
-			if (!empty($row['icons']))
1371
-				$user_profile[$id]['icons'] = $row['icons'];
1372
-			if (!empty($row['member_group_color']))
1373
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1374 1440
 		}
1375 1441
 	}
1376 1442
 
@@ -1392,12 +1458,14 @@  discard block
 block discarded – undo
1392 1458
 	static $loadedLanguages = array();
1393 1459
 
1394 1460
 	// If this person's data is already loaded, skip it.
1395
-	if (isset($dataLoaded[$user]))
1396
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1397 1464
 
1398 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1399
-	if ($user == 0)
1400
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1401 1469
 	if (!isset($user_profile[$user]))
1402 1470
 	{
1403 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1423,12 +1491,16 @@  discard block
 block discarded – undo
1423 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1424 1492
 
1425 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1426
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1427 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1428
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1429 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1431 1502
 		$group_icon_url = '';
1503
+	}
1432 1504
 
1433 1505
 	// These minimal values are always loaded
1434 1506
 	$memberContext[$user] = array(
@@ -1447,8 +1519,9 @@  discard block
 block discarded – undo
1447 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1448 1520
 	{
1449 1521
 		// Go the extra mile and load the user's native language name.
1450
-		if (empty($loadedLanguages))
1451
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1452 1525
 
1453 1526
 		$memberContext[$user] += array(
1454 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1502,31 +1575,33 @@  discard block
 block discarded – undo
1502 1575
 	{
1503 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1504 1577
 		{
1505
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1506
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1507
-			else
1508
-				$image = get_gravatar_url($profile['email_address']);
1509
-		}
1510
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1511 1584
 		{
1512 1585
 			// So it's stored in the member table?
1513 1586
 			if (!empty($profile['avatar']))
1514 1587
 			{
1515 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1591
 			}
1517
-			elseif (!empty($profile['filename']))
1518
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1519 1592
 			// Right... no avatar...use the default one
1520
-			else
1521
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1522 1596
 		}
1523
-		if (!empty($image))
1524
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1525 1599
 				'name' => $profile['avatar'],
1526 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1527 1601
 				'href' => $image,
1528 1602
 				'url' => $image,
1529 1603
 			);
1604
+		}
1530 1605
 	}
1531 1606
 
1532 1607
 	// Are we also loading the members custom fields into context?
@@ -1534,35 +1609,41 @@  discard block
 block discarded – undo
1534 1609
 	{
1535 1610
 		$memberContext[$user]['custom_fields'] = array();
1536 1611
 
1537
-		if (!isset($context['display_fields']))
1538
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1614
+		}
1539 1615
 
1540 1616
 		foreach ($context['display_fields'] as $custom)
1541 1617
 		{
1542
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1543
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1544 1621
 
1545 1622
 			$value = $profile['options'][$custom['col_name']];
1546 1623
 
1547 1624
 			// Don't show the "disabled" option for the "gender" field.
1548
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1549
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1550 1628
 
1551 1629
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1554 1633
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1557 1637
 
1558 1638
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1561 1641
 					'{SCRIPTURL}' => $scripturl,
1562 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1644
 					'{INPUT}' => $value,
1565 1645
 				));
1646
+			}
1566 1647
 
1567 1648
 			$memberContext[$user]['custom_fields'][] = array(
1568 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1670,9 @@  discard block
 block discarded – undo
1589 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1671
 
1591 1672
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1594 1676
 
1595 1677
 	// Make sure it's an array.
1596 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1614,31 +1696,36 @@  discard block
 block discarded – undo
1614 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1615 1697
 	{
1616 1698
 		// BBC?
1617
-		if (!empty($row['bbc']))
1618
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1619 1702
 
1620 1703
 		// ... or checkbox?
1621
-		elseif (isset($row['type']) && $row['type'] == 'check')
1622
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1623 1707
 
1624 1708
 		// Enclosing the user input within some other text?
1625
-		if (!empty($row['enclose']))
1626
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1627 1711
 				'{SCRIPTURL}' => $scripturl,
1628 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1629 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1630 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1631 1715
 			));
1716
+		}
1632 1717
 
1633 1718
 		// Send a simple array if there is just 1 param
1634
-		if (count($params) == 1)
1635
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1636 1722
 
1637 1723
 		// More than 1? knock yourself out...
1638 1724
 		else
1639 1725
 		{
1640
-			if (!isset($return[$row['id_member']]))
1641
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1642 1729
 
1643 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1644 1731
 		}
@@ -1672,8 +1759,9 @@  discard block
 block discarded – undo
1672 1759
 	global $context;
1673 1760
 
1674 1761
 	// Don't know any browser!
1675
-	if (empty($context['browser']))
1676
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1677 1765
 
1678 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1679 1767
 }
@@ -1691,8 +1779,9 @@  discard block
 block discarded – undo
1691 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1692 1780
 
1693 1781
 	// The theme was specified by parameter.
1694
-	if (!empty($id_theme))
1695
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1696 1785
 	// The theme was specified by REQUEST.
1697 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1698 1787
 	{
@@ -1700,51 +1789,58 @@  discard block
 block discarded – undo
1700 1789
 		$_SESSION['id_theme'] = $id_theme;
1701 1790
 	}
1702 1791
 	// The theme was specified by REQUEST... previously.
1703
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1704
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1705 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1706
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1707
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1708 1799
 	// The theme was specified by the board.
1709
-	elseif (!empty($board_info['theme']))
1710
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1711 1803
 	// The theme is the forum's default.
1712
-	else
1713
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1714 1807
 
1715 1808
 	// Verify the id_theme... no foul play.
1716 1809
 	// Always allow the board specific theme, if they are overriding.
1717
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1718
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1719 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1720
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1721
-		$id_theme = (int) $id_theme;
1722
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1723 1817
 	{
1724 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1725
-		if (!in_array($id_theme, $themes))
1726
-			$id_theme = $modSettings['theme_guests'];
1727
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1728 1825
 			$id_theme = (int) $id_theme;
1729 1826
 	}
1730
-	else
1731
-		$id_theme = (int) $id_theme;
1732 1827
 
1733 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1734 1829
 
1735 1830
 	// Disable image proxy if we don't have SSL enabled
1736
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1737
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1738 1834
 
1739 1835
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1740 1836
 	{
1741 1837
 		$themeData = $temp;
1742 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1743 1843
 	}
1744
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1745
-		$themeData = $temp + array($member => array());
1746
-	else
1747
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1844
 
1749 1845
 	if (empty($flag))
1750 1846
 	{
@@ -1763,31 +1859,37 @@  discard block
 block discarded – undo
1763 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1764 1860
 		{
1765 1861
 			// There are just things we shouldn't be able to change as members.
1766
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1767
-				continue;
1862
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1863
+							continue;
1864
+			}
1768 1865
 
1769 1866
 			// If this is the theme_dir of the default theme, store it.
1770
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1771
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1772 1870
 
1773 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1774
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1775
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1776 1875
 		}
1777 1876
 		$smcFunc['db_free_result']($result);
1778 1877
 
1779
-		if (!empty($themeData[-1]))
1780
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1781 1880
 			{
1782 1881
 				if (!isset($themeData[$member][$k]))
1783 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1784 1884
 			}
1785 1885
 
1786
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1787
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1788 1889
 		// Only if we didn't already load that part of the cache...
1789
-		elseif (!isset($temp))
1790
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1791 1893
 	}
1792 1894
 
1793 1895
 	$settings = $themeData[0];
@@ -1804,20 +1906,24 @@  discard block
 block discarded – undo
1804 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1805 1907
 
1806 1908
 	// Based on theme (if there is one).
1807
-	if (!empty($settings['base_theme_dir']))
1808
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1809 1912
 
1810 1913
 	// Lastly the default theme.
1811
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1812
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1813 1917
 
1814
-	if (!$initialize)
1815
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1816 1921
 
1817 1922
 	// Check to see if we're forcing SSL
1818 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1821 1927
 
1822 1928
 	// Check to see if they're accessing it from the wrong place.
1823 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1931,9 @@  discard block
 block discarded – undo
1825 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1830 1937
 	}
1831 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1939
 	{
@@ -1838,8 +1945,9 @@  discard block
 block discarded – undo
1838 1945
 			foreach ($aliases as $alias)
1839 1946
 			{
1840 1947
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1843 1951
 			}
1844 1952
 		}
1845 1953
 
@@ -1847,20 +1955,22 @@  discard block
 block discarded – undo
1847 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1956
 		{
1849 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1853 1961
 			{
1854 1962
 				list ($k, $v) = each($_GET);
1855 1963
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1858 1967
 			}
1859 1968
 		}
1860 1969
 
1861 1970
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1864 1974
 
1865 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1894,8 +2004,9 @@  discard block
 block discarded – undo
1894 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1895 2005
 				}
1896 2006
 			}
1897
-			foreach ($context['linktree'] as $k => $dummy)
1898
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1899 2010
 		}
1900 2011
 	}
1901 2012
 	// Set up the contextual user array.
@@ -1914,16 +2025,16 @@  discard block
 block discarded – undo
1914 2025
 			'email' => $user_info['email'],
1915 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1916 2027
 		);
1917
-		if (!$context['user']['is_guest'])
1918
-			$context['user']['name'] = $user_info['name'];
1919
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1920
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1921 2033
 
1922 2034
 		// Determine the current smiley set.
1923 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1924 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1925
-	}
1926
-	else
2037
+	} else
1927 2038
 	{
1928 2039
 		$context['user'] = array(
1929 2040
 			'id' => -1,
@@ -1939,18 +2050,24 @@  discard block
 block discarded – undo
1939 2050
 	}
1940 2051
 
1941 2052
 	// Some basic information...
1942
-	if (!isset($context['html_headers']))
1943
-		$context['html_headers'] = '';
1944
-	if (!isset($context['javascript_files']))
1945
-		$context['javascript_files'] = array();
1946
-	if (!isset($context['css_files']))
1947
-		$context['css_files'] = array();
1948
-	if (!isset($context['css_header']))
1949
-		$context['css_header'] = array();
1950
-	if (!isset($context['javascript_inline']))
1951
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1952
-	if (!isset($context['javascript_vars']))
1953
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1954 2071
 
1955 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1956 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1962,8 +2079,9 @@  discard block
 block discarded – undo
1962 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1963 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1964 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1965
-	if (isset($modSettings['load_average']))
1966
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1967 2085
 
1968 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1969 2087
 	detectBrowser();
@@ -1977,8 +2095,9 @@  discard block
 block discarded – undo
1977 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1978 2096
 	$context['insert_after_template'] = '';
1979 2097
 
1980
-	if (!isset($txt))
1981
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1982 2101
 
1983 2102
 	$simpleActions = array(
1984 2103
 		'findmember',
@@ -2024,9 +2143,10 @@  discard block
 block discarded – undo
2024 2143
 
2025 2144
 	// See if theres any extra param to check.
2026 2145
 	$requiresXML = false;
2027
-	foreach ($extraParams as $key => $extra)
2028
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2029 2148
 			$requiresXML = true;
2149
+	}
2030 2150
 
2031 2151
 	// Output is fully XML, so no need for the index template.
2032 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2041,37 +2161,39 @@  discard block
 block discarded – undo
2041 2161
 	{
2042 2162
 		loadLanguage('index+Modifications');
2043 2163
 		$context['template_layers'] = array();
2044
-	}
2045
-
2046
-	else
2164
+	} else
2047 2165
 	{
2048 2166
 		// Custom templates to load, or just default?
2049
-		if (isset($settings['theme_templates']))
2050
-			$templates = explode(',', $settings['theme_templates']);
2051
-		else
2052
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2053 2172
 
2054 2173
 		// Load each template...
2055
-		foreach ($templates as $template)
2056
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2057 2177
 
2058 2178
 		// ...and attempt to load their associated language files.
2059 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2060 2180
 		loadLanguage($required_files, '', false);
2061 2181
 
2062 2182
 		// Custom template layers?
2063
-		if (isset($settings['theme_layers']))
2064
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2065
-		else
2066
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Initialize the theme.
2070 2191
 	loadSubTemplate('init', 'ignore');
2071 2192
 
2072 2193
 	// Allow overriding the board wide time/number formats.
2073
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2074
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2075 2197
 
2076 2198
 	// Set the character set from the template.
2077 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2079,12 +2201,14 @@  discard block
 block discarded – undo
2079 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2080 2202
 
2081 2203
 	// Guests may still need a name.
2082
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2083
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2084 2207
 
2085 2208
 	// Any theme-related strings that need to be loaded?
2086
-	if (!empty($settings['require_theme_strings']))
2087
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2088 2212
 
2089 2213
 	// Make a special URL for the language.
2090 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2095,8 +2219,9 @@  discard block
 block discarded – undo
2095 2219
 	// Here is my luvly Responsive CSS
2096 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2097 2221
 
2098
-	if ($context['right_to_left'])
2099
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2100 2225
 
2101 2226
 	// We allow theme variants, because we're cool.
2102 2227
 	$context['theme_variant'] = '';
@@ -2104,14 +2229,17 @@  discard block
 block discarded – undo
2104 2229
 	if (!empty($settings['theme_variants']))
2105 2230
 	{
2106 2231
 		// Overriding - for previews and that ilk.
2107
-		if (!empty($_REQUEST['variant']))
2108
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2109 2235
 		// User selection?
2110
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2111
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2112 2239
 		// If not a user variant, select the default.
2113
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2114
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2115 2243
 
2116 2244
 		// Do this to keep things easier in the templates.
2117 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2120,20 +2248,23 @@  discard block
 block discarded – undo
2120 2248
 		if (!empty($context['theme_variant']))
2121 2249
 		{
2122 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2123
-			if ($context['right_to_left'])
2124
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2125 2254
 		}
2126 2255
 	}
2127 2256
 
2128 2257
 	// Let's be compatible with old themes!
2129
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2130
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2131 2261
 
2132 2262
 	$context['tabindex'] = 1;
2133 2263
 
2134 2264
 	// Compatibility.
2135
-	if (!isset($settings['theme_version']))
2136
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2137 2268
 
2138 2269
 	// Default JS variables for use in every theme
2139 2270
 	$context['javascript_vars'] = array(
@@ -2152,18 +2283,18 @@  discard block
 block discarded – undo
2152 2283
 	);
2153 2284
 
2154 2285
 	// Add the JQuery library to the list of files to load.
2155
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2156
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2159
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2160
-
2161
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2162
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2163 2293
 
2164 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2165
-	else
2166
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2167 2298
 
2168 2299
 	// Queue our JQuery plugins!
2169 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2186,12 +2317,12 @@  discard block
 block discarded – undo
2186 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2187 2318
 
2188 2319
 			// What to do, what to do?!
2189
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2190
-				AutoTask();
2191
-			else
2192
-				ReduceMailQueue();
2193
-		}
2194
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2195 2326
 		{
2196 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2197 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2242,8 +2373,9 @@  discard block
 block discarded – undo
2242 2373
 		foreach ($theme_includes as $include)
2243 2374
 		{
2244 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2245
-			if (file_exists($include))
2246
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2247 2379
 		}
2248 2380
 	}
2249 2381
 
@@ -2273,16 +2405,19 @@  discard block
 block discarded – undo
2273 2405
 	// Do any style sheets first, cause we're easy with those.
2274 2406
 	if (!empty($style_sheets))
2275 2407
 	{
2276
-		if (!is_array($style_sheets))
2277
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2278 2411
 
2279
-		foreach ($style_sheets as $sheet)
2280
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2281 2415
 	}
2282 2416
 
2283 2417
 	// No template to load?
2284
-	if ($template_name === false)
2285
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2286 2421
 
2287 2422
 	$loaded = false;
2288 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2297,12 +2432,14 @@  discard block
 block discarded – undo
2297 2432
 
2298 2433
 	if ($loaded)
2299 2434
 	{
2300
-		if ($db_show_debug === true)
2301
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2302 2438
 
2303 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2304
-		if (function_exists('template_' . $template_name . '_init'))
2305
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2306 2443
 	}
2307 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2308 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2322,13 +2459,14 @@  discard block
 block discarded – undo
2322 2459
 		loadTemplate($template_name);
2323 2460
 	}
2324 2461
 	// Cause an error otherwise.
2325
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2326
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2327
-	elseif ($fatal)
2328
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2329
-	else
2330
-		return false;
2331
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2332 2470
 
2333 2471
 /**
2334 2472
  * Load a sub-template.
@@ -2346,17 +2484,19 @@  discard block
 block discarded – undo
2346 2484
 {
2347 2485
 	global $context, $txt, $db_show_debug;
2348 2486
 
2349
-	if ($db_show_debug === true)
2350
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2351 2490
 
2352 2491
 	// Figure out what the template function is named.
2353 2492
 	$theme_function = 'template_' . $sub_template_name;
2354
-	if (function_exists($theme_function))
2355
-		$theme_function();
2356
-	elseif ($fatal === false)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2358
-	elseif ($fatal !== 'ignore')
2359
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2499
+	}
2360 2500
 
2361 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2362 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2393,8 +2533,9 @@  discard block
 block discarded – undo
2393 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2394 2534
 
2395 2535
 	// If this is an external file, automatically set this to false.
2396
-	if (!empty($params['external']))
2397
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2398 2539
 
2399 2540
 	// Account for shorthand like admin.css?alp21 filenames
2400 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2411,13 +2552,10 @@  discard block
 block discarded – undo
2411 2552
 			{
2412 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2413 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2414 2557
 			}
2415
-
2416
-			else
2417
-				$fileUrl = false;
2418
-		}
2419
-
2420
-		else
2558
+		} else
2421 2559
 		{
2422 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2423 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2432,12 +2570,14 @@  discard block
 block discarded – undo
2432 2570
 	}
2433 2571
 
2434 2572
 	// Add it to the array for use in the template
2435
-	if (!empty($fileName))
2436
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2437 2576
 
2438
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2439
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2440
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2441 2581
 
2442 2582
 /**
2443 2583
  * Add a block of inline css code to be executed later
@@ -2454,8 +2594,9 @@  discard block
 block discarded – undo
2454 2594
 	global $context;
2455 2595
 
2456 2596
 	// Gotta add something...
2457
-	if (empty($css))
2458
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2459 2600
 
2460 2601
 	$context['css_header'][] = $css;
2461 2602
 }
@@ -2490,8 +2631,9 @@  discard block
 block discarded – undo
2490 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2491 2632
 
2492 2633
 	// If this is an external file, automatically set this to false.
2493
-	if (!empty($params['external']))
2494
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2495 2637
 
2496 2638
 	// Account for shorthand like admin.js?alp21 filenames
2497 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2508,16 +2650,12 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2510 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2511
-			}
2512
-
2513
-			else
2653
+			} else
2514 2654
 			{
2515 2655
 				$fileUrl = false;
2516 2656
 				$filePath = false;
2517 2657
 			}
2518
-		}
2519
-
2520
-		else
2658
+		} else
2521 2659
 		{
2522 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2523 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2532,9 +2670,10 @@  discard block
 block discarded – undo
2532 2670
 	}
2533 2671
 
2534 2672
 	// Add it to the array for use in the template
2535
-	if (!empty($fileName))
2536
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2537
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2538 2677
 
2539 2678
 /**
2540 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2548,9 +2687,10 @@  discard block
 block discarded – undo
2548 2687
 {
2549 2688
 	global $context;
2550 2689
 
2551
-	if (!empty($key) && (!empty($value) || $value === '0'))
2552
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2553
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2554 2694
 
2555 2695
 /**
2556 2696
  * Add a block of inline Javascript code to be executed later
@@ -2567,8 +2707,9 @@  discard block
 block discarded – undo
2567 2707
 {
2568 2708
 	global $context;
2569 2709
 
2570
-	if (empty($javascript))
2571
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2572 2713
 
2573 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2574 2715
 }
@@ -2589,15 +2730,18 @@  discard block
 block discarded – undo
2589 2730
 	static $already_loaded = array();
2590 2731
 
2591 2732
 	// Default to the user's language.
2592
-	if ($lang == '')
2593
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2594 2736
 
2595 2737
 	// Do we want the English version of language file as fallback?
2596
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2597
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2598 2741
 
2599
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2600
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2601 2745
 
2602 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2603 2747
 	if (empty($settings['default_theme_dir']))
@@ -2608,8 +2752,9 @@  discard block
 block discarded – undo
2608 2752
 
2609 2753
 	// What theme are we in?
2610 2754
 	$theme_name = basename($settings['theme_url']);
2611
-	if (empty($theme_name))
2612
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2613 2758
 
2614 2759
 	// For each file open it up and write it out!
2615 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2651,8 +2796,9 @@  discard block
 block discarded – undo
2651 2796
 				$found = true;
2652 2797
 
2653 2798
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2654
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2655
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2799
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2800
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2801
+				}
2656 2802
 
2657 2803
 				break;
2658 2804
 			}
@@ -2692,8 +2838,9 @@  discard block
 block discarded – undo
2692 2838
 	}
2693 2839
 
2694 2840
 	// Keep track of what we're up to soldier.
2695
-	if ($db_show_debug === true)
2696
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2841
+	if ($db_show_debug === true) {
2842
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2843
+	}
2697 2844
 
2698 2845
 	// Remember what we have loaded, and in which language.
2699 2846
 	$already_loaded[$template_name] = $lang;
@@ -2739,8 +2886,9 @@  discard block
 block discarded – undo
2739 2886
 				)
2740 2887
 			);
2741 2888
 			// In the EXTREMELY unlikely event this happens, give an error message.
2742
-			if ($smcFunc['db_num_rows']($result) == 0)
2743
-				fatal_lang_error('parent_not_found', 'critical');
2889
+			if ($smcFunc['db_num_rows']($result) == 0) {
2890
+							fatal_lang_error('parent_not_found', 'critical');
2891
+			}
2744 2892
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2745 2893
 			{
2746 2894
 				if (!isset($boards[$row['id_board']]))
@@ -2757,8 +2905,8 @@  discard block
 block discarded – undo
2757 2905
 					);
2758 2906
 				}
2759 2907
 				// If a moderator exists for this board, add that moderator for all children too.
2760
-				if (!empty($row['id_moderator']))
2761
-					foreach ($boards as $id => $dummy)
2908
+				if (!empty($row['id_moderator'])) {
2909
+									foreach ($boards as $id => $dummy)
2762 2910
 					{
2763 2911
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2764 2912
 							'id' => $row['id_moderator'],
@@ -2766,11 +2914,12 @@  discard block
 block discarded – undo
2766 2914
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2767 2915
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2768 2916
 						);
2917
+				}
2769 2918
 					}
2770 2919
 
2771 2920
 				// If a moderator group exists for this board, add that moderator group for all children too
2772
-				if (!empty($row['id_moderator_group']))
2773
-					foreach ($boards as $id => $dummy)
2921
+				if (!empty($row['id_moderator_group'])) {
2922
+									foreach ($boards as $id => $dummy)
2774 2923
 					{
2775 2924
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2776 2925
 							'id' => $row['id_moderator_group'],
@@ -2778,6 +2927,7 @@  discard block
 block discarded – undo
2778 2927
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2779 2928
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2780 2929
 						);
2930
+				}
2781 2931
 					}
2782 2932
 			}
2783 2933
 			$smcFunc['db_free_result']($result);
@@ -2804,23 +2954,27 @@  discard block
 block discarded – undo
2804 2954
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2805 2955
 	{
2806 2956
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2807
-		if (empty($smcFunc['ucwords']))
2808
-			reloadSettings();
2957
+		if (empty($smcFunc['ucwords'])) {
2958
+					reloadSettings();
2959
+		}
2809 2960
 
2810 2961
 		// If we don't have our theme information yet, let's get it.
2811
-		if (empty($settings['default_theme_dir']))
2812
-			loadTheme(0, false);
2962
+		if (empty($settings['default_theme_dir'])) {
2963
+					loadTheme(0, false);
2964
+		}
2813 2965
 
2814 2966
 		// Default language directories to try.
2815 2967
 		$language_directories = array(
2816 2968
 			$settings['default_theme_dir'] . '/languages',
2817 2969
 		);
2818
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2819
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2970
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2971
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2972
+		}
2820 2973
 
2821 2974
 		// We possibly have a base theme directory.
2822
-		if (!empty($settings['base_theme_dir']))
2823
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2975
+		if (!empty($settings['base_theme_dir'])) {
2976
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2977
+		}
2824 2978
 
2825 2979
 		// Remove any duplicates.
2826 2980
 		$language_directories = array_unique($language_directories);
@@ -2834,20 +2988,21 @@  discard block
 block discarded – undo
2834 2988
 		foreach ($language_directories as $language_dir)
2835 2989
 		{
2836 2990
 			// Can't look in here... doesn't exist!
2837
-			if (!file_exists($language_dir))
2838
-				continue;
2991
+			if (!file_exists($language_dir)) {
2992
+							continue;
2993
+			}
2839 2994
 
2840 2995
 			$dir = dir($language_dir);
2841 2996
 			while ($entry = $dir->read())
2842 2997
 			{
2843 2998
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2844
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2845
-					continue;
2846
-
2847
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2848
-					$langName = $langList[$matches[1]];
2999
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3000
+									continue;
3001
+				}
2849 3002
 
2850
-				else
3003
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3004
+									$langName = $langList[$matches[1]];
3005
+				} else
2851 3006
 				{
2852 3007
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2853 3008
 
@@ -2888,12 +3043,14 @@  discard block
 block discarded – undo
2888 3043
 		}
2889 3044
 
2890 3045
 		// Do we need to store the lang list?
2891
-		if (empty($langList))
2892
-			updateSettings(array('langList' => json_encode($catchLang)));
3046
+		if (empty($langList)) {
3047
+					updateSettings(array('langList' => json_encode($catchLang)));
3048
+		}
2893 3049
 
2894 3050
 		// Let's cash in on this deal.
2895
-		if (!empty($modSettings['cache_enable']))
2896
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3051
+		if (!empty($modSettings['cache_enable'])) {
3052
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3053
+		}
2897 3054
 	}
2898 3055
 
2899 3056
 	return $context['languages'];
@@ -2916,8 +3073,9 @@  discard block
 block discarded – undo
2916 3073
 	global $modSettings, $options, $txt;
2917 3074
 	static $censor_vulgar = null, $censor_proper;
2918 3075
 
2919
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2920
-		return $text;
3076
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3077
+			return $text;
3078
+	}
2921 3079
 
2922 3080
 	// If they haven't yet been loaded, load them.
2923 3081
 	if ($censor_vulgar == null)
@@ -2945,9 +3103,9 @@  discard block
 block discarded – undo
2945 3103
 	{
2946 3104
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2947 3105
 		$text = $func($censor_vulgar, $censor_proper, $text);
3106
+	} else {
3107
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2948 3108
 	}
2949
-	else
2950
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2951 3109
 
2952 3110
 	return $text;
2953 3111
 }
@@ -2973,38 +3131,42 @@  discard block
 block discarded – undo
2973 3131
 	@ini_set('track_errors', '1');
2974 3132
 
2975 3133
 	// Don't include the file more than once, if $once is true.
2976
-	if ($once && in_array($filename, $templates))
2977
-		return;
3134
+	if ($once && in_array($filename, $templates)) {
3135
+			return;
3136
+	}
2978 3137
 	// Add this file to the include list, whether $once is true or not.
2979
-	else
2980
-		$templates[] = $filename;
3138
+	else {
3139
+			$templates[] = $filename;
3140
+	}
2981 3141
 
2982 3142
 	// Are we going to use eval?
2983 3143
 	if (empty($modSettings['disableTemplateEval']))
2984 3144
 	{
2985 3145
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2986 3146
 		$settings['current_include_filename'] = $filename;
2987
-	}
2988
-	else
3147
+	} else
2989 3148
 	{
2990 3149
 		$file_found = file_exists($filename);
2991 3150
 
2992
-		if ($once && $file_found)
2993
-			require_once($filename);
2994
-		elseif ($file_found)
2995
-			require($filename);
3151
+		if ($once && $file_found) {
3152
+					require_once($filename);
3153
+		} elseif ($file_found) {
3154
+					require($filename);
3155
+		}
2996 3156
 	}
2997 3157
 
2998 3158
 	if ($file_found !== true)
2999 3159
 	{
3000 3160
 		ob_end_clean();
3001
-		if (!empty($modSettings['enableCompressedOutput']))
3002
-			@ob_start('ob_gzhandler');
3003
-		else
3004
-			ob_start();
3161
+		if (!empty($modSettings['enableCompressedOutput'])) {
3162
+					@ob_start('ob_gzhandler');
3163
+		} else {
3164
+					ob_start();
3165
+		}
3005 3166
 
3006
-		if (isset($_GET['debug']))
3007
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3167
+		if (isset($_GET['debug'])) {
3168
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3169
+		}
3008 3170
 
3009 3171
 		// Don't cache error pages!!
3010 3172
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3023,12 +3185,13 @@  discard block
 block discarded – undo
3023 3185
 		echo '<!DOCTYPE html>
3024 3186
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3025 3187
 	<head>';
3026
-		if (isset($context['character_set']))
3027
-			echo '
3188
+		if (isset($context['character_set'])) {
3189
+					echo '
3028 3190
 		<meta charset="', $context['character_set'], '">';
3191
+		}
3029 3192
 
3030
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3031
-			echo '
3193
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3194
+					echo '
3032 3195
 		<title>', $mtitle, '</title>
3033 3196
 	</head>
3034 3197
 	<body>
@@ -3036,8 +3199,8 @@  discard block
 block discarded – undo
3036 3199
 		', $mmessage, '
3037 3200
 	</body>
3038 3201
 </html>';
3039
-		elseif (!allowedTo('admin_forum'))
3040
-			echo '
3202
+		} elseif (!allowedTo('admin_forum')) {
3203
+					echo '
3041 3204
 		<title>', $txt['template_parse_error'], '</title>
3042 3205
 	</head>
3043 3206
 	<body>
@@ -3045,16 +3208,18 @@  discard block
 block discarded – undo
3045 3208
 		', $txt['template_parse_error_message'], '
3046 3209
 	</body>
3047 3210
 </html>';
3048
-		else
3211
+		} else
3049 3212
 		{
3050 3213
 			require_once($sourcedir . '/Subs-Package.php');
3051 3214
 
3052 3215
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3053 3216
 			$error_array = error_get_last();
3054
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3055
-				$error = $error_array['message'];
3056
-			if (empty($error))
3057
-				$error = $txt['template_parse_errmsg'];
3217
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3218
+							$error = $error_array['message'];
3219
+			}
3220
+			if (empty($error)) {
3221
+							$error = $txt['template_parse_errmsg'];
3222
+			}
3058 3223
 
3059 3224
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3060 3225
 
@@ -3065,11 +3230,12 @@  discard block
 block discarded – undo
3065 3230
 		<h3>', $txt['template_parse_error'], '</h3>
3066 3231
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3067 3232
 
3068
-			if (!empty($error))
3069
-				echo '
3233
+			if (!empty($error)) {
3234
+							echo '
3070 3235
 		<hr>
3071 3236
 
3072 3237
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3238
+			}
3073 3239
 
3074 3240
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3075 3241
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3079,10 +3245,11 @@  discard block
 block discarded – undo
3079 3245
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3080 3246
 
3081 3247
 				// Fix the PHP code stuff...
3082
-				if (!isBrowser('gecko'))
3083
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3084
-				else
3085
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3248
+				if (!isBrowser('gecko')) {
3249
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3250
+				} else {
3251
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3252
+				}
3086 3253
 
3087 3254
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3088 3255
 				$j = -1;
@@ -3090,8 +3257,9 @@  discard block
 block discarded – undo
3090 3257
 				{
3091 3258
 					$j++;
3092 3259
 
3093
-					if (substr_count($line, '<br>') == 0)
3094
-						continue;
3260
+					if (substr_count($line, '<br>') == 0) {
3261
+											continue;
3262
+					}
3095 3263
 
3096 3264
 					$n = substr_count($line, '<br>');
3097 3265
 					for ($i = 0; $i < $n; $i++)
@@ -3110,38 +3278,42 @@  discard block
 block discarded – undo
3110 3278
 				// Figure out what the color coding was before...
3111 3279
 				$line = max($match[1] - 9, 1);
3112 3280
 				$last_line = '';
3113
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3114
-					if (strpos($data2[$line2], '<') !== false)
3281
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3282
+									if (strpos($data2[$line2], '<') !== false)
3115 3283
 					{
3116 3284
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3117 3285
 							$last_line = $color_match[1];
3286
+				}
3118 3287
 						break;
3119 3288
 					}
3120 3289
 
3121 3290
 				// Show the relevant lines...
3122 3291
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3123 3292
 				{
3124
-					if ($line == $match[1])
3125
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3293
+					if ($line == $match[1]) {
3294
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3295
+					}
3126 3296
 
3127 3297
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3128
-					if (isset($data2[$line]) && $data2[$line] != '')
3129
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3298
+					if (isset($data2[$line]) && $data2[$line] != '') {
3299
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3300
+					}
3130 3301
 
3131 3302
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3132 3303
 					{
3133 3304
 						$last_line = $color_match[1];
3134 3305
 						echo '</', substr($last_line, 1, 4), '>';
3306
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3307
+											$last_line = '';
3308
+					} elseif ($last_line != '' && $data2[$line] != '') {
3309
+											echo '</', substr($last_line, 1, 4), '>';
3135 3310
 					}
3136
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3137
-						$last_line = '';
3138
-					elseif ($last_line != '' && $data2[$line] != '')
3139
-						echo '</', substr($last_line, 1, 4), '>';
3140 3311
 
3141
-					if ($line == $match[1])
3142
-						echo '</pre></div><pre style="margin: 0;">';
3143
-					else
3144
-						echo "\n";
3312
+					if ($line == $match[1]) {
3313
+											echo '</pre></div><pre style="margin: 0;">';
3314
+					} else {
3315
+											echo "\n";
3316
+					}
3145 3317
 				}
3146 3318
 
3147 3319
 				echo '</pre></div>';
@@ -3165,8 +3337,9 @@  discard block
 block discarded – undo
3165 3337
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3166 3338
 
3167 3339
 	// Figure out what type of database we are using.
3168
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3169
-		$db_type = 'mysql';
3340
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3341
+			$db_type = 'mysql';
3342
+	}
3170 3343
 
3171 3344
 	// Load the file for the database.
3172 3345
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3174,8 +3347,9 @@  discard block
 block discarded – undo
3174 3347
 	$db_options = array();
3175 3348
 
3176 3349
 	// Add in the port if needed
3177
-	if (!empty($db_port))
3178
-		$db_options['port'] = $db_port;
3350
+	if (!empty($db_port)) {
3351
+			$db_options['port'] = $db_port;
3352
+	}
3179 3353
 
3180 3354
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3181 3355
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3194,13 +3368,15 @@  discard block
 block discarded – undo
3194 3368
 	}
3195 3369
 
3196 3370
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3197
-	if (!$db_connection)
3198
-		display_db_error();
3371
+	if (!$db_connection) {
3372
+			display_db_error();
3373
+	}
3199 3374
 
3200 3375
 	// If in SSI mode fix up the prefix.
3201
-	if (SMF == 'SSI')
3202
-		db_fix_prefix($db_prefix, $db_name);
3203
-}
3376
+	if (SMF == 'SSI') {
3377
+			db_fix_prefix($db_prefix, $db_name);
3378
+	}
3379
+	}
3204 3380
 
3205 3381
 /**
3206 3382
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3214,10 +3390,11 @@  discard block
 block discarded – undo
3214 3390
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3215 3391
 
3216 3392
 	// Not overriding this and we have a cacheAPI, send it back.
3217
-	if (empty($overrideCache) && is_object($cacheAPI))
3218
-		return $cacheAPI;
3219
-	elseif (is_null($cacheAPI))
3220
-		$cacheAPI = false;
3393
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3394
+			return $cacheAPI;
3395
+	} elseif (is_null($cacheAPI)) {
3396
+			$cacheAPI = false;
3397
+	}
3221 3398
 
3222 3399
 	// Make sure our class is in session.
3223 3400
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3238,8 +3415,9 @@  discard block
 block discarded – undo
3238 3415
 		if (!$testAPI->isSupported())
3239 3416
 		{
3240 3417
 			// Can we save ourselves?
3241
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3242
-				return loadCacheAccelerator(null, false);
3418
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3419
+							return loadCacheAccelerator(null, false);
3420
+			}
3243 3421
 			return false;
3244 3422
 		}
3245 3423
 
@@ -3251,9 +3429,9 @@  discard block
 block discarded – undo
3251 3429
 		{
3252 3430
 			$cacheAPI = $testAPI;
3253 3431
 			return $cacheAPI;
3432
+		} else {
3433
+					return $testAPI;
3254 3434
 		}
3255
-		else
3256
-			return $testAPI;
3257 3435
 	}
3258 3436
 }
3259 3437
 
@@ -3273,8 +3451,9 @@  discard block
 block discarded – undo
3273 3451
 
3274 3452
 	// @todo Why are we doing this if caching is disabled?
3275 3453
 
3276
-	if (function_exists('call_integration_hook'))
3277
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3454
+	if (function_exists('call_integration_hook')) {
3455
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3456
+	}
3278 3457
 
3279 3458
 	/* Refresh the cache if either:
3280 3459
 		1. Caching is disabled.
@@ -3288,16 +3467,19 @@  discard block
 block discarded – undo
3288 3467
 		require_once($sourcedir . '/' . $file);
3289 3468
 		$cache_block = call_user_func_array($function, $params);
3290 3469
 
3291
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3292
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3470
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3471
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3472
+		}
3293 3473
 	}
3294 3474
 
3295 3475
 	// Some cached data may need a freshening up after retrieval.
3296
-	if (!empty($cache_block['post_retri_eval']))
3297
-		eval($cache_block['post_retri_eval']);
3476
+	if (!empty($cache_block['post_retri_eval'])) {
3477
+			eval($cache_block['post_retri_eval']);
3478
+	}
3298 3479
 
3299
-	if (function_exists('call_integration_hook'))
3300
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3480
+	if (function_exists('call_integration_hook')) {
3481
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3482
+	}
3301 3483
 
3302 3484
 	return $cache_block['data'];
3303 3485
 }
@@ -3324,8 +3506,9 @@  discard block
 block discarded – undo
3324 3506
 	global $cache_enable, $cacheAPI;
3325 3507
 	global $cache_hits, $cache_count, $db_show_debug;
3326 3508
 
3327
-	if (empty($cache_enable) || empty($cacheAPI))
3328
-		return;
3509
+	if (empty($cache_enable) || empty($cacheAPI)) {
3510
+			return;
3511
+	}
3329 3512
 
3330 3513
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3331 3514
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3338,12 +3521,14 @@  discard block
 block discarded – undo
3338 3521
 	$value = $value === null ? null : json_encode($value);
3339 3522
 	$cacheAPI->putData($key, $value, $ttl);
3340 3523
 
3341
-	if (function_exists('call_integration_hook'))
3342
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3524
+	if (function_exists('call_integration_hook')) {
3525
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3526
+	}
3343 3527
 
3344
-	if (isset($db_show_debug) && $db_show_debug === true)
3345
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3346
-}
3528
+	if (isset($db_show_debug) && $db_show_debug === true) {
3529
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3530
+	}
3531
+	}
3347 3532
 
3348 3533
 /**
3349 3534
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3359,8 +3544,9 @@  discard block
 block discarded – undo
3359 3544
 	global $cache_enable, $cacheAPI;
3360 3545
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3361 3546
 
3362
-	if (empty($cache_enable) || empty($cacheAPI))
3363
-		return;
3547
+	if (empty($cache_enable) || empty($cacheAPI)) {
3548
+			return;
3549
+	}
3364 3550
 
3365 3551
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3366 3552
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3380,16 +3566,18 @@  discard block
 block discarded – undo
3380 3566
 
3381 3567
 		if (empty($value))
3382 3568
 		{
3383
-			if (!is_array($cache_misses))
3384
-				$cache_misses = array();
3569
+			if (!is_array($cache_misses)) {
3570
+							$cache_misses = array();
3571
+			}
3385 3572
 
3386 3573
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3387 3574
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3388 3575
 		}
3389 3576
 	}
3390 3577
 
3391
-	if (function_exists('call_integration_hook') && isset($value))
3392
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3578
+	if (function_exists('call_integration_hook') && isset($value)) {
3579
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3580
+	}
3393 3581
 
3394 3582
 	return empty($value) ? null : smf_json_decode($value, true);
3395 3583
 }
@@ -3411,8 +3599,9 @@  discard block
 block discarded – undo
3411 3599
 	global $cacheAPI;
3412 3600
 
3413 3601
 	// If we can't get to the API, can't do this.
3414
-	if (empty($cacheAPI))
3415
-		return;
3602
+	if (empty($cacheAPI)) {
3603
+			return;
3604
+	}
3416 3605
 
3417 3606
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3418 3607
 	$cacheAPI->cleanCache($type);
@@ -3437,8 +3626,9 @@  discard block
 block discarded – undo
3437 3626
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3438 3627
 
3439 3628
 	// Come on!
3440
-	if (empty($data))
3441
-		return array();
3629
+	if (empty($data)) {
3630
+			return array();
3631
+	}
3442 3632
 
3443 3633
 	// Set a nice default var.
3444 3634
 	$image = '';
@@ -3446,11 +3636,11 @@  discard block
 block discarded – undo
3446 3636
 	// Gravatar has been set as mandatory!
3447 3637
 	if (!empty($modSettings['gravatarOverride']))
3448 3638
 	{
3449
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3450
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3451
-
3452
-		else if (!empty($data['email']))
3453
-			$image = get_gravatar_url($data['email']);
3639
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3640
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3641
+		} else if (!empty($data['email'])) {
3642
+					$image = get_gravatar_url($data['email']);
3643
+		}
3454 3644
 	}
3455 3645
 
3456 3646
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3462,54 +3652,60 @@  discard block
 block discarded – undo
3462 3652
 			// Gravatar.
3463 3653
 			if (stristr($data['avatar'], 'gravatar://'))
3464 3654
 			{
3465
-				if ($data['avatar'] == 'gravatar://')
3466
-					$image = get_gravatar_url($data['email']);
3467
-
3468
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3469
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3655
+				if ($data['avatar'] == 'gravatar://') {
3656
+									$image = get_gravatar_url($data['email']);
3657
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3658
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3659
+				}
3470 3660
 			}
3471 3661
 
3472 3662
 			// External url.
3473 3663
 			else
3474 3664
 			{
3475 3665
 				// Using ssl?
3476
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3477
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3666
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3667
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3668
+				}
3478 3669
 
3479 3670
 				// Just a plain external url.
3480
-				else
3481
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3671
+				else {
3672
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3673
+				}
3482 3674
 			}
3483 3675
 		}
3484 3676
 
3485 3677
 		// Perhaps this user has an attachment as avatar...
3486
-		else if (!empty($data['filename']))
3487
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3678
+		else if (!empty($data['filename'])) {
3679
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3680
+		}
3488 3681
 
3489 3682
 		// Right... no avatar... use our default image.
3490
-		else
3491
-			$image = $modSettings['avatar_url'] . '/default.png';
3683
+		else {
3684
+					$image = $modSettings['avatar_url'] . '/default.png';
3685
+		}
3492 3686
 	}
3493 3687
 
3494 3688
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3495 3689
 
3496 3690
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3497
-	if (!empty($image))
3498
-		return array(
3691
+	if (!empty($image)) {
3692
+			return array(
3499 3693
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3500 3694
 			'image' => '<img class="avatar" src="' . $image . '" />',
3501 3695
 			'href' => $image,
3502 3696
 			'url' => $image,
3503 3697
 		);
3698
+	}
3504 3699
 
3505 3700
 	// Fallback to make life easier for everyone...
3506
-	else
3507
-		return array(
3701
+	else {
3702
+			return array(
3508 3703
 			'name' => '',
3509 3704
 			'image' => '',
3510 3705
 			'href' => '',
3511 3706
 			'url' => '',
3512 3707
 		);
3513
-}
3708
+	}
3709
+	}
3514 3710
 
3515 3711
 ?>
3516 3712
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Class-CurlFetchWeb.php 1 patch
Braces   +30 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,8 +10,9 @@  discard block
 block discarded – undo
10 10
  * @version 2.1 Beta 4
11 11
  */
12 12
 
13
-if (!defined('SMF'))
13
+if (!defined('SMF')) {
14 14
 	die('No direct access...');
15
+}
15 16
 
16 17
 /**
17 18
  * Class curl_fetch_web_data
@@ -121,10 +122,11 @@  discard block
 block discarded – undo
121 122
 	public function get_url_data($url, $post_data = array())
122 123
 	{
123 124
 		// POSTing some data perhaps?
124
-		if (!empty($post_data) && is_array($post_data))
125
-			$this->post_data = $this->build_post_data($post_data);
126
-		elseif (!empty($post_data))
127
-			$this->post_data = trim($post_data);
125
+		if (!empty($post_data) && is_array($post_data)) {
126
+					$this->post_data = $this->build_post_data($post_data);
127
+		} elseif (!empty($post_data)) {
128
+					$this->post_data = trim($post_data);
129
+		}
128 130
 
129 131
 		// set the options and get it
130 132
 		$this->set_options();
@@ -145,10 +147,11 @@  discard block
 block discarded – undo
145 147
 	private function curl_request($url, $redirect = false)
146 148
 	{
147 149
 		// we do have a url I hope
148
-		if ($url == '')
149
-			return false;
150
-		else
151
-			$this->options[CURLOPT_URL] = $url;
150
+		if ($url == '') {
151
+					return false;
152
+		} else {
153
+					$this->options[CURLOPT_URL] = $url;
154
+		}
152 155
 
153 156
 		// if we have not already been redirected, set it up so we can if needed
154 157
 		if (!$redirect)
@@ -228,10 +231,11 @@  discard block
 block discarded – undo
228 231
 		$max_result = count($this->response) - 1;
229 232
 
230 233
 		// just return a specifed area or the entire result?
231
-		if ($area == '')
232
-			return $this->response[$max_result];
233
-		else
234
-			return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
234
+		if ($area == '') {
235
+					return $this->response[$max_result];
236
+		} else {
237
+					return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
238
+		}
235 239
 	}
236 240
 
237 241
 	/**
@@ -244,9 +248,9 @@  discard block
 block discarded – undo
244 248
 	*/
245 249
 	public function result_raw($response_number = '')
246 250
 	{
247
-		if (!is_numeric($response_number))
248
-			return $this->response;
249
-		else
251
+		if (!is_numeric($response_number)) {
252
+					return $this->response;
253
+		} else
250 254
 		{
251 255
 			$response_number = min($response_number, count($this->response) - 1);
252 256
 			return $this->response[$response_number];
@@ -268,13 +272,14 @@  discard block
 block discarded – undo
268 272
 			$postvars = array();
269 273
 
270 274
 			// build the post data, drop ones with leading @'s since those can be used to send files, we don't support that.
271
-			foreach ($post_data as $name => $value)
272
-				$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
275
+			foreach ($post_data as $name => $value) {
276
+							$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
277
+			}
273 278
 
274 279
 			return implode('&', $postvars);
280
+		} else {
281
+					return $post_data;
275 282
 		}
276
-		else
277
-			return $post_data;
278 283
 
279 284
 	}
280 285
 
@@ -295,9 +300,9 @@  discard block
 block discarded – undo
295 300
 			$keys = array_merge(array_keys($this->default_options), array_keys($this->user_options));
296 301
 			$vals = array_merge($this->default_options, $this->user_options);
297 302
 			$this->options = array_combine($keys, $vals);
303
+		} else {
304
+					$this->options = $this->default_options;
298 305
 		}
299
-		else
300
-			$this->options = $this->default_options;
301 306
 
302 307
 		// POST data options, here we don't allow any overide
303 308
 		if (isset($this->post_data))
@@ -336,8 +341,9 @@  discard block
 block discarded – undo
336 341
 		$temp = explode(': ', $_header, 2);
337 342
 
338 343
 		// set proper headers only
339
-		if (isset($temp[0]) && isset($temp[1]))
340
-			$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
344
+		if (isset($temp[0]) && isset($temp[1])) {
345
+					$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
346
+		}
341 347
 
342 348
 		// return the length of what was passed unless you want a Failed writing header error ;)
343 349
 		return strlen($header);
Please login to merge, or discard this patch.
Sources/CacheAPI-xcache.php 1 patch
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	{
45 46
 		$supported = function_exists('xcache_get') && function_exists('xcache_set') && ini_get('xcache.var_size') > 0;
46 47
 
47
-		if ($test)
48
-			return $supported;
48
+		if ($test) {
49
+					return $supported;
50
+		}
49 51
 		return parent::isSupported() && $supported;
50 52
 	}
51 53
 
@@ -66,10 +68,11 @@  discard block
 block discarded – undo
66 68
 	{
67 69
 		$key = $this->prefix . strtr($key, ':/', '-_');
68 70
 
69
-		if ($value === null)
70
-			return xcache_unset($key);
71
-		else
72
-			return xcache_set($key, $value, $ttl);
71
+		if ($value === null) {
72
+					return xcache_unset($key);
73
+		} else {
74
+					return xcache_set($key, $value, $ttl);
75
+		}
73 76
 	}
74 77
 
75 78
 	/**
@@ -88,10 +91,12 @@  discard block
 block discarded – undo
88 91
 		}
89 92
 
90 93
 		// if passed a type, clear that type out
91
-		if ($type === '' || $type === 'user')
92
-			xcache_clear_cache(XC_TYPE_VAR, 0);
93
-		if ($type === '' || $type === 'data')
94
-			xcache_clear_cache(XC_TYPE_PHP, 0);
94
+		if ($type === '' || $type === 'user') {
95
+					xcache_clear_cache(XC_TYPE_VAR, 0);
96
+		}
97
+		if ($type === '' || $type === 'data') {
98
+					xcache_clear_cache(XC_TYPE_PHP, 0);
99
+		}
95 100
 
96 101
 		$this->invalidateCache();
97 102
 		return true;
@@ -110,8 +115,9 @@  discard block
 block discarded – undo
110 115
 		// While we could md5 this when saving, this could be tricky to be sure it doesn't get corrupted on additional saves.
111 116
 		$config_vars[] = array('xcache_adminpass', $txt['cache_xcache_adminpass'], 'db', 'text', 0);
112 117
 
113
-		if (!isset($context['settings_post_javascript']))
114
-			$context['settings_post_javascript'] = '';
118
+		if (!isset($context['settings_post_javascript'])) {
119
+					$context['settings_post_javascript'] = '';
120
+		}
115 121
 
116 122
 		$context['settings_post_javascript'] .= '
117 123
 			$("#cache_accelerator").change(function (e) {
Please login to merge, or discard this patch.
Sources/Reminder.php 1 patch
Braces   +66 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 4
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * This is the controlling delegator
@@ -38,13 +39,15 @@  discard block
 block discarded – undo
38 39
 	);
39 40
 
40 41
 	// Any subaction?  If none, fall through to the main template, which will ask for one.
41
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
42
-		call_helper($subActions[$_REQUEST['sa']]);
42
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
43
+			call_helper($subActions[$_REQUEST['sa']]);
44
+	}
43 45
 
44 46
 	// Creating a one time token.
45
-	else
46
-		createToken('remind');
47
-}
47
+	else {
48
+			createToken('remind');
49
+	}
50
+	}
48 51
 
49 52
 /**
50 53
  * Allows the user to pick how they wish to be reminded
@@ -62,8 +65,7 @@  discard block
 block discarded – undo
62 65
 	{
63 66
 		$where = 'id_member = {int:id_member}';
64 67
 		$where_params['id_member'] = (int) $_REQUEST['uid'];
65
-	}
66
-	elseif (isset($_POST['user']) && $_POST['user'] != '')
68
+	} elseif (isset($_POST['user']) && $_POST['user'] != '')
67 69
 	{
68 70
 		$where = 'member_name = {string:member_name}';
69 71
 		$where_params['member_name'] = $_POST['user'];
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 	}
72 74
 
73 75
 	// You must enter a username/email address.
74
-	if (empty($where))
75
-		fatal_lang_error('username_no_exist', false);
76
+	if (empty($where)) {
77
+			fatal_lang_error('username_no_exist', false);
78
+	}
76 79
 
77 80
 	// Make sure we are not being slammed
78 81
 	// Don't call this if you're coming from the "Choose a reminder type" page - otherwise you'll likely get an error
@@ -101,8 +104,9 @@  discard block
 block discarded – undo
101 104
 			LIMIT 1',
102 105
 			$where_params
103 106
 		);
104
-		if ($smcFunc['db_num_rows']($request) == 0)
105
-			fatal_lang_error('no_user_with_email', false);
107
+		if ($smcFunc['db_num_rows']($request) == 0) {
108
+					fatal_lang_error('no_user_with_email', false);
109
+		}
106 110
 	}
107 111
 
108 112
 	$row = $smcFunc['db_fetch_assoc']($request);
@@ -112,16 +116,18 @@  discard block
 block discarded – undo
112 116
 	if ($row['is_activated'] != 1)
113 117
 	{
114 118
 		// Awaiting approval...
115
-		if (trim($row['validation_code']) == '')
116
-			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
117
-		else
118
-			fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
119
+		if (trim($row['validation_code']) == '') {
120
+					fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
121
+		} else {
122
+					fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
123
+		}
119 124
 	}
120 125
 
121 126
 	// You can't get emailed if you have no email address.
122 127
 	$row['email_address'] = trim($row['email_address']);
123
-	if ($row['email_address'] == '')
124
-		fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
128
+	if ($row['email_address'] == '') {
129
+			fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
130
+	}
125 131
 
126 132
 	// If they have no secret question then they can only get emailed the item, or they are requesting the email, send them an email.
127 133
 	if (empty($row['secret_question']) || (isset($_POST['reminder_type']) && $_POST['reminder_type'] == 'email'))
@@ -176,8 +182,9 @@  discard block
 block discarded – undo
176 182
 	loadLanguage('Login');
177 183
 
178 184
 	// You need a code!
179
-	if (!isset($_REQUEST['code']))
180
-		fatal_lang_error('no_access', false);
185
+	if (!isset($_REQUEST['code'])) {
186
+			fatal_lang_error('no_access', false);
187
+	}
181 188
 
182 189
 	// Fill the context array.
183 190
 	$context += array(
@@ -203,16 +210,19 @@  discard block
 block discarded – undo
203 210
 	checkSession();
204 211
 	validateToken('remind-sp');
205 212
 
206
-	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2']))
207
-		fatal_lang_error('no_access', false);
213
+	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2'])) {
214
+			fatal_lang_error('no_access', false);
215
+	}
208 216
 
209 217
 	$_POST['u'] = (int) $_POST['u'];
210 218
 
211
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
212
-		fatal_lang_error('passwords_dont_match', false);
219
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
220
+			fatal_lang_error('passwords_dont_match', false);
221
+	}
213 222
 
214
-	if ($_POST['passwrd1'] == '')
215
-		fatal_lang_error('no_password', false);
223
+	if ($_POST['passwrd1'] == '') {
224
+			fatal_lang_error('no_password', false);
225
+	}
216 226
 
217 227
 	loadLanguage('Login');
218 228
 
@@ -232,8 +242,9 @@  discard block
 block discarded – undo
232 242
 	);
233 243
 
234 244
 	// Does this user exist at all?
235
-	if ($smcFunc['db_num_rows']($request) == 0)
236
-		fatal_lang_error('invalid_userid', false);
245
+	if ($smcFunc['db_num_rows']($request) == 0) {
246
+			fatal_lang_error('invalid_userid', false);
247
+	}
237 248
 
238 249
 	list ($realCode, $username, $email, $flood_value) = $smcFunc['db_fetch_row']($request);
239 250
 	$smcFunc['db_free_result']($request);
@@ -243,8 +254,9 @@  discard block
 block discarded – undo
243 254
 	$passwordError = validatePassword($_POST['passwrd1'], $username, array($email));
244 255
 
245 256
 	// What - it's not?
246
-	if ($passwordError != null)
247
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
257
+	if ($passwordError != null) {
258
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
259
+	}
248 260
 
249 261
 	require_once($sourcedir . '/LogInOut.php');
250 262
 
@@ -291,8 +303,9 @@  discard block
 block discarded – undo
291 303
 	loadLanguage('Login');
292 304
 
293 305
 	// Check they entered something...
294
-	if (empty($_REQUEST['uid']))
295
-		fatal_lang_error('username_no_exist', false);
306
+	if (empty($_REQUEST['uid'])) {
307
+			fatal_lang_error('username_no_exist', false);
308
+	}
296 309
 
297 310
 	// Get the stuff....
298 311
 	$request = $smcFunc['db_query']('', '
@@ -304,15 +317,17 @@  discard block
 block discarded – undo
304 317
 			'id_member' => (int) $_REQUEST['uid'],
305 318
 		)
306 319
 	);
307
-	if ($smcFunc['db_num_rows']($request) == 0)
308
-		fatal_lang_error('username_no_exist', false);
320
+	if ($smcFunc['db_num_rows']($request) == 0) {
321
+			fatal_lang_error('username_no_exist', false);
322
+	}
309 323
 
310 324
 	$row = $smcFunc['db_fetch_assoc']($request);
311 325
 	$smcFunc['db_free_result']($request);
312 326
 
313 327
 	// If there is NO secret question - then throw an error.
314
-	if (trim($row['secret_question']) == '')
315
-		fatal_lang_error('registration_no_secret_question', false);
328
+	if (trim($row['secret_question']) == '') {
329
+			fatal_lang_error('registration_no_secret_question', false);
330
+	}
316 331
 
317 332
 	// Ask for the answer...
318 333
 	$context['remind_user'] = $row['id_member'];
@@ -335,8 +350,9 @@  discard block
 block discarded – undo
335 350
 	validateToken('remind-sai');
336 351
 
337 352
 	// Hacker?  How did you get this far without an email or username?
338
-	if (empty($_REQUEST['uid']))
339
-		fatal_lang_error('username_no_exist', false);
353
+	if (empty($_REQUEST['uid'])) {
354
+			fatal_lang_error('username_no_exist', false);
355
+	}
340 356
 
341 357
 	loadLanguage('Login');
342 358
 
@@ -350,8 +366,9 @@  discard block
 block discarded – undo
350 366
 			'id_member' => $_REQUEST['uid'],
351 367
 		)
352 368
 	);
353
-	if ($smcFunc['db_num_rows']($request) == 0)
354
-		fatal_lang_error('username_no_exist', false);
369
+	if ($smcFunc['db_num_rows']($request) == 0) {
370
+			fatal_lang_error('username_no_exist', false);
371
+	}
355 372
 
356 373
 	$row = $smcFunc['db_fetch_assoc']($request);
357 374
 	$smcFunc['db_free_result']($request);
@@ -364,20 +381,23 @@  discard block
 block discarded – undo
364 381
 	}
365 382
 
366 383
 	// You can't use a blank one!
367
-	if (strlen(trim($_POST['passwrd1'])) === 0)
368
-		fatal_lang_error('no_password', false);
384
+	if (strlen(trim($_POST['passwrd1'])) === 0) {
385
+			fatal_lang_error('no_password', false);
386
+	}
369 387
 
370 388
 	// They have to be the same too.
371
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
372
-		fatal_lang_error('passwords_dont_match', false);
389
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
390
+			fatal_lang_error('passwords_dont_match', false);
391
+	}
373 392
 
374 393
 	// Make sure they have a strong enough password.
375 394
 	require_once($sourcedir . '/Subs-Auth.php');
376 395
 	$passwordError = validatePassword($_POST['passwrd1'], $row['member_name'], array($row['email_address']));
377 396
 
378 397
 	// Invalid?
379
-	if ($passwordError != null)
380
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
398
+	if ($passwordError != null) {
399
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
400
+	}
381 401
 
382 402
 	// Alright, so long as 'yer sure.
383 403
 	updateMemberData($row['id_member'], array('passwd' => hash_password($row['member_name'], $_POST['passwrd1'])));
Please login to merge, or discard this patch.
Sources/DbExtra-mysql.php 1 patch
Braces   +66 added lines, -46 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
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -32,7 +33,8 @@  discard block
 block discarded – undo
32 33
 			'db_get_version' => 'smf_db_get_version',
33 34
 			'db_get_engine' => 'smf_db_get_engine',
34 35
 		);
35
-}
36
+	}
37
+	}
36 38
 
37 39
 /**
38 40
  * Backup $table to $backup_table.
@@ -74,8 +76,9 @@  discard block
 block discarded – undo
74 76
 			));
75 77
 
76 78
 		// Old school or no school?
77
-		if ($request)
78
-			return $request;
79
+		if ($request) {
80
+					return $request;
81
+		}
79 82
 	}
80 83
 
81 84
 	// At this point, the quick method failed.
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	foreach ($create as $k => $l)
100 103
 	{
101 104
 		// Get the name of the auto_increment column.
102
-		if (strpos($l, 'auto_increment'))
103
-			$auto_inc = trim($l);
105
+		if (strpos($l, 'auto_increment')) {
106
+					$auto_inc = trim($l);
107
+		}
104 108
 
105 109
 		// For the engine type, see if we can work out what it is.
106 110
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -108,30 +112,36 @@  discard block
 block discarded – undo
108 112
 			// Extract the engine type.
109 113
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
110 114
 
111
-			if (!empty($match[1]))
112
-				$engine = $match[1];
115
+			if (!empty($match[1])) {
116
+							$engine = $match[1];
117
+			}
113 118
 
114
-			if (!empty($match[2]))
115
-				$engine = $match[2];
119
+			if (!empty($match[2])) {
120
+							$engine = $match[2];
121
+			}
116 122
 
117
-			if (!empty($match[5]))
118
-				$charset = $match[5];
123
+			if (!empty($match[5])) {
124
+							$charset = $match[5];
125
+			}
119 126
 
120
-			if (!empty($match[7]))
121
-				$collate = $match[7];
127
+			if (!empty($match[7])) {
128
+							$collate = $match[7];
129
+			}
122 130
 		}
123 131
 
124 132
 		// Skip everything but keys...
125
-		if (strpos($l, 'KEY') === false)
126
-			unset($create[$k]);
133
+		if (strpos($l, 'KEY') === false) {
134
+					unset($create[$k]);
135
+		}
127 136
 	}
128 137
 
129
-	if (!empty($create))
130
-		$create = '(
138
+	if (!empty($create)) {
139
+			$create = '(
131 140
 			' . implode('
132 141
 			', $create) . ')';
133
-	else
134
-		$create = '';
142
+	} else {
143
+			$create = '';
144
+	}
135 145
 
136 146
 	$request = $smcFunc['db_query']('', '
137 147
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -150,8 +160,9 @@  discard block
 block discarded – undo
150 160
 
151 161
 	if ($auto_inc != '')
152 162
 	{
153
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
154
-			$auto_inc = substr($auto_inc, 0, -1);
163
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
164
+					$auto_inc = substr($auto_inc, 0, -1);
165
+		}
155 166
 
156 167
 		$smcFunc['db_query']('', '
157 168
 			ALTER TABLE {raw:backup_table}
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 				'table' => $table,
196 207
 			)
197 208
 		);
198
-	if (!$request)
199
-		return -1;
209
+	if (!$request) {
210
+			return -1;
211
+	}
200 212
 
201 213
 	// How much left?
202 214
 	$request = $smcFunc['db_query']('', '
@@ -239,8 +251,9 @@  discard block
 block discarded – undo
239 251
 		)
240 252
 	);
241 253
 	$tables = array();
242
-	while ($row = $smcFunc['db_fetch_row']($request))
243
-		$tables[] = $row[0];
254
+	while ($row = $smcFunc['db_fetch_row']($request)) {
255
+			$tables[] = $row[0];
256
+	}
244 257
 	$smcFunc['db_free_result']($request);
245 258
 
246 259
 	return $tables;
@@ -284,8 +297,9 @@  discard block
 block discarded – undo
284 297
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
285 298
 		{
286 299
 			// Make a special case of auto-timestamp.
287
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
288
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
300
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
301
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
302
+			}
289 303
 			// Text shouldn't have a default.
290 304
 			elseif ($row['Default'] !== null)
291 305
 			{
@@ -320,14 +334,16 @@  discard block
 block discarded – undo
320 334
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
321 335
 
322 336
 		// Is this the first column in the index?
323
-		if (empty($indexes[$row['Key_name']]))
324
-			$indexes[$row['Key_name']] = array();
337
+		if (empty($indexes[$row['Key_name']])) {
338
+					$indexes[$row['Key_name']] = array();
339
+		}
325 340
 
326 341
 		// A sub part, like only indexing 15 characters of a varchar.
327
-		if (!empty($row['Sub_part']))
328
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
329
-		else
330
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
342
+		if (!empty($row['Sub_part'])) {
343
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
344
+		} else {
345
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
346
+		}
331 347
 	}
332 348
 	$smcFunc['db_free_result']($result);
333 349
 
@@ -365,8 +381,9 @@  discard block
 block discarded – undo
365 381
 {
366 382
 	static $ver;
367 383
 
368
-	if (!empty($ver))
369
-		return $ver;
384
+	if (!empty($ver)) {
385
+			return $ver;
386
+	}
370 387
 
371 388
 	global $smcFunc;
372 389
 
@@ -391,8 +408,9 @@  discard block
 block discarded – undo
391 408
 	global $smcFunc;
392 409
 	static $db_type;
393 410
 
394
-	if (!empty($db_type))
395
-		return $db_type;
411
+	if (!empty($db_type)) {
412
+			return $db_type;
413
+	}
396 414
 
397 415
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
398 416
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -401,13 +419,15 @@  discard block
 block discarded – undo
401 419
 	// Skip these if we don't have a comment.
402 420
 	if (!empty($comment))
403 421
 	{
404
-		if (stripos($comment, 'percona') !== false)
405
-			return 'Percona';
406
-		if (stripos($comment, 'mariadb') !== false)
407
-			return 'MariaDB';
422
+		if (stripos($comment, 'percona') !== false) {
423
+					return 'Percona';
424
+		}
425
+		if (stripos($comment, 'mariadb') !== false) {
426
+					return 'MariaDB';
427
+		}
428
+	} else {
429
+			return 'fail';
408 430
 	}
409
-	else
410
-		return 'fail';
411 431
 
412 432
 	return 'MySQL';
413 433
 }
Please login to merge, or discard this patch.
Sources/Profile.php 1 patch
Braces   +155 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -29,18 +30,21 @@  discard block
 block discarded – undo
29 30
 	global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc;
30 31
 
31 32
 	// Don't reload this as we may have processed error strings.
32
-	if (empty($post_errors))
33
-		loadLanguage('Profile+Drafts');
33
+	if (empty($post_errors)) {
34
+			loadLanguage('Profile+Drafts');
35
+	}
34 36
 	loadTemplate('Profile');
35 37
 
36 38
 	require_once($sourcedir . '/Subs-Menu.php');
37 39
 
38 40
 	// Did we get the user by name...
39
-	if (isset($_REQUEST['user']))
40
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
41
+	if (isset($_REQUEST['user'])) {
42
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
43
+	}
41 44
 	// ... or by id_member?
42
-	elseif (!empty($_REQUEST['u']))
43
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
45
+	elseif (!empty($_REQUEST['u'])) {
46
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
47
+	}
44 48
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
45 49
 	else
46 50
 	{
@@ -50,8 +54,9 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 
52 56
 	// Check if loadMemberData() has returned a valid result.
53
-	if (!$memberResult)
54
-		fatal_lang_error('not_a_user', false, 404);
57
+	if (!$memberResult) {
58
+			fatal_lang_error('not_a_user', false, 404);
59
+	}
55 60
 
56 61
 	// If all went well, we have a valid member ID!
57 62
 	list ($memID) = $memberResult;
@@ -67,8 +72,9 @@  discard block
 block discarded – undo
67 72
 
68 73
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
69 74
 	// And we care about what the current user can do, not what the user whose profile it is.
70
-	if ($user_info['mod_cache']['gq'] != '0=1')
71
-		$user_info['permissions'][] = 'approve_group_requests';
75
+	if ($user_info['mod_cache']['gq'] != '0=1') {
76
+			$user_info['permissions'][] = 'approve_group_requests';
77
+	}
72 78
 
73 79
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
74 80
 	$context['subs_available'] = false;
@@ -436,21 +442,25 @@  discard block
 block discarded – undo
436 442
 		foreach ($section['areas'] as $area_id => $area)
437 443
 		{
438 444
 			// If it said no permissions that meant it wasn't valid!
439
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
440
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
445
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
446
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
447
+			}
441 448
 			// Otherwise pick the right set.
442
-			else
443
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
449
+			else {
450
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
451
+			}
444 452
 
445 453
 			// Password required in most cases
446
-			if (!empty($area['password']))
447
-				$context['password_areas'][] = $area_id;
454
+			if (!empty($area['password'])) {
455
+							$context['password_areas'][] = $area_id;
456
+			}
448 457
 		}
449 458
 	}
450 459
 
451 460
 	// Is there an updated message to show?
452
-	if (isset($_GET['updated']))
453
-		$context['profile_updated'] = $txt['profile_updated_own'];
461
+	if (isset($_GET['updated'])) {
462
+			$context['profile_updated'] = $txt['profile_updated_own'];
463
+	}
454 464
 
455 465
 	// Set a few options for the menu.
456 466
 	$menuOptions = array(
@@ -465,8 +475,9 @@  discard block
 block discarded – undo
465 475
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
466 476
 
467 477
 	// No menu means no access.
468
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
469
-		fatal_lang_error('no_access', false);
478
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
479
+			fatal_lang_error('no_access', false);
480
+	}
470 481
 
471 482
 	// Make a note of the Unique ID for this menu.
472 483
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -492,8 +503,9 @@  discard block
 block discarded – undo
492 503
 			if ($current_area == $area_id)
493 504
 			{
494 505
 				// This can't happen - but is a security check.
495
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
496
-					fatal_lang_error('no_access', false);
506
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
507
+									fatal_lang_error('no_access', false);
508
+				}
497 509
 
498 510
 				// Are we saving data in a valid area?
499 511
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -512,12 +524,14 @@  discard block
 block discarded – undo
512 524
 				}
513 525
 
514 526
 				// Does this require session validating?
515
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
516
-					$security_checks['validate'] = true;
527
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
528
+									$security_checks['validate'] = true;
529
+				}
517 530
 
518 531
 				// Permissions for good measure.
519
-				if (!empty($profile_include_data['permission']))
520
-					$security_checks['permission'] = $profile_include_data['permission'];
532
+				if (!empty($profile_include_data['permission'])) {
533
+									$security_checks['permission'] = $profile_include_data['permission'];
534
+				}
521 535
 
522 536
 				// Either way got something.
523 537
 				$found_area = true;
@@ -526,21 +540,26 @@  discard block
 block discarded – undo
526 540
 	}
527 541
 
528 542
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
529
-	if (!$found_area)
530
-		fatal_lang_error('no_access', false);
543
+	if (!$found_area) {
544
+			fatal_lang_error('no_access', false);
545
+	}
531 546
 
532 547
 	// Release this now.
533 548
 	unset($profile_areas);
534 549
 
535 550
 	// Now the context is setup have we got any security checks to carry out additional to that above?
536
-	if (isset($security_checks['session']))
537
-		checkSession($security_checks['session']);
538
-	if (isset($security_checks['validate']))
539
-		validateSession();
540
-	if (isset($security_checks['validateToken']))
541
-		validateToken($token_name, $token_type);
542
-	if (isset($security_checks['permission']))
543
-		isAllowedTo($security_checks['permission']);
551
+	if (isset($security_checks['session'])) {
552
+			checkSession($security_checks['session']);
553
+	}
554
+	if (isset($security_checks['validate'])) {
555
+			validateSession();
556
+	}
557
+	if (isset($security_checks['validateToken'])) {
558
+			validateToken($token_name, $token_type);
559
+	}
560
+	if (isset($security_checks['permission'])) {
561
+			isAllowedTo($security_checks['permission']);
562
+	}
544 563
 
545 564
 	// Create a token if needed.
546 565
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -550,8 +569,9 @@  discard block
 block discarded – undo
550 569
 	}
551 570
 
552 571
 	// File to include?
553
-	if (isset($profile_include_data['file']))
554
-		require_once($sourcedir . '/' . $profile_include_data['file']);
572
+	if (isset($profile_include_data['file'])) {
573
+			require_once($sourcedir . '/' . $profile_include_data['file']);
574
+	}
555 575
 
556 576
 	// Build the link tree.
557 577
 	$context['linktree'][] = array(
@@ -559,17 +579,19 @@  discard block
 block discarded – undo
559 579
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
560 580
 	);
561 581
 
562
-	if (!empty($profile_include_data['label']))
563
-		$context['linktree'][] = array(
582
+	if (!empty($profile_include_data['label'])) {
583
+			$context['linktree'][] = array(
564 584
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
565 585
 			'name' => $profile_include_data['label'],
566 586
 		);
587
+	}
567 588
 
568
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
569
-		$context['linktree'][] = array(
589
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
590
+			$context['linktree'][] = array(
570 591
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
571 592
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
572 593
 		);
594
+	}
573 595
 
574 596
 	// Set the template for this area and add the profile layer.
575 597
 	$context['sub_template'] = $profile_include_data['function'];
@@ -595,12 +617,14 @@  discard block
 block discarded – undo
595 617
 		if ($check_password)
596 618
 		{
597 619
 			// Check to ensure we're forcing SSL for authentication
598
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
621
+							fatal_lang_error('login_ssl_required');
622
+			}
600 623
 
601 624
 			// You didn't even enter a password!
602
-			if (trim($_POST['oldpasswrd']) == '')
603
-				$post_errors[] = 'no_password';
625
+			if (trim($_POST['oldpasswrd']) == '') {
626
+							$post_errors[] = 'no_password';
627
+			}
604 628
 
605 629
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
606 630
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -609,33 +633,35 @@  discard block
 block discarded – undo
609 633
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
610 634
 
611 635
 			// Bad password!!!
612
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
613
-				$post_errors[] = 'bad_password';
636
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
637
+							$post_errors[] = 'bad_password';
638
+			}
614 639
 
615 640
 			// Warn other elements not to jump the gun and do custom changes!
616
-			if (in_array('bad_password', $post_errors))
617
-				$context['password_auth_failed'] = true;
641
+			if (in_array('bad_password', $post_errors)) {
642
+							$context['password_auth_failed'] = true;
643
+			}
618 644
 		}
619 645
 
620 646
 		// Change the IP address in the database.
621
-		if ($context['user']['is_owner'])
622
-			$profile_vars['member_ip'] = $user_info['ip'];
647
+		if ($context['user']['is_owner']) {
648
+					$profile_vars['member_ip'] = $user_info['ip'];
649
+		}
623 650
 
624 651
 		// Now call the sub-action function...
625 652
 		if ($current_area == 'activateaccount')
626 653
 		{
627
-			if (empty($post_errors))
628
-				activateAccount($memID);
629
-		}
630
-		elseif ($current_area == 'deleteaccount')
654
+			if (empty($post_errors)) {
655
+							activateAccount($memID);
656
+			}
657
+		} elseif ($current_area == 'deleteaccount')
631 658
 		{
632 659
 			if (empty($post_errors))
633 660
 			{
634 661
 				deleteAccount2($memID);
635 662
 				redirectexit();
636 663
 			}
637
-		}
638
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
664
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
639 665
 		{
640 666
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
641 667
 
@@ -646,10 +672,9 @@  discard block
 block discarded – undo
646 672
 		elseif ($current_area == 'authentication')
647 673
 		{
648 674
 			authentication($memID, true);
649
-		}
650
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
651
-			saveProfileFields();
652
-		else
675
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
676
+					saveProfileFields();
677
+		} else
653 678
 		{
654 679
 			$force_redirect = true;
655 680
 			// Ensure we include this.
@@ -665,34 +690,36 @@  discard block
 block discarded – undo
665 690
 			// Load the language file so we can give a nice explanation of the errors.
666 691
 			loadLanguage('Errors');
667 692
 			$context['post_errors'] = $post_errors;
668
-		}
669
-		elseif (!empty($profile_vars))
693
+		} elseif (!empty($profile_vars))
670 694
 		{
671 695
 			// If we've changed the password, notify any integration that may be listening in.
672
-			if (isset($profile_vars['passwd']))
673
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
696
+			if (isset($profile_vars['passwd'])) {
697
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
698
+			}
674 699
 
675 700
 			updateMemberData($memID, $profile_vars);
676 701
 
677 702
 			// What if this is the newest member?
678
-			if ($modSettings['latestMember'] == $memID)
679
-				updateStats('member');
680
-			elseif (isset($profile_vars['real_name']))
681
-				updateSettings(array('memberlist_updated' => time()));
703
+			if ($modSettings['latestMember'] == $memID) {
704
+							updateStats('member');
705
+			} elseif (isset($profile_vars['real_name'])) {
706
+							updateSettings(array('memberlist_updated' => time()));
707
+			}
682 708
 
683 709
 			// If the member changed his/her birthdate, update calendar statistics.
684
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
685
-				updateSettings(array(
710
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
711
+							updateSettings(array(
686 712
 					'calendar_updated' => time(),
687 713
 				));
714
+			}
688 715
 
689 716
 			// Anything worth logging?
690 717
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
691 718
 			{
692 719
 				$log_changes = array();
693 720
 				require_once($sourcedir . '/Logging.php');
694
-				foreach ($context['log_changes'] as $k => $v)
695
-					$log_changes[] = array(
721
+				foreach ($context['log_changes'] as $k => $v) {
722
+									$log_changes[] = array(
696 723
 						'action' => $k,
697 724
 						'log_type' => 'user',
698 725
 						'extra' => array_merge($v, array(
@@ -700,14 +727,16 @@  discard block
 block discarded – undo
700 727
 							'member_affected' => $memID,
701 728
 						)),
702 729
 					);
730
+				}
703 731
 
704 732
 				logActions($log_changes);
705 733
 			}
706 734
 
707 735
 			// Have we got any post save functions to execute?
708
-			if (!empty($context['profile_execute_on_save']))
709
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
736
+			if (!empty($context['profile_execute_on_save'])) {
737
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
710 738
 					$saveFunc();
739
+			}
711 740
 
712 741
 			// Let them know it worked!
713 742
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -721,27 +750,31 @@  discard block
 block discarded – undo
721 750
 	if (!empty($post_errors))
722 751
 	{
723 752
 		// Set all the errors so the template knows what went wrong.
724
-		foreach ($post_errors as $error_type)
725
-			$context['modify_error'][$error_type] = true;
753
+		foreach ($post_errors as $error_type) {
754
+					$context['modify_error'][$error_type] = true;
755
+		}
726 756
 	}
727 757
 	// If it's you then we should redirect upon save.
728
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
729
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
730
-	elseif (!empty($force_redirect))
731
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
758
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
759
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
760
+	} elseif (!empty($force_redirect)) {
761
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
762
+	}
732 763
 
733 764
 
734 765
 	// Get the right callable.
735 766
 	$call = call_helper($profile_include_data['function'], true);
736 767
 
737 768
 	// Is it valid?
738
-	if (!empty($call))
739
-		call_user_func($call, $memID);
769
+	if (!empty($call)) {
770
+			call_user_func($call, $memID);
771
+	}
740 772
 
741 773
 	// Set the page title if it's not already set...
742
-	if (!isset($context['page_title']))
743
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
744
-}
774
+	if (!isset($context['page_title'])) {
775
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
776
+	}
777
+	}
745 778
 
746 779
 /**
747 780
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -864,16 +897,18 @@  discard block
 block discarded – undo
864 897
 	if (!allowedTo('admin_forum') && $area != 'register')
865 898
 	{
866 899
 		// If it's the owner they can see two types of private fields, regardless.
867
-		if ($memID == $user_info['id'])
868
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
869
-		else
870
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
900
+		if ($memID == $user_info['id']) {
901
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
902
+		} else {
903
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
904
+		}
871 905
 	}
872 906
 
873
-	if ($area == 'register')
874
-		$where .= ' AND show_reg != 0';
875
-	elseif ($area != 'summary')
876
-		$where .= ' AND show_profile = {string:area}';
907
+	if ($area == 'register') {
908
+			$where .= ' AND show_reg != 0';
909
+	} elseif ($area != 'summary') {
910
+			$where .= ' AND show_profile = {string:area}';
911
+	}
877 912
 
878 913
 	// Load all the relevant fields - and data.
879 914
 	$request = $smcFunc['db_query']('', '
@@ -899,13 +934,15 @@  discard block
 block discarded – undo
899 934
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
900 935
 		{
901 936
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
902
-			if (in_array($row['field_type'], array('select', 'radio')))
903
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
937
+			if (in_array($row['field_type'], array('select', 'radio'))) {
938
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
939
+			}
904 940
 		}
905 941
 
906 942
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
907
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled')
908
-			continue;
943
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') {
944
+					continue;
945
+		}
909 946
 
910 947
 		// HTML for the input form.
911 948
 		$output_html = $value;
@@ -914,8 +951,7 @@  discard block
 block discarded – undo
914 951
 			$true = (!$exists && $row['default_value']) || $value;
915 952
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . ' class="input_check">';
916 953
 			$output_html = $true ? $txt['yes'] : $txt['no'];
917
-		}
918
-		elseif ($row['field_type'] == 'select')
954
+		} elseif ($row['field_type'] == 'select')
919 955
 		{
920 956
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
921 957
 			$options = explode(',', $row['field_options']);
@@ -923,13 +959,13 @@  discard block
 block discarded – undo
923 959
 			{
924 960
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
925 961
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
926
-				if ($true)
927
-					$output_html = $v;
962
+				if ($true) {
963
+									$output_html = $v;
964
+				}
928 965
 			}
929 966
 
930 967
 			$input_html .= '</select>';
931
-		}
932
-		elseif ($row['field_type'] == 'radio')
968
+		} elseif ($row['field_type'] == 'radio')
933 969
 		{
934 970
 			$input_html = '<fieldset>';
935 971
 			$options = explode(',', $row['field_options']);
@@ -937,36 +973,37 @@  discard block
 block discarded – undo
937 973
 			{
938 974
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
939 975
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
940
-				if ($true)
941
-					$output_html = $v;
976
+				if ($true) {
977
+									$output_html = $v;
978
+				}
942 979
 			}
943 980
 			$input_html .= '</fieldset>';
944
-		}
945
-		elseif ($row['field_type'] == 'text')
981
+		} elseif ($row['field_type'] == 'text')
946 982
 		{
947 983
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '" class="input_text"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
948
-		}
949
-		else
984
+		} else
950 985
 		{
951 986
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
952 987
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
953 988
 		}
954 989
 
955 990
 		// Parse BBCode
956
-		if ($row['bbc'])
957
-			$output_html = parse_bbc($output_html);
958
-		elseif ($row['field_type'] == 'textarea')
959
-			// Allow for newlines at least
991
+		if ($row['bbc']) {
992
+					$output_html = parse_bbc($output_html);
993
+		} elseif ($row['field_type'] == 'textarea') {
994
+					// Allow for newlines at least
960 995
 			$output_html = strtr($output_html, array("\n" => '<br>'));
996
+		}
961 997
 
962 998
 		// Enclosing the user input within some other text?
963
-		if (!empty($row['enclose']) && !empty($output_html))
964
-			$output_html = strtr($row['enclose'], array(
999
+		if (!empty($row['enclose']) && !empty($output_html)) {
1000
+					$output_html = strtr($row['enclose'], array(
965 1001
 				'{SCRIPTURL}' => $scripturl,
966 1002
 				'{IMAGES_URL}' => $settings['images_url'],
967 1003
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
968 1004
 				'{INPUT}' => un_htmlspecialchars($output_html),
969 1005
 			));
1006
+		}
970 1007
 
971 1008
 		$context['custom_fields'][] = array(
972 1009
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.