| @@ -13,8 +13,9 @@ discard block | ||
| 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 | * Update some basic statistics. | 
| @@ -122,10 +123,11 @@ discard block | ||
| 122 | 123 | $smcFunc['db_free_result']($result); | 
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members | 
| 125 | - if (!empty($changes['unapprovedMembers'])) | |
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; | |
| 127 | - else | |
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; | |
| 126 | +						if (!empty($changes['unapprovedMembers'])) { | |
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; | |
| 128 | +						} else { | |
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; | |
| 130 | + } | |
| 129 | 131 | } | 
| 130 | 132 | } | 
| 131 | 133 | } | 
| @@ -133,9 +135,9 @@ discard block | ||
| 133 | 135 | break; | 
| 134 | 136 | |
| 135 | 137 | case 'message': | 
| 136 | - if ($parameter1 === true && $parameter2 !== null) | |
| 137 | -				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); | |
| 138 | - else | |
| 138 | +			if ($parameter1 === true && $parameter2 !== null) { | |
| 139 | +							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); | |
| 140 | + } else | |
| 139 | 141 |  			{ | 
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. | 
| 141 | 143 |  				$result = $smcFunc['db_query']('', ' | 
| @@ -175,23 +177,25 @@ discard block | ||
| 175 | 177 | $parameter2 = text2words($parameter2); | 
| 176 | 178 | |
| 177 | 179 | $inserts = array(); | 
| 178 | - foreach ($parameter2 as $word) | |
| 179 | - $inserts[] = array($word, $parameter1); | |
| 180 | +				foreach ($parameter2 as $word) { | |
| 181 | + $inserts[] = array($word, $parameter1); | |
| 182 | + } | |
| 180 | 183 | |
| 181 | - if (!empty($inserts)) | |
| 182 | -					$smcFunc['db_insert']('ignore', | |
| 184 | +				if (!empty($inserts)) { | |
| 185 | +									$smcFunc['db_insert']('ignore', | |
| 183 | 186 |  						'{db_prefix}log_search_subjects', | 
| 184 | 187 |  						array('word' => 'string', 'id_topic' => 'int'), | 
| 185 | 188 | $inserts, | 
| 186 | 189 |  						array('word', 'id_topic') | 
| 187 | 190 | ); | 
| 191 | + } | |
| 188 | 192 | } | 
| 189 | 193 | break; | 
| 190 | 194 | |
| 191 | 195 | case 'topic': | 
| 192 | - if ($parameter1 === true) | |
| 193 | -				updateSettings(array('totalTopics' => true), true); | |
| 194 | - else | |
| 196 | +			if ($parameter1 === true) { | |
| 197 | +							updateSettings(array('totalTopics' => true), true); | |
| 198 | + } else | |
| 195 | 199 |  			{ | 
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. | 
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. | 
| @@ -212,8 +216,9 @@ discard block | ||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': | 
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. | 
| 215 | -			if ($parameter2 !== null && !in_array('posts', $parameter2)) | |
| 216 | - return; | |
| 219 | +			if ($parameter2 !== null && !in_array('posts', $parameter2)) { | |
| 220 | + return; | |
| 221 | + } | |
| 217 | 222 | |
| 218 | 223 |  			$postgroups = cache_get_data('updateStats:postgroups', 360); | 
| 219 | 224 | if ($postgroups == null || $parameter1 == null) | 
| @@ -228,8 +233,9 @@ discard block | ||
| 228 | 233 | ) | 
| 229 | 234 | ); | 
| 230 | 235 | $postgroups = array(); | 
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; | |
| 236 | +				while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; | |
| 238 | + } | |
| 233 | 239 | $smcFunc['db_free_result']($request); | 
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. | 
| @@ -239,8 +245,9 @@ discard block | ||
| 239 | 245 | } | 
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. | 
| 242 | - if (empty($postgroups)) | |
| 243 | - return; | |
| 248 | +			if (empty($postgroups)) { | |
| 249 | + return; | |
| 250 | + } | |
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. | 
| 246 | 253 | $conditions = ''; | 
| @@ -298,10 +305,9 @@ discard block | ||
| 298 | 305 |  	{ | 
| 299 | 306 |  		$condition = 'id_member IN ({array_int:members})'; | 
| 300 | 307 | $parameters['members'] = $members; | 
| 301 | - } | |
| 302 | - elseif ($members === null) | |
| 303 | - $condition = '1=1'; | |
| 304 | - else | |
| 308 | +	} elseif ($members === null) { | |
| 309 | + $condition = '1=1'; | |
| 310 | + } else | |
| 305 | 311 |  	{ | 
| 306 | 312 |  		$condition = 'id_member = {int:member}'; | 
| 307 | 313 | $parameters['member'] = $members; | 
| @@ -341,9 +347,9 @@ discard block | ||
| 341 | 347 | if (count($vars_to_integrate) != 0) | 
| 342 | 348 |  		{ | 
| 343 | 349 | // Fetch a list of member_names if necessary | 
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) | |
| 345 | - $member_names = array($user_info['username']); | |
| 346 | - else | |
| 350 | +			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { | |
| 351 | + $member_names = array($user_info['username']); | |
| 352 | + } else | |
| 347 | 353 |  			{ | 
| 348 | 354 | $member_names = array(); | 
| 349 | 355 |  				$request = $smcFunc['db_query']('', ' | 
| @@ -352,14 +358,16 @@ discard block | ||
| 352 | 358 | WHERE ' . $condition, | 
| 353 | 359 | $parameters | 
| 354 | 360 | ); | 
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 356 | - $member_names[] = $row['member_name']; | |
| 361 | +				while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 362 | + $member_names[] = $row['member_name']; | |
| 363 | + } | |
| 357 | 364 | $smcFunc['db_free_result']($request); | 
| 358 | 365 | } | 
| 359 | 366 | |
| 360 | - if (!empty($member_names)) | |
| 361 | - foreach ($vars_to_integrate as $var) | |
| 367 | +			if (!empty($member_names)) { | |
| 368 | + foreach ($vars_to_integrate as $var) | |
| 362 | 369 |  					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); | 
| 370 | + } | |
| 363 | 371 | } | 
| 364 | 372 | } | 
| 365 | 373 | |
| @@ -367,16 +375,17 @@ discard block | ||
| 367 | 375 | foreach ($data as $var => $val) | 
| 368 | 376 |  	{ | 
| 369 | 377 | $type = 'string'; | 
| 370 | - if (in_array($var, $knownInts)) | |
| 371 | - $type = 'int'; | |
| 372 | - elseif (in_array($var, $knownFloats)) | |
| 373 | - $type = 'float'; | |
| 374 | - elseif ($var == 'birthdate') | |
| 375 | - $type = 'date'; | |
| 376 | - elseif ($var == 'member_ip') | |
| 377 | - $type = 'inet'; | |
| 378 | - elseif ($var == 'member_ip2') | |
| 379 | - $type = 'inet'; | |
| 378 | +		if (in_array($var, $knownInts)) { | |
| 379 | + $type = 'int'; | |
| 380 | +		} elseif (in_array($var, $knownFloats)) { | |
| 381 | + $type = 'float'; | |
| 382 | +		} elseif ($var == 'birthdate') { | |
| 383 | + $type = 'date'; | |
| 384 | +		} elseif ($var == 'member_ip') { | |
| 385 | + $type = 'inet'; | |
| 386 | +		} elseif ($var == 'member_ip2') { | |
| 387 | + $type = 'inet'; | |
| 388 | + } | |
| 380 | 389 | |
| 381 | 390 | // Doing an increment? | 
| 382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) | 
| @@ -390,8 +399,9 @@ discard block | ||
| 390 | 399 |  		{ | 
| 391 | 400 |  			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) | 
| 392 | 401 |  			{ | 
| 393 | - if ($match[1] != '+ ') | |
| 394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; | |
| 402 | +				if ($match[1] != '+ ') { | |
| 403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; | |
| 404 | + } | |
| 395 | 405 | $type = 'raw'; | 
| 396 | 406 | } | 
| 397 | 407 | } | 
| @@ -412,8 +422,9 @@ discard block | ||
| 412 | 422 | // Clear any caching? | 
| 413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) | 
| 414 | 424 |  	{ | 
| 415 | - if (!is_array($members)) | |
| 416 | - $members = array($members); | |
| 425 | +		if (!is_array($members)) { | |
| 426 | + $members = array($members); | |
| 427 | + } | |
| 417 | 428 | |
| 418 | 429 | foreach ($members as $member) | 
| 419 | 430 |  		{ | 
| @@ -446,29 +457,32 @@ discard block | ||
| 446 | 457 |  { | 
| 447 | 458 | global $modSettings, $smcFunc; | 
| 448 | 459 | |
| 449 | - if (empty($changeArray) || !is_array($changeArray)) | |
| 450 | - return; | |
| 460 | +	if (empty($changeArray) || !is_array($changeArray)) { | |
| 461 | + return; | |
| 462 | + } | |
| 451 | 463 | |
| 452 | 464 | $toRemove = array(); | 
| 453 | 465 | |
| 454 | 466 | // Go check if there is any setting to be removed. | 
| 455 | - foreach ($changeArray as $k => $v) | |
| 456 | - if ($v === null) | |
| 467 | +	foreach ($changeArray as $k => $v) { | |
| 468 | + if ($v === null) | |
| 457 | 469 |  		{ | 
| 458 | 470 | // Found some, remove them from the original array and add them to ours. | 
| 459 | 471 | unset($changeArray[$k]); | 
| 472 | + } | |
| 460 | 473 | $toRemove[] = $k; | 
| 461 | 474 | } | 
| 462 | 475 | |
| 463 | 476 | // Proceed with the deletion. | 
| 464 | - if (!empty($toRemove)) | |
| 465 | -		$smcFunc['db_query']('', ' | |
| 477 | +	if (!empty($toRemove)) { | |
| 478 | +			$smcFunc['db_query']('', ' | |
| 466 | 479 |  			DELETE FROM {db_prefix}settings | 
| 467 | 480 |  			WHERE variable IN ({array_string:remove})', | 
| 468 | 481 | array( | 
| 469 | 482 | 'remove' => $toRemove, | 
| 470 | 483 | ) | 
| 471 | 484 | ); | 
| 485 | + } | |
| 472 | 486 | |
| 473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. | 
| 474 | 488 | if ($update) | 
| @@ -497,19 +511,22 @@ discard block | ||
| 497 | 511 | foreach ($changeArray as $variable => $value) | 
| 498 | 512 |  	{ | 
| 499 | 513 | // Don't bother if it's already like that ;). | 
| 500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) | |
| 501 | - continue; | |
| 514 | +		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { | |
| 515 | + continue; | |
| 516 | + } | |
| 502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. | 
| 503 | - elseif (!isset($modSettings[$variable]) && empty($value)) | |
| 504 | - continue; | |
| 518 | +		elseif (!isset($modSettings[$variable]) && empty($value)) { | |
| 519 | + continue; | |
| 520 | + } | |
| 505 | 521 | |
| 506 | 522 | $replaceArray[] = array($variable, $value); | 
| 507 | 523 | |
| 508 | 524 | $modSettings[$variable] = $value; | 
| 509 | 525 | } | 
| 510 | 526 | |
| 511 | - if (empty($replaceArray)) | |
| 512 | - return; | |
| 527 | +	if (empty($replaceArray)) { | |
| 528 | + return; | |
| 529 | + } | |
| 513 | 530 | |
| 514 | 531 |  	$smcFunc['db_insert']('replace', | 
| 515 | 532 |  		'{db_prefix}settings', | 
| @@ -555,14 +572,17 @@ discard block | ||
| 555 | 572 | $start_invalid = $start < 0; | 
| 556 | 573 | |
| 557 | 574 | // Make sure $start is a proper variable - not less than 0. | 
| 558 | - if ($start_invalid) | |
| 559 | - $start = 0; | |
| 575 | +	if ($start_invalid) { | |
| 576 | + $start = 0; | |
| 577 | + } | |
| 560 | 578 | // Not greater than the upper bound. | 
| 561 | - elseif ($start >= $max_value) | |
| 562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); | |
| 579 | +	elseif ($start >= $max_value) { | |
| 580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); | |
| 581 | + } | |
| 563 | 582 | // And it has to be a multiple of $num_per_page! | 
| 564 | - else | |
| 565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); | |
| 583 | +	else { | |
| 584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); | |
| 585 | + } | |
| 566 | 586 | |
| 567 | 587 | $context['current_page'] = $start / $num_per_page; | 
| 568 | 588 | |
| @@ -592,77 +612,87 @@ discard block | ||
| 592 | 612 | |
| 593 | 613 | // Show all the pages. | 
| 594 | 614 | $display_page = 1; | 
| 595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) | |
| 596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); | |
| 615 | +		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { | |
| 616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); | |
| 617 | + } | |
| 597 | 618 | |
| 598 | 619 | // Show the right arrow. | 
| 599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); | 
| 600 | - if ($start != $counter - $max_value && !$start_invalid) | |
| 601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); | |
| 602 | - } | |
| 603 | - else | |
| 621 | +		if ($start != $counter - $max_value && !$start_invalid) { | |
| 622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); | |
| 623 | + } | |
| 624 | + } else | |
| 604 | 625 |  	{ | 
| 605 | 626 | // If they didn't enter an odd value, pretend they did. | 
| 606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; | 
| 607 | 628 | |
| 608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) | 
| 609 | - if (!empty($start) && $show_prevnext) | |
| 610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); | |
| 611 | - else | |
| 612 | - $pageindex .= ''; | |
| 630 | +		if (!empty($start) && $show_prevnext) { | |
| 631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); | |
| 632 | +		} else { | |
| 633 | + $pageindex .= ''; | |
| 634 | + } | |
| 613 | 635 | |
| 614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) | 
| 615 | - if ($start > $num_per_page * $PageContiguous) | |
| 616 | - $pageindex .= sprintf($base_link, 0, '1'); | |
| 637 | +		if ($start > $num_per_page * $PageContiguous) { | |
| 638 | + $pageindex .= sprintf($base_link, 0, '1'); | |
| 639 | + } | |
| 617 | 640 | |
| 618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) | 
| 619 | - if ($start > $num_per_page * ($PageContiguous + 1)) | |
| 620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( | |
| 642 | +		if ($start > $num_per_page * ($PageContiguous + 1)) { | |
| 643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( | |
| 621 | 644 |  				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), | 
| 622 | 645 |  				'{FIRST_PAGE}' => $num_per_page, | 
| 623 | 646 |  				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, | 
| 624 | 647 |  				'{PER_PAGE}' => $num_per_page, | 
| 625 | 648 | )); | 
| 649 | + } | |
| 626 | 650 | |
| 627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) | 
| 628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) | |
| 629 | - if ($start >= $num_per_page * $nCont) | |
| 652 | +		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { | |
| 653 | + if ($start >= $num_per_page * $nCont) | |
| 630 | 654 |  			{ | 
| 631 | 655 | $tmpStart = $start - $num_per_page * $nCont; | 
| 656 | + } | |
| 632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); | 
| 633 | 658 | } | 
| 634 | 659 | |
| 635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) | 
| 636 | - if (!$start_invalid) | |
| 637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); | |
| 638 | - else | |
| 639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); | |
| 661 | +		if (!$start_invalid) { | |
| 662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); | |
| 663 | +		} else { | |
| 664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); | |
| 665 | + } | |
| 640 | 666 | |
| 641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) | 
| 642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; | 
| 643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) | |
| 644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) | |
| 669 | +		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { | |
| 670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) | |
| 645 | 671 |  			{ | 
| 646 | 672 | $tmpStart = $start + $num_per_page * $nCont; | 
| 673 | + } | |
| 647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); | 
| 648 | 675 | } | 
| 649 | 676 | |
| 650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) | 
| 651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) | |
| 652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( | |
| 678 | +		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { | |
| 679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( | |
| 653 | 680 |  				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), | 
| 654 | 681 |  				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), | 
| 655 | 682 |  				'{LAST_PAGE}' => $tmpMaxPages, | 
| 656 | 683 |  				'{PER_PAGE}' => $num_per_page, | 
| 657 | 684 | )); | 
| 685 | + } | |
| 658 | 686 | |
| 659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) | 
| 660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) | |
| 661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); | |
| 688 | +		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { | |
| 689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); | |
| 690 | + } | |
| 662 | 691 | |
| 663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) | 
| 664 | - if ($start != $tmpMaxPages && $show_prevnext) | |
| 665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); | |
| 693 | +		if ($start != $tmpMaxPages && $show_prevnext) { | |
| 694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); | |
| 695 | + } | |
| 666 | 696 | } | 
| 667 | 697 | $pageindex .= $settings['page_index']['extra_after']; | 
| 668 | 698 | |
| @@ -688,8 +718,9 @@ discard block | ||
| 688 | 718 | if ($decimal_separator === null) | 
| 689 | 719 |  	{ | 
| 690 | 720 | // Not set for whatever reason? | 
| 691 | -		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) | |
| 692 | - return $number; | |
| 721 | +		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { | |
| 722 | + return $number; | |
| 723 | + } | |
| 693 | 724 | |
| 694 | 725 | // Cache these each load... | 
| 695 | 726 | $thousands_separator = $matches[1]; | 
| @@ -723,17 +754,20 @@ discard block | ||
| 723 | 754 | static $unsupportedFormats, $finalizedFormats; | 
| 724 | 755 | |
| 725 | 756 | // Offset the time. | 
| 726 | - if (!$offset_type) | |
| 727 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; | |
| 757 | +	if (!$offset_type) { | |
| 758 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; | |
| 759 | + } | |
| 728 | 760 | // Just the forum offset? | 
| 729 | - elseif ($offset_type == 'forum') | |
| 730 | - $time = $log_time + $modSettings['time_offset'] * 3600; | |
| 731 | - else | |
| 732 | - $time = $log_time; | |
| 761 | +	elseif ($offset_type == 'forum') { | |
| 762 | + $time = $log_time + $modSettings['time_offset'] * 3600; | |
| 763 | +	} else { | |
| 764 | + $time = $log_time; | |
| 765 | + } | |
| 733 | 766 | |
| 734 | 767 | // We can't have a negative date (on Windows, at least.) | 
| 735 | - if ($log_time < 0) | |
| 736 | - $log_time = 0; | |
| 768 | +	if ($log_time < 0) { | |
| 769 | + $log_time = 0; | |
| 770 | + } | |
| 737 | 771 | |
| 738 | 772 | // Today and Yesterday? | 
| 739 | 773 | if ($modSettings['todayMod'] >= 1 && $show_today === true) | 
| @@ -750,24 +784,27 @@ discard block | ||
| 750 | 784 |  		{ | 
| 751 | 785 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; | 
| 752 | 786 | $today_fmt = $h . ':%M' . $s . ' %p'; | 
| 787 | +		} else { | |
| 788 | + $today_fmt = '%H:%M' . $s; | |
| 753 | 789 | } | 
| 754 | - else | |
| 755 | - $today_fmt = '%H:%M' . $s; | |
| 756 | 790 | |
| 757 | 791 | // Same day of the year, same year.... Today! | 
| 758 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) | |
| 759 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); | |
| 792 | +		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { | |
| 793 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); | |
| 794 | + } | |
| 760 | 795 | |
| 761 | 796 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... | 
| 762 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) | |
| 763 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); | |
| 797 | +		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { | |
| 798 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); | |
| 799 | + } | |
| 764 | 800 | } | 
| 765 | 801 | |
| 766 | 802 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; | 
| 767 | 803 | |
| 768 | 804 | // Use the cached formats if available | 
| 769 | - if (is_null($finalizedFormats)) | |
| 770 | -		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); | |
| 805 | +	if (is_null($finalizedFormats)) { | |
| 806 | +			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); | |
| 807 | + } | |
| 771 | 808 | |
| 772 | 809 | // Make a supported version for this format if we don't already have one | 
| 773 | 810 | if (empty($finalizedFormats[$str])) | 
| @@ -796,8 +833,9 @@ discard block | ||
| 796 | 833 | ); | 
| 797 | 834 | |
| 798 | 835 | // No need to do this part again if we already did it once | 
| 799 | - if (is_null($unsupportedFormats)) | |
| 800 | -			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); | |
| 836 | +		if (is_null($unsupportedFormats)) { | |
| 837 | +					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); | |
| 838 | + } | |
| 801 | 839 | if (empty($unsupportedFormats)) | 
| 802 | 840 |  		{ | 
| 803 | 841 | foreach($strftimeFormatSubstitutions as $format => $substitution) | 
| @@ -806,20 +844,23 @@ discard block | ||
| 806 | 844 | |
| 807 | 845 | // Windows will return false for unsupported formats | 
| 808 | 846 | // Other operating systems return the format string as a literal | 
| 809 | - if ($value === false || $value === $format) | |
| 810 | - $unsupportedFormats[] = $format; | |
| 847 | +				if ($value === false || $value === $format) { | |
| 848 | + $unsupportedFormats[] = $format; | |
| 849 | + } | |
| 811 | 850 | } | 
| 812 | 851 |  			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); | 
| 813 | 852 | } | 
| 814 | 853 | |
| 815 | 854 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' | 
| 816 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') | |
| 817 | -			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); | |
| 855 | +		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { | |
| 856 | +					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); | |
| 857 | + } | |
| 818 | 858 | |
| 819 | 859 | // Substitute unsupported formats with supported ones | 
| 820 | - if (!empty($unsupportedFormats)) | |
| 821 | -			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) | |
| 860 | +		if (!empty($unsupportedFormats)) { | |
| 861 | +					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) | |
| 822 | 862 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); | 
| 863 | + } | |
| 823 | 864 | |
| 824 | 865 | // Remember this so we don't need to do it again | 
| 825 | 866 | $finalizedFormats[$str] = $timeformat; | 
| @@ -828,33 +869,39 @@ discard block | ||
| 828 | 869 | |
| 829 | 870 | $str = $finalizedFormats[$str]; | 
| 830 | 871 | |
| 831 | - if (!isset($locale_cache)) | |
| 832 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); | |
| 872 | +	if (!isset($locale_cache)) { | |
| 873 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale']); | |
| 874 | + } | |
| 833 | 875 | |
| 834 | 876 | if ($locale_cache !== false) | 
| 835 | 877 |  	{ | 
| 836 | 878 | // Check if another process changed the locale | 
| 837 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) | |
| 838 | - setlocale(LC_TIME, $txt['lang_locale']); | |
| 879 | +		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { | |
| 880 | + setlocale(LC_TIME, $txt['lang_locale']); | |
| 881 | + } | |
| 839 | 882 | |
| 840 | - if (!isset($non_twelve_hour)) | |
| 841 | -			$non_twelve_hour = trim(strftime('%p')) === ''; | |
| 842 | - if ($non_twelve_hour && strpos($str, '%p') !== false) | |
| 843 | -			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); | |
| 883 | +		if (!isset($non_twelve_hour)) { | |
| 884 | +					$non_twelve_hour = trim(strftime('%p')) === ''; | |
| 885 | + } | |
| 886 | +		if ($non_twelve_hour && strpos($str, '%p') !== false) { | |
| 887 | +					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); | |
| 888 | + } | |
| 844 | 889 | |
| 845 | -		foreach (array('%a', '%A', '%b', '%B') as $token) | |
| 846 | - if (strpos($str, $token) !== false) | |
| 890 | +		foreach (array('%a', '%A', '%b', '%B') as $token) { | |
| 891 | + if (strpos($str, $token) !== false) | |
| 847 | 892 | $str = str_replace($token, strftime($token, $time), $str); | 
| 848 | - } | |
| 849 | - else | |
| 893 | + } | |
| 894 | + } else | |
| 850 | 895 |  	{ | 
| 851 | 896 | // Do-it-yourself time localization. Fun. | 
| 852 | -		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) | |
| 853 | - if (strpos($str, $token) !== false) | |
| 897 | +		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { | |
| 898 | + if (strpos($str, $token) !== false) | |
| 854 | 899 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); | 
| 900 | + } | |
| 855 | 901 | |
| 856 | - if (strpos($str, '%p') !== false) | |
| 857 | -			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); | |
| 902 | +		if (strpos($str, '%p') !== false) { | |
| 903 | +					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); | |
| 904 | + } | |
| 858 | 905 | } | 
| 859 | 906 | |
| 860 | 907 | // Format the time and then restore any literal percent characters | 
| @@ -877,16 +924,19 @@ discard block | ||
| 877 | 924 | static $translation = array(); | 
| 878 | 925 | |
| 879 | 926 | // Determine the character set... Default to UTF-8 | 
| 880 | - if (empty($context['character_set'])) | |
| 881 | - $charset = 'UTF-8'; | |
| 927 | +	if (empty($context['character_set'])) { | |
| 928 | + $charset = 'UTF-8'; | |
| 929 | + } | |
| 882 | 930 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... | 
| 883 | -	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) | |
| 884 | - $charset = 'ISO-8859-1'; | |
| 885 | - else | |
| 886 | - $charset = $context['character_set']; | |
| 931 | +	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { | |
| 932 | + $charset = 'ISO-8859-1'; | |
| 933 | +	} else { | |
| 934 | + $charset = $context['character_set']; | |
| 935 | + } | |
| 887 | 936 | |
| 888 | - if (empty($translation)) | |
| 889 | -		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); | |
| 937 | +	if (empty($translation)) { | |
| 938 | +			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); | |
| 939 | + } | |
| 890 | 940 | |
| 891 | 941 | return strtr($string, $translation); | 
| 892 | 942 | } | 
| @@ -908,8 +958,9 @@ discard block | ||
| 908 | 958 | global $smcFunc; | 
| 909 | 959 | |
| 910 | 960 | // It was already short enough! | 
| 911 | - if ($smcFunc['strlen']($subject) <= $len) | |
| 912 | - return $subject; | |
| 961 | +	if ($smcFunc['strlen']($subject) <= $len) { | |
| 962 | + return $subject; | |
| 963 | + } | |
| 913 | 964 | |
| 914 | 965 | // Shorten it by the length it was too long, and strip off junk from the end. | 
| 915 | 966 | return $smcFunc['substr']($subject, 0, $len) . '...'; | 
| @@ -928,10 +979,11 @@ discard block | ||
| 928 | 979 |  { | 
| 929 | 980 | global $user_info, $modSettings; | 
| 930 | 981 | |
| 931 | - if ($timestamp === null) | |
| 932 | - $timestamp = time(); | |
| 933 | - elseif ($timestamp == 0) | |
| 934 | - return 0; | |
| 982 | +	if ($timestamp === null) { | |
| 983 | + $timestamp = time(); | |
| 984 | +	} elseif ($timestamp == 0) { | |
| 985 | + return 0; | |
| 986 | + } | |
| 935 | 987 | |
| 936 | 988 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; | 
| 937 | 989 | } | 
| @@ -960,8 +1012,9 @@ discard block | ||
| 960 | 1012 | $array[$i] = $array[$j]; | 
| 961 | 1013 | $array[$j] = $temp; | 
| 962 | 1014 | |
| 963 | - for ($i = 1; $p[$i] == 0; $i++) | |
| 964 | - $p[$i] = 1; | |
| 1015 | +		for ($i = 1; $p[$i] == 0; $i++) { | |
| 1016 | + $p[$i] = 1; | |
| 1017 | + } | |
| 965 | 1018 | |
| 966 | 1019 | $orders[] = $array; | 
| 967 | 1020 | } | 
| @@ -993,12 +1046,14 @@ discard block | ||
| 993 | 1046 | static $disabled; | 
| 994 | 1047 | |
| 995 | 1048 | // Don't waste cycles | 
| 996 | - if ($message === '') | |
| 997 | - return ''; | |
| 1049 | +	if ($message === '') { | |
| 1050 | + return ''; | |
| 1051 | + } | |
| 998 | 1052 | |
| 999 | 1053 | // Just in case it wasn't determined yet whether UTF-8 is enabled. | 
| 1000 | - if (!isset($context['utf8'])) | |
| 1001 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; | |
| 1054 | +	if (!isset($context['utf8'])) { | |
| 1055 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; | |
| 1056 | + } | |
| 1002 | 1057 | |
| 1003 | 1058 | // Clean up any cut/paste issues we may have | 
| 1004 | 1059 | $message = sanitizeMSCutPaste($message); | 
| @@ -1010,13 +1065,15 @@ discard block | ||
| 1010 | 1065 | return $message; | 
| 1011 | 1066 | } | 
| 1012 | 1067 | |
| 1013 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) | |
| 1014 | - $smileys = (bool) $smileys; | |
| 1068 | +	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { | |
| 1069 | + $smileys = (bool) $smileys; | |
| 1070 | + } | |
| 1015 | 1071 | |
| 1016 | 1072 | if (empty($modSettings['enableBBC']) && $message !== false) | 
| 1017 | 1073 |  	{ | 
| 1018 | - if ($smileys === true) | |
| 1019 | - parsesmileys($message); | |
| 1074 | +		if ($smileys === true) { | |
| 1075 | + parsesmileys($message); | |
| 1076 | + } | |
| 1020 | 1077 | |
| 1021 | 1078 | return $message; | 
| 1022 | 1079 | } | 
| @@ -1029,8 +1086,9 @@ discard block | ||
| 1029 | 1086 | } | 
| 1030 | 1087 | |
| 1031 | 1088 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker | 
| 1032 | - if (!empty($modSettings['autoLinkUrls'])) | |
| 1033 | - set_tld_regex(); | |
| 1089 | +	if (!empty($modSettings['autoLinkUrls'])) { | |
| 1090 | + set_tld_regex(); | |
| 1091 | + } | |
| 1034 | 1092 | |
| 1035 | 1093 | // Allow mods access before entering the main parse_bbc loop | 
| 1036 | 1094 |  	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); | 
| @@ -1044,12 +1102,14 @@ discard block | ||
| 1044 | 1102 | |
| 1045 | 1103 |  			$temp = explode(',', strtolower($modSettings['disabledBBC'])); | 
| 1046 | 1104 | |
| 1047 | - foreach ($temp as $tag) | |
| 1048 | - $disabled[trim($tag)] = true; | |
| 1105 | +			foreach ($temp as $tag) { | |
| 1106 | + $disabled[trim($tag)] = true; | |
| 1107 | + } | |
| 1049 | 1108 | } | 
| 1050 | 1109 | |
| 1051 | - if (empty($modSettings['enableEmbeddedFlash'])) | |
| 1052 | - $disabled['flash'] = true; | |
| 1110 | +		if (empty($modSettings['enableEmbeddedFlash'])) { | |
| 1111 | + $disabled['flash'] = true; | |
| 1112 | + } | |
| 1053 | 1113 | |
| 1054 | 1114 | /* The following bbc are formatted as an array, with keys as follows: | 
| 1055 | 1115 | |
| @@ -1170,8 +1230,9 @@ discard block | ||
| 1170 | 1230 | $returnContext = ''; | 
| 1171 | 1231 | |
| 1172 | 1232 | // BBC or the entire attachments feature is disabled | 
| 1173 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) | |
| 1174 | - return $data; | |
| 1233 | +					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { | |
| 1234 | + return $data; | |
| 1235 | + } | |
| 1175 | 1236 | |
| 1176 | 1237 | // Save the attach ID. | 
| 1177 | 1238 | $attachID = $data; | 
| @@ -1182,8 +1243,9 @@ discard block | ||
| 1182 | 1243 | $currentAttachment = parseAttachBBC($attachID); | 
| 1183 | 1244 | |
| 1184 | 1245 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. | 
| 1185 | - if (is_string($currentAttachment)) | |
| 1186 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; | |
| 1246 | +					if (is_string($currentAttachment)) { | |
| 1247 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; | |
| 1248 | + } | |
| 1187 | 1249 | |
| 1188 | 1250 | if (!empty($currentAttachment['is_image'])) | 
| 1189 | 1251 |  					{ | 
| @@ -1199,15 +1261,17 @@ discard block | ||
| 1199 | 1261 | $height = ' height="' . $currentAttachment['height'] . '"'; | 
| 1200 | 1262 | } | 
| 1201 | 1263 | |
| 1202 | -						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) | |
| 1203 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; | |
| 1204 | - else | |
| 1205 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; | |
| 1264 | +						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { | |
| 1265 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; | |
| 1266 | +						} else { | |
| 1267 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; | |
| 1268 | + } | |
| 1206 | 1269 | } | 
| 1207 | 1270 | |
| 1208 | 1271 | // No image. Show a link. | 
| 1209 | - else | |
| 1210 | - $returnContext .= $currentAttachment['link']; | |
| 1272 | +					else { | |
| 1273 | + $returnContext .= $currentAttachment['link']; | |
| 1274 | + } | |
| 1211 | 1275 | |
| 1212 | 1276 | // Gotta append what we just did. | 
| 1213 | 1277 | $data = $returnContext; | 
| @@ -1238,8 +1302,9 @@ discard block | ||
| 1238 | 1302 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) | 
| 1239 | 1303 |  						{ | 
| 1240 | 1304 | // Do PHP code coloring? | 
| 1241 | - if ($php_parts[$php_i] != '<?php') | |
| 1242 | - continue; | |
| 1305 | +							if ($php_parts[$php_i] != '<?php') { | |
| 1306 | + continue; | |
| 1307 | + } | |
| 1243 | 1308 | |
| 1244 | 1309 | $php_string = ''; | 
| 1245 | 1310 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') | 
| @@ -1255,8 +1320,9 @@ discard block | ||
| 1255 | 1320 |  						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); | 
| 1256 | 1321 | |
| 1257 | 1322 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. | 
| 1258 | - if ($context['browser']['is_opera']) | |
| 1259 | - $data .= ' '; | |
| 1323 | +						if ($context['browser']['is_opera']) { | |
| 1324 | + $data .= ' '; | |
| 1325 | + } | |
| 1260 | 1326 | } | 
| 1261 | 1327 | }, | 
| 1262 | 1328 | 'block_level' => true, | 
| @@ -1275,8 +1341,9 @@ discard block | ||
| 1275 | 1341 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) | 
| 1276 | 1342 |  						{ | 
| 1277 | 1343 | // Do PHP code coloring? | 
| 1278 | - if ($php_parts[$php_i] != '<?php') | |
| 1279 | - continue; | |
| 1344 | +							if ($php_parts[$php_i] != '<?php') { | |
| 1345 | + continue; | |
| 1346 | + } | |
| 1280 | 1347 | |
| 1281 | 1348 | $php_string = ''; | 
| 1282 | 1349 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') | 
| @@ -1292,8 +1359,9 @@ discard block | ||
| 1292 | 1359 |  						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); | 
| 1293 | 1360 | |
| 1294 | 1361 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. | 
| 1295 | - if ($context['browser']['is_opera']) | |
| 1296 | - $data[0] .= ' '; | |
| 1362 | +						if ($context['browser']['is_opera']) { | |
| 1363 | + $data[0] .= ' '; | |
| 1364 | + } | |
| 1297 | 1365 | } | 
| 1298 | 1366 | }, | 
| 1299 | 1367 | 'block_level' => true, | 
| @@ -1331,11 +1399,13 @@ discard block | ||
| 1331 | 1399 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', | 
| 1332 | 1400 | 'validate' => function (&$tag, &$data, $disabled) | 
| 1333 | 1401 |  				{ | 
| 1334 | - if (isset($disabled['url'])) | |
| 1335 | - $tag['content'] = '$1'; | |
| 1402 | +					if (isset($disabled['url'])) { | |
| 1403 | + $tag['content'] = '$1'; | |
| 1404 | + } | |
| 1336 | 1405 | $scheme = parse_url($data[0], PHP_URL_SCHEME); | 
| 1337 | - if (empty($scheme)) | |
| 1338 | - $data[0] = '//' . ltrim($data[0], ':/'); | |
| 1406 | +					if (empty($scheme)) { | |
| 1407 | + $data[0] = '//' . ltrim($data[0], ':/'); | |
| 1408 | + } | |
| 1339 | 1409 | }, | 
| 1340 | 1410 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', | 
| 1341 | 1411 | ), | 
| @@ -1349,10 +1419,11 @@ discard block | ||
| 1349 | 1419 |  				{ | 
| 1350 | 1420 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; | 
| 1351 | 1421 | |
| 1352 | -					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) | |
| 1353 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; | |
| 1354 | - else | |
| 1355 | - $css = ''; | |
| 1422 | +					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { | |
| 1423 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; | |
| 1424 | +					} else { | |
| 1425 | + $css = ''; | |
| 1426 | + } | |
| 1356 | 1427 | |
| 1357 | 1428 | $data = $class . $css; | 
| 1358 | 1429 | }, | 
| @@ -1402,14 +1473,16 @@ discard block | ||
| 1402 | 1473 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1403 | 1474 | if ($image_proxy_enabled) | 
| 1404 | 1475 |  					{ | 
| 1405 | - if (empty($scheme)) | |
| 1406 | - $data = 'http://' . ltrim($data, ':/'); | |
| 1476 | +						if (empty($scheme)) { | |
| 1477 | + $data = 'http://' . ltrim($data, ':/'); | |
| 1478 | + } | |
| 1407 | 1479 | |
| 1408 | - if ($scheme != 'https') | |
| 1409 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); | |
| 1480 | +						if ($scheme != 'https') { | |
| 1481 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); | |
| 1482 | + } | |
| 1483 | +					} elseif (empty($scheme)) { | |
| 1484 | + $data = '//' . ltrim($data, ':/'); | |
| 1410 | 1485 | } | 
| 1411 | - elseif (empty($scheme)) | |
| 1412 | - $data = '//' . ltrim($data, ':/'); | |
| 1413 | 1486 | }, | 
| 1414 | 1487 | 'disabled_content' => '($1)', | 
| 1415 | 1488 | ), | 
| @@ -1425,14 +1498,16 @@ discard block | ||
| 1425 | 1498 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1426 | 1499 | if ($image_proxy_enabled) | 
| 1427 | 1500 |  					{ | 
| 1428 | - if (empty($scheme)) | |
| 1429 | - $data = 'http://' . ltrim($data, ':/'); | |
| 1501 | +						if (empty($scheme)) { | |
| 1502 | + $data = 'http://' . ltrim($data, ':/'); | |
| 1503 | + } | |
| 1430 | 1504 | |
| 1431 | - if ($scheme != 'https') | |
| 1432 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); | |
| 1505 | +						if ($scheme != 'https') { | |
| 1506 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); | |
| 1507 | + } | |
| 1508 | +					} elseif (empty($scheme)) { | |
| 1509 | + $data = '//' . ltrim($data, ':/'); | |
| 1433 | 1510 | } | 
| 1434 | - elseif (empty($scheme)) | |
| 1435 | - $data = '//' . ltrim($data, ':/'); | |
| 1436 | 1511 | }, | 
| 1437 | 1512 | 'disabled_content' => '($1)', | 
| 1438 | 1513 | ), | 
| @@ -1444,8 +1519,9 @@ discard block | ||
| 1444 | 1519 |  				{ | 
| 1445 | 1520 |  					$data = strtr($data, array('<br>' => '')); | 
| 1446 | 1521 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1447 | - if (empty($scheme)) | |
| 1448 | - $data = '//' . ltrim($data, ':/'); | |
| 1522 | +					if (empty($scheme)) { | |
| 1523 | + $data = '//' . ltrim($data, ':/'); | |
| 1524 | + } | |
| 1449 | 1525 | }, | 
| 1450 | 1526 | ), | 
| 1451 | 1527 | array( | 
| @@ -1456,13 +1532,14 @@ discard block | ||
| 1456 | 1532 | 'after' => '</a>', | 
| 1457 | 1533 | 'validate' => function (&$tag, &$data, $disabled) | 
| 1458 | 1534 |  				{ | 
| 1459 | - if (substr($data, 0, 1) == '#') | |
| 1460 | - $data = '#post_' . substr($data, 1); | |
| 1461 | - else | |
| 1535 | +					if (substr($data, 0, 1) == '#') { | |
| 1536 | + $data = '#post_' . substr($data, 1); | |
| 1537 | + } else | |
| 1462 | 1538 |  					{ | 
| 1463 | 1539 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1464 | - if (empty($scheme)) | |
| 1465 | - $data = '//' . ltrim($data, ':/'); | |
| 1540 | +						if (empty($scheme)) { | |
| 1541 | + $data = '//' . ltrim($data, ':/'); | |
| 1542 | + } | |
| 1466 | 1543 | } | 
| 1467 | 1544 | }, | 
| 1468 | 1545 |  				'disallow_children' => array('email', 'ftp', 'url', 'iurl'), | 
| @@ -1540,8 +1617,9 @@ discard block | ||
| 1540 | 1617 |  					{ | 
| 1541 | 1618 | $add_begin = substr(trim($data), 0, 5) != '<?'; | 
| 1542 | 1619 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); | 
| 1543 | - if ($add_begin) | |
| 1544 | -							$data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); | |
| 1620 | +						if ($add_begin) { | |
| 1621 | +													$data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); | |
| 1622 | + } | |
| 1545 | 1623 | } | 
| 1546 | 1624 | }, | 
| 1547 | 1625 | 'block_level' => false, | 
| @@ -1672,10 +1750,11 @@ discard block | ||
| 1672 | 1750 | 'content' => '$1', | 
| 1673 | 1751 | 'validate' => function (&$tag, &$data, $disabled) | 
| 1674 | 1752 |  				{ | 
| 1675 | - if (is_numeric($data)) | |
| 1676 | - $data = timeformat($data); | |
| 1677 | - else | |
| 1678 | - $tag['content'] = '[time]$1[/time]'; | |
| 1753 | +					if (is_numeric($data)) { | |
| 1754 | + $data = timeformat($data); | |
| 1755 | +					} else { | |
| 1756 | + $tag['content'] = '[time]$1[/time]'; | |
| 1757 | + } | |
| 1679 | 1758 | }, | 
| 1680 | 1759 | ), | 
| 1681 | 1760 | array( | 
| @@ -1702,8 +1781,9 @@ discard block | ||
| 1702 | 1781 |  				{ | 
| 1703 | 1782 |  					$data = strtr($data, array('<br>' => '')); | 
| 1704 | 1783 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1705 | - if (empty($scheme)) | |
| 1706 | - $data = '//' . ltrim($data, ':/'); | |
| 1784 | +					if (empty($scheme)) { | |
| 1785 | + $data = '//' . ltrim($data, ':/'); | |
| 1786 | + } | |
| 1707 | 1787 | }, | 
| 1708 | 1788 | ), | 
| 1709 | 1789 | array( | 
| @@ -1715,8 +1795,9 @@ discard block | ||
| 1715 | 1795 | 'validate' => function (&$tag, &$data, $disabled) | 
| 1716 | 1796 |  				{ | 
| 1717 | 1797 | $scheme = parse_url($data, PHP_URL_SCHEME); | 
| 1718 | - if (empty($scheme)) | |
| 1719 | - $data = '//' . ltrim($data, ':/'); | |
| 1798 | +					if (empty($scheme)) { | |
| 1799 | + $data = '//' . ltrim($data, ':/'); | |
| 1800 | + } | |
| 1720 | 1801 | }, | 
| 1721 | 1802 |  				'disallow_children' => array('email', 'ftp', 'url', 'iurl'), | 
| 1722 | 1803 | 'disabled_after' => ' ($1)', | 
| @@ -1736,8 +1817,9 @@ discard block | ||
| 1736 | 1817 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. | 
| 1737 | 1818 | if ($message === false) | 
| 1738 | 1819 |  		{ | 
| 1739 | - if (isset($temp_bbc)) | |
| 1740 | - $bbc_codes = $temp_bbc; | |
| 1820 | +			if (isset($temp_bbc)) { | |
| 1821 | + $bbc_codes = $temp_bbc; | |
| 1822 | + } | |
| 1741 | 1823 |  			usort($codes, function ($a, $b) { | 
| 1742 | 1824 | return strcmp($a['tag'], $b['tag']); | 
| 1743 | 1825 | }); | 
| @@ -1757,8 +1839,9 @@ discard block | ||
| 1757 | 1839 | ); | 
| 1758 | 1840 | if (!isset($disabled['li']) && !isset($disabled['list'])) | 
| 1759 | 1841 |  		{ | 
| 1760 | - foreach ($itemcodes as $c => $dummy) | |
| 1761 | - $bbc_codes[$c] = array(); | |
| 1842 | +			foreach ($itemcodes as $c => $dummy) { | |
| 1843 | + $bbc_codes[$c] = array(); | |
| 1844 | + } | |
| 1762 | 1845 | } | 
| 1763 | 1846 | |
| 1764 | 1847 | // Shhhh! | 
| @@ -1779,12 +1862,14 @@ discard block | ||
| 1779 | 1862 | foreach ($codes as $code) | 
| 1780 | 1863 |  		{ | 
| 1781 | 1864 | // Make it easier to process parameters later | 
| 1782 | - if (!empty($code['parameters'])) | |
| 1783 | - ksort($code['parameters'], SORT_STRING); | |
| 1865 | +			if (!empty($code['parameters'])) { | |
| 1866 | + ksort($code['parameters'], SORT_STRING); | |
| 1867 | + } | |
| 1784 | 1868 | |
| 1785 | 1869 | // If we are not doing every tag only do ones we are interested in. | 
| 1786 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) | |
| 1787 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; | |
| 1870 | +			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { | |
| 1871 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; | |
| 1872 | + } | |
| 1788 | 1873 | } | 
| 1789 | 1874 | $codes = null; | 
| 1790 | 1875 | } | 
| @@ -1795,8 +1880,9 @@ discard block | ||
| 1795 | 1880 | // It's likely this will change if the message is modified. | 
| 1796 | 1881 |  		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); | 
| 1797 | 1882 | |
| 1798 | - if (($temp = cache_get_data($cache_key, 240)) != null) | |
| 1799 | - return $temp; | |
| 1883 | +		if (($temp = cache_get_data($cache_key, 240)) != null) { | |
| 1884 | + return $temp; | |
| 1885 | + } | |
| 1800 | 1886 | |
| 1801 | 1887 | $cache_t = microtime(); | 
| 1802 | 1888 | } | 
| @@ -1828,8 +1914,9 @@ discard block | ||
| 1828 | 1914 | $disabled['flash'] = true; | 
| 1829 | 1915 | |
| 1830 | 1916 | // @todo Change maybe? | 
| 1831 | - if (!isset($_GET['images'])) | |
| 1832 | - $disabled['img'] = true; | |
| 1917 | +		if (!isset($_GET['images'])) { | |
| 1918 | + $disabled['img'] = true; | |
| 1919 | + } | |
| 1833 | 1920 | |
| 1834 | 1921 | // @todo Interface/setting to add more? | 
| 1835 | 1922 | } | 
| @@ -1853,8 +1940,9 @@ discard block | ||
| 1853 | 1940 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; | 
| 1854 | 1941 | |
| 1855 | 1942 | // Failsafe. | 
| 1856 | - if ($pos === false || $last_pos > $pos) | |
| 1857 | - $pos = strlen($message) + 1; | |
| 1943 | +		if ($pos === false || $last_pos > $pos) { | |
| 1944 | + $pos = strlen($message) + 1; | |
| 1945 | + } | |
| 1858 | 1946 | |
| 1859 | 1947 | // Can't have a one letter smiley, URL, or email! (sorry.) | 
| 1860 | 1948 | if ($last_pos < $pos - 1) | 
| @@ -1873,8 +1961,9 @@ discard block | ||
| 1873 | 1961 | |
| 1874 | 1962 | // <br> should be empty. | 
| 1875 | 1963 |  				$empty_tags = array('br', 'hr'); | 
| 1876 | - foreach ($empty_tags as $tag) | |
| 1877 | -					$data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); | |
| 1964 | +				foreach ($empty_tags as $tag) { | |
| 1965 | +									$data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); | |
| 1966 | + } | |
| 1878 | 1967 | |
| 1879 | 1968 | // b, u, i, s, pre... basic tags. | 
| 1880 | 1969 |  				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); | 
| @@ -1883,8 +1972,9 @@ discard block | ||
| 1883 | 1972 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); | 
| 1884 | 1973 |  					$data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); | 
| 1885 | 1974 | |
| 1886 | - if ($diff > 0) | |
| 1887 | -						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); | |
| 1975 | +					if ($diff > 0) { | |
| 1976 | +											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); | |
| 1977 | + } | |
| 1888 | 1978 | } | 
| 1889 | 1979 | |
| 1890 | 1980 | // Do <img ...> - with security... action= -> action-. | 
| @@ -1897,8 +1987,9 @@ discard block | ||
| 1897 | 1987 |  						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); | 
| 1898 | 1988 | |
| 1899 | 1989 | // Remove action= from the URL - no funny business, now. | 
| 1900 | -						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) | |
| 1901 | -							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); | |
| 1990 | +						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { | |
| 1991 | +													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); | |
| 1992 | + } | |
| 1902 | 1993 | |
| 1903 | 1994 | // Check if the image is larger than allowed. | 
| 1904 | 1995 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) | 
| @@ -1919,9 +2010,9 @@ discard block | ||
| 1919 | 2010 | |
| 1920 | 2011 | // Set the new image tag. | 
| 1921 | 2012 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; | 
| 2013 | +						} else { | |
| 2014 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; | |
| 1922 | 2015 | } | 
| 1923 | - else | |
| 1924 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; | |
| 1925 | 2016 | } | 
| 1926 | 2017 | |
| 1927 | 2018 | $data = strtr($data, $replaces); | 
| @@ -1934,16 +2025,18 @@ discard block | ||
| 1934 | 2025 | $no_autolink_area = false; | 
| 1935 | 2026 | if (!empty($open_tags)) | 
| 1936 | 2027 |  				{ | 
| 1937 | - foreach ($open_tags as $open_tag) | |
| 1938 | - if (in_array($open_tag['tag'], $no_autolink_tags)) | |
| 2028 | +					foreach ($open_tags as $open_tag) { | |
| 2029 | + if (in_array($open_tag['tag'], $no_autolink_tags)) | |
| 1939 | 2030 | $no_autolink_area = true; | 
| 2031 | + } | |
| 1940 | 2032 | } | 
| 1941 | 2033 | |
| 1942 | 2034 | // Don't go backwards. | 
| 1943 | 2035 | // @todo Don't think is the real solution.... | 
| 1944 | 2036 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; | 
| 1945 | - if ($pos < $lastAutoPos) | |
| 1946 | - $no_autolink_area = true; | |
| 2037 | +				if ($pos < $lastAutoPos) { | |
| 2038 | + $no_autolink_area = true; | |
| 2039 | + } | |
| 1947 | 2040 | $lastAutoPos = $pos; | 
| 1948 | 2041 | |
| 1949 | 2042 | if (!$no_autolink_area) | 
| @@ -2052,17 +2145,19 @@ discard block | ||
| 2052 | 2145 | if ($scheme == 'mailto') | 
| 2053 | 2146 |  							{ | 
| 2054 | 2147 |  								$email_address = str_replace('mailto:', '', $url); | 
| 2055 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) | |
| 2056 | - return '[email=' . $email_address . ']' . $url . '[/email]'; | |
| 2057 | - else | |
| 2058 | - return $url; | |
| 2148 | +								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { | |
| 2149 | + return '[email=' . $email_address . ']' . $url . '[/email]'; | |
| 2150 | +								} else { | |
| 2151 | + return $url; | |
| 2152 | + } | |
| 2059 | 2153 | } | 
| 2060 | 2154 | |
| 2061 | 2155 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? | 
| 2062 | - if (empty($scheme)) | |
| 2063 | - $fullUrl = '//' . ltrim($url, ':/'); | |
| 2064 | - else | |
| 2065 | - $fullUrl = $url; | |
| 2156 | +							if (empty($scheme)) { | |
| 2157 | + $fullUrl = '//' . ltrim($url, ':/'); | |
| 2158 | +							} else { | |
| 2159 | + $fullUrl = $url; | |
| 2160 | + } | |
| 2066 | 2161 | |
| 2067 | 2162 |  							return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; | 
| 2068 | 2163 | }, $data); | 
| @@ -2111,16 +2206,18 @@ discard block | ||
| 2111 | 2206 | } | 
| 2112 | 2207 | |
| 2113 | 2208 | // Are we there yet? Are we there yet? | 
| 2114 | - if ($pos >= strlen($message) - 1) | |
| 2115 | - break; | |
| 2209 | +		if ($pos >= strlen($message) - 1) { | |
| 2210 | + break; | |
| 2211 | + } | |
| 2116 | 2212 | |
| 2117 | 2213 | $tags = strtolower($message[$pos + 1]); | 
| 2118 | 2214 | |
| 2119 | 2215 | if ($tags == '/' && !empty($open_tags)) | 
| 2120 | 2216 |  		{ | 
| 2121 | 2217 | $pos2 = strpos($message, ']', $pos + 1); | 
| 2122 | - if ($pos2 == $pos + 2) | |
| 2123 | - continue; | |
| 2218 | +			if ($pos2 == $pos + 2) { | |
| 2219 | + continue; | |
| 2220 | + } | |
| 2124 | 2221 | |
| 2125 | 2222 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); | 
| 2126 | 2223 | |
| @@ -2130,8 +2227,9 @@ discard block | ||
| 2130 | 2227 | do | 
| 2131 | 2228 |  			{ | 
| 2132 | 2229 | $tag = array_pop($open_tags); | 
| 2133 | - if (!$tag) | |
| 2134 | - break; | |
| 2230 | +				if (!$tag) { | |
| 2231 | + break; | |
| 2232 | + } | |
| 2135 | 2233 | |
| 2136 | 2234 | if (!empty($tag['block_level'])) | 
| 2137 | 2235 |  				{ | 
| @@ -2145,10 +2243,11 @@ discard block | ||
| 2145 | 2243 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. | 
| 2146 | 2244 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) | 
| 2147 | 2245 |  					{ | 
| 2148 | - foreach ($bbc_codes[$look_for[0]] as $temp) | |
| 2149 | - if ($temp['tag'] == $look_for) | |
| 2246 | +						foreach ($bbc_codes[$look_for[0]] as $temp) { | |
| 2247 | + if ($temp['tag'] == $look_for) | |
| 2150 | 2248 |  							{ | 
| 2151 | 2249 | $block_level = !empty($temp['block_level']); | 
| 2250 | + } | |
| 2152 | 2251 | break; | 
| 2153 | 2252 | } | 
| 2154 | 2253 | } | 
| @@ -2170,15 +2269,15 @@ discard block | ||
| 2170 | 2269 |  			{ | 
| 2171 | 2270 | $open_tags = $to_close; | 
| 2172 | 2271 | continue; | 
| 2173 | - } | |
| 2174 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) | |
| 2272 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) | |
| 2175 | 2273 |  			{ | 
| 2176 | 2274 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) | 
| 2177 | 2275 |  				{ | 
| 2178 | - foreach ($bbc_codes[$look_for[0]] as $temp) | |
| 2179 | - if ($temp['tag'] == $look_for) | |
| 2276 | +					foreach ($bbc_codes[$look_for[0]] as $temp) { | |
| 2277 | + if ($temp['tag'] == $look_for) | |
| 2180 | 2278 |  						{ | 
| 2181 | 2279 | $block_level = !empty($temp['block_level']); | 
| 2280 | + } | |
| 2182 | 2281 | break; | 
| 2183 | 2282 | } | 
| 2184 | 2283 | } | 
| @@ -2186,8 +2285,9 @@ discard block | ||
| 2186 | 2285 | // We're not looking for a block level tag (or maybe even a tag that exists...) | 
| 2187 | 2286 | if (!$block_level) | 
| 2188 | 2287 |  				{ | 
| 2189 | - foreach ($to_close as $tag) | |
| 2190 | - array_push($open_tags, $tag); | |
| 2288 | +					foreach ($to_close as $tag) { | |
| 2289 | + array_push($open_tags, $tag); | |
| 2290 | + } | |
| 2191 | 2291 | continue; | 
| 2192 | 2292 | } | 
| 2193 | 2293 | } | 
| @@ -2200,14 +2300,17 @@ discard block | ||
| 2200 | 2300 | |
| 2201 | 2301 | // See the comment at the end of the big loop - just eating whitespace ;). | 
| 2202 | 2302 | $whitespace_regex = ''; | 
| 2203 | - if (!empty($tag['block_level'])) | |
| 2204 | - $whitespace_regex .= '( |\s)*(<br>)?'; | |
| 2303 | +				if (!empty($tag['block_level'])) { | |
| 2304 | + $whitespace_regex .= '( |\s)*(<br>)?'; | |
| 2305 | + } | |
| 2205 | 2306 | // Trim one line of whitespace after unnested tags, but all of it after nested ones | 
| 2206 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') | |
| 2207 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; | |
| 2307 | +				if (!empty($tag['trim']) && $tag['trim'] != 'inside') { | |
| 2308 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; | |
| 2309 | + } | |
| 2208 | 2310 | |
| 2209 | -				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) | |
| 2210 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); | |
| 2311 | +				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { | |
| 2312 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); | |
| 2313 | + } | |
| 2211 | 2314 | } | 
| 2212 | 2315 | |
| 2213 | 2316 | if (!empty($to_close)) | 
| @@ -2220,8 +2323,9 @@ discard block | ||
| 2220 | 2323 | } | 
| 2221 | 2324 | |
| 2222 | 2325 | // No tags for this character, so just keep going (fastest possible course.) | 
| 2223 | - if (!isset($bbc_codes[$tags])) | |
| 2224 | - continue; | |
| 2326 | +		if (!isset($bbc_codes[$tags])) { | |
| 2327 | + continue; | |
| 2328 | + } | |
| 2225 | 2329 | |
| 2226 | 2330 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; | 
| 2227 | 2331 | $tag = null; | 
| @@ -2230,44 +2334,52 @@ discard block | ||
| 2230 | 2334 | $pt_strlen = strlen($possible['tag']); | 
| 2231 | 2335 | |
| 2232 | 2336 | // Not a match? | 
| 2233 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) | |
| 2234 | - continue; | |
| 2337 | +			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { | |
| 2338 | + continue; | |
| 2339 | + } | |
| 2235 | 2340 | |
| 2236 | 2341 | $next_c = $message[$pos + 1 + $pt_strlen]; | 
| 2237 | 2342 | |
| 2238 | 2343 | // A test validation? | 
| 2239 | -			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) | |
| 2240 | - continue; | |
| 2344 | +			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { | |
| 2345 | + continue; | |
| 2346 | + } | |
| 2241 | 2347 | // Do we want parameters? | 
| 2242 | 2348 | elseif (!empty($possible['parameters'])) | 
| 2243 | 2349 |  			{ | 
| 2244 | - if ($next_c != ' ') | |
| 2245 | - continue; | |
| 2246 | - } | |
| 2247 | - elseif (isset($possible['type'])) | |
| 2350 | +				if ($next_c != ' ') { | |
| 2351 | + continue; | |
| 2352 | + } | |
| 2353 | + } elseif (isset($possible['type'])) | |
| 2248 | 2354 |  			{ | 
| 2249 | 2355 | // Do we need an equal sign? | 
| 2250 | -				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') | |
| 2251 | - continue; | |
| 2356 | +				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { | |
| 2357 | + continue; | |
| 2358 | + } | |
| 2252 | 2359 | // Maybe we just want a /... | 
| 2253 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') | |
| 2254 | - continue; | |
| 2360 | +				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { | |
| 2361 | + continue; | |
| 2362 | + } | |
| 2255 | 2363 | // An immediate ]? | 
| 2256 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') | |
| 2257 | - continue; | |
| 2364 | +				if ($possible['type'] == 'unparsed_content' && $next_c != ']') { | |
| 2365 | + continue; | |
| 2366 | + } | |
| 2258 | 2367 | } | 
| 2259 | 2368 | // No type means 'parsed_content', which demands an immediate ] without parameters! | 
| 2260 | - elseif ($next_c != ']') | |
| 2261 | - continue; | |
| 2369 | +			elseif ($next_c != ']') { | |
| 2370 | + continue; | |
| 2371 | + } | |
| 2262 | 2372 | |
| 2263 | 2373 | // Check allowed tree? | 
| 2264 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) | |
| 2265 | - continue; | |
| 2266 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) | |
| 2267 | - continue; | |
| 2374 | +			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { | |
| 2375 | + continue; | |
| 2376 | +			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { | |
| 2377 | + continue; | |
| 2378 | + } | |
| 2268 | 2379 | // If this is in the list of disallowed child tags, don't parse it. | 
| 2269 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) | |
| 2270 | - continue; | |
| 2380 | +			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { | |
| 2381 | + continue; | |
| 2382 | + } | |
| 2271 | 2383 | |
| 2272 | 2384 | $pos1 = $pos + 1 + $pt_strlen + 1; | 
| 2273 | 2385 | |
| @@ -2279,8 +2391,9 @@ discard block | ||
| 2279 | 2391 | foreach ($open_tags as $open_quote) | 
| 2280 | 2392 |  				{ | 
| 2281 | 2393 | // Every parent quote this quote has flips the styling | 
| 2282 | - if ($open_quote['tag'] == 'quote') | |
| 2283 | - $quote_alt = !$quote_alt; | |
| 2394 | +					if ($open_quote['tag'] == 'quote') { | |
| 2395 | + $quote_alt = !$quote_alt; | |
| 2396 | + } | |
| 2284 | 2397 | } | 
| 2285 | 2398 | // Add a class to the quote to style alternating blockquotes | 
| 2286 | 2399 |  				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); | 
| @@ -2291,8 +2404,9 @@ discard block | ||
| 2291 | 2404 |  			{ | 
| 2292 | 2405 | // Build a regular expression for each parameter for the current tag. | 
| 2293 | 2406 | $preg = array(); | 
| 2294 | - foreach ($possible['parameters'] as $p => $info) | |
| 2295 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); | |
| 2407 | +				foreach ($possible['parameters'] as $p => $info) { | |
| 2408 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); | |
| 2409 | + } | |
| 2296 | 2410 | |
| 2297 | 2411 | // Extract the string that potentially holds our parameters. | 
| 2298 | 2412 |  				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); | 
| @@ -2312,24 +2426,27 @@ discard block | ||
| 2312 | 2426 | |
| 2313 | 2427 |  					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; | 
| 2314 | 2428 | |
| 2315 | - if ($match) | |
| 2316 | - $blob_counter = count($blobs) + 1; | |
| 2429 | +					if ($match) { | |
| 2430 | + $blob_counter = count($blobs) + 1; | |
| 2431 | + } | |
| 2317 | 2432 | } | 
| 2318 | 2433 | |
| 2319 | 2434 | // Didn't match our parameter list, try the next possible. | 
| 2320 | - if (!$match) | |
| 2321 | - continue; | |
| 2435 | +				if (!$match) { | |
| 2436 | + continue; | |
| 2437 | + } | |
| 2322 | 2438 | |
| 2323 | 2439 | $params = array(); | 
| 2324 | 2440 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) | 
| 2325 | 2441 |  				{ | 
| 2326 | 2442 | $key = strtok(ltrim($matches[$i]), '='); | 
| 2327 | - if (isset($possible['parameters'][$key]['value'])) | |
| 2328 | -						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); | |
| 2329 | - elseif (isset($possible['parameters'][$key]['validate'])) | |
| 2330 | -						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); | |
| 2331 | - else | |
| 2332 | -						$params['{' . $key . '}'] = $matches[$i + 1]; | |
| 2443 | +					if (isset($possible['parameters'][$key]['value'])) { | |
| 2444 | +											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); | |
| 2445 | +					} elseif (isset($possible['parameters'][$key]['validate'])) { | |
| 2446 | +											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); | |
| 2447 | +					} else { | |
| 2448 | +											$params['{' . $key . '}'] = $matches[$i + 1]; | |
| 2449 | + } | |
| 2333 | 2450 | |
| 2334 | 2451 |  					// Just to make sure: replace any $ or { so they can't interpolate wrongly. | 
| 2335 | 2452 |  					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); | 
| @@ -2337,23 +2454,26 @@ discard block | ||
| 2337 | 2454 | |
| 2338 | 2455 | foreach ($possible['parameters'] as $p => $info) | 
| 2339 | 2456 |  				{ | 
| 2340 | -					if (!isset($params['{' . $p . '}'])) | |
| 2341 | -						$params['{' . $p . '}'] = ''; | |
| 2457 | +					if (!isset($params['{' . $p . '}'])) { | |
| 2458 | +											$params['{' . $p . '}'] = ''; | |
| 2459 | + } | |
| 2342 | 2460 | } | 
| 2343 | 2461 | |
| 2344 | 2462 | $tag = $possible; | 
| 2345 | 2463 | |
| 2346 | 2464 | // Put the parameters into the string. | 
| 2347 | - if (isset($tag['before'])) | |
| 2348 | - $tag['before'] = strtr($tag['before'], $params); | |
| 2349 | - if (isset($tag['after'])) | |
| 2350 | - $tag['after'] = strtr($tag['after'], $params); | |
| 2351 | - if (isset($tag['content'])) | |
| 2352 | - $tag['content'] = strtr($tag['content'], $params); | |
| 2465 | +				if (isset($tag['before'])) { | |
| 2466 | + $tag['before'] = strtr($tag['before'], $params); | |
| 2467 | + } | |
| 2468 | +				if (isset($tag['after'])) { | |
| 2469 | + $tag['after'] = strtr($tag['after'], $params); | |
| 2470 | + } | |
| 2471 | +				if (isset($tag['content'])) { | |
| 2472 | + $tag['content'] = strtr($tag['content'], $params); | |
| 2473 | + } | |
| 2353 | 2474 | |
| 2354 | 2475 | $pos1 += strlen($given_param_string); | 
| 2355 | - } | |
| 2356 | - else | |
| 2476 | + } else | |
| 2357 | 2477 |  			{ | 
| 2358 | 2478 | $tag = $possible; | 
| 2359 | 2479 | $params = array(); | 
| @@ -2364,8 +2484,9 @@ discard block | ||
| 2364 | 2484 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! | 
| 2365 | 2485 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) | 
| 2366 | 2486 |  		{ | 
| 2367 | -			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) | |
| 2368 | - continue; | |
| 2487 | +			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { | |
| 2488 | + continue; | |
| 2489 | + } | |
| 2369 | 2490 | |
| 2370 | 2491 | $tag = $itemcodes[$message[$pos + 1]]; | 
| 2371 | 2492 | |
| @@ -2386,9 +2507,9 @@ discard block | ||
| 2386 | 2507 |  			{ | 
| 2387 | 2508 | array_pop($open_tags); | 
| 2388 | 2509 | $code = '</li>'; | 
| 2510 | +			} else { | |
| 2511 | + $code = ''; | |
| 2389 | 2512 | } | 
| 2390 | - else | |
| 2391 | - $code = ''; | |
| 2392 | 2513 | |
| 2393 | 2514 | // Now we open a new tag. | 
| 2394 | 2515 | $open_tags[] = array( | 
| @@ -2435,12 +2556,14 @@ discard block | ||
| 2435 | 2556 | } | 
| 2436 | 2557 | |
| 2437 | 2558 | // No tag? Keep looking, then. Silly people using brackets without actual tags. | 
| 2438 | - if ($tag === null) | |
| 2439 | - continue; | |
| 2559 | +		if ($tag === null) { | |
| 2560 | + continue; | |
| 2561 | + } | |
| 2440 | 2562 | |
| 2441 | 2563 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) | 
| 2442 | - if (isset($inside['disallow_children'])) | |
| 2443 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; | |
| 2564 | +		if (isset($inside['disallow_children'])) { | |
| 2565 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; | |
| 2566 | + } | |
| 2444 | 2567 | |
| 2445 | 2568 | // Is this tag disabled? | 
| 2446 | 2569 | if (isset($disabled[$tag['tag']])) | 
| @@ -2450,14 +2573,13 @@ discard block | ||
| 2450 | 2573 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; | 
| 2451 | 2574 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; | 
| 2452 | 2575 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); | 
| 2453 | - } | |
| 2454 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) | |
| 2576 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) | |
| 2455 | 2577 |  			{ | 
| 2456 | 2578 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); | 
| 2457 | 2579 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); | 
| 2580 | +			} else { | |
| 2581 | + $tag['content'] = $tag['disabled_content']; | |
| 2458 | 2582 | } | 
| 2459 | - else | |
| 2460 | - $tag['content'] = $tag['disabled_content']; | |
| 2461 | 2583 | } | 
| 2462 | 2584 | |
| 2463 | 2585 | // we use this a lot | 
| @@ -2467,8 +2589,9 @@ discard block | ||
| 2467 | 2589 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) | 
| 2468 | 2590 |  		{ | 
| 2469 | 2591 | $n = count($open_tags) - 1; | 
| 2470 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) | |
| 2471 | - $n--; | |
| 2592 | +			while (empty($open_tags[$n]['block_level']) && $n >= 0) { | |
| 2593 | + $n--; | |
| 2594 | + } | |
| 2472 | 2595 | |
| 2473 | 2596 | // Close all the non block level tags so this tag isn't surrounded by them. | 
| 2474 | 2597 | for ($i = count($open_tags) - 1; $i > $n; $i--) | 
| @@ -2480,12 +2603,15 @@ discard block | ||
| 2480 | 2603 | |
| 2481 | 2604 | // Trim or eat trailing stuff... see comment at the end of the big loop. | 
| 2482 | 2605 | $whitespace_regex = ''; | 
| 2483 | - if (!empty($tag['block_level'])) | |
| 2484 | - $whitespace_regex .= '( |\s)*(<br>)?'; | |
| 2485 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') | |
| 2486 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; | |
| 2487 | -				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) | |
| 2488 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); | |
| 2606 | +				if (!empty($tag['block_level'])) { | |
| 2607 | + $whitespace_regex .= '( |\s)*(<br>)?'; | |
| 2608 | + } | |
| 2609 | +				if (!empty($tag['trim']) && $tag['trim'] != 'inside') { | |
| 2610 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; | |
| 2611 | + } | |
| 2612 | +				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { | |
| 2613 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); | |
| 2614 | + } | |
| 2489 | 2615 | |
| 2490 | 2616 | array_pop($open_tags); | 
| 2491 | 2617 | } | 
| @@ -2503,16 +2629,19 @@ discard block | ||
| 2503 | 2629 | elseif ($tag['type'] == 'unparsed_content') | 
| 2504 | 2630 |  		{ | 
| 2505 | 2631 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); | 
| 2506 | - if ($pos2 === false) | |
| 2507 | - continue; | |
| 2632 | +			if ($pos2 === false) { | |
| 2633 | + continue; | |
| 2634 | + } | |
| 2508 | 2635 | |
| 2509 | 2636 | $data = substr($message, $pos1, $pos2 - $pos1); | 
| 2510 | 2637 | |
| 2511 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') | |
| 2512 | - $data = substr($data, 4); | |
| 2638 | +			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { | |
| 2639 | + $data = substr($data, 4); | |
| 2640 | + } | |
| 2513 | 2641 | |
| 2514 | - if (isset($tag['validate'])) | |
| 2515 | - $tag['validate']($tag, $data, $disabled, $params); | |
| 2642 | +			if (isset($tag['validate'])) { | |
| 2643 | + $tag['validate']($tag, $data, $disabled, $params); | |
| 2644 | + } | |
| 2516 | 2645 | |
| 2517 | 2646 |  			$code = strtr($tag['content'], array('$1' => $data)); | 
| 2518 | 2647 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); | 
| @@ -2528,34 +2657,40 @@ discard block | ||
| 2528 | 2657 | if (isset($tag['quoted'])) | 
| 2529 | 2658 |  			{ | 
| 2530 | 2659 | $quoted = substr($message, $pos1, 6) == '"'; | 
| 2531 | - if ($tag['quoted'] != 'optional' && !$quoted) | |
| 2532 | - continue; | |
| 2660 | +				if ($tag['quoted'] != 'optional' && !$quoted) { | |
| 2661 | + continue; | |
| 2662 | + } | |
| 2533 | 2663 | |
| 2534 | - if ($quoted) | |
| 2535 | - $pos1 += 6; | |
| 2664 | +				if ($quoted) { | |
| 2665 | + $pos1 += 6; | |
| 2666 | + } | |
| 2667 | +			} else { | |
| 2668 | + $quoted = false; | |
| 2536 | 2669 | } | 
| 2537 | - else | |
| 2538 | - $quoted = false; | |
| 2539 | 2670 | |
| 2540 | 2671 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); | 
| 2541 | - if ($pos2 === false) | |
| 2542 | - continue; | |
| 2672 | +			if ($pos2 === false) { | |
| 2673 | + continue; | |
| 2674 | + } | |
| 2543 | 2675 | |
| 2544 | 2676 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); | 
| 2545 | - if ($pos3 === false) | |
| 2546 | - continue; | |
| 2677 | +			if ($pos3 === false) { | |
| 2678 | + continue; | |
| 2679 | + } | |
| 2547 | 2680 | |
| 2548 | 2681 | $data = array( | 
| 2549 | 2682 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), | 
| 2550 | 2683 | substr($message, $pos1, $pos2 - $pos1) | 
| 2551 | 2684 | ); | 
| 2552 | 2685 | |
| 2553 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') | |
| 2554 | - $data[0] = substr($data[0], 4); | |
| 2686 | +			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { | |
| 2687 | + $data[0] = substr($data[0], 4); | |
| 2688 | + } | |
| 2555 | 2689 | |
| 2556 | 2690 | // Validation for my parking, please! | 
| 2557 | - if (isset($tag['validate'])) | |
| 2558 | - $tag['validate']($tag, $data, $disabled, $params); | |
| 2691 | +			if (isset($tag['validate'])) { | |
| 2692 | + $tag['validate']($tag, $data, $disabled, $params); | |
| 2693 | + } | |
| 2559 | 2694 | |
| 2560 | 2695 |  			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); | 
| 2561 | 2696 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); | 
| @@ -2572,23 +2707,27 @@ discard block | ||
| 2572 | 2707 | elseif ($tag['type'] == 'unparsed_commas_content') | 
| 2573 | 2708 |  		{ | 
| 2574 | 2709 | $pos2 = strpos($message, ']', $pos1); | 
| 2575 | - if ($pos2 === false) | |
| 2576 | - continue; | |
| 2710 | +			if ($pos2 === false) { | |
| 2711 | + continue; | |
| 2712 | + } | |
| 2577 | 2713 | |
| 2578 | 2714 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); | 
| 2579 | - if ($pos3 === false) | |
| 2580 | - continue; | |
| 2715 | +			if ($pos3 === false) { | |
| 2716 | + continue; | |
| 2717 | + } | |
| 2581 | 2718 | |
| 2582 | 2719 | // We want $1 to be the content, and the rest to be csv. | 
| 2583 | 2720 |  			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); | 
| 2584 | 2721 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); | 
| 2585 | 2722 | |
| 2586 | - if (isset($tag['validate'])) | |
| 2587 | - $tag['validate']($tag, $data, $disabled, $params); | |
| 2723 | +			if (isset($tag['validate'])) { | |
| 2724 | + $tag['validate']($tag, $data, $disabled, $params); | |
| 2725 | + } | |
| 2588 | 2726 | |
| 2589 | 2727 | $code = $tag['content']; | 
| 2590 | - foreach ($data as $k => $d) | |
| 2591 | -				$code = strtr($code, array('$' . ($k + 1) => trim($d))); | |
| 2728 | +			foreach ($data as $k => $d) { | |
| 2729 | +							$code = strtr($code, array('$' . ($k + 1) => trim($d))); | |
| 2730 | + } | |
| 2592 | 2731 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); | 
| 2593 | 2732 | $pos += strlen($code) - 1 + 2; | 
| 2594 | 2733 | } | 
| @@ -2596,24 +2735,28 @@ discard block | ||
| 2596 | 2735 | elseif ($tag['type'] == 'unparsed_commas') | 
| 2597 | 2736 |  		{ | 
| 2598 | 2737 | $pos2 = strpos($message, ']', $pos1); | 
| 2599 | - if ($pos2 === false) | |
| 2600 | - continue; | |
| 2738 | +			if ($pos2 === false) { | |
| 2739 | + continue; | |
| 2740 | + } | |
| 2601 | 2741 | |
| 2602 | 2742 |  			$data = explode(',', substr($message, $pos1, $pos2 - $pos1)); | 
| 2603 | 2743 | |
| 2604 | - if (isset($tag['validate'])) | |
| 2605 | - $tag['validate']($tag, $data, $disabled, $params); | |
| 2744 | +			if (isset($tag['validate'])) { | |
| 2745 | + $tag['validate']($tag, $data, $disabled, $params); | |
| 2746 | + } | |
| 2606 | 2747 | |
| 2607 | 2748 | // Fix after, for disabled code mainly. | 
| 2608 | - foreach ($data as $k => $d) | |
| 2609 | -				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); | |
| 2749 | +			foreach ($data as $k => $d) { | |
| 2750 | +							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); | |
| 2751 | + } | |
| 2610 | 2752 | |
| 2611 | 2753 | $open_tags[] = $tag; | 
| 2612 | 2754 | |
| 2613 | 2755 | // Replace them out, $1, $2, $3, $4, etc. | 
| 2614 | 2756 | $code = $tag['before']; | 
| 2615 | - foreach ($data as $k => $d) | |
| 2616 | -				$code = strtr($code, array('$' . ($k + 1) => trim($d))); | |
| 2757 | +			foreach ($data as $k => $d) { | |
| 2758 | +							$code = strtr($code, array('$' . ($k + 1) => trim($d))); | |
| 2759 | + } | |
| 2617 | 2760 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); | 
| 2618 | 2761 | $pos += strlen($code) - 1 + 2; | 
| 2619 | 2762 | } | 
| @@ -2624,28 +2767,33 @@ discard block | ||
| 2624 | 2767 | if (isset($tag['quoted'])) | 
| 2625 | 2768 |  			{ | 
| 2626 | 2769 | $quoted = substr($message, $pos1, 6) == '"'; | 
| 2627 | - if ($tag['quoted'] != 'optional' && !$quoted) | |
| 2628 | - continue; | |
| 2770 | +				if ($tag['quoted'] != 'optional' && !$quoted) { | |
| 2771 | + continue; | |
| 2772 | + } | |
| 2629 | 2773 | |
| 2630 | - if ($quoted) | |
| 2631 | - $pos1 += 6; | |
| 2774 | +				if ($quoted) { | |
| 2775 | + $pos1 += 6; | |
| 2776 | + } | |
| 2777 | +			} else { | |
| 2778 | + $quoted = false; | |
| 2632 | 2779 | } | 
| 2633 | - else | |
| 2634 | - $quoted = false; | |
| 2635 | 2780 | |
| 2636 | 2781 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); | 
| 2637 | - if ($pos2 === false) | |
| 2638 | - continue; | |
| 2782 | +			if ($pos2 === false) { | |
| 2783 | + continue; | |
| 2784 | + } | |
| 2639 | 2785 | |
| 2640 | 2786 | $data = substr($message, $pos1, $pos2 - $pos1); | 
| 2641 | 2787 | |
| 2642 | 2788 | // Validation for my parking, please! | 
| 2643 | - if (isset($tag['validate'])) | |
| 2644 | - $tag['validate']($tag, $data, $disabled, $params); | |
| 2789 | +			if (isset($tag['validate'])) { | |
| 2790 | + $tag['validate']($tag, $data, $disabled, $params); | |
| 2791 | + } | |
| 2645 | 2792 | |
| 2646 | 2793 | // For parsed content, we must recurse to avoid security problems. | 
| 2647 | - if ($tag['type'] != 'unparsed_equals') | |
| 2648 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); | |
| 2794 | +			if ($tag['type'] != 'unparsed_equals') { | |
| 2795 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); | |
| 2796 | + } | |
| 2649 | 2797 | |
| 2650 | 2798 |  			$tag['after'] = strtr($tag['after'], array('$1' => $data)); | 
| 2651 | 2799 | |
| @@ -2657,34 +2805,40 @@ discard block | ||
| 2657 | 2805 | } | 
| 2658 | 2806 | |
| 2659 | 2807 | // If this is block level, eat any breaks after it. | 
| 2660 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') | |
| 2661 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); | |
| 2808 | +		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { | |
| 2809 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); | |
| 2810 | + } | |
| 2662 | 2811 | |
| 2663 | 2812 | // Are we trimming outside this tag? | 
| 2664 | -		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) | |
| 2665 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); | |
| 2813 | +		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { | |
| 2814 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); | |
| 2815 | + } | |
| 2666 | 2816 | } | 
| 2667 | 2817 | |
| 2668 | 2818 | // Close any remaining tags. | 
| 2669 | - while ($tag = array_pop($open_tags)) | |
| 2670 | - $message .= "\n" . $tag['after'] . "\n"; | |
| 2819 | +	while ($tag = array_pop($open_tags)) { | |
| 2820 | + $message .= "\n" . $tag['after'] . "\n"; | |
| 2821 | + } | |
| 2671 | 2822 | |
| 2672 | 2823 | // Parse the smileys within the parts where it can be done safely. | 
| 2673 | 2824 | if ($smileys === true) | 
| 2674 | 2825 |  	{ | 
| 2675 | 2826 |  		$message_parts = explode("\n", $message); | 
| 2676 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) | |
| 2677 | - parsesmileys($message_parts[$i]); | |
| 2827 | +		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { | |
| 2828 | + parsesmileys($message_parts[$i]); | |
| 2829 | + } | |
| 2678 | 2830 | |
| 2679 | 2831 |  		$message = implode('', $message_parts); | 
| 2680 | 2832 | } | 
| 2681 | 2833 | |
| 2682 | 2834 | // No smileys, just get rid of the markers. | 
| 2683 | - else | |
| 2684 | -		$message = strtr($message, array("\n" => '')); | |
| 2835 | +	else { | |
| 2836 | +			$message = strtr($message, array("\n" => '')); | |
| 2837 | + } | |
| 2685 | 2838 | |
| 2686 | - if ($message !== '' && $message[0] === ' ') | |
| 2687 | - $message = ' ' . substr($message, 1); | |
| 2839 | +	if ($message !== '' && $message[0] === ' ') { | |
| 2840 | + $message = ' ' . substr($message, 1); | |
| 2841 | + } | |
| 2688 | 2842 | |
| 2689 | 2843 | // Cleanup whitespace. | 
| 2690 | 2844 |  	$message = strtr($message, array('  ' => '  ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', '
' => "\n")); | 
| @@ -2693,15 +2847,16 @@ discard block | ||
| 2693 | 2847 |  	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); | 
| 2694 | 2848 | |
| 2695 | 2849 | // Cache the output if it took some time... | 
| 2696 | -	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) | |
| 2697 | - cache_put_data($cache_key, $message, 240); | |
| 2850 | +	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { | |
| 2851 | + cache_put_data($cache_key, $message, 240); | |
| 2852 | + } | |
| 2698 | 2853 | |
| 2699 | 2854 | // If this was a force parse revert if needed. | 
| 2700 | 2855 | if (!empty($parse_tags)) | 
| 2701 | 2856 |  	{ | 
| 2702 | - if (empty($temp_bbc)) | |
| 2703 | - $bbc_codes = array(); | |
| 2704 | - else | |
| 2857 | +		if (empty($temp_bbc)) { | |
| 2858 | + $bbc_codes = array(); | |
| 2859 | + } else | |
| 2705 | 2860 |  		{ | 
| 2706 | 2861 | $bbc_codes = $temp_bbc; | 
| 2707 | 2862 | unset($temp_bbc); | 
| @@ -2728,8 +2883,9 @@ discard block | ||
| 2728 | 2883 | static $smileyPregSearch = null, $smileyPregReplacements = array(); | 
| 2729 | 2884 | |
| 2730 | 2885 | // No smiley set at all?! | 
| 2731 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') | |
| 2732 | - return; | |
| 2886 | +	if ($user_info['smiley_set'] == 'none' || trim($message) == '') { | |
| 2887 | + return; | |
| 2888 | + } | |
| 2733 | 2889 | |
| 2734 | 2890 | // If smileyPregSearch hasn't been set, do it now. | 
| 2735 | 2891 | if (empty($smileyPregSearch)) | 
| @@ -2740,8 +2896,7 @@ discard block | ||
| 2740 | 2896 |  			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); | 
| 2741 | 2897 |  			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); | 
| 2742 | 2898 |  			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); | 
| 2743 | - } | |
| 2744 | - else | |
| 2899 | + } else | |
| 2745 | 2900 |  		{ | 
| 2746 | 2901 | // Load the smileys in reverse order by length so they don't get parsed wrong. | 
| 2747 | 2902 |  			if (($temp = cache_get_data('parsing_smileys', 480)) == null) | 
| @@ -2765,9 +2920,9 @@ discard block | ||
| 2765 | 2920 | $smcFunc['db_free_result']($result); | 
| 2766 | 2921 | |
| 2767 | 2922 |  				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); | 
| 2923 | +			} else { | |
| 2924 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; | |
| 2768 | 2925 | } | 
| 2769 | - else | |
| 2770 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; | |
| 2771 | 2926 | } | 
| 2772 | 2927 | |
| 2773 | 2928 | // The non-breaking-space is a complex thing... | 
| @@ -2844,35 +2999,41 @@ discard block | ||
| 2844 | 2999 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; | 
| 2845 | 3000 | |
| 2846 | 3001 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... | 
| 2847 | - if (!empty($context['flush_mail'])) | |
| 2848 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ | |
| 3002 | +	if (!empty($context['flush_mail'])) { | |
| 3003 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ | |
| 2849 | 3004 | AddMailQueue(true); | 
| 3005 | + } | |
| 2850 | 3006 | |
| 2851 | 3007 |  	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; | 
| 2852 | 3008 | |
| 2853 | - if ($add) | |
| 2854 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); | |
| 3009 | +	if ($add) { | |
| 3010 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); | |
| 3011 | + } | |
| 2855 | 3012 | |
| 2856 | 3013 | // Put the session ID in. | 
| 2857 | -	if (defined('SID') && SID != '') | |
| 2858 | -		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); | |
| 3014 | +	if (defined('SID') && SID != '') { | |
| 3015 | +			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); | |
| 3016 | + } | |
| 2859 | 3017 | // Keep that debug in their for template debugging! | 
| 2860 | - elseif (isset($_GET['debug'])) | |
| 2861 | -		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); | |
| 3018 | +	elseif (isset($_GET['debug'])) { | |
| 3019 | +			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); | |
| 3020 | + } | |
| 2862 | 3021 | |
| 2863 | 3022 |  	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) | 
| 2864 | 3023 |  	{ | 
| 2865 | -		if (defined('SID') && SID != '') | |
| 2866 | -			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', | |
| 3024 | +		if (defined('SID') && SID != '') { | |
| 3025 | +					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', | |
| 2867 | 3026 | function ($m) use ($scripturl) | 
| 2868 | 3027 |  				{ | 
| 2869 | 3028 |  					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); | 
| 3029 | + } | |
| 2870 | 3030 | }, $setLocation); | 
| 2871 | - else | |
| 2872 | -			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', | |
| 3031 | +		else { | |
| 3032 | +					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', | |
| 2873 | 3033 | function ($m) use ($scripturl) | 
| 2874 | 3034 |  				{ | 
| 2875 | 3035 |  					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); | 
| 3036 | + } | |
| 2876 | 3037 | }, $setLocation); | 
| 2877 | 3038 | } | 
| 2878 | 3039 | |
| @@ -2883,8 +3044,9 @@ discard block | ||
| 2883 | 3044 |  	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); | 
| 2884 | 3045 | |
| 2885 | 3046 | // Debugging. | 
| 2886 | - if (isset($db_show_debug) && $db_show_debug === true) | |
| 2887 | - $_SESSION['debug_redirect'] = $db_cache; | |
| 3047 | +	if (isset($db_show_debug) && $db_show_debug === true) { | |
| 3048 | + $_SESSION['debug_redirect'] = $db_cache; | |
| 3049 | + } | |
| 2888 | 3050 | |
| 2889 | 3051 | obExit(false); | 
| 2890 | 3052 | } | 
| @@ -2903,51 +3065,60 @@ discard block | ||
| 2903 | 3065 | |
| 2904 | 3066 | // Attempt to prevent a recursive loop. | 
| 2905 | 3067 | ++$level; | 
| 2906 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) | |
| 2907 | - exit; | |
| 2908 | - if ($from_fatal_error) | |
| 2909 | - $has_fatal_error = true; | |
| 3068 | +	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { | |
| 3069 | + exit; | |
| 3070 | + } | |
| 3071 | +	if ($from_fatal_error) { | |
| 3072 | + $has_fatal_error = true; | |
| 3073 | + } | |
| 2910 | 3074 | |
| 2911 | 3075 | // Clear out the stat cache. | 
| 2912 | 3076 | trackStats(); | 
| 2913 | 3077 | |
| 2914 | 3078 | // If we have mail to send, send it. | 
| 2915 | - if (!empty($context['flush_mail'])) | |
| 2916 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ | |
| 3079 | +	if (!empty($context['flush_mail'])) { | |
| 3080 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ | |
| 2917 | 3081 | AddMailQueue(true); | 
| 3082 | + } | |
| 2918 | 3083 | |
| 2919 | 3084 | $do_header = $header === null ? !$header_done : $header; | 
| 2920 | - if ($do_footer === null) | |
| 2921 | - $do_footer = $do_header; | |
| 3085 | +	if ($do_footer === null) { | |
| 3086 | + $do_footer = $do_header; | |
| 3087 | + } | |
| 2922 | 3088 | |
| 2923 | 3089 | // Has the template/header been done yet? | 
| 2924 | 3090 | if ($do_header) | 
| 2925 | 3091 |  	{ | 
| 2926 | 3092 | // Was the page title set last minute? Also update the HTML safe one. | 
| 2927 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) | |
| 2928 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); | |
| 3093 | +		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { | |
| 3094 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); | |
| 3095 | + } | |
| 2929 | 3096 | |
| 2930 | 3097 | // Start up the session URL fixer. | 
| 2931 | 3098 |  		ob_start('ob_sessrewrite'); | 
| 2932 | 3099 | |
| 2933 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) | |
| 2934 | -			$buffers = explode(',', $settings['output_buffers']); | |
| 2935 | - elseif (!empty($settings['output_buffers'])) | |
| 2936 | - $buffers = $settings['output_buffers']; | |
| 2937 | - else | |
| 2938 | - $buffers = array(); | |
| 3100 | +		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { | |
| 3101 | +					$buffers = explode(',', $settings['output_buffers']); | |
| 3102 | +		} elseif (!empty($settings['output_buffers'])) { | |
| 3103 | + $buffers = $settings['output_buffers']; | |
| 3104 | +		} else { | |
| 3105 | + $buffers = array(); | |
| 3106 | + } | |
| 2939 | 3107 | |
| 2940 | - if (isset($modSettings['integrate_buffer'])) | |
| 2941 | -			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); | |
| 3108 | +		if (isset($modSettings['integrate_buffer'])) { | |
| 3109 | +					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); | |
| 3110 | + } | |
| 2942 | 3111 | |
| 2943 | - if (!empty($buffers)) | |
| 2944 | - foreach ($buffers as $function) | |
| 3112 | +		if (!empty($buffers)) { | |
| 3113 | + foreach ($buffers as $function) | |
| 2945 | 3114 |  			{ | 
| 2946 | 3115 | $call = call_helper($function, true); | 
| 3116 | + } | |
| 2947 | 3117 | |
| 2948 | 3118 | // Is it valid? | 
| 2949 | - if (!empty($call)) | |
| 2950 | - ob_start($call); | |
| 3119 | +				if (!empty($call)) { | |
| 3120 | + ob_start($call); | |
| 3121 | + } | |
| 2951 | 3122 | } | 
| 2952 | 3123 | |
| 2953 | 3124 | // Display the screen in the logical order. | 
| @@ -2959,8 +3130,9 @@ discard block | ||
| 2959 | 3130 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); | 
| 2960 | 3131 | |
| 2961 | 3132 | // Anything special to put out? | 
| 2962 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) | |
| 2963 | - echo $context['insert_after_template']; | |
| 3133 | +		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { | |
| 3134 | + echo $context['insert_after_template']; | |
| 3135 | + } | |
| 2964 | 3136 | |
| 2965 | 3137 | // Just so we don't get caught in an endless loop of errors from the footer... | 
| 2966 | 3138 | if (!$footer_done) | 
| @@ -2969,14 +3141,16 @@ discard block | ||
| 2969 | 3141 | template_footer(); | 
| 2970 | 3142 | |
| 2971 | 3143 | // (since this is just debugging... it's okay that it's after </html>.) | 
| 2972 | - if (!isset($_REQUEST['xml'])) | |
| 2973 | - displayDebug(); | |
| 3144 | +			if (!isset($_REQUEST['xml'])) { | |
| 3145 | + displayDebug(); | |
| 3146 | + } | |
| 2974 | 3147 | } | 
| 2975 | 3148 | } | 
| 2976 | 3149 | |
| 2977 | 3150 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. | 
| 2978 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) | |
| 2979 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; | |
| 3151 | +	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { | |
| 3152 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; | |
| 3153 | + } | |
| 2980 | 3154 | |
| 2981 | 3155 | // For session check verification.... don't switch browsers... | 
| 2982 | 3156 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; | 
| @@ -2985,9 +3159,10 @@ discard block | ||
| 2985 | 3159 |  	call_integration_hook('integrate_exit', array($do_footer)); | 
| 2986 | 3160 | |
| 2987 | 3161 | // Don't exit if we're coming from index.php; that will pass through normally. | 
| 2988 | - if (!$from_index) | |
| 2989 | - exit; | |
| 2990 | -} | |
| 3162 | +	if (!$from_index) { | |
| 3163 | + exit; | |
| 3164 | + } | |
| 3165 | + } | |
| 2991 | 3166 | |
| 2992 | 3167 | /** | 
| 2993 | 3168 | * Get the size of a specified image with better error handling. | 
| @@ -3006,8 +3181,9 @@ discard block | ||
| 3006 | 3181 |  	$url = str_replace(' ', '%20', $url); | 
| 3007 | 3182 | |
| 3008 | 3183 | // Can we pull this from the cache... please please? | 
| 3009 | -	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) | |
| 3010 | - return $temp; | |
| 3184 | +	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { | |
| 3185 | + return $temp; | |
| 3186 | + } | |
| 3011 | 3187 | $t = microtime(); | 
| 3012 | 3188 | |
| 3013 | 3189 | // Get the host to pester... | 
| @@ -3017,12 +3193,10 @@ discard block | ||
| 3017 | 3193 | if ($url == '' || $url == 'http://' || $url == 'https://') | 
| 3018 | 3194 |  	{ | 
| 3019 | 3195 | return false; | 
| 3020 | - } | |
| 3021 | - elseif (!isset($match[1])) | |
| 3196 | + } elseif (!isset($match[1])) | |
| 3022 | 3197 |  	{ | 
| 3023 | 3198 | $size = @getimagesize($url); | 
| 3024 | - } | |
| 3025 | - else | |
| 3199 | + } else | |
| 3026 | 3200 |  	{ | 
| 3027 | 3201 | // Try to connect to the server... give it half a second. | 
| 3028 | 3202 | $temp = 0; | 
| @@ -3061,12 +3235,14 @@ discard block | ||
| 3061 | 3235 | } | 
| 3062 | 3236 | |
| 3063 | 3237 | // If we didn't get it, we failed. | 
| 3064 | - if (!isset($size)) | |
| 3065 | - $size = false; | |
| 3238 | +	if (!isset($size)) { | |
| 3239 | + $size = false; | |
| 3240 | + } | |
| 3066 | 3241 | |
| 3067 | 3242 | // If this took a long time, we may never have to do it again, but then again we might... | 
| 3068 | -	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) | |
| 3069 | -		cache_put_data('url_image_size-' . md5($url), $size, 240); | |
| 3243 | +	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { | |
| 3244 | +			cache_put_data('url_image_size-' . md5($url), $size, 240); | |
| 3245 | + } | |
| 3070 | 3246 | |
| 3071 | 3247 | // Didn't work. | 
| 3072 | 3248 | return $size; | 
| @@ -3084,8 +3260,9 @@ discard block | ||
| 3084 | 3260 | |
| 3085 | 3261 | // Under SSI this function can be called more then once. That can cause some problems. | 
| 3086 | 3262 | // So only run the function once unless we are forced to run it again. | 
| 3087 | - if ($loaded && !$forceload) | |
| 3088 | - return; | |
| 3263 | +	if ($loaded && !$forceload) { | |
| 3264 | + return; | |
| 3265 | + } | |
| 3089 | 3266 | |
| 3090 | 3267 | $loaded = true; | 
| 3091 | 3268 | |
| @@ -3097,14 +3274,16 @@ discard block | ||
| 3097 | 3274 |  	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); | 
| 3098 | 3275 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) | 
| 3099 | 3276 |  	{ | 
| 3100 | - if (trim($context['news_lines'][$i]) == '') | |
| 3101 | - continue; | |
| 3277 | +		if (trim($context['news_lines'][$i]) == '') { | |
| 3278 | + continue; | |
| 3279 | + } | |
| 3102 | 3280 | |
| 3103 | 3281 | // Clean it up for presentation ;). | 
| 3104 | 3282 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); | 
| 3105 | 3283 | } | 
| 3106 | - if (!empty($context['news_lines'])) | |
| 3107 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; | |
| 3284 | +	if (!empty($context['news_lines'])) { | |
| 3285 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; | |
| 3286 | + } | |
| 3108 | 3287 | |
| 3109 | 3288 | if (!$user_info['is_guest']) | 
| 3110 | 3289 |  	{ | 
| @@ -3113,40 +3292,48 @@ discard block | ||
| 3113 | 3292 | $context['user']['alerts'] = &$user_info['alerts']; | 
| 3114 | 3293 | |
| 3115 | 3294 | // Personal message popup... | 
| 3116 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) | |
| 3117 | - $context['user']['popup_messages'] = true; | |
| 3118 | - else | |
| 3119 | - $context['user']['popup_messages'] = false; | |
| 3295 | +		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { | |
| 3296 | + $context['user']['popup_messages'] = true; | |
| 3297 | +		} else { | |
| 3298 | + $context['user']['popup_messages'] = false; | |
| 3299 | + } | |
| 3120 | 3300 | $_SESSION['unread_messages'] = $user_info['unread_messages']; | 
| 3121 | 3301 | |
| 3122 | -		if (allowedTo('moderate_forum')) | |
| 3123 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; | |
| 3302 | +		if (allowedTo('moderate_forum')) { | |
| 3303 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; | |
| 3304 | + } | |
| 3124 | 3305 | |
| 3125 | 3306 | $context['user']['avatar'] = array(); | 
| 3126 | 3307 | |
| 3127 | 3308 | // Check for gravatar first since we might be forcing them... | 
| 3128 | 3309 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) | 
| 3129 | 3310 |  		{ | 
| 3130 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) | |
| 3131 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); | |
| 3132 | - else | |
| 3133 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); | |
| 3311 | +			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { | |
| 3312 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); | |
| 3313 | +			} else { | |
| 3314 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); | |
| 3315 | + } | |
| 3134 | 3316 | } | 
| 3135 | 3317 | // Uploaded? | 
| 3136 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) | |
| 3137 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; | |
| 3318 | +		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { | |
| 3319 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; | |
| 3320 | + } | |
| 3138 | 3321 | // Full URL? | 
| 3139 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) | |
| 3140 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; | |
| 3322 | +		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { | |
| 3323 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; | |
| 3324 | + } | |
| 3141 | 3325 | // Otherwise we assume it's server stored. | 
| 3142 | - elseif ($user_info['avatar']['url'] != '') | |
| 3143 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); | |
| 3326 | +		elseif ($user_info['avatar']['url'] != '') { | |
| 3327 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); | |
| 3328 | + } | |
| 3144 | 3329 | // No avatar at all? Fine, we have a big fat default avatar ;) | 
| 3145 | - else | |
| 3146 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; | |
| 3330 | +		else { | |
| 3331 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; | |
| 3332 | + } | |
| 3147 | 3333 | |
| 3148 | - if (!empty($context['user']['avatar'])) | |
| 3149 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; | |
| 3334 | +		if (!empty($context['user']['avatar'])) { | |
| 3335 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; | |
| 3336 | + } | |
| 3150 | 3337 | |
| 3151 | 3338 | // Figure out how long they've been logged in. | 
| 3152 | 3339 | $context['user']['total_time_logged_in'] = array( | 
| @@ -3154,8 +3341,7 @@ discard block | ||
| 3154 | 3341 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), | 
| 3155 | 3342 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) | 
| 3156 | 3343 | ); | 
| 3157 | - } | |
| 3158 | - else | |
| 3344 | + } else | |
| 3159 | 3345 |  	{ | 
| 3160 | 3346 | $context['user']['messages'] = 0; | 
| 3161 | 3347 | $context['user']['unread_messages'] = 0; | 
| @@ -3163,12 +3349,14 @@ discard block | ||
| 3163 | 3349 |  		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); | 
| 3164 | 3350 | $context['user']['popup_messages'] = false; | 
| 3165 | 3351 | |
| 3166 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) | |
| 3167 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; | |
| 3352 | +		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { | |
| 3353 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; | |
| 3354 | + } | |
| 3168 | 3355 | |
| 3169 | 3356 | // If we've upgraded recently, go easy on the passwords. | 
| 3170 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) | |
| 3171 | - $context['disable_login_hashing'] = true; | |
| 3357 | +		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { | |
| 3358 | + $context['disable_login_hashing'] = true; | |
| 3359 | + } | |
| 3172 | 3360 | } | 
| 3173 | 3361 | |
| 3174 | 3362 | // Setup the main menu items. | 
| @@ -3181,8 +3369,8 @@ discard block | ||
| 3181 | 3369 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); | 
| 3182 | 3370 | |
| 3183 | 3371 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. | 
| 3184 | - if ($context['show_pm_popup']) | |
| 3185 | -		addInlineJavaScript(' | |
| 3372 | +	if ($context['show_pm_popup']) { | |
| 3373 | +			addInlineJavaScript(' | |
| 3186 | 3374 |  		jQuery(document).ready(function($) { | 
| 3187 | 3375 |  			new smc_Popup({ | 
| 3188 | 3376 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', | 
| @@ -3190,15 +3378,17 @@ discard block | ||
| 3190 | 3378 | icon_class: \'generic_icons mail_new\' | 
| 3191 | 3379 | }); | 
| 3192 | 3380 | });'); | 
| 3381 | + } | |
| 3193 | 3382 | |
| 3194 | 3383 | // Add a generic "Are you sure?" confirmation message. | 
| 3195 | 3384 |  	addInlineJavaScript(' | 
| 3196 | 3385 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); | 
| 3197 | 3386 | |
| 3198 | 3387 | // Now add the capping code for avatars. | 
| 3199 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') | |
| 3200 | -		addInlineCss(' | |
| 3388 | +	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { | |
| 3389 | +			addInlineCss(' | |
| 3201 | 3390 |  img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); | 
| 3391 | + } | |
| 3202 | 3392 | |
| 3203 | 3393 | // This looks weird, but it's because BoardIndex.php references the variable. | 
| 3204 | 3394 | $context['common_stats']['latest_member'] = array( | 
| @@ -3215,11 +3405,13 @@ discard block | ||
| 3215 | 3405 | ); | 
| 3216 | 3406 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); | 
| 3217 | 3407 | |
| 3218 | - if (empty($settings['theme_version'])) | |
| 3219 | -		addJavaScriptVar('smf_scripturl', $scripturl); | |
| 3408 | +	if (empty($settings['theme_version'])) { | |
| 3409 | +			addJavaScriptVar('smf_scripturl', $scripturl); | |
| 3410 | + } | |
| 3220 | 3411 | |
| 3221 | - if (!isset($context['page_title'])) | |
| 3222 | - $context['page_title'] = ''; | |
| 3412 | +	if (!isset($context['page_title'])) { | |
| 3413 | + $context['page_title'] = ''; | |
| 3414 | + } | |
| 3223 | 3415 | |
| 3224 | 3416 | // Set some specific vars. | 
| 3225 | 3417 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); | 
| @@ -3229,21 +3421,23 @@ discard block | ||
| 3229 | 3421 |  	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); | 
| 3230 | 3422 |  	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); | 
| 3231 | 3423 | |
| 3232 | - if (!empty($context['meta_keywords'])) | |
| 3233 | -		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); | |
| 3424 | +	if (!empty($context['meta_keywords'])) { | |
| 3425 | +			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); | |
| 3426 | + } | |
| 3234 | 3427 | |
| 3235 | - if (!empty($context['canonical_url'])) | |
| 3236 | -		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); | |
| 3428 | +	if (!empty($context['canonical_url'])) { | |
| 3429 | +			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); | |
| 3430 | + } | |
| 3237 | 3431 | |
| 3238 | - if (!empty($settings['og_image'])) | |
| 3239 | -		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); | |
| 3432 | +	if (!empty($settings['og_image'])) { | |
| 3433 | +			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); | |
| 3434 | + } | |
| 3240 | 3435 | |
| 3241 | 3436 | if (!empty($context['meta_description'])) | 
| 3242 | 3437 |  	{ | 
| 3243 | 3438 |  		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); | 
| 3244 | 3439 |  		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); | 
| 3245 | - } | |
| 3246 | - else | |
| 3440 | + } else | |
| 3247 | 3441 |  	{ | 
| 3248 | 3442 |  		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); | 
| 3249 | 3443 |  		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); | 
| @@ -3268,8 +3462,9 @@ discard block | ||
| 3268 | 3462 | $memory_needed = memoryReturnBytes($needed); | 
| 3269 | 3463 | |
| 3270 | 3464 | // should we account for how much is currently being used? | 
| 3271 | - if ($in_use) | |
| 3272 | -		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); | |
| 3465 | +	if ($in_use) { | |
| 3466 | +			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); | |
| 3467 | + } | |
| 3273 | 3468 | |
| 3274 | 3469 | // if more is needed, request it | 
| 3275 | 3470 | if ($memory_current < $memory_needed) | 
| @@ -3292,8 +3487,9 @@ discard block | ||
| 3292 | 3487 | */ | 
| 3293 | 3488 | function memoryReturnBytes($val) | 
| 3294 | 3489 |  { | 
| 3295 | - if (is_integer($val)) | |
| 3296 | - return $val; | |
| 3490 | +	if (is_integer($val)) { | |
| 3491 | + return $val; | |
| 3492 | + } | |
| 3297 | 3493 | |
| 3298 | 3494 | // Separate the number from the designator | 
| 3299 | 3495 | $val = trim($val); | 
| @@ -3329,10 +3525,11 @@ discard block | ||
| 3329 | 3525 |  		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | 
| 3330 | 3526 | |
| 3331 | 3527 | // Are we debugging the template/html content? | 
| 3332 | -		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) | |
| 3333 | -			header('Content-Type: application/xhtml+xml'); | |
| 3334 | - elseif (!isset($_REQUEST['xml'])) | |
| 3335 | -			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); | |
| 3528 | +		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { | |
| 3529 | +					header('Content-Type: application/xhtml+xml'); | |
| 3530 | +		} elseif (!isset($_REQUEST['xml'])) { | |
| 3531 | +					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); | |
| 3532 | + } | |
| 3336 | 3533 | } | 
| 3337 | 3534 | |
| 3338 | 3535 |  	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); | 
| @@ -3341,8 +3538,9 @@ discard block | ||
| 3341 | 3538 | if ($context['in_maintenance'] && $context['user']['is_admin']) | 
| 3342 | 3539 |  	{ | 
| 3343 | 3540 |  		$position = array_search('body', $context['template_layers']); | 
| 3344 | - if ($position === false) | |
| 3345 | -			$position = array_search('main', $context['template_layers']); | |
| 3541 | +		if ($position === false) { | |
| 3542 | +					$position = array_search('main', $context['template_layers']); | |
| 3543 | + } | |
| 3346 | 3544 | |
| 3347 | 3545 | if ($position !== false) | 
| 3348 | 3546 |  		{ | 
| @@ -3370,23 +3568,25 @@ discard block | ||
| 3370 | 3568 | |
| 3371 | 3569 | foreach ($securityFiles as $i => $securityFile) | 
| 3372 | 3570 |  			{ | 
| 3373 | - if (!file_exists($boarddir . '/' . $securityFile)) | |
| 3374 | - unset($securityFiles[$i]); | |
| 3571 | +				if (!file_exists($boarddir . '/' . $securityFile)) { | |
| 3572 | + unset($securityFiles[$i]); | |
| 3573 | + } | |
| 3375 | 3574 | } | 
| 3376 | 3575 | |
| 3377 | 3576 | // We are already checking so many files...just few more doesn't make any difference! :P | 
| 3378 | - if (!empty($modSettings['currentAttachmentUploadDir'])) | |
| 3379 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; | |
| 3380 | - | |
| 3381 | - else | |
| 3382 | - $path = $modSettings['attachmentUploadDir']; | |
| 3577 | +			if (!empty($modSettings['currentAttachmentUploadDir'])) { | |
| 3578 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; | |
| 3579 | +			} else { | |
| 3580 | + $path = $modSettings['attachmentUploadDir']; | |
| 3581 | + } | |
| 3383 | 3582 | |
| 3384 | 3583 | secureDirectory($path, true); | 
| 3385 | 3584 | secureDirectory($cachedir); | 
| 3386 | 3585 | |
| 3387 | 3586 | // If agreement is enabled, at least the english version shall exists | 
| 3388 | - if ($modSettings['requireAgreement']) | |
| 3389 | - $agreement = !file_exists($boarddir . '/agreement.txt'); | |
| 3587 | +			if ($modSettings['requireAgreement']) { | |
| 3588 | + $agreement = !file_exists($boarddir . '/agreement.txt'); | |
| 3589 | + } | |
| 3390 | 3590 | |
| 3391 | 3591 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) | 
| 3392 | 3592 |  			{ | 
| @@ -3401,18 +3601,21 @@ discard block | ||
| 3401 | 3601 | echo ' | 
| 3402 | 3602 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; | 
| 3403 | 3603 | |
| 3404 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') | |
| 3405 | - echo ' | |
| 3604 | +					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { | |
| 3605 | + echo ' | |
| 3406 | 3606 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; | 
| 3607 | + } | |
| 3407 | 3608 | } | 
| 3408 | 3609 | |
| 3409 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) | |
| 3410 | - echo ' | |
| 3610 | +				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { | |
| 3611 | + echo ' | |
| 3411 | 3612 | <strong>', $txt['cache_writable'], '</strong><br>'; | 
| 3613 | + } | |
| 3412 | 3614 | |
| 3413 | - if (!empty($agreement)) | |
| 3414 | - echo ' | |
| 3615 | +				if (!empty($agreement)) { | |
| 3616 | + echo ' | |
| 3415 | 3617 | <strong>', $txt['agreement_missing'], '</strong><br>'; | 
| 3618 | + } | |
| 3416 | 3619 | |
| 3417 | 3620 | echo ' | 
| 3418 | 3621 | </p> | 
| @@ -3427,16 +3630,18 @@ discard block | ||
| 3427 | 3630 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> | 
| 3428 | 3631 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); | 
| 3429 | 3632 | |
| 3430 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) | |
| 3431 | - echo ' | |
| 3633 | +			if (!empty($_SESSION['ban']['cannot_post']['reason'])) { | |
| 3634 | + echo ' | |
| 3432 | 3635 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; | 
| 3636 | + } | |
| 3433 | 3637 | |
| 3434 | - if (!empty($_SESSION['ban']['expire_time'])) | |
| 3435 | - echo ' | |
| 3638 | +			if (!empty($_SESSION['ban']['expire_time'])) { | |
| 3639 | + echo ' | |
| 3436 | 3640 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; | 
| 3437 | - else | |
| 3438 | - echo ' | |
| 3641 | +			} else { | |
| 3642 | + echo ' | |
| 3439 | 3643 | <div>', $txt['your_ban_expires_never'], '</div>'; | 
| 3644 | + } | |
| 3440 | 3645 | |
| 3441 | 3646 | echo ' | 
| 3442 | 3647 | </div>'; | 
| @@ -3452,8 +3657,9 @@ discard block | ||
| 3452 | 3657 | global $forum_copyright, $software_year, $forum_version; | 
| 3453 | 3658 | |
| 3454 | 3659 | // Don't display copyright for things like SSI. | 
| 3455 | - if (!isset($forum_version) || !isset($software_year)) | |
| 3456 | - return; | |
| 3660 | +	if (!isset($forum_version) || !isset($software_year)) { | |
| 3661 | + return; | |
| 3662 | + } | |
| 3457 | 3663 | |
| 3458 | 3664 | // Put in the version... | 
| 3459 | 3665 | printf($forum_copyright, $forum_version, $software_year); | 
| @@ -3471,9 +3677,10 @@ discard block | ||
| 3471 | 3677 |  	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); | 
| 3472 | 3678 | $context['load_queries'] = $db_count; | 
| 3473 | 3679 | |
| 3474 | - foreach (array_reverse($context['template_layers']) as $layer) | |
| 3475 | - loadSubTemplate($layer . '_below', true); | |
| 3476 | -} | |
| 3680 | +	foreach (array_reverse($context['template_layers']) as $layer) { | |
| 3681 | + loadSubTemplate($layer . '_below', true); | |
| 3682 | + } | |
| 3683 | + } | |
| 3477 | 3684 | |
| 3478 | 3685 | /** | 
| 3479 | 3686 | * Output the Javascript files | 
| @@ -3504,8 +3711,7 @@ discard block | ||
| 3504 | 3711 |  			{ | 
| 3505 | 3712 | echo ' | 
| 3506 | 3713 | var ', $key, ';'; | 
| 3507 | - } | |
| 3508 | - else | |
| 3714 | + } else | |
| 3509 | 3715 |  			{ | 
| 3510 | 3716 | echo ' | 
| 3511 | 3717 | var ', $key, ' = ', $value, ';'; | 
| @@ -3520,26 +3726,27 @@ discard block | ||
| 3520 | 3726 | foreach ($context['javascript_files'] as $id => $js_file) | 
| 3521 | 3727 |  	{ | 
| 3522 | 3728 | // Last minute call! allow theme authors to disable single files. | 
| 3523 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) | |
| 3524 | - continue; | |
| 3729 | +		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { | |
| 3730 | + continue; | |
| 3731 | + } | |
| 3525 | 3732 | |
| 3526 | 3733 | // By default all files don't get minimized unless the file explicitly says so! | 
| 3527 | 3734 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) | 
| 3528 | 3735 |  		{ | 
| 3529 | - if ($do_deferred && !empty($js_file['options']['defer'])) | |
| 3530 | - $toMinifyDefer[] = $js_file; | |
| 3531 | - | |
| 3532 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) | |
| 3533 | - $toMinify[] = $js_file; | |
| 3736 | +			if ($do_deferred && !empty($js_file['options']['defer'])) { | |
| 3737 | + $toMinifyDefer[] = $js_file; | |
| 3738 | +			} elseif (!$do_deferred && empty($js_file['options']['defer'])) { | |
| 3739 | + $toMinify[] = $js_file; | |
| 3740 | + } | |
| 3534 | 3741 | |
| 3535 | 3742 | // Grab a random seed. | 
| 3536 | - if (!isset($minSeed)) | |
| 3537 | - $minSeed = $js_file['options']['seed']; | |
| 3538 | - } | |
| 3539 | - | |
| 3540 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) | |
| 3541 | - echo ' | |
| 3743 | +			if (!isset($minSeed)) { | |
| 3744 | + $minSeed = $js_file['options']['seed']; | |
| 3745 | + } | |
| 3746 | +		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { | |
| 3747 | + echo ' | |
| 3542 | 3748 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; | 
| 3749 | + } | |
| 3543 | 3750 | } | 
| 3544 | 3751 | |
| 3545 | 3752 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) | 
| @@ -3547,14 +3754,14 @@ discard block | ||
| 3547 | 3754 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); | 
| 3548 | 3755 | |
| 3549 | 3756 | // Minify process couldn't work, print each individual files. | 
| 3550 | - if (!empty($result) && is_array($result)) | |
| 3551 | - foreach ($result as $minFailedFile) | |
| 3757 | +		if (!empty($result) && is_array($result)) { | |
| 3758 | + foreach ($result as $minFailedFile) | |
| 3552 | 3759 | echo ' | 
| 3553 | 3760 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; | 
| 3554 | - | |
| 3555 | - else | |
| 3556 | - echo ' | |
| 3761 | +		} else { | |
| 3762 | + echo ' | |
| 3557 | 3763 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; | 
| 3764 | + } | |
| 3558 | 3765 | } | 
| 3559 | 3766 | |
| 3560 | 3767 | // Inline JavaScript - Actually useful some times! | 
| @@ -3565,8 +3772,9 @@ discard block | ||
| 3565 | 3772 | echo ' | 
| 3566 | 3773 | <script>'; | 
| 3567 | 3774 | |
| 3568 | - foreach ($context['javascript_inline']['defer'] as $js_code) | |
| 3569 | - echo $js_code; | |
| 3775 | +			foreach ($context['javascript_inline']['defer'] as $js_code) { | |
| 3776 | + echo $js_code; | |
| 3777 | + } | |
| 3570 | 3778 | |
| 3571 | 3779 | echo ' | 
| 3572 | 3780 | </script>'; | 
| @@ -3577,8 +3785,9 @@ discard block | ||
| 3577 | 3785 | echo ' | 
| 3578 | 3786 | <script>'; | 
| 3579 | 3787 | |
| 3580 | - foreach ($context['javascript_inline']['standard'] as $js_code) | |
| 3581 | - echo $js_code; | |
| 3788 | +			foreach ($context['javascript_inline']['standard'] as $js_code) { | |
| 3789 | + echo $js_code; | |
| 3790 | + } | |
| 3582 | 3791 | |
| 3583 | 3792 | echo ' | 
| 3584 | 3793 | </script>'; | 
| @@ -3603,8 +3812,9 @@ discard block | ||
| 3603 | 3812 | foreach ($context['css_files'] as $id => $file) | 
| 3604 | 3813 |  	{ | 
| 3605 | 3814 | // Last minute call! allow theme authors to disable single files. | 
| 3606 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) | |
| 3607 | - continue; | |
| 3815 | +		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { | |
| 3816 | + continue; | |
| 3817 | + } | |
| 3608 | 3818 | |
| 3609 | 3819 | // By default all files don't get minimized unless the file explicitly says so! | 
| 3610 | 3820 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) | 
| @@ -3612,12 +3822,12 @@ discard block | ||
| 3612 | 3822 | $toMinify[] = $file; | 
| 3613 | 3823 | |
| 3614 | 3824 | // Grab a random seed. | 
| 3615 | - if (!isset($minSeed)) | |
| 3616 | - $minSeed = $file['options']['seed']; | |
| 3825 | +			if (!isset($minSeed)) { | |
| 3826 | + $minSeed = $file['options']['seed']; | |
| 3827 | + } | |
| 3828 | +		} else { | |
| 3829 | + $normal[] = $file['fileUrl']; | |
| 3617 | 3830 | } | 
| 3618 | - | |
| 3619 | - else | |
| 3620 | - $normal[] = $file['fileUrl']; | |
| 3621 | 3831 | } | 
| 3622 | 3832 | |
| 3623 | 3833 | if (!empty($toMinify)) | 
| @@ -3625,28 +3835,30 @@ discard block | ||
| 3625 | 3835 | $result = custMinify($toMinify, 'css'); | 
| 3626 | 3836 | |
| 3627 | 3837 | // Minify process couldn't work, print each individual files. | 
| 3628 | - if (!empty($result) && is_array($result)) | |
| 3629 | - foreach ($result as $minFailedFile) | |
| 3838 | +		if (!empty($result) && is_array($result)) { | |
| 3839 | + foreach ($result as $minFailedFile) | |
| 3630 | 3840 | echo ' | 
| 3631 | 3841 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; | 
| 3632 | - | |
| 3633 | - else | |
| 3634 | - echo ' | |
| 3842 | +		} else { | |
| 3843 | + echo ' | |
| 3635 | 3844 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; | 
| 3845 | + } | |
| 3636 | 3846 | } | 
| 3637 | 3847 | |
| 3638 | 3848 | // Print the rest after the minified files. | 
| 3639 | - if (!empty($normal)) | |
| 3640 | - foreach ($normal as $nf) | |
| 3849 | +	if (!empty($normal)) { | |
| 3850 | + foreach ($normal as $nf) | |
| 3641 | 3851 | echo ' | 
| 3642 | 3852 | <link rel="stylesheet" href="', $nf ,'">'; | 
| 3853 | + } | |
| 3643 | 3854 | |
| 3644 | 3855 | if ($db_show_debug === true) | 
| 3645 | 3856 |  	{ | 
| 3646 | 3857 | // Try to keep only what's useful. | 
| 3647 | 3858 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); | 
| 3648 | - foreach ($context['css_files'] as $file) | |
| 3649 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); | |
| 3859 | +		foreach ($context['css_files'] as $file) { | |
| 3860 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); | |
| 3861 | + } | |
| 3650 | 3862 | } | 
| 3651 | 3863 | |
| 3652 | 3864 | if (!empty($context['css_header'])) | 
| @@ -3654,9 +3866,10 @@ discard block | ||
| 3654 | 3866 | echo ' | 
| 3655 | 3867 | <style>'; | 
| 3656 | 3868 | |
| 3657 | - foreach ($context['css_header'] as $css) | |
| 3658 | - echo $css .' | |
| 3869 | +		foreach ($context['css_header'] as $css) { | |
| 3870 | + echo $css .' | |
| 3659 | 3871 | '; | 
| 3872 | + } | |
| 3660 | 3873 | |
| 3661 | 3874 | echo' | 
| 3662 | 3875 | </style>'; | 
| @@ -3680,15 +3893,17 @@ discard block | ||
| 3680 | 3893 | $type = !empty($type) && in_array($type, $types) ? $type : false; | 
| 3681 | 3894 | $data = !empty($data) ? $data : false; | 
| 3682 | 3895 | |
| 3683 | - if (empty($type) || empty($data)) | |
| 3684 | - return false; | |
| 3896 | +	if (empty($type) || empty($data)) { | |
| 3897 | + return false; | |
| 3898 | + } | |
| 3685 | 3899 | |
| 3686 | 3900 | // Did we already did this? | 
| 3687 | 3901 |  	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); | 
| 3688 | 3902 | |
| 3689 | 3903 | // Already done? | 
| 3690 | - if (!empty($toCache)) | |
| 3691 | - return true; | |
| 3904 | +	if (!empty($toCache)) { | |
| 3905 | + return true; | |
| 3906 | + } | |
| 3692 | 3907 | |
| 3693 | 3908 | // No namespaces, sorry! | 
| 3694 | 3909 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); | 
| @@ -3770,8 +3985,9 @@ discard block | ||
| 3770 | 3985 | global $modSettings, $smcFunc; | 
| 3771 | 3986 | |
| 3772 | 3987 | // Just make up a nice hash... | 
| 3773 | - if ($new) | |
| 3774 | - return sha1(md5($filename . time()) . mt_rand()); | |
| 3988 | +	if ($new) { | |
| 3989 | + return sha1(md5($filename . time()) . mt_rand()); | |
| 3990 | + } | |
| 3775 | 3991 | |
| 3776 | 3992 | // Just make sure that attachment id is only a int | 
| 3777 | 3993 | $attachment_id = (int) $attachment_id; | 
| @@ -3788,23 +4004,25 @@ discard block | ||
| 3788 | 4004 | 'id_attach' => $attachment_id, | 
| 3789 | 4005 | )); | 
| 3790 | 4006 | |
| 3791 | - if ($smcFunc['db_num_rows']($request) === 0) | |
| 3792 | - return false; | |
| 4007 | +		if ($smcFunc['db_num_rows']($request) === 0) { | |
| 4008 | + return false; | |
| 4009 | + } | |
| 3793 | 4010 | |
| 3794 | 4011 | list ($file_hash) = $smcFunc['db_fetch_row']($request); | 
| 3795 | 4012 | $smcFunc['db_free_result']($request); | 
| 3796 | 4013 | } | 
| 3797 | 4014 | |
| 3798 | 4015 | // Still no hash? mmm... | 
| 3799 | - if (empty($file_hash)) | |
| 3800 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); | |
| 4016 | +	if (empty($file_hash)) { | |
| 4017 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); | |
| 4018 | + } | |
| 3801 | 4019 | |
| 3802 | 4020 | // Are we using multiple directories? | 
| 3803 | - if (is_array($modSettings['attachmentUploadDir'])) | |
| 3804 | - $path = $modSettings['attachmentUploadDir'][$dir]; | |
| 3805 | - | |
| 3806 | - else | |
| 3807 | - $path = $modSettings['attachmentUploadDir']; | |
| 4021 | +	if (is_array($modSettings['attachmentUploadDir'])) { | |
| 4022 | + $path = $modSettings['attachmentUploadDir'][$dir]; | |
| 4023 | +	} else { | |
| 4024 | + $path = $modSettings['attachmentUploadDir']; | |
| 4025 | + } | |
| 3808 | 4026 | |
| 3809 | 4027 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; | 
| 3810 | 4028 | } | 
| @@ -3819,8 +4037,9 @@ discard block | ||
| 3819 | 4037 | function ip2range($fullip) | 
| 3820 | 4038 |  { | 
| 3821 | 4039 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) | 
| 3822 | - if ($fullip == 'unknown') | |
| 3823 | - $fullip = '255.255.255.255'; | |
| 4040 | +	if ($fullip == 'unknown') { | |
| 4041 | + $fullip = '255.255.255.255'; | |
| 4042 | + } | |
| 3824 | 4043 | |
| 3825 | 4044 |  	$ip_parts = explode('-', $fullip); | 
| 3826 | 4045 | $ip_array = array(); | 
| @@ -3844,10 +4063,11 @@ discard block | ||
| 3844 | 4063 | $ip_array['low'] = $ip_parts[0]; | 
| 3845 | 4064 | $ip_array['high'] = $ip_parts[1]; | 
| 3846 | 4065 | return $ip_array; | 
| 3847 | - } | |
| 3848 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* | |
| 4066 | +	} elseif (count($ip_parts) == 2) { | |
| 4067 | + // if ip 22.22.*-22.22.* | |
| 3849 | 4068 |  	{ | 
| 3850 | 4069 | $valid_low = isValidIP($ip_parts[0]); | 
| 4070 | + } | |
| 3851 | 4071 | $valid_high = isValidIP($ip_parts[1]); | 
| 3852 | 4072 | $count = 0; | 
| 3853 | 4073 |  		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); | 
| @@ -3862,7 +4082,9 @@ discard block | ||
| 3862 | 4082 | $ip_parts[0] .= $mode . $min; | 
| 3863 | 4083 | $valid_low = isValidIP($ip_parts[0]); | 
| 3864 | 4084 | $count++; | 
| 3865 | - if ($count > 9) break; | |
| 4085 | +				if ($count > 9) { | |
| 4086 | + break; | |
| 4087 | + } | |
| 3866 | 4088 | } | 
| 3867 | 4089 | } | 
| 3868 | 4090 | |
| @@ -3876,7 +4098,9 @@ discard block | ||
| 3876 | 4098 | $ip_parts[1] .= $mode . $max; | 
| 3877 | 4099 | $valid_high = isValidIP($ip_parts[1]); | 
| 3878 | 4100 | $count++; | 
| 3879 | - if ($count > 9) break; | |
| 4101 | +				if ($count > 9) { | |
| 4102 | + break; | |
| 4103 | + } | |
| 3880 | 4104 | } | 
| 3881 | 4105 | } | 
| 3882 | 4106 | |
| @@ -3901,46 +4125,54 @@ discard block | ||
| 3901 | 4125 |  { | 
| 3902 | 4126 | global $modSettings; | 
| 3903 | 4127 | |
| 3904 | -	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) | |
| 3905 | - return $host; | |
| 4128 | +	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { | |
| 4129 | + return $host; | |
| 4130 | + } | |
| 3906 | 4131 | $t = microtime(); | 
| 3907 | 4132 | |
| 3908 | 4133 | // Try the Linux host command, perhaps? | 
| 3909 | 4134 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) | 
| 3910 | 4135 |  	{ | 
| 3911 | - if (!isset($modSettings['host_to_dis'])) | |
| 3912 | -			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); | |
| 3913 | - else | |
| 3914 | -			$test = @shell_exec('host ' . @escapeshellarg($ip)); | |
| 4136 | +		if (!isset($modSettings['host_to_dis'])) { | |
| 4137 | +					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); | |
| 4138 | +		} else { | |
| 4139 | +					$test = @shell_exec('host ' . @escapeshellarg($ip)); | |
| 4140 | + } | |
| 3915 | 4141 | |
| 3916 | 4142 | // Did host say it didn't find anything? | 
| 3917 | - if (strpos($test, 'not found') !== false) | |
| 3918 | - $host = ''; | |
| 4143 | +		if (strpos($test, 'not found') !== false) { | |
| 4144 | + $host = ''; | |
| 4145 | + } | |
| 3919 | 4146 | // Invalid server option? | 
| 3920 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) | |
| 3921 | -			updateSettings(array('host_to_dis' => 1)); | |
| 4147 | +		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { | |
| 4148 | +					updateSettings(array('host_to_dis' => 1)); | |
| 4149 | + } | |
| 3922 | 4150 | // Maybe it found something, after all? | 
| 3923 | -		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) | |
| 3924 | - $host = $match[1]; | |
| 4151 | +		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { | |
| 4152 | + $host = $match[1]; | |
| 4153 | + } | |
| 3925 | 4154 | } | 
| 3926 | 4155 | |
| 3927 | 4156 | // This is nslookup; usually only Windows, but possibly some Unix? | 
| 3928 | 4157 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) | 
| 3929 | 4158 |  	{ | 
| 3930 | 4159 |  		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); | 
| 3931 | - if (strpos($test, 'Non-existent domain') !== false) | |
| 3932 | - $host = ''; | |
| 3933 | -		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) | |
| 3934 | - $host = $match[1]; | |
| 4160 | +		if (strpos($test, 'Non-existent domain') !== false) { | |
| 4161 | + $host = ''; | |
| 4162 | +		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { | |
| 4163 | + $host = $match[1]; | |
| 4164 | + } | |
| 3935 | 4165 | } | 
| 3936 | 4166 | |
| 3937 | 4167 | // This is the last try :/. | 
| 3938 | - if (!isset($host) || $host === false) | |
| 3939 | - $host = @gethostbyaddr($ip); | |
| 4168 | +	if (!isset($host) || $host === false) { | |
| 4169 | + $host = @gethostbyaddr($ip); | |
| 4170 | + } | |
| 3940 | 4171 | |
| 3941 | 4172 | // It took a long time, so let's cache it! | 
| 3942 | -	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) | |
| 3943 | -		cache_put_data('hostlookup-' . $ip, $host, 600); | |
| 4173 | +	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { | |
| 4174 | +			cache_put_data('hostlookup-' . $ip, $host, 600); | |
| 4175 | + } | |
| 3944 | 4176 | |
| 3945 | 4177 | return $host; | 
| 3946 | 4178 | } | 
| @@ -3976,20 +4208,21 @@ discard block | ||
| 3976 | 4208 |  			{ | 
| 3977 | 4209 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); | 
| 3978 | 4210 | $total = 0; | 
| 3979 | - for ($i = 0; $i < $max_chars; $i++) | |
| 3980 | -					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); | |
| 4211 | +				for ($i = 0; $i < $max_chars; $i++) { | |
| 4212 | +									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); | |
| 4213 | + } | |
| 3981 | 4214 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; | 
| 3982 | 4215 | } | 
| 3983 | 4216 | } | 
| 3984 | 4217 | return array_unique($returned_ints); | 
| 3985 | - } | |
| 3986 | - else | |
| 4218 | + } else | |
| 3987 | 4219 |  	{ | 
| 3988 | 4220 | // Trim characters before and after and add slashes for database insertion. | 
| 3989 | 4221 | $returned_words = array(); | 
| 3990 | - foreach ($words as $word) | |
| 3991 | - if (($word = trim($word, '-_\'')) !== '') | |
| 4222 | +		foreach ($words as $word) { | |
| 4223 | + if (($word = trim($word, '-_\'')) !== '') | |
| 3992 | 4224 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); | 
| 4225 | + } | |
| 3993 | 4226 | |
| 3994 | 4227 | // Filter out all words that occur more than once. | 
| 3995 | 4228 | return array_unique($returned_words); | 
| @@ -4011,16 +4244,18 @@ discard block | ||
| 4011 | 4244 | global $settings, $txt; | 
| 4012 | 4245 | |
| 4013 | 4246 | // Does the current loaded theme have this and we are not forcing the usage of this function? | 
| 4014 | -	if (function_exists('template_create_button') && !$force_use) | |
| 4015 | - return template_create_button($name, $alt, $label = '', $custom = ''); | |
| 4247 | +	if (function_exists('template_create_button') && !$force_use) { | |
| 4248 | + return template_create_button($name, $alt, $label = '', $custom = ''); | |
| 4249 | + } | |
| 4016 | 4250 | |
| 4017 | - if (!$settings['use_image_buttons']) | |
| 4018 | - return $txt[$alt]; | |
| 4019 | - elseif (!empty($settings['use_buttons'])) | |
| 4020 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); | |
| 4021 | - else | |
| 4022 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; | |
| 4023 | -} | |
| 4251 | +	if (!$settings['use_image_buttons']) { | |
| 4252 | + return $txt[$alt]; | |
| 4253 | +	} elseif (!empty($settings['use_buttons'])) { | |
| 4254 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); | |
| 4255 | +	} else { | |
| 4256 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; | |
| 4257 | + } | |
| 4258 | + } | |
| 4024 | 4259 | |
| 4025 | 4260 | /** | 
| 4026 | 4261 | * Sets up all of the top menu buttons | 
| @@ -4063,9 +4298,10 @@ discard block | ||
| 4063 | 4298 | var user_menus = new smc_PopupMenu(); | 
| 4064 | 4299 |  	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); | 
| 4065 | 4300 |  	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); | 
| 4066 | - if ($context['allow_pm']) | |
| 4067 | -			addInlineJavaScript(' | |
| 4301 | +		if ($context['allow_pm']) { | |
| 4302 | +					addInlineJavaScript(' | |
| 4068 | 4303 |  	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); | 
| 4304 | + } | |
| 4069 | 4305 | |
| 4070 | 4306 | if (!empty($modSettings['enable_ajax_alerts'])) | 
| 4071 | 4307 |  		{ | 
| @@ -4225,88 +4461,96 @@ discard block | ||
| 4225 | 4461 | |
| 4226 | 4462 | // Now we put the buttons in the context so the theme can use them. | 
| 4227 | 4463 | $menu_buttons = array(); | 
| 4228 | - foreach ($buttons as $act => $button) | |
| 4229 | - if (!empty($button['show'])) | |
| 4464 | +		foreach ($buttons as $act => $button) { | |
| 4465 | + if (!empty($button['show'])) | |
| 4230 | 4466 |  			{ | 
| 4231 | 4467 | $button['active_button'] = false; | 
| 4468 | + } | |
| 4232 | 4469 | |
| 4233 | 4470 | // This button needs some action. | 
| 4234 | - if (isset($button['action_hook'])) | |
| 4235 | - $needs_action_hook = true; | |
| 4471 | +				if (isset($button['action_hook'])) { | |
| 4472 | + $needs_action_hook = true; | |
| 4473 | + } | |
| 4236 | 4474 | |
| 4237 | 4475 | // Make sure the last button truly is the last button. | 
| 4238 | 4476 | if (!empty($button['is_last'])) | 
| 4239 | 4477 |  				{ | 
| 4240 | - if (isset($last_button)) | |
| 4241 | - unset($menu_buttons[$last_button]['is_last']); | |
| 4478 | +					if (isset($last_button)) { | |
| 4479 | + unset($menu_buttons[$last_button]['is_last']); | |
| 4480 | + } | |
| 4242 | 4481 | $last_button = $act; | 
| 4243 | 4482 | } | 
| 4244 | 4483 | |
| 4245 | 4484 | // Go through the sub buttons if there are any. | 
| 4246 | - if (!empty($button['sub_buttons'])) | |
| 4247 | - foreach ($button['sub_buttons'] as $key => $subbutton) | |
| 4485 | +				if (!empty($button['sub_buttons'])) { | |
| 4486 | + foreach ($button['sub_buttons'] as $key => $subbutton) | |
| 4248 | 4487 |  					{ | 
| 4249 | 4488 | if (empty($subbutton['show'])) | 
| 4250 | 4489 | unset($button['sub_buttons'][$key]); | 
| 4490 | + } | |
| 4251 | 4491 | |
| 4252 | 4492 | // 2nd level sub buttons next... | 
| 4253 | 4493 | if (!empty($subbutton['sub_buttons'])) | 
| 4254 | 4494 |  						{ | 
| 4255 | 4495 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) | 
| 4256 | 4496 |  							{ | 
| 4257 | - if (empty($sub_button2['show'])) | |
| 4258 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); | |
| 4497 | +								if (empty($sub_button2['show'])) { | |
| 4498 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); | |
| 4499 | + } | |
| 4259 | 4500 | } | 
| 4260 | 4501 | } | 
| 4261 | 4502 | } | 
| 4262 | 4503 | |
| 4263 | 4504 | // Does this button have its own icon? | 
| 4264 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) | |
| 4265 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; | |
| 4266 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) | |
| 4267 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; | |
| 4268 | - elseif (isset($button['icon'])) | |
| 4269 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; | |
| 4270 | - else | |
| 4271 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; | |
| 4505 | +				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { | |
| 4506 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; | |
| 4507 | +				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { | |
| 4508 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; | |
| 4509 | +				} elseif (isset($button['icon'])) { | |
| 4510 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; | |
| 4511 | +				} else { | |
| 4512 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; | |
| 4513 | + } | |
| 4272 | 4514 | |
| 4273 | 4515 | $menu_buttons[$act] = $button; | 
| 4274 | 4516 | } | 
| 4275 | 4517 | |
| 4276 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) | |
| 4277 | -			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); | |
| 4518 | +		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { | |
| 4519 | +					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); | |
| 4520 | + } | |
| 4278 | 4521 | } | 
| 4279 | 4522 | |
| 4280 | 4523 | $context['menu_buttons'] = $menu_buttons; | 
| 4281 | 4524 | |
| 4282 | 4525 | // Logging out requires the session id in the url. | 
| 4283 | - if (isset($context['menu_buttons']['logout'])) | |
| 4284 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); | |
| 4526 | +	if (isset($context['menu_buttons']['logout'])) { | |
| 4527 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); | |
| 4528 | + } | |
| 4285 | 4529 | |
| 4286 | 4530 | // Figure out which action we are doing so we can set the active tab. | 
| 4287 | 4531 | // Default to home. | 
| 4288 | 4532 | $current_action = 'home'; | 
| 4289 | 4533 | |
| 4290 | - if (isset($context['menu_buttons'][$context['current_action']])) | |
| 4291 | - $current_action = $context['current_action']; | |
| 4292 | - elseif ($context['current_action'] == 'search2') | |
| 4293 | - $current_action = 'search'; | |
| 4294 | - elseif ($context['current_action'] == 'theme') | |
| 4295 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; | |
| 4296 | - elseif ($context['current_action'] == 'register2') | |
| 4297 | - $current_action = 'register'; | |
| 4298 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) | |
| 4299 | - $current_action = 'login'; | |
| 4300 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) | |
| 4301 | - $current_action = 'moderate'; | |
| 4534 | +	if (isset($context['menu_buttons'][$context['current_action']])) { | |
| 4535 | + $current_action = $context['current_action']; | |
| 4536 | +	} elseif ($context['current_action'] == 'search2') { | |
| 4537 | + $current_action = 'search'; | |
| 4538 | +	} elseif ($context['current_action'] == 'theme') { | |
| 4539 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; | |
| 4540 | +	} elseif ($context['current_action'] == 'register2') { | |
| 4541 | + $current_action = 'register'; | |
| 4542 | +	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { | |
| 4543 | + $current_action = 'login'; | |
| 4544 | +	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { | |
| 4545 | + $current_action = 'moderate'; | |
| 4546 | + } | |
| 4302 | 4547 | |
| 4303 | 4548 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. | 
| 4304 | 4549 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) | 
| 4305 | 4550 |  	{ | 
| 4306 | 4551 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; | 
| 4307 | 4552 | $context[$current_action] = true; | 
| 4308 | - } | |
| 4309 | - elseif ($context['current_action'] == 'pm') | |
| 4553 | + } elseif ($context['current_action'] == 'pm') | |
| 4310 | 4554 |  	{ | 
| 4311 | 4555 | $current_action = 'self_pm'; | 
| 4312 | 4556 | $context['self_pm'] = true; | 
| @@ -4347,12 +4591,14 @@ discard block | ||
| 4347 | 4591 | } | 
| 4348 | 4592 | |
| 4349 | 4593 | // Not all actions are simple. | 
| 4350 | - if (!empty($needs_action_hook)) | |
| 4351 | -		call_integration_hook('integrate_current_action', array(&$current_action)); | |
| 4594 | +	if (!empty($needs_action_hook)) { | |
| 4595 | +			call_integration_hook('integrate_current_action', array(&$current_action)); | |
| 4596 | + } | |
| 4352 | 4597 | |
| 4353 | - if (isset($context['menu_buttons'][$current_action])) | |
| 4354 | - $context['menu_buttons'][$current_action]['active_button'] = true; | |
| 4355 | -} | |
| 4598 | +	if (isset($context['menu_buttons'][$current_action])) { | |
| 4599 | + $context['menu_buttons'][$current_action]['active_button'] = true; | |
| 4600 | + } | |
| 4601 | + } | |
| 4356 | 4602 | |
| 4357 | 4603 | /** | 
| 4358 | 4604 | * Generate a random seed and ensure it's stored in settings. | 
| @@ -4376,30 +4622,35 @@ discard block | ||
| 4376 | 4622 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; | 
| 4377 | 4623 | global $context, $txt; | 
| 4378 | 4624 | |
| 4379 | - if ($db_show_debug === true) | |
| 4380 | - $context['debug']['hooks'][] = $hook; | |
| 4625 | +	if ($db_show_debug === true) { | |
| 4626 | + $context['debug']['hooks'][] = $hook; | |
| 4627 | + } | |
| 4381 | 4628 | |
| 4382 | 4629 | // Need to have some control. | 
| 4383 | - if (!isset($context['instances'])) | |
| 4384 | - $context['instances'] = array(); | |
| 4630 | +	if (!isset($context['instances'])) { | |
| 4631 | + $context['instances'] = array(); | |
| 4632 | + } | |
| 4385 | 4633 | |
| 4386 | 4634 | $results = array(); | 
| 4387 | - if (empty($modSettings[$hook])) | |
| 4388 | - return $results; | |
| 4635 | +	if (empty($modSettings[$hook])) { | |
| 4636 | + return $results; | |
| 4637 | + } | |
| 4389 | 4638 | |
| 4390 | 4639 |  	$functions = explode(',', $modSettings[$hook]); | 
| 4391 | 4640 | // Loop through each function. | 
| 4392 | 4641 | foreach ($functions as $function) | 
| 4393 | 4642 |  	{ | 
| 4394 | 4643 | // Hook has been marked as "disabled". Skip it! | 
| 4395 | - if (strpos($function, '!') !== false) | |
| 4396 | - continue; | |
| 4644 | +		if (strpos($function, '!') !== false) { | |
| 4645 | + continue; | |
| 4646 | + } | |
| 4397 | 4647 | |
| 4398 | 4648 | $call = call_helper($function, true); | 
| 4399 | 4649 | |
| 4400 | 4650 | // Is it valid? | 
| 4401 | - if (!empty($call)) | |
| 4402 | - $results[$function] = call_user_func_array($call, $parameters); | |
| 4651 | +		if (!empty($call)) { | |
| 4652 | + $results[$function] = call_user_func_array($call, $parameters); | |
| 4653 | + } | |
| 4403 | 4654 | |
| 4404 | 4655 | // Whatever it was suppose to call, it failed :( | 
| 4405 | 4656 | elseif (!empty($function)) | 
| @@ -4415,8 +4666,9 @@ discard block | ||
| 4415 | 4666 | } | 
| 4416 | 4667 | |
| 4417 | 4668 | // "Assume" the file resides on $boarddir somewhere... | 
| 4418 | - else | |
| 4419 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); | |
| 4669 | +			else { | |
| 4670 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); | |
| 4671 | + } | |
| 4420 | 4672 | } | 
| 4421 | 4673 | } | 
| 4422 | 4674 | |
| @@ -4438,12 +4690,14 @@ discard block | ||
| 4438 | 4690 | global $smcFunc, $modSettings; | 
| 4439 | 4691 | |
| 4440 | 4692 | // Any objects? | 
| 4441 | - if ($object) | |
| 4442 | - $function = $function . '#'; | |
| 4693 | +	if ($object) { | |
| 4694 | + $function = $function . '#'; | |
| 4695 | + } | |
| 4443 | 4696 | |
| 4444 | 4697 | // Any files to load? | 
| 4445 | - if (!empty($file) && is_string($file)) | |
| 4446 | - $function = $file . (!empty($function) ? '|' . $function : ''); | |
| 4698 | +	if (!empty($file) && is_string($file)) { | |
| 4699 | + $function = $file . (!empty($function) ? '|' . $function : ''); | |
| 4700 | + } | |
| 4447 | 4701 | |
| 4448 | 4702 | // Get the correct string. | 
| 4449 | 4703 | $integration_call = $function; | 
| @@ -4465,13 +4719,14 @@ discard block | ||
| 4465 | 4719 | if (!empty($current_functions)) | 
| 4466 | 4720 |  		{ | 
| 4467 | 4721 |  			$current_functions = explode(',', $current_functions); | 
| 4468 | - if (in_array($integration_call, $current_functions)) | |
| 4469 | - return; | |
| 4722 | +			if (in_array($integration_call, $current_functions)) { | |
| 4723 | + return; | |
| 4724 | + } | |
| 4470 | 4725 | |
| 4471 | 4726 | $permanent_functions = array_merge($current_functions, array($integration_call)); | 
| 4727 | +		} else { | |
| 4728 | + $permanent_functions = array($integration_call); | |
| 4472 | 4729 | } | 
| 4473 | - else | |
| 4474 | - $permanent_functions = array($integration_call); | |
| 4475 | 4730 | |
| 4476 | 4731 |  		updateSettings(array($hook => implode(',', $permanent_functions))); | 
| 4477 | 4732 | } | 
| @@ -4480,8 +4735,9 @@ discard block | ||
| 4480 | 4735 |  	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); | 
| 4481 | 4736 | |
| 4482 | 4737 | // Do nothing, if it's already there. | 
| 4483 | - if (in_array($integration_call, $functions)) | |
| 4484 | - return; | |
| 4738 | +	if (in_array($integration_call, $functions)) { | |
| 4739 | + return; | |
| 4740 | + } | |
| 4485 | 4741 | |
| 4486 | 4742 | $functions[] = $integration_call; | 
| 4487 | 4743 |  	$modSettings[$hook] = implode(',', $functions); | 
| @@ -4504,12 +4760,14 @@ discard block | ||
| 4504 | 4760 | global $smcFunc, $modSettings; | 
| 4505 | 4761 | |
| 4506 | 4762 | // Any objects? | 
| 4507 | - if ($object) | |
| 4508 | - $function = $function . '#'; | |
| 4763 | +	if ($object) { | |
| 4764 | + $function = $function . '#'; | |
| 4765 | + } | |
| 4509 | 4766 | |
| 4510 | 4767 | // Any files to load? | 
| 4511 | - if (!empty($file) && is_string($file)) | |
| 4512 | - $function = $file . '|' . $function; | |
| 4768 | +	if (!empty($file) && is_string($file)) { | |
| 4769 | + $function = $file . '|' . $function; | |
| 4770 | + } | |
| 4513 | 4771 | |
| 4514 | 4772 | // Get the correct string. | 
| 4515 | 4773 | $integration_call = $function; | 
| @@ -4530,16 +4788,18 @@ discard block | ||
| 4530 | 4788 |  	{ | 
| 4531 | 4789 |  		$current_functions = explode(',', $current_functions); | 
| 4532 | 4790 | |
| 4533 | - if (in_array($integration_call, $current_functions)) | |
| 4534 | -			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); | |
| 4791 | +		if (in_array($integration_call, $current_functions)) { | |
| 4792 | +					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); | |
| 4793 | + } | |
| 4535 | 4794 | } | 
| 4536 | 4795 | |
| 4537 | 4796 | // Turn the function list into something usable. | 
| 4538 | 4797 |  	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); | 
| 4539 | 4798 | |
| 4540 | 4799 | // You can only remove it if it's available. | 
| 4541 | - if (!in_array($integration_call, $functions)) | |
| 4542 | - return; | |
| 4800 | +	if (!in_array($integration_call, $functions)) { | |
| 4801 | + return; | |
| 4802 | + } | |
| 4543 | 4803 | |
| 4544 | 4804 | $functions = array_diff($functions, array($integration_call)); | 
| 4545 | 4805 |  	$modSettings[$hook] = implode(',', $functions); | 
| @@ -4560,17 +4820,20 @@ discard block | ||
| 4560 | 4820 | global $context, $smcFunc, $txt, $db_show_debug; | 
| 4561 | 4821 | |
| 4562 | 4822 | // Really? | 
| 4563 | - if (empty($string)) | |
| 4564 | - return false; | |
| 4823 | +	if (empty($string)) { | |
| 4824 | + return false; | |
| 4825 | + } | |
| 4565 | 4826 | |
| 4566 | 4827 | // An array? should be a "callable" array IE array(object/class, valid_callable). | 
| 4567 | 4828 | // A closure? should be a callable one. | 
| 4568 | - if (is_array($string) || $string instanceof Closure) | |
| 4569 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); | |
| 4829 | +	if (is_array($string) || $string instanceof Closure) { | |
| 4830 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); | |
| 4831 | + } | |
| 4570 | 4832 | |
| 4571 | 4833 | // No full objects, sorry! pass a method or a property instead! | 
| 4572 | - if (is_object($string)) | |
| 4573 | - return false; | |
| 4834 | +	if (is_object($string)) { | |
| 4835 | + return false; | |
| 4836 | + } | |
| 4574 | 4837 | |
| 4575 | 4838 | // Stay vitaminized my friends... | 
| 4576 | 4839 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); | 
| @@ -4579,8 +4842,9 @@ discard block | ||
| 4579 | 4842 | $string = load_file($string); | 
| 4580 | 4843 | |
| 4581 | 4844 | // Loaded file failed | 
| 4582 | - if (empty($string)) | |
| 4583 | - return false; | |
| 4845 | +	if (empty($string)) { | |
| 4846 | + return false; | |
| 4847 | + } | |
| 4584 | 4848 | |
| 4585 | 4849 | // Found a method. | 
| 4586 | 4850 | if (strpos($string, '::') !== false) | 
| @@ -4601,8 +4865,9 @@ discard block | ||
| 4601 | 4865 | // Add another one to the list. | 
| 4602 | 4866 | if ($db_show_debug === true) | 
| 4603 | 4867 |  				{ | 
| 4604 | - if (!isset($context['debug']['instances'])) | |
| 4605 | - $context['debug']['instances'] = array(); | |
| 4868 | +					if (!isset($context['debug']['instances'])) { | |
| 4869 | + $context['debug']['instances'] = array(); | |
| 4870 | + } | |
| 4606 | 4871 | |
| 4607 | 4872 | $context['debug']['instances'][$class] = $class; | 
| 4608 | 4873 | } | 
| @@ -4612,13 +4877,15 @@ discard block | ||
| 4612 | 4877 | } | 
| 4613 | 4878 | |
| 4614 | 4879 | // Right then. This is a call to a static method. | 
| 4615 | - else | |
| 4616 | - $func = array($class, $method); | |
| 4880 | +		else { | |
| 4881 | + $func = array($class, $method); | |
| 4882 | + } | |
| 4617 | 4883 | } | 
| 4618 | 4884 | |
| 4619 | 4885 | // Nope! just a plain regular function. | 
| 4620 | - else | |
| 4621 | - $func = $string; | |
| 4886 | +	else { | |
| 4887 | + $func = $string; | |
| 4888 | + } | |
| 4622 | 4889 | |
| 4623 | 4890 | // Right, we got what we need, time to do some checks. | 
| 4624 | 4891 | if (!is_callable($func, false, $callable_name)) | 
| @@ -4634,17 +4901,18 @@ discard block | ||
| 4634 | 4901 | else | 
| 4635 | 4902 |  	{ | 
| 4636 | 4903 | // What are we gonna do about it? | 
| 4637 | - if ($return) | |
| 4638 | - return $func; | |
| 4904 | +		if ($return) { | |
| 4905 | + return $func; | |
| 4906 | + } | |
| 4639 | 4907 | |
| 4640 | 4908 | // If this is a plain function, avoid the heat of calling call_user_func(). | 
| 4641 | 4909 | else | 
| 4642 | 4910 |  		{ | 
| 4643 | - if (is_array($func)) | |
| 4644 | - call_user_func($func); | |
| 4645 | - | |
| 4646 | - else | |
| 4647 | - $func(); | |
| 4911 | +			if (is_array($func)) { | |
| 4912 | + call_user_func($func); | |
| 4913 | +			} else { | |
| 4914 | + $func(); | |
| 4915 | + } | |
| 4648 | 4916 | } | 
| 4649 | 4917 | } | 
| 4650 | 4918 | } | 
| @@ -4661,31 +4929,34 @@ discard block | ||
| 4661 | 4929 |  { | 
| 4662 | 4930 | global $sourcedir, $txt, $boarddir, $settings; | 
| 4663 | 4931 | |
| 4664 | - if (empty($string)) | |
| 4665 | - return false; | |
| 4932 | +	if (empty($string)) { | |
| 4933 | + return false; | |
| 4934 | + } | |
| 4666 | 4935 | |
| 4667 | 4936 | if (strpos($string, '|') !== false) | 
| 4668 | 4937 |  	{ | 
| 4669 | 4938 |  		list ($file, $string) = explode('|', $string); | 
| 4670 | 4939 | |
| 4671 | 4940 | // Match the wildcards to their regular vars. | 
| 4672 | - if (empty($settings['theme_dir'])) | |
| 4673 | -			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); | |
| 4674 | - | |
| 4675 | - else | |
| 4676 | -			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); | |
| 4941 | +		if (empty($settings['theme_dir'])) { | |
| 4942 | +					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); | |
| 4943 | +		} else { | |
| 4944 | +					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); | |
| 4945 | + } | |
| 4677 | 4946 | |
| 4678 | 4947 | // Load the file if it can be loaded. | 
| 4679 | - if (file_exists($absPath)) | |
| 4680 | - require_once($absPath); | |
| 4948 | +		if (file_exists($absPath)) { | |
| 4949 | + require_once($absPath); | |
| 4950 | + } | |
| 4681 | 4951 | |
| 4682 | 4952 | // No? try a fallback to $sourcedir | 
| 4683 | 4953 | else | 
| 4684 | 4954 |  		{ | 
| 4685 | 4955 | $absPath = $sourcedir .'/'. $file; | 
| 4686 | 4956 | |
| 4687 | - if (file_exists($absPath)) | |
| 4688 | - require_once($absPath); | |
| 4957 | +			if (file_exists($absPath)) { | |
| 4958 | + require_once($absPath); | |
| 4959 | + } | |
| 4689 | 4960 | |
| 4690 | 4961 | // Sorry, can't do much for you at this point. | 
| 4691 | 4962 | else | 
| @@ -4712,8 +4983,9 @@ discard block | ||
| 4712 | 4983 | global $user_info, $smcFunc; | 
| 4713 | 4984 | |
| 4714 | 4985 | // Make sure we have something to work with. | 
| 4715 | - if (empty($topic)) | |
| 4716 | - return array(); | |
| 4986 | +	if (empty($topic)) { | |
| 4987 | + return array(); | |
| 4988 | + } | |
| 4717 | 4989 | |
| 4718 | 4990 | |
| 4719 | 4991 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. | 
| @@ -4736,8 +5008,9 @@ discard block | ||
| 4736 | 5008 | 'topic' => $topic, | 
| 4737 | 5009 | ) | 
| 4738 | 5010 | ); | 
| 4739 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 4740 | - $temp[] = (int) $row['content_id']; | |
| 5011 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 5012 | + $temp[] = (int) $row['content_id']; | |
| 5013 | + } | |
| 4741 | 5014 | |
| 4742 | 5015 | cache_put_data($cache_key, $temp, $ttl); | 
| 4743 | 5016 | } | 
| @@ -4758,8 +5031,9 @@ discard block | ||
| 4758 | 5031 |  { | 
| 4759 | 5032 | global $context; | 
| 4760 | 5033 | |
| 4761 | - if (empty($string)) | |
| 4762 | - return $string; | |
| 5034 | +	if (empty($string)) { | |
| 5035 | + return $string; | |
| 5036 | + } | |
| 4763 | 5037 | |
| 4764 | 5038 | // UTF-8 occurences of MS special characters | 
| 4765 | 5039 | $findchars_utf8 = array( | 
| @@ -4800,10 +5074,11 @@ discard block | ||
| 4800 | 5074 | '--', // — | 
| 4801 | 5075 | ); | 
| 4802 | 5076 | |
| 4803 | - if ($context['utf8']) | |
| 4804 | - $string = str_replace($findchars_utf8, $replacechars, $string); | |
| 4805 | - else | |
| 4806 | - $string = str_replace($findchars_iso, $replacechars, $string); | |
| 5077 | +	if ($context['utf8']) { | |
| 5078 | + $string = str_replace($findchars_utf8, $replacechars, $string); | |
| 5079 | +	} else { | |
| 5080 | + $string = str_replace($findchars_iso, $replacechars, $string); | |
| 5081 | + } | |
| 4807 | 5082 | |
| 4808 | 5083 | return $string; | 
| 4809 | 5084 | } | 
| @@ -4822,49 +5097,59 @@ discard block | ||
| 4822 | 5097 |  { | 
| 4823 | 5098 | global $context; | 
| 4824 | 5099 | |
| 4825 | - if (!isset($matches[2])) | |
| 4826 | - return ''; | |
| 5100 | +	if (!isset($matches[2])) { | |
| 5101 | + return ''; | |
| 5102 | + } | |
| 4827 | 5103 | |
| 4828 | 5104 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; | 
| 4829 | 5105 | |
| 4830 | 5106 | // remove left to right / right to left overrides | 
| 4831 | - if ($num === 0x202D || $num === 0x202E) | |
| 4832 | - return ''; | |
| 5107 | +	if ($num === 0x202D || $num === 0x202E) { | |
| 5108 | + return ''; | |
| 5109 | + } | |
| 4833 | 5110 | |
| 4834 | 5111 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced | 
| 4835 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) | |
| 4836 | - return '&#' . $num . ';'; | |
| 5112 | +	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { | |
| 5113 | + return '&#' . $num . ';'; | |
| 5114 | + } | |
| 4837 | 5115 | |
| 4838 | 5116 | if (empty($context['utf8'])) | 
| 4839 | 5117 |  	{ | 
| 4840 | 5118 | // no control characters | 
| 4841 | - if ($num < 0x20) | |
| 4842 | - return ''; | |
| 5119 | +		if ($num < 0x20) { | |
| 5120 | + return ''; | |
| 5121 | + } | |
| 4843 | 5122 | // text is text | 
| 4844 | - elseif ($num < 0x80) | |
| 4845 | - return chr($num); | |
| 5123 | +		elseif ($num < 0x80) { | |
| 5124 | + return chr($num); | |
| 5125 | + } | |
| 4846 | 5126 | // all others get html-ised | 
| 4847 | - else | |
| 4848 | - return '&#' . $matches[2] . ';'; | |
| 4849 | - } | |
| 4850 | - else | |
| 5127 | +		else { | |
| 5128 | + return '&#' . $matches[2] . ';'; | |
| 5129 | + } | |
| 5130 | + } else | |
| 4851 | 5131 |  	{ | 
| 4852 | 5132 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set | 
| 4853 | 5133 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) | 
| 4854 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) | |
| 4855 | - return ''; | |
| 5134 | +		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { | |
| 5135 | + return ''; | |
| 5136 | + } | |
| 4856 | 5137 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation | 
| 4857 | - elseif ($num < 0x80) | |
| 4858 | - return chr($num); | |
| 5138 | +		elseif ($num < 0x80) { | |
| 5139 | + return chr($num); | |
| 5140 | + } | |
| 4859 | 5141 | // <0x800 (2048) | 
| 4860 | - elseif ($num < 0x800) | |
| 4861 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); | |
| 5142 | +		elseif ($num < 0x800) { | |
| 5143 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); | |
| 5144 | + } | |
| 4862 | 5145 | // < 0x10000 (65536) | 
| 4863 | - elseif ($num < 0x10000) | |
| 4864 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5146 | +		elseif ($num < 0x10000) { | |
| 5147 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5148 | + } | |
| 4865 | 5149 | // <= 0x10FFFF (1114111) | 
| 4866 | - else | |
| 4867 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5150 | +		else { | |
| 5151 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5152 | + } | |
| 4868 | 5153 | } | 
| 4869 | 5154 | } | 
| 4870 | 5155 | |
| @@ -4880,28 +5165,34 @@ discard block | ||
| 4880 | 5165 | */ | 
| 4881 | 5166 | function fixchar__callback($matches) | 
| 4882 | 5167 |  { | 
| 4883 | - if (!isset($matches[1])) | |
| 4884 | - return ''; | |
| 5168 | +	if (!isset($matches[1])) { | |
| 5169 | + return ''; | |
| 5170 | + } | |
| 4885 | 5171 | |
| 4886 | 5172 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; | 
| 4887 | 5173 | |
| 4888 | 5174 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set | 
| 4889 | 5175 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides | 
| 4890 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) | |
| 4891 | - return ''; | |
| 5176 | +	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { | |
| 5177 | + return ''; | |
| 5178 | + } | |
| 4892 | 5179 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation | 
| 4893 | - elseif ($num < 0x80) | |
| 4894 | - return chr($num); | |
| 5180 | +	elseif ($num < 0x80) { | |
| 5181 | + return chr($num); | |
| 5182 | + } | |
| 4895 | 5183 | // <0x800 (2048) | 
| 4896 | - elseif ($num < 0x800) | |
| 4897 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); | |
| 5184 | +	elseif ($num < 0x800) { | |
| 5185 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); | |
| 5186 | + } | |
| 4898 | 5187 | // < 0x10000 (65536) | 
| 4899 | - elseif ($num < 0x10000) | |
| 4900 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5188 | +	elseif ($num < 0x10000) { | |
| 5189 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5190 | + } | |
| 4901 | 5191 | // <= 0x10FFFF (1114111) | 
| 4902 | - else | |
| 4903 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 4904 | -} | |
| 5192 | +	else { | |
| 5193 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); | |
| 5194 | + } | |
| 5195 | + } | |
| 4905 | 5196 | |
| 4906 | 5197 | /** | 
| 4907 | 5198 | * Strips out invalid html entities, replaces others with html style { codes | 
| @@ -4914,17 +5205,19 @@ discard block | ||
| 4914 | 5205 | */ | 
| 4915 | 5206 | function entity_fix__callback($matches) | 
| 4916 | 5207 |  { | 
| 4917 | - if (!isset($matches[2])) | |
| 4918 | - return ''; | |
| 5208 | +	if (!isset($matches[2])) { | |
| 5209 | + return ''; | |
| 5210 | + } | |
| 4919 | 5211 | |
| 4920 | 5212 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; | 
| 4921 | 5213 | |
| 4922 | 5214 | // we don't allow control characters, characters out of range, byte markers, etc | 
| 4923 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) | |
| 4924 | - return ''; | |
| 4925 | - else | |
| 4926 | - return '&#' . $num . ';'; | |
| 4927 | -} | |
| 5215 | +	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { | |
| 5216 | + return ''; | |
| 5217 | +	} else { | |
| 5218 | + return '&#' . $num . ';'; | |
| 5219 | + } | |
| 5220 | + } | |
| 4928 | 5221 | |
| 4929 | 5222 | /** | 
| 4930 | 5223 | * Return a Gravatar URL based on | 
| @@ -4948,18 +5241,23 @@ discard block | ||
| 4948 | 5241 |  		$ratings = array('G', 'PG', 'R', 'X'); | 
| 4949 | 5242 |  		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); | 
| 4950 | 5243 | $url_params = array(); | 
| 4951 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) | |
| 4952 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; | |
| 4953 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) | |
| 4954 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; | |
| 4955 | - if (!empty($modSettings['avatar_max_width_external'])) | |
| 4956 | - $size_string = (int) $modSettings['avatar_max_width_external']; | |
| 4957 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) | |
| 4958 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) | |
| 5244 | +		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { | |
| 5245 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; | |
| 5246 | + } | |
| 5247 | +		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { | |
| 5248 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; | |
| 5249 | + } | |
| 5250 | +		if (!empty($modSettings['avatar_max_width_external'])) { | |
| 5251 | + $size_string = (int) $modSettings['avatar_max_width_external']; | |
| 5252 | + } | |
| 5253 | +		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { | |
| 5254 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) | |
| 4959 | 5255 | $size_string = $modSettings['avatar_max_height_external']; | 
| 5256 | + } | |
| 4960 | 5257 | |
| 4961 | - if (!empty($size_string)) | |
| 4962 | - $url_params[] = 's=' . $size_string; | |
| 5258 | +		if (!empty($size_string)) { | |
| 5259 | + $url_params[] = 's=' . $size_string; | |
| 5260 | + } | |
| 4963 | 5261 | } | 
| 4964 | 5262 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; | 
| 4965 | 5263 | |
| @@ -4978,22 +5276,26 @@ discard block | ||
| 4978 | 5276 | static $timezones = null, $lastwhen = null; | 
| 4979 | 5277 | |
| 4980 | 5278 | // No point doing this over if we already did it once | 
| 4981 | - if (!empty($timezones) && $when == $lastwhen) | |
| 4982 | - return $timezones; | |
| 4983 | - else | |
| 4984 | - $lastwhen = $when; | |
| 5279 | +	if (!empty($timezones) && $when == $lastwhen) { | |
| 5280 | + return $timezones; | |
| 5281 | +	} else { | |
| 5282 | + $lastwhen = $when; | |
| 5283 | + } | |
| 4985 | 5284 | |
| 4986 | 5285 | // Parseable datetime string? | 
| 4987 | - if (is_int($timestamp = strtotime($when))) | |
| 4988 | - $when = $timestamp; | |
| 5286 | +	if (is_int($timestamp = strtotime($when))) { | |
| 5287 | + $when = $timestamp; | |
| 5288 | + } | |
| 4989 | 5289 | |
| 4990 | 5290 | // A Unix timestamp? | 
| 4991 | - elseif (is_numeric($when)) | |
| 4992 | - $when = intval($when); | |
| 5291 | +	elseif (is_numeric($when)) { | |
| 5292 | + $when = intval($when); | |
| 5293 | + } | |
| 4993 | 5294 | |
| 4994 | 5295 | // Invalid value? Just get current Unix timestamp. | 
| 4995 | - else | |
| 4996 | - $when = time(); | |
| 5296 | +	else { | |
| 5297 | + $when = time(); | |
| 5298 | + } | |
| 4997 | 5299 | |
| 4998 | 5300 | // We'll need these too | 
| 4999 | 5301 |  	$date_when = date_create('@' . $when); | 
| @@ -5057,8 +5359,9 @@ discard block | ||
| 5057 | 5359 | foreach ($priority_countries as $country) | 
| 5058 | 5360 |  	{ | 
| 5059 | 5361 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); | 
| 5060 | - if (!empty($country_tzids)) | |
| 5061 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); | |
| 5362 | +		if (!empty($country_tzids)) { | |
| 5363 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); | |
| 5364 | + } | |
| 5062 | 5365 | } | 
| 5063 | 5366 | |
| 5064 | 5367 | // Process the preferred timezones first, then the rest. | 
| @@ -5068,8 +5371,9 @@ discard block | ||
| 5068 | 5371 | foreach ($tzids as $tzid) | 
| 5069 | 5372 |  	{ | 
| 5070 | 5373 | // We don't want UTC right now | 
| 5071 | - if ($tzid == 'UTC') | |
| 5072 | - continue; | |
| 5374 | +		if ($tzid == 'UTC') { | |
| 5375 | + continue; | |
| 5376 | + } | |
| 5073 | 5377 | |
| 5074 | 5378 | $tz = timezone_open($tzid); | 
| 5075 | 5379 | |
| @@ -5084,12 +5388,14 @@ discard block | ||
| 5084 | 5388 | $tzgeo = timezone_location_get($tz); | 
| 5085 | 5389 | |
| 5086 | 5390 | // Don't overwrite our preferred tzids | 
| 5087 | - if (empty($zones[$tzkey]['tzid'])) | |
| 5088 | - $zones[$tzkey]['tzid'] = $tzid; | |
| 5391 | +		if (empty($zones[$tzkey]['tzid'])) { | |
| 5392 | + $zones[$tzkey]['tzid'] = $tzid; | |
| 5393 | + } | |
| 5089 | 5394 | |
| 5090 | 5395 | // A time zone from a prioritized country? | 
| 5091 | - if (in_array($tzid, $priority_tzids)) | |
| 5092 | - $priority_zones[$tzkey] = true; | |
| 5396 | +		if (in_array($tzid, $priority_tzids)) { | |
| 5397 | + $priority_zones[$tzkey] = true; | |
| 5398 | + } | |
| 5093 | 5399 | |
| 5094 | 5400 | // Keep track of the location and offset for this tzid | 
| 5095 | 5401 |  		$tzid_parts = explode('/', $tzid); | 
| @@ -5111,15 +5417,17 @@ discard block | ||
| 5111 | 5417 | |
| 5112 | 5418 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); | 
| 5113 | 5419 | |
| 5114 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) | |
| 5115 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; | |
| 5116 | - else | |
| 5117 | -			$desc = implode(', ', array_unique($tzvalue['locations'])); | |
| 5420 | +		if (!empty($timezone_descriptions[$tzvalue['tzid']])) { | |
| 5421 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; | |
| 5422 | +		} else { | |
| 5423 | +					$desc = implode(', ', array_unique($tzvalue['locations'])); | |
| 5424 | + } | |
| 5118 | 5425 | |
| 5119 | - if (isset($priority_zones[$tzkey])) | |
| 5120 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; | |
| 5121 | - else | |
| 5122 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; | |
| 5426 | +		if (isset($priority_zones[$tzkey])) { | |
| 5427 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; | |
| 5428 | +		} else { | |
| 5429 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; | |
| 5430 | + } | |
| 5123 | 5431 | } | 
| 5124 | 5432 | |
| 5125 | 5433 | $timezones = array_merge( | 
| @@ -5173,9 +5481,9 @@ discard block | ||
| 5173 | 5481 | 'Indian/Kerguelen' => 'TFT', | 
| 5174 | 5482 | ); | 
| 5175 | 5483 | |
| 5176 | - if (!empty($missing_tz_abbrs[$tzid])) | |
| 5177 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; | |
| 5178 | - else | |
| 5484 | +		if (!empty($missing_tz_abbrs[$tzid])) { | |
| 5485 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; | |
| 5486 | + } else | |
| 5179 | 5487 |  		{ | 
| 5180 | 5488 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow | 
| 5181 | 5489 | $tz_location = timezone_location_get(timezone_open($tzid)); | 
| @@ -5203,8 +5511,9 @@ discard block | ||
| 5203 | 5511 | */ | 
| 5204 | 5512 | function inet_ptod($ip_address) | 
| 5205 | 5513 |  { | 
| 5206 | - if (!isValidIP($ip_address)) | |
| 5207 | - return $ip_address; | |
| 5514 | +	if (!isValidIP($ip_address)) { | |
| 5515 | + return $ip_address; | |
| 5516 | + } | |
| 5208 | 5517 | |
| 5209 | 5518 | $bin = inet_pton($ip_address); | 
| 5210 | 5519 | return $bin; | 
| @@ -5216,13 +5525,15 @@ discard block | ||
| 5216 | 5525 | */ | 
| 5217 | 5526 | function inet_dtop($bin) | 
| 5218 | 5527 |  { | 
| 5219 | - if(empty($bin)) | |
| 5220 | - return ''; | |
| 5528 | +	if(empty($bin)) { | |
| 5529 | + return ''; | |
| 5530 | + } | |
| 5221 | 5531 | |
| 5222 | 5532 | global $db_type; | 
| 5223 | 5533 | |
| 5224 | - if ($db_type == 'postgresql') | |
| 5225 | - return $bin; | |
| 5534 | +	if ($db_type == 'postgresql') { | |
| 5535 | + return $bin; | |
| 5536 | + } | |
| 5226 | 5537 | |
| 5227 | 5538 | $ip_address = inet_ntop($bin); | 
| 5228 | 5539 | |
| @@ -5247,26 +5558,32 @@ discard block | ||
| 5247 | 5558 | */ | 
| 5248 | 5559 | function _safe_serialize($value) | 
| 5249 | 5560 |  { | 
| 5250 | - if(is_null($value)) | |
| 5251 | - return 'N;'; | |
| 5561 | +	if(is_null($value)) { | |
| 5562 | + return 'N;'; | |
| 5563 | + } | |
| 5252 | 5564 | |
| 5253 | - if(is_bool($value)) | |
| 5254 | - return 'b:'. (int) $value .';'; | |
| 5565 | +	if(is_bool($value)) { | |
| 5566 | + return 'b:'. (int) $value .';'; | |
| 5567 | + } | |
| 5255 | 5568 | |
| 5256 | - if(is_int($value)) | |
| 5257 | - return 'i:'. $value .';'; | |
| 5569 | +	if(is_int($value)) { | |
| 5570 | + return 'i:'. $value .';'; | |
| 5571 | + } | |
| 5258 | 5572 | |
| 5259 | - if(is_float($value)) | |
| 5260 | -		return 'd:'. str_replace(',', '.', $value) .';'; | |
| 5573 | +	if(is_float($value)) { | |
| 5574 | +			return 'd:'. str_replace(',', '.', $value) .';'; | |
| 5575 | + } | |
| 5261 | 5576 | |
| 5262 | - if(is_string($value)) | |
| 5263 | - return 's:'. strlen($value) .':"'. $value .'";'; | |
| 5577 | +	if(is_string($value)) { | |
| 5578 | + return 's:'. strlen($value) .':"'. $value .'";'; | |
| 5579 | + } | |
| 5264 | 5580 | |
| 5265 | 5581 | if(is_array($value)) | 
| 5266 | 5582 |  	{ | 
| 5267 | 5583 | $out = ''; | 
| 5268 | - foreach($value as $k => $v) | |
| 5269 | - $out .= _safe_serialize($k) . _safe_serialize($v); | |
| 5584 | +		foreach($value as $k => $v) { | |
| 5585 | + $out .= _safe_serialize($k) . _safe_serialize($v); | |
| 5586 | + } | |
| 5270 | 5587 | |
| 5271 | 5588 |  		return 'a:'. count($value) .':{'. $out .'}'; | 
| 5272 | 5589 | } | 
| @@ -5292,8 +5609,9 @@ discard block | ||
| 5292 | 5609 | |
| 5293 | 5610 | $out = _safe_serialize($value); | 
| 5294 | 5611 | |
| 5295 | - if (isset($mbIntEnc)) | |
| 5296 | - mb_internal_encoding($mbIntEnc); | |
| 5612 | +	if (isset($mbIntEnc)) { | |
| 5613 | + mb_internal_encoding($mbIntEnc); | |
| 5614 | + } | |
| 5297 | 5615 | |
| 5298 | 5616 | return $out; | 
| 5299 | 5617 | } | 
| @@ -5310,8 +5628,9 @@ discard block | ||
| 5310 | 5628 | function _safe_unserialize($str) | 
| 5311 | 5629 |  { | 
| 5312 | 5630 | // Input is not a string. | 
| 5313 | - if(empty($str) || !is_string($str)) | |
| 5314 | - return false; | |
| 5631 | +	if(empty($str) || !is_string($str)) { | |
| 5632 | + return false; | |
| 5633 | + } | |
| 5315 | 5634 | |
| 5316 | 5635 | $stack = array(); | 
| 5317 | 5636 | $expected = array(); | 
| @@ -5327,43 +5646,38 @@ discard block | ||
| 5327 | 5646 | while($state != 1) | 
| 5328 | 5647 |  	{ | 
| 5329 | 5648 | $type = isset($str[0]) ? $str[0] : ''; | 
| 5330 | - if($type == '}') | |
| 5331 | - $str = substr($str, 1); | |
| 5332 | - | |
| 5333 | - else if($type == 'N' && $str[1] == ';') | |
| 5649 | +		if($type == '}') { | |
| 5650 | + $str = substr($str, 1); | |
| 5651 | + } else if($type == 'N' && $str[1] == ';') | |
| 5334 | 5652 |  		{ | 
| 5335 | 5653 | $value = null; | 
| 5336 | 5654 | $str = substr($str, 2); | 
| 5337 | - } | |
| 5338 | -		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) | |
| 5655 | +		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) | |
| 5339 | 5656 |  		{ | 
| 5340 | 5657 | $value = $matches[1] == '1' ? true : false; | 
| 5341 | 5658 | $str = substr($str, 4); | 
| 5342 | - } | |
| 5343 | -		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) | |
| 5659 | +		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) | |
| 5344 | 5660 |  		{ | 
| 5345 | 5661 | $value = (int)$matches[1]; | 
| 5346 | 5662 | $str = $matches[2]; | 
| 5347 | - } | |
| 5348 | -		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) | |
| 5663 | +		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) | |
| 5349 | 5664 |  		{ | 
| 5350 | 5665 | $value = (float)$matches[1]; | 
| 5351 | 5666 | $str = $matches[3]; | 
| 5352 | - } | |
| 5353 | -		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') | |
| 5667 | +		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') | |
| 5354 | 5668 |  		{ | 
| 5355 | 5669 | $value = substr($matches[2], 0, (int)$matches[1]); | 
| 5356 | 5670 | $str = substr($matches[2], (int)$matches[1] + 2); | 
| 5357 | - } | |
| 5358 | -		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) | |
| 5671 | +		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) | |
| 5359 | 5672 |  		{ | 
| 5360 | 5673 | $expectedLength = (int)$matches[1]; | 
| 5361 | 5674 | $str = $matches[2]; | 
| 5362 | 5675 | } | 
| 5363 | 5676 | |
| 5364 | 5677 | // Object or unknown/malformed type. | 
| 5365 | - else | |
| 5366 | - return false; | |
| 5678 | +		else { | |
| 5679 | + return false; | |
| 5680 | + } | |
| 5367 | 5681 | |
| 5368 | 5682 | switch($state) | 
| 5369 | 5683 |  		{ | 
| @@ -5391,8 +5705,9 @@ discard block | ||
| 5391 | 5705 | if($type == '}') | 
| 5392 | 5706 |  				{ | 
| 5393 | 5707 | // Array size is less than expected. | 
| 5394 | - if(count($list) < end($expected)) | |
| 5395 | - return false; | |
| 5708 | +					if(count($list) < end($expected)) { | |
| 5709 | + return false; | |
| 5710 | + } | |
| 5396 | 5711 | |
| 5397 | 5712 | unset($list); | 
| 5398 | 5713 | $list = &$stack[count($stack)-1]; | 
| @@ -5401,8 +5716,9 @@ discard block | ||
| 5401 | 5716 | // Go to terminal state if we're at the end of the root array. | 
| 5402 | 5717 | array_pop($expected); | 
| 5403 | 5718 | |
| 5404 | - if(count($expected) == 0) | |
| 5405 | - $state = 1; | |
| 5719 | +					if(count($expected) == 0) { | |
| 5720 | + $state = 1; | |
| 5721 | + } | |
| 5406 | 5722 | |
| 5407 | 5723 | break; | 
| 5408 | 5724 | } | 
| @@ -5410,8 +5726,9 @@ discard block | ||
| 5410 | 5726 | if($type == 'i' || $type == 's') | 
| 5411 | 5727 |  				{ | 
| 5412 | 5728 | // Array size exceeds expected length. | 
| 5413 | - if(count($list) >= end($expected)) | |
| 5414 | - return false; | |
| 5729 | +					if(count($list) >= end($expected)) { | |
| 5730 | + return false; | |
| 5731 | + } | |
| 5415 | 5732 | |
| 5416 | 5733 | $key = $value; | 
| 5417 | 5734 | $state = 3; | 
| @@ -5445,8 +5762,9 @@ discard block | ||
| 5445 | 5762 | } | 
| 5446 | 5763 | |
| 5447 | 5764 | // Trailing data in input. | 
| 5448 | - if(!empty($str)) | |
| 5449 | - return false; | |
| 5765 | +	if(!empty($str)) { | |
| 5766 | + return false; | |
| 5767 | + } | |
| 5450 | 5768 | |
| 5451 | 5769 | return $data; | 
| 5452 | 5770 | } | 
| @@ -5469,8 +5787,9 @@ discard block | ||
| 5469 | 5787 | |
| 5470 | 5788 | $out = _safe_unserialize($str); | 
| 5471 | 5789 | |
| 5472 | - if (isset($mbIntEnc)) | |
| 5473 | - mb_internal_encoding($mbIntEnc); | |
| 5790 | +	if (isset($mbIntEnc)) { | |
| 5791 | + mb_internal_encoding($mbIntEnc); | |
| 5792 | + } | |
| 5474 | 5793 | |
| 5475 | 5794 | return $out; | 
| 5476 | 5795 | } | 
| @@ -5485,12 +5804,14 @@ discard block | ||
| 5485 | 5804 | function smf_chmod($file, $value = 0) | 
| 5486 | 5805 |  { | 
| 5487 | 5806 | // No file? no checks! | 
| 5488 | - if (empty($file)) | |
| 5489 | - return false; | |
| 5807 | +	if (empty($file)) { | |
| 5808 | + return false; | |
| 5809 | + } | |
| 5490 | 5810 | |
| 5491 | 5811 | // Already writable? | 
| 5492 | - if (is_writable($file)) | |
| 5493 | - return true; | |
| 5812 | +	if (is_writable($file)) { | |
| 5813 | + return true; | |
| 5814 | + } | |
| 5494 | 5815 | |
| 5495 | 5816 | // Do we have a file or a dir? | 
| 5496 | 5817 | $isDir = is_dir($file); | 
| @@ -5506,10 +5827,9 @@ discard block | ||
| 5506 | 5827 |  		{ | 
| 5507 | 5828 | $isWritable = true; | 
| 5508 | 5829 | break; | 
| 5830 | +		} else { | |
| 5831 | + @chmod($file, $val); | |
| 5509 | 5832 | } | 
| 5510 | - | |
| 5511 | - else | |
| 5512 | - @chmod($file, $val); | |
| 5513 | 5833 | } | 
| 5514 | 5834 | |
| 5515 | 5835 | return $isWritable; | 
| @@ -5528,8 +5848,9 @@ discard block | ||
| 5528 | 5848 | global $txt; | 
| 5529 | 5849 | |
| 5530 | 5850 | // Come on... | 
| 5531 | - if (empty($json) || !is_string($json)) | |
| 5532 | - return array(); | |
| 5851 | +	if (empty($json) || !is_string($json)) { | |
| 5852 | + return array(); | |
| 5853 | + } | |
| 5533 | 5854 | |
| 5534 | 5855 | $returnArray = @json_decode($json, $returnAsArray); | 
| 5535 | 5856 | |
| @@ -5567,11 +5888,11 @@ discard block | ||
| 5567 | 5888 | $jsonDebug = $jsonDebug[0]; | 
| 5568 | 5889 |  		loadLanguage('Errors'); | 
| 5569 | 5890 | |
| 5570 | - if (!empty($jsonDebug)) | |
| 5571 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); | |
| 5572 | - | |
| 5573 | - else | |
| 5574 | - log_error($txt['json_'. $jsonError], 'critical'); | |
| 5891 | +		if (!empty($jsonDebug)) { | |
| 5892 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); | |
| 5893 | +		} else { | |
| 5894 | + log_error($txt['json_'. $jsonError], 'critical'); | |
| 5895 | + } | |
| 5575 | 5896 | |
| 5576 | 5897 | // Everyone expects an array. | 
| 5577 | 5898 | return array(); | 
| @@ -5601,8 +5922,9 @@ discard block | ||
| 5601 | 5922 | global $db_show_debug, $modSettings; | 
| 5602 | 5923 | |
| 5603 | 5924 | // Defensive programming anyone? | 
| 5604 | - if (empty($data)) | |
| 5605 | - return false; | |
| 5925 | +	if (empty($data)) { | |
| 5926 | + return false; | |
| 5927 | + } | |
| 5606 | 5928 | |
| 5607 | 5929 | // Don't need extra stuff... | 
| 5608 | 5930 | $db_show_debug = false; | 
| @@ -5610,11 +5932,11 @@ discard block | ||
| 5610 | 5932 | // Kill anything else. | 
| 5611 | 5933 | ob_end_clean(); | 
| 5612 | 5934 | |
| 5613 | - if (!empty($modSettings['CompressedOutput'])) | |
| 5614 | -		@ob_start('ob_gzhandler'); | |
| 5615 | - | |
| 5616 | - else | |
| 5617 | - ob_start(); | |
| 5935 | +	if (!empty($modSettings['CompressedOutput'])) { | |
| 5936 | +			@ob_start('ob_gzhandler'); | |
| 5937 | +	} else { | |
| 5938 | + ob_start(); | |
| 5939 | + } | |
| 5618 | 5940 | |
| 5619 | 5941 | // Set the header. | 
| 5620 | 5942 | header($type); | 
| @@ -5646,8 +5968,9 @@ discard block | ||
| 5646 | 5968 | static $done = false; | 
| 5647 | 5969 | |
| 5648 | 5970 | // If we don't need to do anything, don't | 
| 5649 | - if (!$update && $done) | |
| 5650 | - return; | |
| 5971 | +	if (!$update && $done) { | |
| 5972 | + return; | |
| 5973 | + } | |
| 5651 | 5974 | |
| 5652 | 5975 | // Should we get a new copy of the official list of TLDs? | 
| 5653 | 5976 | if ($update) | 
| @@ -5656,8 +5979,9 @@ discard block | ||
| 5656 | 5979 |  		$tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt'); | 
| 5657 | 5980 | |
| 5658 | 5981 | // If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored. | 
| 5659 | - if ($tlds === false) | |
| 5660 | - $postapocalypticNightmare = true; | |
| 5982 | +		if ($tlds === false) { | |
| 5983 | + $postapocalypticNightmare = true; | |
| 5984 | + } | |
| 5661 | 5985 | } | 
| 5662 | 5986 | // If we aren't updating and the regex is valid, we're done | 
| 5663 | 5987 |  	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) | 
| @@ -5672,10 +5996,11 @@ discard block | ||
| 5672 | 5996 | // Clean $tlds and convert it to an array | 
| 5673 | 5997 |  		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { | 
| 5674 | 5998 | $line = trim($line); | 
| 5675 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) | |
| 5676 | - return false; | |
| 5677 | - else | |
| 5678 | - return true; | |
| 5999 | +			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { | |
| 6000 | + return false; | |
| 6001 | +			} else { | |
| 6002 | + return true; | |
| 6003 | + } | |
| 5679 | 6004 | }); | 
| 5680 | 6005 | |
| 5681 | 6006 | // Convert Punycode to Unicode | 
| @@ -5729,8 +6054,9 @@ discard block | ||
| 5729 | 6054 | $idx += $digit * $w; | 
| 5730 | 6055 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); | 
| 5731 | 6056 | |
| 5732 | - if ($digit < $t) | |
| 5733 | - break; | |
| 6057 | +						if ($digit < $t) { | |
| 6058 | + break; | |
| 6059 | + } | |
| 5734 | 6060 | |
| 5735 | 6061 | $w = (int) ($w * ($base - $t)); | 
| 5736 | 6062 | } | 
| @@ -5739,8 +6065,9 @@ discard block | ||
| 5739 | 6065 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); | 
| 5740 | 6066 | $delta += intval($delta / ($deco_len + 1)); | 
| 5741 | 6067 | |
| 5742 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) | |
| 5743 | - $delta = intval($delta / ($base - $tmin)); | |
| 6068 | +					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { | |
| 6069 | + $delta = intval($delta / ($base - $tmin)); | |
| 6070 | + } | |
| 5744 | 6071 | |
| 5745 | 6072 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); | 
| 5746 | 6073 | $is_first = false; | 
| @@ -5749,8 +6076,9 @@ discard block | ||
| 5749 | 6076 | |
| 5750 | 6077 | if ($deco_len > 0) | 
| 5751 | 6078 |  					{ | 
| 5752 | - for ($i = $deco_len; $i > $idx; $i--) | |
| 5753 | - $decoded[$i] = $decoded[($i - 1)]; | |
| 6079 | +						for ($i = $deco_len; $i > $idx; $i--) { | |
| 6080 | + $decoded[$i] = $decoded[($i - 1)]; | |
| 6081 | + } | |
| 5754 | 6082 | } | 
| 5755 | 6083 | $decoded[$idx++] = $char; | 
| 5756 | 6084 | } | 
| @@ -5758,24 +6086,29 @@ discard block | ||
| 5758 | 6086 | foreach ($decoded as $k => $v) | 
| 5759 | 6087 |  				{ | 
| 5760 | 6088 | // 7bit are transferred literally | 
| 5761 | - if ($v < 128) | |
| 5762 | - $output .= chr($v); | |
| 6089 | +					if ($v < 128) { | |
| 6090 | + $output .= chr($v); | |
| 6091 | + } | |
| 5763 | 6092 | |
| 5764 | 6093 | // 2 bytes | 
| 5765 | - elseif ($v < (1 << 11)) | |
| 5766 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); | |
| 6094 | +					elseif ($v < (1 << 11)) { | |
| 6095 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); | |
| 6096 | + } | |
| 5767 | 6097 | |
| 5768 | 6098 | // 3 bytes | 
| 5769 | - elseif ($v < (1 << 16)) | |
| 5770 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); | |
| 6099 | +					elseif ($v < (1 << 16)) { | |
| 6100 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); | |
| 6101 | + } | |
| 5771 | 6102 | |
| 5772 | 6103 | // 4 bytes | 
| 5773 | - elseif ($v < (1 << 21)) | |
| 5774 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); | |
| 6104 | +					elseif ($v < (1 << 21)) { | |
| 6105 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); | |
| 6106 | + } | |
| 5775 | 6107 | |
| 5776 | 6108 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k | 
| 5777 | - else | |
| 5778 | - $output .= $safe_char; | |
| 6109 | +					else { | |
| 6110 | + $output .= $safe_char; | |
| 6111 | + } | |
| 5779 | 6112 | } | 
| 5780 | 6113 | |
| 5781 | 6114 | $output_parts[] = $output; | 
| @@ -5869,8 +6202,7 @@ discard block | ||
| 5869 | 6202 | |
| 5870 | 6203 | $strlen = 'mb_strlen'; | 
| 5871 | 6204 | $substr = 'mb_substr'; | 
| 5872 | - } | |
| 5873 | - else | |
| 6205 | + } else | |
| 5874 | 6206 |  	{ | 
| 5875 | 6207 | $strlen = $smcFunc['strlen']; | 
| 5876 | 6208 | $substr = $smcFunc['substr']; | 
| @@ -5884,20 +6216,21 @@ discard block | ||
| 5884 | 6216 | |
| 5885 | 6217 | $first = $substr($string, 0, 1); | 
| 5886 | 6218 | |
| 5887 | - if (empty($index[$first])) | |
| 5888 | - $index[$first] = array(); | |
| 6219 | +		if (empty($index[$first])) { | |
| 6220 | + $index[$first] = array(); | |
| 6221 | + } | |
| 5889 | 6222 | |
| 5890 | 6223 | if ($strlen($string) > 1) | 
| 5891 | 6224 |  		{ | 
| 5892 | 6225 | // Sanity check on recursion | 
| 5893 | - if ($depth > 99) | |
| 5894 | - $index[$first][$substr($string, 1)] = ''; | |
| 5895 | - | |
| 5896 | - else | |
| 5897 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); | |
| 6226 | +			if ($depth > 99) { | |
| 6227 | + $index[$first][$substr($string, 1)] = ''; | |
| 6228 | +			} else { | |
| 6229 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); | |
| 6230 | + } | |
| 6231 | +		} else { | |
| 6232 | + $index[$first][''] = ''; | |
| 5898 | 6233 | } | 
| 5899 | - else | |
| 5900 | - $index[$first][''] = ''; | |
| 5901 | 6234 | |
| 5902 | 6235 | $depth--; | 
| 5903 | 6236 | return $index; | 
| @@ -5920,9 +6253,9 @@ discard block | ||
| 5920 | 6253 | $key_regex = preg_quote($key, $delim); | 
| 5921 | 6254 | $new_key = $key; | 
| 5922 | 6255 | |
| 5923 | - if (empty($value)) | |
| 5924 | - $sub_regex = ''; | |
| 5925 | - else | |
| 6256 | +			if (empty($value)) { | |
| 6257 | + $sub_regex = ''; | |
| 6258 | + } else | |
| 5926 | 6259 |  			{ | 
| 5927 | 6260 | $sub_regex = $index_to_regex($value, $delim); | 
| 5928 | 6261 | |
| @@ -5930,22 +6263,22 @@ discard block | ||
| 5930 | 6263 |  				{ | 
| 5931 | 6264 |  					$new_key_array = explode('(?'.'>', $sub_regex); | 
| 5932 | 6265 | $new_key .= $new_key_array[0]; | 
| 6266 | +				} else { | |
| 6267 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; | |
| 5933 | 6268 | } | 
| 5934 | - else | |
| 5935 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; | |
| 5936 | 6269 | } | 
| 5937 | 6270 | |
| 5938 | - if ($depth > 1) | |
| 5939 | - $regex[$new_key] = $key_regex . $sub_regex; | |
| 5940 | - else | |
| 6271 | +			if ($depth > 1) { | |
| 6272 | + $regex[$new_key] = $key_regex . $sub_regex; | |
| 6273 | + } else | |
| 5941 | 6274 |  			{ | 
| 5942 | 6275 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) | 
| 5943 | 6276 |  				{ | 
| 5944 | 6277 | $regex[$new_key] = $key_regex . $sub_regex; | 
| 5945 | 6278 | unset($index[$key]); | 
| 6279 | +				} else { | |
| 6280 | + break; | |
| 5946 | 6281 | } | 
| 5947 | - else | |
| 5948 | - break; | |
| 5949 | 6282 | } | 
| 5950 | 6283 | } | 
| 5951 | 6284 | |
| @@ -5954,10 +6287,11 @@ discard block | ||
| 5954 | 6287 | $l1 = $strlen($k1); | 
| 5955 | 6288 | $l2 = $strlen($k2); | 
| 5956 | 6289 | |
| 5957 | - if ($l1 == $l2) | |
| 5958 | - return strcmp($k1, $k2) > 0 ? 1 : -1; | |
| 5959 | - else | |
| 5960 | - return $l1 > $l2 ? -1 : 1; | |
| 6290 | +			if ($l1 == $l2) { | |
| 6291 | + return strcmp($k1, $k2) > 0 ? 1 : -1; | |
| 6292 | +			} else { | |
| 6293 | + return $l1 > $l2 ? -1 : 1; | |
| 6294 | + } | |
| 5961 | 6295 | }); | 
| 5962 | 6296 | |
| 5963 | 6297 | $depth--; | 
| @@ -5968,15 +6302,18 @@ discard block | ||
| 5968 | 6302 | $index = array(); | 
| 5969 | 6303 | $regexes = array(); | 
| 5970 | 6304 | |
| 5971 | - foreach ($strings as $string) | |
| 5972 | - $index = $add_string_to_index($string, $index); | |
| 6305 | +	foreach ($strings as $string) { | |
| 6306 | + $index = $add_string_to_index($string, $index); | |
| 6307 | + } | |
| 5973 | 6308 | |
| 5974 | - while (!empty($index)) | |
| 5975 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; | |
| 6309 | +	while (!empty($index)) { | |
| 6310 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; | |
| 6311 | + } | |
| 5976 | 6312 | |
| 5977 | 6313 | // Restore PHP's internal character encoding to whatever it was originally | 
| 5978 | - if (!empty($current_encoding)) | |
| 5979 | - mb_internal_encoding($current_encoding); | |
| 6314 | +	if (!empty($current_encoding)) { | |
| 6315 | + mb_internal_encoding($current_encoding); | |
| 6316 | + } | |
| 5980 | 6317 | |
| 5981 | 6318 | return $regexes; | 
| 5982 | 6319 | } |