@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 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]; |
@@ -721,17 +752,20 @@ discard block |
||
| 721 | 752 | static $non_twelve_hour; |
| 722 | 753 | |
| 723 | 754 | // Offset the time. |
| 724 | - if (!$offset_type) |
|
| 725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 755 | + if (!$offset_type) { |
|
| 756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 757 | + } |
|
| 726 | 758 | // Just the forum offset? |
| 727 | - elseif ($offset_type == 'forum') |
|
| 728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 729 | - else |
|
| 730 | - $time = $log_time; |
|
| 759 | + elseif ($offset_type == 'forum') { |
|
| 760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 761 | + } else { |
|
| 762 | + $time = $log_time; |
|
| 763 | + } |
|
| 731 | 764 | |
| 732 | 765 | // We can't have a negative date (on Windows, at least.) |
| 733 | - if ($log_time < 0) |
|
| 734 | - $log_time = 0; |
|
| 766 | + if ($log_time < 0) { |
|
| 767 | + $log_time = 0; |
|
| 768 | + } |
|
| 735 | 769 | |
| 736 | 770 | // Today and Yesterday? |
| 737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
| 748 | 782 | { |
| 749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 785 | + } else { |
|
| 786 | + $today_fmt = '%H:%M' . $s; |
|
| 751 | 787 | } |
| 752 | - else |
|
| 753 | - $today_fmt = '%H:%M' . $s; |
|
| 754 | 788 | |
| 755 | 789 | // Same day of the year, same year.... Today! |
| 756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 792 | + } |
|
| 758 | 793 | |
| 759 | 794 | // 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... |
| 760 | - 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)) |
|
| 761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 795 | + 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)) { |
|
| 796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 797 | + } |
|
| 762 | 798 | } |
| 763 | 799 | |
| 764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 765 | 801 | |
| 766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
| 767 | 803 | { |
| 768 | - if (!isset($non_twelve_hour)) |
|
| 769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 804 | + if (!isset($non_twelve_hour)) { |
|
| 805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 806 | + } |
|
| 807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 809 | + } |
|
| 772 | 810 | |
| 773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 774 | - if (strpos($str, $token) !== false) |
|
| 811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 812 | + if (strpos($str, $token) !== false) |
|
| 775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
| 776 | - } |
|
| 777 | - else |
|
| 814 | + } |
|
| 815 | + } else |
|
| 778 | 816 | { |
| 779 | 817 | // Do-it-yourself time localization. Fun. |
| 780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 781 | - if (strpos($str, $token) !== false) |
|
| 818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 819 | + if (strpos($str, $token) !== false) |
|
| 782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 821 | + } |
|
| 783 | 822 | |
| 784 | - if (strpos($str, '%p') !== false) |
|
| 785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 823 | + if (strpos($str, '%p') !== false) { |
|
| 824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 825 | + } |
|
| 786 | 826 | } |
| 787 | 827 | |
| 788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
| 789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
| 790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
| 830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 831 | + } |
|
| 791 | 832 | |
| 792 | 833 | // Format any other characters.. |
| 793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
| 809 | 850 | static $translation = array(); |
| 810 | 851 | |
| 811 | 852 | // Determine the character set... Default to UTF-8 |
| 812 | - if (empty($context['character_set'])) |
|
| 813 | - $charset = 'UTF-8'; |
|
| 853 | + if (empty($context['character_set'])) { |
|
| 854 | + $charset = 'UTF-8'; |
|
| 855 | + } |
|
| 814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 816 | - $charset = 'ISO-8859-1'; |
|
| 817 | - else |
|
| 818 | - $charset = $context['character_set']; |
|
| 857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 858 | + $charset = 'ISO-8859-1'; |
|
| 859 | + } else { |
|
| 860 | + $charset = $context['character_set']; |
|
| 861 | + } |
|
| 819 | 862 | |
| 820 | - if (empty($translation)) |
|
| 821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 863 | + if (empty($translation)) { |
|
| 864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 865 | + } |
|
| 822 | 866 | |
| 823 | 867 | return strtr($string, $translation); |
| 824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
| 840 | 884 | global $smcFunc; |
| 841 | 885 | |
| 842 | 886 | // It was already short enough! |
| 843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 844 | - return $subject; |
|
| 887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 888 | + return $subject; |
|
| 889 | + } |
|
| 845 | 890 | |
| 846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
| 860 | 905 | { |
| 861 | 906 | global $user_info, $modSettings; |
| 862 | 907 | |
| 863 | - if ($timestamp === null) |
|
| 864 | - $timestamp = time(); |
|
| 865 | - elseif ($timestamp == 0) |
|
| 866 | - return 0; |
|
| 908 | + if ($timestamp === null) { |
|
| 909 | + $timestamp = time(); |
|
| 910 | + } elseif ($timestamp == 0) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 867 | 913 | |
| 868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
| 892 | 938 | $array[$i] = $array[$j]; |
| 893 | 939 | $array[$j] = $temp; |
| 894 | 940 | |
| 895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 896 | - $p[$i] = 1; |
|
| 941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 942 | + $p[$i] = 1; |
|
| 943 | + } |
|
| 897 | 944 | |
| 898 | 945 | $orders[] = $array; |
| 899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
| 925 | 972 | static $disabled; |
| 926 | 973 | |
| 927 | 974 | // Don't waste cycles |
| 928 | - if ($message === '') |
|
| 929 | - return ''; |
|
| 975 | + if ($message === '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 930 | 978 | |
| 931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 932 | - if (!isset($context['utf8'])) |
|
| 933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 980 | + if (!isset($context['utf8'])) { |
|
| 981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 982 | + } |
|
| 934 | 983 | |
| 935 | 984 | // Clean up any cut/paste issues we may have |
| 936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
| 942 | 991 | return $message; |
| 943 | 992 | } |
| 944 | 993 | |
| 945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 946 | - $smileys = (bool) $smileys; |
|
| 994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 995 | + $smileys = (bool) $smileys; |
|
| 996 | + } |
|
| 947 | 997 | |
| 948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 949 | 999 | { |
| 950 | - if ($smileys === true) |
|
| 951 | - parsesmileys($message); |
|
| 1000 | + if ($smileys === true) { |
|
| 1001 | + parsesmileys($message); |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $message; |
| 954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
| 961 | 1012 | } |
| 962 | 1013 | |
| 963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 965 | - set_tld_regex(); |
|
| 1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1016 | + set_tld_regex(); |
|
| 1017 | + } |
|
| 966 | 1018 | |
| 967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
| 968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
| 976 | 1028 | |
| 977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 978 | 1030 | |
| 979 | - foreach ($temp as $tag) |
|
| 980 | - $disabled[trim($tag)] = true; |
|
| 1031 | + foreach ($temp as $tag) { |
|
| 1032 | + $disabled[trim($tag)] = true; |
|
| 1033 | + } |
|
| 981 | 1034 | } |
| 982 | 1035 | |
| 983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 984 | - $disabled['flash'] = true; |
|
| 1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1037 | + $disabled['flash'] = true; |
|
| 1038 | + } |
|
| 985 | 1039 | |
| 986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
| 987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
| 1102 | 1156 | $returnContext = ''; |
| 1103 | 1157 | |
| 1104 | 1158 | // BBC or the entire attachments feature is disabled |
| 1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1106 | - return $data; |
|
| 1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1160 | + return $data; |
|
| 1161 | + } |
|
| 1107 | 1162 | |
| 1108 | 1163 | // Save the attach ID. |
| 1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
| 1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
| 1115 | 1170 | |
| 1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1117 | - if (is_string($currentAttachment)) |
|
| 1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1172 | + if (is_string($currentAttachment)) { |
|
| 1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1174 | + } |
|
| 1119 | 1175 | |
| 1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
| 1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
| 1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1132 | 1188 | } |
| 1133 | 1189 | |
| 1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1135 | - $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>'; |
|
| 1136 | - else |
|
| 1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1191 | + $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>'; |
|
| 1192 | + } else { |
|
| 1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1194 | + } |
|
| 1138 | 1195 | } |
| 1139 | 1196 | |
| 1140 | 1197 | // No image. Show a link. |
| 1141 | - else |
|
| 1142 | - $returnContext .= $currentAttachment['link']; |
|
| 1198 | + else { |
|
| 1199 | + $returnContext .= $currentAttachment['link']; |
|
| 1200 | + } |
|
| 1143 | 1201 | |
| 1144 | 1202 | // Gotta append what we just did. |
| 1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
| 1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1171 | 1229 | { |
| 1172 | 1230 | // Do PHP code coloring? |
| 1173 | - if ($php_parts[$php_i] != '<?php') |
|
| 1174 | - continue; |
|
| 1231 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1232 | + continue; |
|
| 1233 | + } |
|
| 1175 | 1234 | |
| 1176 | 1235 | $php_string = ''; |
| 1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1188 | 1247 | |
| 1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1190 | - if ($context['browser']['is_opera']) |
|
| 1191 | - $data .= ' '; |
|
| 1249 | + if ($context['browser']['is_opera']) { |
|
| 1250 | + $data .= ' '; |
|
| 1251 | + } |
|
| 1192 | 1252 | } |
| 1193 | 1253 | }, |
| 1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
| 1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1208 | 1268 | { |
| 1209 | 1269 | // Do PHP code coloring? |
| 1210 | - if ($php_parts[$php_i] != '<?php') |
|
| 1211 | - continue; |
|
| 1270 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1212 | 1273 | |
| 1213 | 1274 | $php_string = ''; |
| 1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
| 1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1225 | 1286 | |
| 1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1227 | - if ($context['browser']['is_opera']) |
|
| 1228 | - $data[0] .= ' '; |
|
| 1288 | + if ($context['browser']['is_opera']) { |
|
| 1289 | + $data[0] .= ' '; |
|
| 1290 | + } |
|
| 1229 | 1291 | } |
| 1230 | 1292 | }, |
| 1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
| 1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
| 1265 | 1327 | { |
| 1266 | - if (isset($disabled['url'])) |
|
| 1267 | - $tag['content'] = '$1'; |
|
| 1328 | + if (isset($disabled['url'])) { |
|
| 1329 | + $tag['content'] = '$1'; |
|
| 1330 | + } |
|
| 1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1269 | - if (empty($scheme)) |
|
| 1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1332 | + if (empty($scheme)) { |
|
| 1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1334 | + } |
|
| 1271 | 1335 | }, |
| 1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
| 1273 | 1337 | ), |
@@ -1281,10 +1345,11 @@ discard block |
||
| 1281 | 1345 | { |
| 1282 | 1346 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
| 1283 | 1347 | |
| 1284 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
| 1285 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1286 | - else |
|
| 1287 | - $css = ''; |
|
| 1348 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
| 1349 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1350 | + } else { |
|
| 1351 | + $css = ''; |
|
| 1352 | + } |
|
| 1288 | 1353 | |
| 1289 | 1354 | $data = $class . $css; |
| 1290 | 1355 | }, |
@@ -1334,14 +1399,16 @@ discard block |
||
| 1334 | 1399 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1335 | 1400 | if ($image_proxy_enabled) |
| 1336 | 1401 | { |
| 1337 | - if (empty($scheme)) |
|
| 1338 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1402 | + if (empty($scheme)) { |
|
| 1403 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1404 | + } |
|
| 1339 | 1405 | |
| 1340 | - if ($scheme != 'https') |
|
| 1341 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1406 | + if ($scheme != 'https') { |
|
| 1407 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1408 | + } |
|
| 1409 | + } elseif (empty($scheme)) { |
|
| 1410 | + $data = '//' . ltrim($data, ':/'); |
|
| 1342 | 1411 | } |
| 1343 | - elseif (empty($scheme)) |
|
| 1344 | - $data = '//' . ltrim($data, ':/'); |
|
| 1345 | 1412 | }, |
| 1346 | 1413 | 'disabled_content' => '($1)', |
| 1347 | 1414 | ), |
@@ -1357,14 +1424,16 @@ discard block |
||
| 1357 | 1424 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1358 | 1425 | if ($image_proxy_enabled) |
| 1359 | 1426 | { |
| 1360 | - if (empty($scheme)) |
|
| 1361 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1427 | + if (empty($scheme)) { |
|
| 1428 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1429 | + } |
|
| 1362 | 1430 | |
| 1363 | - if ($scheme != 'https') |
|
| 1364 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1431 | + if ($scheme != 'https') { |
|
| 1432 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1433 | + } |
|
| 1434 | + } elseif (empty($scheme)) { |
|
| 1435 | + $data = '//' . ltrim($data, ':/'); |
|
| 1365 | 1436 | } |
| 1366 | - elseif (empty($scheme)) |
|
| 1367 | - $data = '//' . ltrim($data, ':/'); |
|
| 1368 | 1437 | }, |
| 1369 | 1438 | 'disabled_content' => '($1)', |
| 1370 | 1439 | ), |
@@ -1376,8 +1445,9 @@ discard block |
||
| 1376 | 1445 | { |
| 1377 | 1446 | $data = strtr($data, array('<br>' => '')); |
| 1378 | 1447 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1379 | - if (empty($scheme)) |
|
| 1380 | - $data = '//' . ltrim($data, ':/'); |
|
| 1448 | + if (empty($scheme)) { |
|
| 1449 | + $data = '//' . ltrim($data, ':/'); |
|
| 1450 | + } |
|
| 1381 | 1451 | }, |
| 1382 | 1452 | ), |
| 1383 | 1453 | array( |
@@ -1388,13 +1458,14 @@ discard block |
||
| 1388 | 1458 | 'after' => '</a>', |
| 1389 | 1459 | 'validate' => function (&$tag, &$data, $disabled) |
| 1390 | 1460 | { |
| 1391 | - if (substr($data, 0, 1) == '#') |
|
| 1392 | - $data = '#post_' . substr($data, 1); |
|
| 1393 | - else |
|
| 1461 | + if (substr($data, 0, 1) == '#') { |
|
| 1462 | + $data = '#post_' . substr($data, 1); |
|
| 1463 | + } else |
|
| 1394 | 1464 | { |
| 1395 | 1465 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1396 | - if (empty($scheme)) |
|
| 1397 | - $data = '//' . ltrim($data, ':/'); |
|
| 1466 | + if (empty($scheme)) { |
|
| 1467 | + $data = '//' . ltrim($data, ':/'); |
|
| 1468 | + } |
|
| 1398 | 1469 | } |
| 1399 | 1470 | }, |
| 1400 | 1471 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1472,8 +1543,9 @@ discard block |
||
| 1472 | 1543 | { |
| 1473 | 1544 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1474 | 1545 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1475 | - if ($add_begin) |
|
| 1476 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1546 | + if ($add_begin) { |
|
| 1547 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1548 | + } |
|
| 1477 | 1549 | } |
| 1478 | 1550 | }, |
| 1479 | 1551 | 'block_level' => false, |
@@ -1604,10 +1676,11 @@ discard block |
||
| 1604 | 1676 | 'content' => '$1', |
| 1605 | 1677 | 'validate' => function (&$tag, &$data, $disabled) |
| 1606 | 1678 | { |
| 1607 | - if (is_numeric($data)) |
|
| 1608 | - $data = timeformat($data); |
|
| 1609 | - else |
|
| 1610 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1679 | + if (is_numeric($data)) { |
|
| 1680 | + $data = timeformat($data); |
|
| 1681 | + } else { |
|
| 1682 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1683 | + } |
|
| 1611 | 1684 | }, |
| 1612 | 1685 | ), |
| 1613 | 1686 | array( |
@@ -1634,8 +1707,9 @@ discard block |
||
| 1634 | 1707 | { |
| 1635 | 1708 | $data = strtr($data, array('<br>' => '')); |
| 1636 | 1709 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1637 | - if (empty($scheme)) |
|
| 1638 | - $data = '//' . ltrim($data, ':/'); |
|
| 1710 | + if (empty($scheme)) { |
|
| 1711 | + $data = '//' . ltrim($data, ':/'); |
|
| 1712 | + } |
|
| 1639 | 1713 | }, |
| 1640 | 1714 | ), |
| 1641 | 1715 | array( |
@@ -1647,8 +1721,9 @@ discard block |
||
| 1647 | 1721 | 'validate' => function (&$tag, &$data, $disabled) |
| 1648 | 1722 | { |
| 1649 | 1723 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1650 | - if (empty($scheme)) |
|
| 1651 | - $data = '//' . ltrim($data, ':/'); |
|
| 1724 | + if (empty($scheme)) { |
|
| 1725 | + $data = '//' . ltrim($data, ':/'); |
|
| 1726 | + } |
|
| 1652 | 1727 | }, |
| 1653 | 1728 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1654 | 1729 | 'disabled_after' => ' ($1)', |
@@ -1668,8 +1743,9 @@ discard block |
||
| 1668 | 1743 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1669 | 1744 | if ($message === false) |
| 1670 | 1745 | { |
| 1671 | - if (isset($temp_bbc)) |
|
| 1672 | - $bbc_codes = $temp_bbc; |
|
| 1746 | + if (isset($temp_bbc)) { |
|
| 1747 | + $bbc_codes = $temp_bbc; |
|
| 1748 | + } |
|
| 1673 | 1749 | usort($codes, function ($a, $b) { |
| 1674 | 1750 | return strcmp($a['tag'], $b['tag']); |
| 1675 | 1751 | }); |
@@ -1689,8 +1765,9 @@ discard block |
||
| 1689 | 1765 | ); |
| 1690 | 1766 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1691 | 1767 | { |
| 1692 | - foreach ($itemcodes as $c => $dummy) |
|
| 1693 | - $bbc_codes[$c] = array(); |
|
| 1768 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1769 | + $bbc_codes[$c] = array(); |
|
| 1770 | + } |
|
| 1694 | 1771 | } |
| 1695 | 1772 | |
| 1696 | 1773 | // Shhhh! |
@@ -1711,12 +1788,14 @@ discard block |
||
| 1711 | 1788 | foreach ($codes as $code) |
| 1712 | 1789 | { |
| 1713 | 1790 | // Make it easier to process parameters later |
| 1714 | - if (!empty($code['parameters'])) |
|
| 1715 | - ksort($code['parameters'], SORT_STRING); |
|
| 1791 | + if (!empty($code['parameters'])) { |
|
| 1792 | + ksort($code['parameters'], SORT_STRING); |
|
| 1793 | + } |
|
| 1716 | 1794 | |
| 1717 | 1795 | // If we are not doing every tag only do ones we are interested in. |
| 1718 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1719 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1796 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1797 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1798 | + } |
|
| 1720 | 1799 | } |
| 1721 | 1800 | $codes = null; |
| 1722 | 1801 | } |
@@ -1727,8 +1806,9 @@ discard block |
||
| 1727 | 1806 | // It's likely this will change if the message is modified. |
| 1728 | 1807 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
| 1729 | 1808 | |
| 1730 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1731 | - return $temp; |
|
| 1809 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1810 | + return $temp; |
|
| 1811 | + } |
|
| 1732 | 1812 | |
| 1733 | 1813 | $cache_t = microtime(); |
| 1734 | 1814 | } |
@@ -1760,8 +1840,9 @@ discard block |
||
| 1760 | 1840 | $disabled['flash'] = true; |
| 1761 | 1841 | |
| 1762 | 1842 | // @todo Change maybe? |
| 1763 | - if (!isset($_GET['images'])) |
|
| 1764 | - $disabled['img'] = true; |
|
| 1843 | + if (!isset($_GET['images'])) { |
|
| 1844 | + $disabled['img'] = true; |
|
| 1845 | + } |
|
| 1765 | 1846 | |
| 1766 | 1847 | // @todo Interface/setting to add more? |
| 1767 | 1848 | } |
@@ -1785,8 +1866,9 @@ discard block |
||
| 1785 | 1866 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1786 | 1867 | |
| 1787 | 1868 | // Failsafe. |
| 1788 | - if ($pos === false || $last_pos > $pos) |
|
| 1789 | - $pos = strlen($message) + 1; |
|
| 1869 | + if ($pos === false || $last_pos > $pos) { |
|
| 1870 | + $pos = strlen($message) + 1; |
|
| 1871 | + } |
|
| 1790 | 1872 | |
| 1791 | 1873 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1792 | 1874 | if ($last_pos < $pos - 1) |
@@ -1805,8 +1887,9 @@ discard block |
||
| 1805 | 1887 | |
| 1806 | 1888 | // <br> should be empty. |
| 1807 | 1889 | $empty_tags = array('br', 'hr'); |
| 1808 | - foreach ($empty_tags as $tag) |
|
| 1809 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1890 | + foreach ($empty_tags as $tag) { |
|
| 1891 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1892 | + } |
|
| 1810 | 1893 | |
| 1811 | 1894 | // b, u, i, s, pre... basic tags. |
| 1812 | 1895 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1815,8 +1898,9 @@ discard block |
||
| 1815 | 1898 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1816 | 1899 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1817 | 1900 | |
| 1818 | - if ($diff > 0) |
|
| 1819 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1901 | + if ($diff > 0) { |
|
| 1902 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1903 | + } |
|
| 1820 | 1904 | } |
| 1821 | 1905 | |
| 1822 | 1906 | // Do <img ...> - with security... action= -> action-. |
@@ -1829,8 +1913,9 @@ discard block |
||
| 1829 | 1913 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1830 | 1914 | |
| 1831 | 1915 | // Remove action= from the URL - no funny business, now. |
| 1832 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1833 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1916 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 1917 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1918 | + } |
|
| 1834 | 1919 | |
| 1835 | 1920 | // Check if the image is larger than allowed. |
| 1836 | 1921 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1851,9 +1936,9 @@ discard block |
||
| 1851 | 1936 | |
| 1852 | 1937 | // Set the new image tag. |
| 1853 | 1938 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 1939 | + } else { |
|
| 1940 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1854 | 1941 | } |
| 1855 | - else |
|
| 1856 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1857 | 1942 | } |
| 1858 | 1943 | |
| 1859 | 1944 | $data = strtr($data, $replaces); |
@@ -1866,16 +1951,18 @@ discard block |
||
| 1866 | 1951 | $no_autolink_area = false; |
| 1867 | 1952 | if (!empty($open_tags)) |
| 1868 | 1953 | { |
| 1869 | - foreach ($open_tags as $open_tag) |
|
| 1870 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1954 | + foreach ($open_tags as $open_tag) { |
|
| 1955 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1871 | 1956 | $no_autolink_area = true; |
| 1957 | + } |
|
| 1872 | 1958 | } |
| 1873 | 1959 | |
| 1874 | 1960 | // Don't go backwards. |
| 1875 | 1961 | // @todo Don't think is the real solution.... |
| 1876 | 1962 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1877 | - if ($pos < $lastAutoPos) |
|
| 1878 | - $no_autolink_area = true; |
|
| 1963 | + if ($pos < $lastAutoPos) { |
|
| 1964 | + $no_autolink_area = true; |
|
| 1965 | + } |
|
| 1879 | 1966 | $lastAutoPos = $pos; |
| 1880 | 1967 | |
| 1881 | 1968 | if (!$no_autolink_area) |
@@ -1984,17 +2071,19 @@ discard block |
||
| 1984 | 2071 | if ($scheme == 'mailto') |
| 1985 | 2072 | { |
| 1986 | 2073 | $email_address = str_replace('mailto:', '', $url); |
| 1987 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 1988 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 1989 | - else |
|
| 1990 | - return $url; |
|
| 2074 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2075 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2076 | + } else { |
|
| 2077 | + return $url; |
|
| 2078 | + } |
|
| 1991 | 2079 | } |
| 1992 | 2080 | |
| 1993 | 2081 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 1994 | - if (empty($scheme)) |
|
| 1995 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 1996 | - else |
|
| 1997 | - $fullUrl = $url; |
|
| 2082 | + if (empty($scheme)) { |
|
| 2083 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2084 | + } else { |
|
| 2085 | + $fullUrl = $url; |
|
| 2086 | + } |
|
| 1998 | 2087 | |
| 1999 | 2088 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 2000 | 2089 | }, $data); |
@@ -2043,16 +2132,18 @@ discard block |
||
| 2043 | 2132 | } |
| 2044 | 2133 | |
| 2045 | 2134 | // Are we there yet? Are we there yet? |
| 2046 | - if ($pos >= strlen($message) - 1) |
|
| 2047 | - break; |
|
| 2135 | + if ($pos >= strlen($message) - 1) { |
|
| 2136 | + break; |
|
| 2137 | + } |
|
| 2048 | 2138 | |
| 2049 | 2139 | $tags = strtolower($message[$pos + 1]); |
| 2050 | 2140 | |
| 2051 | 2141 | if ($tags == '/' && !empty($open_tags)) |
| 2052 | 2142 | { |
| 2053 | 2143 | $pos2 = strpos($message, ']', $pos + 1); |
| 2054 | - if ($pos2 == $pos + 2) |
|
| 2055 | - continue; |
|
| 2144 | + if ($pos2 == $pos + 2) { |
|
| 2145 | + continue; |
|
| 2146 | + } |
|
| 2056 | 2147 | |
| 2057 | 2148 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2058 | 2149 | |
@@ -2062,8 +2153,9 @@ discard block |
||
| 2062 | 2153 | do |
| 2063 | 2154 | { |
| 2064 | 2155 | $tag = array_pop($open_tags); |
| 2065 | - if (!$tag) |
|
| 2066 | - break; |
|
| 2156 | + if (!$tag) { |
|
| 2157 | + break; |
|
| 2158 | + } |
|
| 2067 | 2159 | |
| 2068 | 2160 | if (!empty($tag['block_level'])) |
| 2069 | 2161 | { |
@@ -2077,10 +2169,11 @@ discard block |
||
| 2077 | 2169 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2078 | 2170 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2079 | 2171 | { |
| 2080 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2081 | - if ($temp['tag'] == $look_for) |
|
| 2172 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2173 | + if ($temp['tag'] == $look_for) |
|
| 2082 | 2174 | { |
| 2083 | 2175 | $block_level = !empty($temp['block_level']); |
| 2176 | + } |
|
| 2084 | 2177 | break; |
| 2085 | 2178 | } |
| 2086 | 2179 | } |
@@ -2102,15 +2195,15 @@ discard block |
||
| 2102 | 2195 | { |
| 2103 | 2196 | $open_tags = $to_close; |
| 2104 | 2197 | continue; |
| 2105 | - } |
|
| 2106 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2198 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2107 | 2199 | { |
| 2108 | 2200 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2109 | 2201 | { |
| 2110 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2111 | - if ($temp['tag'] == $look_for) |
|
| 2202 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2203 | + if ($temp['tag'] == $look_for) |
|
| 2112 | 2204 | { |
| 2113 | 2205 | $block_level = !empty($temp['block_level']); |
| 2206 | + } |
|
| 2114 | 2207 | break; |
| 2115 | 2208 | } |
| 2116 | 2209 | } |
@@ -2118,8 +2211,9 @@ discard block |
||
| 2118 | 2211 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2119 | 2212 | if (!$block_level) |
| 2120 | 2213 | { |
| 2121 | - foreach ($to_close as $tag) |
|
| 2122 | - array_push($open_tags, $tag); |
|
| 2214 | + foreach ($to_close as $tag) { |
|
| 2215 | + array_push($open_tags, $tag); |
|
| 2216 | + } |
|
| 2123 | 2217 | continue; |
| 2124 | 2218 | } |
| 2125 | 2219 | } |
@@ -2132,14 +2226,17 @@ discard block |
||
| 2132 | 2226 | |
| 2133 | 2227 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2134 | 2228 | $whitespace_regex = ''; |
| 2135 | - if (!empty($tag['block_level'])) |
|
| 2136 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2229 | + if (!empty($tag['block_level'])) { |
|
| 2230 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2231 | + } |
|
| 2137 | 2232 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
| 2138 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2139 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2233 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2234 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2235 | + } |
|
| 2140 | 2236 | |
| 2141 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2142 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2237 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2238 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2239 | + } |
|
| 2143 | 2240 | } |
| 2144 | 2241 | |
| 2145 | 2242 | if (!empty($to_close)) |
@@ -2152,8 +2249,9 @@ discard block |
||
| 2152 | 2249 | } |
| 2153 | 2250 | |
| 2154 | 2251 | // No tags for this character, so just keep going (fastest possible course.) |
| 2155 | - if (!isset($bbc_codes[$tags])) |
|
| 2156 | - continue; |
|
| 2252 | + if (!isset($bbc_codes[$tags])) { |
|
| 2253 | + continue; |
|
| 2254 | + } |
|
| 2157 | 2255 | |
| 2158 | 2256 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2159 | 2257 | $tag = null; |
@@ -2162,44 +2260,52 @@ discard block |
||
| 2162 | 2260 | $pt_strlen = strlen($possible['tag']); |
| 2163 | 2261 | |
| 2164 | 2262 | // Not a match? |
| 2165 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2166 | - continue; |
|
| 2263 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2264 | + continue; |
|
| 2265 | + } |
|
| 2167 | 2266 | |
| 2168 | 2267 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2169 | 2268 | |
| 2170 | 2269 | // A test validation? |
| 2171 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2172 | - continue; |
|
| 2270 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2271 | + continue; |
|
| 2272 | + } |
|
| 2173 | 2273 | // Do we want parameters? |
| 2174 | 2274 | elseif (!empty($possible['parameters'])) |
| 2175 | 2275 | { |
| 2176 | - if ($next_c != ' ') |
|
| 2177 | - continue; |
|
| 2178 | - } |
|
| 2179 | - elseif (isset($possible['type'])) |
|
| 2276 | + if ($next_c != ' ') { |
|
| 2277 | + continue; |
|
| 2278 | + } |
|
| 2279 | + } elseif (isset($possible['type'])) |
|
| 2180 | 2280 | { |
| 2181 | 2281 | // Do we need an equal sign? |
| 2182 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2183 | - continue; |
|
| 2282 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2283 | + continue; |
|
| 2284 | + } |
|
| 2184 | 2285 | // Maybe we just want a /... |
| 2185 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2186 | - continue; |
|
| 2286 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2287 | + continue; |
|
| 2288 | + } |
|
| 2187 | 2289 | // An immediate ]? |
| 2188 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2189 | - continue; |
|
| 2290 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2291 | + continue; |
|
| 2292 | + } |
|
| 2190 | 2293 | } |
| 2191 | 2294 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2192 | - elseif ($next_c != ']') |
|
| 2193 | - continue; |
|
| 2295 | + elseif ($next_c != ']') { |
|
| 2296 | + continue; |
|
| 2297 | + } |
|
| 2194 | 2298 | |
| 2195 | 2299 | // Check allowed tree? |
| 2196 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2197 | - continue; |
|
| 2198 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2199 | - continue; |
|
| 2300 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2301 | + continue; |
|
| 2302 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2303 | + continue; |
|
| 2304 | + } |
|
| 2200 | 2305 | // If this is in the list of disallowed child tags, don't parse it. |
| 2201 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2202 | - continue; |
|
| 2306 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2307 | + continue; |
|
| 2308 | + } |
|
| 2203 | 2309 | |
| 2204 | 2310 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2205 | 2311 | |
@@ -2211,8 +2317,9 @@ discard block |
||
| 2211 | 2317 | foreach ($open_tags as $open_quote) |
| 2212 | 2318 | { |
| 2213 | 2319 | // Every parent quote this quote has flips the styling |
| 2214 | - if ($open_quote['tag'] == 'quote') |
|
| 2215 | - $quote_alt = !$quote_alt; |
|
| 2320 | + if ($open_quote['tag'] == 'quote') { |
|
| 2321 | + $quote_alt = !$quote_alt; |
|
| 2322 | + } |
|
| 2216 | 2323 | } |
| 2217 | 2324 | // Add a class to the quote to style alternating blockquotes |
| 2218 | 2325 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2223,8 +2330,9 @@ discard block |
||
| 2223 | 2330 | { |
| 2224 | 2331 | // Build a regular expression for each parameter for the current tag. |
| 2225 | 2332 | $preg = array(); |
| 2226 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2227 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2333 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2334 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2335 | + } |
|
| 2228 | 2336 | |
| 2229 | 2337 | // Extract the string that potentially holds our parameters. |
| 2230 | 2338 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2244,24 +2352,27 @@ discard block |
||
| 2244 | 2352 | |
| 2245 | 2353 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2246 | 2354 | |
| 2247 | - if ($match) |
|
| 2248 | - $blob_counter = count($blobs) + 1; |
|
| 2355 | + if ($match) { |
|
| 2356 | + $blob_counter = count($blobs) + 1; |
|
| 2357 | + } |
|
| 2249 | 2358 | } |
| 2250 | 2359 | |
| 2251 | 2360 | // Didn't match our parameter list, try the next possible. |
| 2252 | - if (!$match) |
|
| 2253 | - continue; |
|
| 2361 | + if (!$match) { |
|
| 2362 | + continue; |
|
| 2363 | + } |
|
| 2254 | 2364 | |
| 2255 | 2365 | $params = array(); |
| 2256 | 2366 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2257 | 2367 | { |
| 2258 | 2368 | $key = strtok(ltrim($matches[$i]), '='); |
| 2259 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2260 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2261 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2262 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2263 | - else |
|
| 2264 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2369 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2370 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2371 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2372 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2373 | + } else { |
|
| 2374 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2375 | + } |
|
| 2265 | 2376 | |
| 2266 | 2377 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2267 | 2378 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2269,23 +2380,26 @@ discard block |
||
| 2269 | 2380 | |
| 2270 | 2381 | foreach ($possible['parameters'] as $p => $info) |
| 2271 | 2382 | { |
| 2272 | - if (!isset($params['{' . $p . '}'])) |
|
| 2273 | - $params['{' . $p . '}'] = ''; |
|
| 2383 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2384 | + $params['{' . $p . '}'] = ''; |
|
| 2385 | + } |
|
| 2274 | 2386 | } |
| 2275 | 2387 | |
| 2276 | 2388 | $tag = $possible; |
| 2277 | 2389 | |
| 2278 | 2390 | // Put the parameters into the string. |
| 2279 | - if (isset($tag['before'])) |
|
| 2280 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2281 | - if (isset($tag['after'])) |
|
| 2282 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2283 | - if (isset($tag['content'])) |
|
| 2284 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2391 | + if (isset($tag['before'])) { |
|
| 2392 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2393 | + } |
|
| 2394 | + if (isset($tag['after'])) { |
|
| 2395 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2396 | + } |
|
| 2397 | + if (isset($tag['content'])) { |
|
| 2398 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2399 | + } |
|
| 2285 | 2400 | |
| 2286 | 2401 | $pos1 += strlen($given_param_string); |
| 2287 | - } |
|
| 2288 | - else |
|
| 2402 | + } else |
|
| 2289 | 2403 | { |
| 2290 | 2404 | $tag = $possible; |
| 2291 | 2405 | $params = array(); |
@@ -2296,8 +2410,9 @@ discard block |
||
| 2296 | 2410 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2297 | 2411 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2298 | 2412 | { |
| 2299 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2300 | - continue; |
|
| 2413 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2414 | + continue; |
|
| 2415 | + } |
|
| 2301 | 2416 | |
| 2302 | 2417 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2303 | 2418 | |
@@ -2318,9 +2433,9 @@ discard block |
||
| 2318 | 2433 | { |
| 2319 | 2434 | array_pop($open_tags); |
| 2320 | 2435 | $code = '</li>'; |
| 2436 | + } else { |
|
| 2437 | + $code = ''; |
|
| 2321 | 2438 | } |
| 2322 | - else |
|
| 2323 | - $code = ''; |
|
| 2324 | 2439 | |
| 2325 | 2440 | // Now we open a new tag. |
| 2326 | 2441 | $open_tags[] = array( |
@@ -2367,12 +2482,14 @@ discard block |
||
| 2367 | 2482 | } |
| 2368 | 2483 | |
| 2369 | 2484 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2370 | - if ($tag === null) |
|
| 2371 | - continue; |
|
| 2485 | + if ($tag === null) { |
|
| 2486 | + continue; |
|
| 2487 | + } |
|
| 2372 | 2488 | |
| 2373 | 2489 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2374 | - if (isset($inside['disallow_children'])) |
|
| 2375 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2490 | + if (isset($inside['disallow_children'])) { |
|
| 2491 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2492 | + } |
|
| 2376 | 2493 | |
| 2377 | 2494 | // Is this tag disabled? |
| 2378 | 2495 | if (isset($disabled[$tag['tag']])) |
@@ -2382,14 +2499,13 @@ discard block |
||
| 2382 | 2499 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2383 | 2500 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2384 | 2501 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2385 | - } |
|
| 2386 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2502 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2387 | 2503 | { |
| 2388 | 2504 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2389 | 2505 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2506 | + } else { |
|
| 2507 | + $tag['content'] = $tag['disabled_content']; |
|
| 2390 | 2508 | } |
| 2391 | - else |
|
| 2392 | - $tag['content'] = $tag['disabled_content']; |
|
| 2393 | 2509 | } |
| 2394 | 2510 | |
| 2395 | 2511 | // we use this a lot |
@@ -2399,8 +2515,9 @@ discard block |
||
| 2399 | 2515 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2400 | 2516 | { |
| 2401 | 2517 | $n = count($open_tags) - 1; |
| 2402 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2403 | - $n--; |
|
| 2518 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2519 | + $n--; |
|
| 2520 | + } |
|
| 2404 | 2521 | |
| 2405 | 2522 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2406 | 2523 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2412,12 +2529,15 @@ discard block |
||
| 2412 | 2529 | |
| 2413 | 2530 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2414 | 2531 | $whitespace_regex = ''; |
| 2415 | - if (!empty($tag['block_level'])) |
|
| 2416 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2417 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2418 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2419 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2420 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2532 | + if (!empty($tag['block_level'])) { |
|
| 2533 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2534 | + } |
|
| 2535 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2536 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2537 | + } |
|
| 2538 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2539 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2540 | + } |
|
| 2421 | 2541 | |
| 2422 | 2542 | array_pop($open_tags); |
| 2423 | 2543 | } |
@@ -2435,16 +2555,19 @@ discard block |
||
| 2435 | 2555 | elseif ($tag['type'] == 'unparsed_content') |
| 2436 | 2556 | { |
| 2437 | 2557 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2438 | - if ($pos2 === false) |
|
| 2439 | - continue; |
|
| 2558 | + if ($pos2 === false) { |
|
| 2559 | + continue; |
|
| 2560 | + } |
|
| 2440 | 2561 | |
| 2441 | 2562 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2442 | 2563 | |
| 2443 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2444 | - $data = substr($data, 4); |
|
| 2564 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2565 | + $data = substr($data, 4); |
|
| 2566 | + } |
|
| 2445 | 2567 | |
| 2446 | - if (isset($tag['validate'])) |
|
| 2447 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2568 | + if (isset($tag['validate'])) { |
|
| 2569 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2570 | + } |
|
| 2448 | 2571 | |
| 2449 | 2572 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2450 | 2573 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2460,34 +2583,40 @@ discard block |
||
| 2460 | 2583 | if (isset($tag['quoted'])) |
| 2461 | 2584 | { |
| 2462 | 2585 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2463 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2464 | - continue; |
|
| 2586 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2587 | + continue; |
|
| 2588 | + } |
|
| 2465 | 2589 | |
| 2466 | - if ($quoted) |
|
| 2467 | - $pos1 += 6; |
|
| 2590 | + if ($quoted) { |
|
| 2591 | + $pos1 += 6; |
|
| 2592 | + } |
|
| 2593 | + } else { |
|
| 2594 | + $quoted = false; |
|
| 2468 | 2595 | } |
| 2469 | - else |
|
| 2470 | - $quoted = false; |
|
| 2471 | 2596 | |
| 2472 | 2597 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2473 | - if ($pos2 === false) |
|
| 2474 | - continue; |
|
| 2598 | + if ($pos2 === false) { |
|
| 2599 | + continue; |
|
| 2600 | + } |
|
| 2475 | 2601 | |
| 2476 | 2602 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2477 | - if ($pos3 === false) |
|
| 2478 | - continue; |
|
| 2603 | + if ($pos3 === false) { |
|
| 2604 | + continue; |
|
| 2605 | + } |
|
| 2479 | 2606 | |
| 2480 | 2607 | $data = array( |
| 2481 | 2608 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2482 | 2609 | substr($message, $pos1, $pos2 - $pos1) |
| 2483 | 2610 | ); |
| 2484 | 2611 | |
| 2485 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2486 | - $data[0] = substr($data[0], 4); |
|
| 2612 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2613 | + $data[0] = substr($data[0], 4); |
|
| 2614 | + } |
|
| 2487 | 2615 | |
| 2488 | 2616 | // Validation for my parking, please! |
| 2489 | - if (isset($tag['validate'])) |
|
| 2490 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2617 | + if (isset($tag['validate'])) { |
|
| 2618 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2619 | + } |
|
| 2491 | 2620 | |
| 2492 | 2621 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2493 | 2622 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2504,23 +2633,27 @@ discard block |
||
| 2504 | 2633 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2505 | 2634 | { |
| 2506 | 2635 | $pos2 = strpos($message, ']', $pos1); |
| 2507 | - if ($pos2 === false) |
|
| 2508 | - continue; |
|
| 2636 | + if ($pos2 === false) { |
|
| 2637 | + continue; |
|
| 2638 | + } |
|
| 2509 | 2639 | |
| 2510 | 2640 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2511 | - if ($pos3 === false) |
|
| 2512 | - continue; |
|
| 2641 | + if ($pos3 === false) { |
|
| 2642 | + continue; |
|
| 2643 | + } |
|
| 2513 | 2644 | |
| 2514 | 2645 | // We want $1 to be the content, and the rest to be csv. |
| 2515 | 2646 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2516 | 2647 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2517 | 2648 | |
| 2518 | - if (isset($tag['validate'])) |
|
| 2519 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2649 | + if (isset($tag['validate'])) { |
|
| 2650 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2651 | + } |
|
| 2520 | 2652 | |
| 2521 | 2653 | $code = $tag['content']; |
| 2522 | - foreach ($data as $k => $d) |
|
| 2523 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2654 | + foreach ($data as $k => $d) { |
|
| 2655 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2656 | + } |
|
| 2524 | 2657 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2525 | 2658 | $pos += strlen($code) - 1 + 2; |
| 2526 | 2659 | } |
@@ -2528,24 +2661,28 @@ discard block |
||
| 2528 | 2661 | elseif ($tag['type'] == 'unparsed_commas') |
| 2529 | 2662 | { |
| 2530 | 2663 | $pos2 = strpos($message, ']', $pos1); |
| 2531 | - if ($pos2 === false) |
|
| 2532 | - continue; |
|
| 2664 | + if ($pos2 === false) { |
|
| 2665 | + continue; |
|
| 2666 | + } |
|
| 2533 | 2667 | |
| 2534 | 2668 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2535 | 2669 | |
| 2536 | - if (isset($tag['validate'])) |
|
| 2537 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2670 | + if (isset($tag['validate'])) { |
|
| 2671 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2672 | + } |
|
| 2538 | 2673 | |
| 2539 | 2674 | // Fix after, for disabled code mainly. |
| 2540 | - foreach ($data as $k => $d) |
|
| 2541 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2675 | + foreach ($data as $k => $d) { |
|
| 2676 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2677 | + } |
|
| 2542 | 2678 | |
| 2543 | 2679 | $open_tags[] = $tag; |
| 2544 | 2680 | |
| 2545 | 2681 | // Replace them out, $1, $2, $3, $4, etc. |
| 2546 | 2682 | $code = $tag['before']; |
| 2547 | - foreach ($data as $k => $d) |
|
| 2548 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2683 | + foreach ($data as $k => $d) { |
|
| 2684 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2685 | + } |
|
| 2549 | 2686 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2550 | 2687 | $pos += strlen($code) - 1 + 2; |
| 2551 | 2688 | } |
@@ -2556,28 +2693,33 @@ discard block |
||
| 2556 | 2693 | if (isset($tag['quoted'])) |
| 2557 | 2694 | { |
| 2558 | 2695 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2559 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2560 | - continue; |
|
| 2696 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2697 | + continue; |
|
| 2698 | + } |
|
| 2561 | 2699 | |
| 2562 | - if ($quoted) |
|
| 2563 | - $pos1 += 6; |
|
| 2700 | + if ($quoted) { |
|
| 2701 | + $pos1 += 6; |
|
| 2702 | + } |
|
| 2703 | + } else { |
|
| 2704 | + $quoted = false; |
|
| 2564 | 2705 | } |
| 2565 | - else |
|
| 2566 | - $quoted = false; |
|
| 2567 | 2706 | |
| 2568 | 2707 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2569 | - if ($pos2 === false) |
|
| 2570 | - continue; |
|
| 2708 | + if ($pos2 === false) { |
|
| 2709 | + continue; |
|
| 2710 | + } |
|
| 2571 | 2711 | |
| 2572 | 2712 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2573 | 2713 | |
| 2574 | 2714 | // Validation for my parking, please! |
| 2575 | - if (isset($tag['validate'])) |
|
| 2576 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2715 | + if (isset($tag['validate'])) { |
|
| 2716 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2717 | + } |
|
| 2577 | 2718 | |
| 2578 | 2719 | // For parsed content, we must recurse to avoid security problems. |
| 2579 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2580 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2720 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2721 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2722 | + } |
|
| 2581 | 2723 | |
| 2582 | 2724 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2583 | 2725 | |
@@ -2589,34 +2731,40 @@ discard block |
||
| 2589 | 2731 | } |
| 2590 | 2732 | |
| 2591 | 2733 | // If this is block level, eat any breaks after it. |
| 2592 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2593 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2734 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2735 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2736 | + } |
|
| 2594 | 2737 | |
| 2595 | 2738 | // Are we trimming outside this tag? |
| 2596 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2597 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2739 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2740 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2741 | + } |
|
| 2598 | 2742 | } |
| 2599 | 2743 | |
| 2600 | 2744 | // Close any remaining tags. |
| 2601 | - while ($tag = array_pop($open_tags)) |
|
| 2602 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2745 | + while ($tag = array_pop($open_tags)) { |
|
| 2746 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2747 | + } |
|
| 2603 | 2748 | |
| 2604 | 2749 | // Parse the smileys within the parts where it can be done safely. |
| 2605 | 2750 | if ($smileys === true) |
| 2606 | 2751 | { |
| 2607 | 2752 | $message_parts = explode("\n", $message); |
| 2608 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2609 | - parsesmileys($message_parts[$i]); |
|
| 2753 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2754 | + parsesmileys($message_parts[$i]); |
|
| 2755 | + } |
|
| 2610 | 2756 | |
| 2611 | 2757 | $message = implode('', $message_parts); |
| 2612 | 2758 | } |
| 2613 | 2759 | |
| 2614 | 2760 | // No smileys, just get rid of the markers. |
| 2615 | - else |
|
| 2616 | - $message = strtr($message, array("\n" => '')); |
|
| 2761 | + else { |
|
| 2762 | + $message = strtr($message, array("\n" => '')); |
|
| 2763 | + } |
|
| 2617 | 2764 | |
| 2618 | - if ($message !== '' && $message[0] === ' ') |
|
| 2619 | - $message = ' ' . substr($message, 1); |
|
| 2765 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2766 | + $message = ' ' . substr($message, 1); |
|
| 2767 | + } |
|
| 2620 | 2768 | |
| 2621 | 2769 | // Cleanup whitespace. |
| 2622 | 2770 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2625,15 +2773,16 @@ discard block |
||
| 2625 | 2773 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2626 | 2774 | |
| 2627 | 2775 | // Cache the output if it took some time... |
| 2628 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2629 | - cache_put_data($cache_key, $message, 240); |
|
| 2776 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2777 | + cache_put_data($cache_key, $message, 240); |
|
| 2778 | + } |
|
| 2630 | 2779 | |
| 2631 | 2780 | // If this was a force parse revert if needed. |
| 2632 | 2781 | if (!empty($parse_tags)) |
| 2633 | 2782 | { |
| 2634 | - if (empty($temp_bbc)) |
|
| 2635 | - $bbc_codes = array(); |
|
| 2636 | - else |
|
| 2783 | + if (empty($temp_bbc)) { |
|
| 2784 | + $bbc_codes = array(); |
|
| 2785 | + } else |
|
| 2637 | 2786 | { |
| 2638 | 2787 | $bbc_codes = $temp_bbc; |
| 2639 | 2788 | unset($temp_bbc); |
@@ -2660,8 +2809,9 @@ discard block |
||
| 2660 | 2809 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2661 | 2810 | |
| 2662 | 2811 | // No smiley set at all?! |
| 2663 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2664 | - return; |
|
| 2812 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2813 | + return; |
|
| 2814 | + } |
|
| 2665 | 2815 | |
| 2666 | 2816 | // If smileyPregSearch hasn't been set, do it now. |
| 2667 | 2817 | if (empty($smileyPregSearch)) |
@@ -2672,8 +2822,7 @@ discard block |
||
| 2672 | 2822 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2673 | 2823 | $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'); |
| 2674 | 2824 | $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'], '', '', '', ''); |
| 2675 | - } |
|
| 2676 | - else |
|
| 2825 | + } else |
|
| 2677 | 2826 | { |
| 2678 | 2827 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2679 | 2828 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2697,9 +2846,9 @@ discard block |
||
| 2697 | 2846 | $smcFunc['db_free_result']($result); |
| 2698 | 2847 | |
| 2699 | 2848 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2849 | + } else { |
|
| 2850 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2700 | 2851 | } |
| 2701 | - else |
|
| 2702 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2703 | 2852 | } |
| 2704 | 2853 | |
| 2705 | 2854 | // The non-breaking-space is a complex thing... |
@@ -2776,35 +2925,41 @@ discard block |
||
| 2776 | 2925 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2777 | 2926 | |
| 2778 | 2927 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2779 | - if (!empty($context['flush_mail'])) |
|
| 2780 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2928 | + if (!empty($context['flush_mail'])) { |
|
| 2929 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2781 | 2930 | AddMailQueue(true); |
| 2931 | + } |
|
| 2782 | 2932 | |
| 2783 | 2933 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2784 | 2934 | |
| 2785 | - if ($add) |
|
| 2786 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2935 | + if ($add) { |
|
| 2936 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2937 | + } |
|
| 2787 | 2938 | |
| 2788 | 2939 | // Put the session ID in. |
| 2789 | - if (defined('SID') && SID != '') |
|
| 2790 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2940 | + if (defined('SID') && SID != '') { |
|
| 2941 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2942 | + } |
|
| 2791 | 2943 | // Keep that debug in their for template debugging! |
| 2792 | - elseif (isset($_GET['debug'])) |
|
| 2793 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2944 | + elseif (isset($_GET['debug'])) { |
|
| 2945 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2946 | + } |
|
| 2794 | 2947 | |
| 2795 | 2948 | 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']))) |
| 2796 | 2949 | { |
| 2797 | - if (defined('SID') && SID != '') |
|
| 2798 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2950 | + if (defined('SID') && SID != '') { |
|
| 2951 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2799 | 2952 | function ($m) use ($scripturl) |
| 2800 | 2953 | { |
| 2801 | 2954 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 2955 | + } |
|
| 2802 | 2956 | }, $setLocation); |
| 2803 | - else |
|
| 2804 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2957 | + else { |
|
| 2958 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2805 | 2959 | function ($m) use ($scripturl) |
| 2806 | 2960 | { |
| 2807 | 2961 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2962 | + } |
|
| 2808 | 2963 | }, $setLocation); |
| 2809 | 2964 | } |
| 2810 | 2965 | |
@@ -2815,8 +2970,9 @@ discard block |
||
| 2815 | 2970 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2816 | 2971 | |
| 2817 | 2972 | // Debugging. |
| 2818 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2819 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 2973 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 2974 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 2975 | + } |
|
| 2820 | 2976 | |
| 2821 | 2977 | obExit(false); |
| 2822 | 2978 | } |
@@ -2835,51 +2991,60 @@ discard block |
||
| 2835 | 2991 | |
| 2836 | 2992 | // Attempt to prevent a recursive loop. |
| 2837 | 2993 | ++$level; |
| 2838 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2839 | - exit; |
|
| 2840 | - if ($from_fatal_error) |
|
| 2841 | - $has_fatal_error = true; |
|
| 2994 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 2995 | + exit; |
|
| 2996 | + } |
|
| 2997 | + if ($from_fatal_error) { |
|
| 2998 | + $has_fatal_error = true; |
|
| 2999 | + } |
|
| 2842 | 3000 | |
| 2843 | 3001 | // Clear out the stat cache. |
| 2844 | 3002 | trackStats(); |
| 2845 | 3003 | |
| 2846 | 3004 | // If we have mail to send, send it. |
| 2847 | - if (!empty($context['flush_mail'])) |
|
| 2848 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 3005 | + if (!empty($context['flush_mail'])) { |
|
| 3006 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2849 | 3007 | AddMailQueue(true); |
| 3008 | + } |
|
| 2850 | 3009 | |
| 2851 | 3010 | $do_header = $header === null ? !$header_done : $header; |
| 2852 | - if ($do_footer === null) |
|
| 2853 | - $do_footer = $do_header; |
|
| 3011 | + if ($do_footer === null) { |
|
| 3012 | + $do_footer = $do_header; |
|
| 3013 | + } |
|
| 2854 | 3014 | |
| 2855 | 3015 | // Has the template/header been done yet? |
| 2856 | 3016 | if ($do_header) |
| 2857 | 3017 | { |
| 2858 | 3018 | // Was the page title set last minute? Also update the HTML safe one. |
| 2859 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2860 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3019 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 3020 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3021 | + } |
|
| 2861 | 3022 | |
| 2862 | 3023 | // Start up the session URL fixer. |
| 2863 | 3024 | ob_start('ob_sessrewrite'); |
| 2864 | 3025 | |
| 2865 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2866 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2867 | - elseif (!empty($settings['output_buffers'])) |
|
| 2868 | - $buffers = $settings['output_buffers']; |
|
| 2869 | - else |
|
| 2870 | - $buffers = array(); |
|
| 3026 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 3027 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 3028 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 3029 | + $buffers = $settings['output_buffers']; |
|
| 3030 | + } else { |
|
| 3031 | + $buffers = array(); |
|
| 3032 | + } |
|
| 2871 | 3033 | |
| 2872 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2873 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3034 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3035 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3036 | + } |
|
| 2874 | 3037 | |
| 2875 | - if (!empty($buffers)) |
|
| 2876 | - foreach ($buffers as $function) |
|
| 3038 | + if (!empty($buffers)) { |
|
| 3039 | + foreach ($buffers as $function) |
|
| 2877 | 3040 | { |
| 2878 | 3041 | $call = call_helper($function, true); |
| 3042 | + } |
|
| 2879 | 3043 | |
| 2880 | 3044 | // Is it valid? |
| 2881 | - if (!empty($call)) |
|
| 2882 | - ob_start($call); |
|
| 3045 | + if (!empty($call)) { |
|
| 3046 | + ob_start($call); |
|
| 3047 | + } |
|
| 2883 | 3048 | } |
| 2884 | 3049 | |
| 2885 | 3050 | // Display the screen in the logical order. |
@@ -2891,8 +3056,9 @@ discard block |
||
| 2891 | 3056 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2892 | 3057 | |
| 2893 | 3058 | // Anything special to put out? |
| 2894 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2895 | - echo $context['insert_after_template']; |
|
| 3059 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3060 | + echo $context['insert_after_template']; |
|
| 3061 | + } |
|
| 2896 | 3062 | |
| 2897 | 3063 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2898 | 3064 | if (!$footer_done) |
@@ -2901,14 +3067,16 @@ discard block |
||
| 2901 | 3067 | template_footer(); |
| 2902 | 3068 | |
| 2903 | 3069 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2904 | - if (!isset($_REQUEST['xml'])) |
|
| 2905 | - displayDebug(); |
|
| 3070 | + if (!isset($_REQUEST['xml'])) { |
|
| 3071 | + displayDebug(); |
|
| 3072 | + } |
|
| 2906 | 3073 | } |
| 2907 | 3074 | } |
| 2908 | 3075 | |
| 2909 | 3076 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2910 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2911 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3077 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3078 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3079 | + } |
|
| 2912 | 3080 | |
| 2913 | 3081 | // For session check verification.... don't switch browsers... |
| 2914 | 3082 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2917,9 +3085,10 @@ discard block |
||
| 2917 | 3085 | call_integration_hook('integrate_exit', array($do_footer)); |
| 2918 | 3086 | |
| 2919 | 3087 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 2920 | - if (!$from_index) |
|
| 2921 | - exit; |
|
| 2922 | -} |
|
| 3088 | + if (!$from_index) { |
|
| 3089 | + exit; |
|
| 3090 | + } |
|
| 3091 | + } |
|
| 2923 | 3092 | |
| 2924 | 3093 | /** |
| 2925 | 3094 | * Get the size of a specified image with better error handling. |
@@ -2938,8 +3107,9 @@ discard block |
||
| 2938 | 3107 | $url = str_replace(' ', '%20', $url); |
| 2939 | 3108 | |
| 2940 | 3109 | // Can we pull this from the cache... please please? |
| 2941 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 2942 | - return $temp; |
|
| 3110 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3111 | + return $temp; |
|
| 3112 | + } |
|
| 2943 | 3113 | $t = microtime(); |
| 2944 | 3114 | |
| 2945 | 3115 | // Get the host to pester... |
@@ -2949,12 +3119,10 @@ discard block |
||
| 2949 | 3119 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 2950 | 3120 | { |
| 2951 | 3121 | return false; |
| 2952 | - } |
|
| 2953 | - elseif (!isset($match[1])) |
|
| 3122 | + } elseif (!isset($match[1])) |
|
| 2954 | 3123 | { |
| 2955 | 3124 | $size = @getimagesize($url); |
| 2956 | - } |
|
| 2957 | - else |
|
| 3125 | + } else |
|
| 2958 | 3126 | { |
| 2959 | 3127 | // Try to connect to the server... give it half a second. |
| 2960 | 3128 | $temp = 0; |
@@ -2993,12 +3161,14 @@ discard block |
||
| 2993 | 3161 | } |
| 2994 | 3162 | |
| 2995 | 3163 | // If we didn't get it, we failed. |
| 2996 | - if (!isset($size)) |
|
| 2997 | - $size = false; |
|
| 3164 | + if (!isset($size)) { |
|
| 3165 | + $size = false; |
|
| 3166 | + } |
|
| 2998 | 3167 | |
| 2999 | 3168 | // If this took a long time, we may never have to do it again, but then again we might... |
| 3000 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 3001 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3169 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3170 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3171 | + } |
|
| 3002 | 3172 | |
| 3003 | 3173 | // Didn't work. |
| 3004 | 3174 | return $size; |
@@ -3016,8 +3186,9 @@ discard block |
||
| 3016 | 3186 | |
| 3017 | 3187 | // Under SSI this function can be called more then once. That can cause some problems. |
| 3018 | 3188 | // So only run the function once unless we are forced to run it again. |
| 3019 | - if ($loaded && !$forceload) |
|
| 3020 | - return; |
|
| 3189 | + if ($loaded && !$forceload) { |
|
| 3190 | + return; |
|
| 3191 | + } |
|
| 3021 | 3192 | |
| 3022 | 3193 | $loaded = true; |
| 3023 | 3194 | |
@@ -3029,14 +3200,16 @@ discard block |
||
| 3029 | 3200 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3030 | 3201 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3031 | 3202 | { |
| 3032 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3033 | - continue; |
|
| 3203 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3204 | + continue; |
|
| 3205 | + } |
|
| 3034 | 3206 | |
| 3035 | 3207 | // Clean it up for presentation ;). |
| 3036 | 3208 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3037 | 3209 | } |
| 3038 | - if (!empty($context['news_lines'])) |
|
| 3039 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3210 | + if (!empty($context['news_lines'])) { |
|
| 3211 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3212 | + } |
|
| 3040 | 3213 | |
| 3041 | 3214 | if (!$user_info['is_guest']) |
| 3042 | 3215 | { |
@@ -3045,40 +3218,48 @@ discard block |
||
| 3045 | 3218 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3046 | 3219 | |
| 3047 | 3220 | // Personal message popup... |
| 3048 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3049 | - $context['user']['popup_messages'] = true; |
|
| 3050 | - else |
|
| 3051 | - $context['user']['popup_messages'] = false; |
|
| 3221 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3222 | + $context['user']['popup_messages'] = true; |
|
| 3223 | + } else { |
|
| 3224 | + $context['user']['popup_messages'] = false; |
|
| 3225 | + } |
|
| 3052 | 3226 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3053 | 3227 | |
| 3054 | - if (allowedTo('moderate_forum')) |
|
| 3055 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3228 | + if (allowedTo('moderate_forum')) { |
|
| 3229 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3230 | + } |
|
| 3056 | 3231 | |
| 3057 | 3232 | $context['user']['avatar'] = array(); |
| 3058 | 3233 | |
| 3059 | 3234 | // Check for gravatar first since we might be forcing them... |
| 3060 | 3235 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3061 | 3236 | { |
| 3062 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3063 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3064 | - else |
|
| 3065 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3237 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3238 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3239 | + } else { |
|
| 3240 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3241 | + } |
|
| 3066 | 3242 | } |
| 3067 | 3243 | // Uploaded? |
| 3068 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3069 | - $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'; |
|
| 3244 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3245 | + $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'; |
|
| 3246 | + } |
|
| 3070 | 3247 | // Full URL? |
| 3071 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3072 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3248 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3249 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3250 | + } |
|
| 3073 | 3251 | // Otherwise we assume it's server stored. |
| 3074 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3075 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3252 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3253 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3254 | + } |
|
| 3076 | 3255 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3077 | - else |
|
| 3078 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3256 | + else { |
|
| 3257 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3258 | + } |
|
| 3079 | 3259 | |
| 3080 | - if (!empty($context['user']['avatar'])) |
|
| 3081 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3260 | + if (!empty($context['user']['avatar'])) { |
|
| 3261 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3262 | + } |
|
| 3082 | 3263 | |
| 3083 | 3264 | // Figure out how long they've been logged in. |
| 3084 | 3265 | $context['user']['total_time_logged_in'] = array( |
@@ -3086,8 +3267,7 @@ discard block |
||
| 3086 | 3267 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3087 | 3268 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3088 | 3269 | ); |
| 3089 | - } |
|
| 3090 | - else |
|
| 3270 | + } else |
|
| 3091 | 3271 | { |
| 3092 | 3272 | $context['user']['messages'] = 0; |
| 3093 | 3273 | $context['user']['unread_messages'] = 0; |
@@ -3095,12 +3275,14 @@ discard block |
||
| 3095 | 3275 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3096 | 3276 | $context['user']['popup_messages'] = false; |
| 3097 | 3277 | |
| 3098 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3099 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3278 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3279 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3280 | + } |
|
| 3100 | 3281 | |
| 3101 | 3282 | // If we've upgraded recently, go easy on the passwords. |
| 3102 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3103 | - $context['disable_login_hashing'] = true; |
|
| 3283 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3284 | + $context['disable_login_hashing'] = true; |
|
| 3285 | + } |
|
| 3104 | 3286 | } |
| 3105 | 3287 | |
| 3106 | 3288 | // Setup the main menu items. |
@@ -3113,8 +3295,8 @@ discard block |
||
| 3113 | 3295 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3114 | 3296 | |
| 3115 | 3297 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3116 | - if ($context['show_pm_popup']) |
|
| 3117 | - addInlineJavaScript(' |
|
| 3298 | + if ($context['show_pm_popup']) { |
|
| 3299 | + addInlineJavaScript(' |
|
| 3118 | 3300 | jQuery(document).ready(function($) { |
| 3119 | 3301 | new smc_Popup({ |
| 3120 | 3302 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3122,15 +3304,17 @@ discard block |
||
| 3122 | 3304 | icon_class: \'generic_icons mail_new\' |
| 3123 | 3305 | }); |
| 3124 | 3306 | });'); |
| 3307 | + } |
|
| 3125 | 3308 | |
| 3126 | 3309 | // Add a generic "Are you sure?" confirmation message. |
| 3127 | 3310 | addInlineJavaScript(' |
| 3128 | 3311 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3129 | 3312 | |
| 3130 | 3313 | // Now add the capping code for avatars. |
| 3131 | - 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') |
|
| 3132 | - addInlineCss(' |
|
| 3314 | + 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') { |
|
| 3315 | + addInlineCss(' |
|
| 3133 | 3316 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3317 | + } |
|
| 3134 | 3318 | |
| 3135 | 3319 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3136 | 3320 | $context['common_stats']['latest_member'] = array( |
@@ -3147,11 +3331,13 @@ discard block |
||
| 3147 | 3331 | ); |
| 3148 | 3332 | $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']); |
| 3149 | 3333 | |
| 3150 | - if (empty($settings['theme_version'])) |
|
| 3151 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3334 | + if (empty($settings['theme_version'])) { |
|
| 3335 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3336 | + } |
|
| 3152 | 3337 | |
| 3153 | - if (!isset($context['page_title'])) |
|
| 3154 | - $context['page_title'] = ''; |
|
| 3338 | + if (!isset($context['page_title'])) { |
|
| 3339 | + $context['page_title'] = ''; |
|
| 3340 | + } |
|
| 3155 | 3341 | |
| 3156 | 3342 | // Set some specific vars. |
| 3157 | 3343 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3161,21 +3347,23 @@ discard block |
||
| 3161 | 3347 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3162 | 3348 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3163 | 3349 | |
| 3164 | - if (!empty($context['meta_keywords'])) |
|
| 3165 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3350 | + if (!empty($context['meta_keywords'])) { |
|
| 3351 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3352 | + } |
|
| 3166 | 3353 | |
| 3167 | - if (!empty($context['canonical_url'])) |
|
| 3168 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3354 | + if (!empty($context['canonical_url'])) { |
|
| 3355 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3356 | + } |
|
| 3169 | 3357 | |
| 3170 | - if (!empty($settings['og_image'])) |
|
| 3171 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3358 | + if (!empty($settings['og_image'])) { |
|
| 3359 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3360 | + } |
|
| 3172 | 3361 | |
| 3173 | 3362 | if (!empty($context['meta_description'])) |
| 3174 | 3363 | { |
| 3175 | 3364 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3176 | 3365 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3177 | - } |
|
| 3178 | - else |
|
| 3366 | + } else |
|
| 3179 | 3367 | { |
| 3180 | 3368 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3181 | 3369 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3200,8 +3388,9 @@ discard block |
||
| 3200 | 3388 | $memory_needed = memoryReturnBytes($needed); |
| 3201 | 3389 | |
| 3202 | 3390 | // should we account for how much is currently being used? |
| 3203 | - if ($in_use) |
|
| 3204 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3391 | + if ($in_use) { |
|
| 3392 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3393 | + } |
|
| 3205 | 3394 | |
| 3206 | 3395 | // if more is needed, request it |
| 3207 | 3396 | if ($memory_current < $memory_needed) |
@@ -3224,8 +3413,9 @@ discard block |
||
| 3224 | 3413 | */ |
| 3225 | 3414 | function memoryReturnBytes($val) |
| 3226 | 3415 | { |
| 3227 | - if (is_integer($val)) |
|
| 3228 | - return $val; |
|
| 3416 | + if (is_integer($val)) { |
|
| 3417 | + return $val; |
|
| 3418 | + } |
|
| 3229 | 3419 | |
| 3230 | 3420 | // Separate the number from the designator |
| 3231 | 3421 | $val = trim($val); |
@@ -3261,10 +3451,11 @@ discard block |
||
| 3261 | 3451 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3262 | 3452 | |
| 3263 | 3453 | // Are we debugging the template/html content? |
| 3264 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3265 | - header('Content-Type: application/xhtml+xml'); |
|
| 3266 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3267 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3454 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3455 | + header('Content-Type: application/xhtml+xml'); |
|
| 3456 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3457 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3458 | + } |
|
| 3268 | 3459 | } |
| 3269 | 3460 | |
| 3270 | 3461 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3273,8 +3464,9 @@ discard block |
||
| 3273 | 3464 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3274 | 3465 | { |
| 3275 | 3466 | $position = array_search('body', $context['template_layers']); |
| 3276 | - if ($position === false) |
|
| 3277 | - $position = array_search('main', $context['template_layers']); |
|
| 3467 | + if ($position === false) { |
|
| 3468 | + $position = array_search('main', $context['template_layers']); |
|
| 3469 | + } |
|
| 3278 | 3470 | |
| 3279 | 3471 | if ($position !== false) |
| 3280 | 3472 | { |
@@ -3302,23 +3494,25 @@ discard block |
||
| 3302 | 3494 | |
| 3303 | 3495 | foreach ($securityFiles as $i => $securityFile) |
| 3304 | 3496 | { |
| 3305 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3306 | - unset($securityFiles[$i]); |
|
| 3497 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3498 | + unset($securityFiles[$i]); |
|
| 3499 | + } |
|
| 3307 | 3500 | } |
| 3308 | 3501 | |
| 3309 | 3502 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3310 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3311 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3312 | - |
|
| 3313 | - else |
|
| 3314 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3503 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3504 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3505 | + } else { |
|
| 3506 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3507 | + } |
|
| 3315 | 3508 | |
| 3316 | 3509 | secureDirectory($path, true); |
| 3317 | 3510 | secureDirectory($cachedir); |
| 3318 | 3511 | |
| 3319 | 3512 | // If agreement is enabled, at least the english version shall exists |
| 3320 | - if ($modSettings['requireAgreement']) |
|
| 3321 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3513 | + if ($modSettings['requireAgreement']) { |
|
| 3514 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3515 | + } |
|
| 3322 | 3516 | |
| 3323 | 3517 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3324 | 3518 | { |
@@ -3333,18 +3527,21 @@ discard block |
||
| 3333 | 3527 | echo ' |
| 3334 | 3528 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3335 | 3529 | |
| 3336 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3337 | - echo ' |
|
| 3530 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3531 | + echo ' |
|
| 3338 | 3532 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3533 | + } |
|
| 3339 | 3534 | } |
| 3340 | 3535 | |
| 3341 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3342 | - echo ' |
|
| 3536 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3537 | + echo ' |
|
| 3343 | 3538 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3539 | + } |
|
| 3344 | 3540 | |
| 3345 | - if (!empty($agreement)) |
|
| 3346 | - echo ' |
|
| 3541 | + if (!empty($agreement)) { |
|
| 3542 | + echo ' |
|
| 3347 | 3543 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3544 | + } |
|
| 3348 | 3545 | |
| 3349 | 3546 | echo ' |
| 3350 | 3547 | </p> |
@@ -3359,16 +3556,18 @@ discard block |
||
| 3359 | 3556 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3360 | 3557 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3361 | 3558 | |
| 3362 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3363 | - echo ' |
|
| 3559 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3560 | + echo ' |
|
| 3364 | 3561 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3562 | + } |
|
| 3365 | 3563 | |
| 3366 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3367 | - echo ' |
|
| 3564 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3565 | + echo ' |
|
| 3368 | 3566 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3369 | - else |
|
| 3370 | - echo ' |
|
| 3567 | + } else { |
|
| 3568 | + echo ' |
|
| 3371 | 3569 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3570 | + } |
|
| 3372 | 3571 | |
| 3373 | 3572 | echo ' |
| 3374 | 3573 | </div>'; |
@@ -3384,8 +3583,9 @@ discard block |
||
| 3384 | 3583 | global $forum_copyright, $software_year, $forum_version; |
| 3385 | 3584 | |
| 3386 | 3585 | // Don't display copyright for things like SSI. |
| 3387 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3388 | - return; |
|
| 3586 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3587 | + return; |
|
| 3588 | + } |
|
| 3389 | 3589 | |
| 3390 | 3590 | // Put in the version... |
| 3391 | 3591 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3403,9 +3603,10 @@ discard block |
||
| 3403 | 3603 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
| 3404 | 3604 | $context['load_queries'] = $db_count; |
| 3405 | 3605 | |
| 3406 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3407 | - loadSubTemplate($layer . '_below', true); |
|
| 3408 | -} |
|
| 3606 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3607 | + loadSubTemplate($layer . '_below', true); |
|
| 3608 | + } |
|
| 3609 | + } |
|
| 3409 | 3610 | |
| 3410 | 3611 | /** |
| 3411 | 3612 | * Output the Javascript files |
@@ -3436,8 +3637,7 @@ discard block |
||
| 3436 | 3637 | { |
| 3437 | 3638 | echo ' |
| 3438 | 3639 | var ', $key, ';'; |
| 3439 | - } |
|
| 3440 | - else |
|
| 3640 | + } else |
|
| 3441 | 3641 | { |
| 3442 | 3642 | echo ' |
| 3443 | 3643 | var ', $key, ' = ', $value, ';'; |
@@ -3452,26 +3652,27 @@ discard block |
||
| 3452 | 3652 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3453 | 3653 | { |
| 3454 | 3654 | // Last minute call! allow theme authors to disable single files. |
| 3455 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3456 | - continue; |
|
| 3655 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3656 | + continue; |
|
| 3657 | + } |
|
| 3457 | 3658 | |
| 3458 | 3659 | // By default all files don't get minimized unless the file explicitly says so! |
| 3459 | 3660 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3460 | 3661 | { |
| 3461 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3462 | - $toMinifyDefer[] = $js_file; |
|
| 3463 | - |
|
| 3464 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3465 | - $toMinify[] = $js_file; |
|
| 3662 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3663 | + $toMinifyDefer[] = $js_file; |
|
| 3664 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3665 | + $toMinify[] = $js_file; |
|
| 3666 | + } |
|
| 3466 | 3667 | |
| 3467 | 3668 | // Grab a random seed. |
| 3468 | - if (!isset($minSeed)) |
|
| 3469 | - $minSeed = $js_file['options']['seed']; |
|
| 3470 | - } |
|
| 3471 | - |
|
| 3472 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3473 | - echo ' |
|
| 3669 | + if (!isset($minSeed)) { |
|
| 3670 | + $minSeed = $js_file['options']['seed']; |
|
| 3671 | + } |
|
| 3672 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3673 | + echo ' |
|
| 3474 | 3674 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3675 | + } |
|
| 3475 | 3676 | } |
| 3476 | 3677 | |
| 3477 | 3678 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3479,14 +3680,14 @@ discard block |
||
| 3479 | 3680 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3480 | 3681 | |
| 3481 | 3682 | // Minify process couldn't work, print each individual files. |
| 3482 | - if (!empty($result) && is_array($result)) |
|
| 3483 | - foreach ($result as $minFailedFile) |
|
| 3683 | + if (!empty($result) && is_array($result)) { |
|
| 3684 | + foreach ($result as $minFailedFile) |
|
| 3484 | 3685 | echo ' |
| 3485 | 3686 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3486 | - |
|
| 3487 | - else |
|
| 3488 | - echo ' |
|
| 3687 | + } else { |
|
| 3688 | + echo ' |
|
| 3489 | 3689 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3690 | + } |
|
| 3490 | 3691 | } |
| 3491 | 3692 | |
| 3492 | 3693 | // Inline JavaScript - Actually useful some times! |
@@ -3497,8 +3698,9 @@ discard block |
||
| 3497 | 3698 | echo ' |
| 3498 | 3699 | <script>'; |
| 3499 | 3700 | |
| 3500 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3501 | - echo $js_code; |
|
| 3701 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3702 | + echo $js_code; |
|
| 3703 | + } |
|
| 3502 | 3704 | |
| 3503 | 3705 | echo ' |
| 3504 | 3706 | </script>'; |
@@ -3509,8 +3711,9 @@ discard block |
||
| 3509 | 3711 | echo ' |
| 3510 | 3712 | <script>'; |
| 3511 | 3713 | |
| 3512 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3513 | - echo $js_code; |
|
| 3714 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3715 | + echo $js_code; |
|
| 3716 | + } |
|
| 3514 | 3717 | |
| 3515 | 3718 | echo ' |
| 3516 | 3719 | </script>'; |
@@ -3535,8 +3738,9 @@ discard block |
||
| 3535 | 3738 | foreach ($context['css_files'] as $id => $file) |
| 3536 | 3739 | { |
| 3537 | 3740 | // Last minute call! allow theme authors to disable single files. |
| 3538 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3539 | - continue; |
|
| 3741 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3742 | + continue; |
|
| 3743 | + } |
|
| 3540 | 3744 | |
| 3541 | 3745 | // By default all files don't get minimized unless the file explicitly says so! |
| 3542 | 3746 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3544,12 +3748,12 @@ discard block |
||
| 3544 | 3748 | $toMinify[] = $file; |
| 3545 | 3749 | |
| 3546 | 3750 | // Grab a random seed. |
| 3547 | - if (!isset($minSeed)) |
|
| 3548 | - $minSeed = $file['options']['seed']; |
|
| 3751 | + if (!isset($minSeed)) { |
|
| 3752 | + $minSeed = $file['options']['seed']; |
|
| 3753 | + } |
|
| 3754 | + } else { |
|
| 3755 | + $normal[] = $file['fileUrl']; |
|
| 3549 | 3756 | } |
| 3550 | - |
|
| 3551 | - else |
|
| 3552 | - $normal[] = $file['fileUrl']; |
|
| 3553 | 3757 | } |
| 3554 | 3758 | |
| 3555 | 3759 | if (!empty($toMinify)) |
@@ -3557,28 +3761,30 @@ discard block |
||
| 3557 | 3761 | $result = custMinify($toMinify, 'css'); |
| 3558 | 3762 | |
| 3559 | 3763 | // Minify process couldn't work, print each individual files. |
| 3560 | - if (!empty($result) && is_array($result)) |
|
| 3561 | - foreach ($result as $minFailedFile) |
|
| 3764 | + if (!empty($result) && is_array($result)) { |
|
| 3765 | + foreach ($result as $minFailedFile) |
|
| 3562 | 3766 | echo ' |
| 3563 | 3767 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3564 | - |
|
| 3565 | - else |
|
| 3566 | - echo ' |
|
| 3768 | + } else { |
|
| 3769 | + echo ' |
|
| 3567 | 3770 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3771 | + } |
|
| 3568 | 3772 | } |
| 3569 | 3773 | |
| 3570 | 3774 | // Print the rest after the minified files. |
| 3571 | - if (!empty($normal)) |
|
| 3572 | - foreach ($normal as $nf) |
|
| 3775 | + if (!empty($normal)) { |
|
| 3776 | + foreach ($normal as $nf) |
|
| 3573 | 3777 | echo ' |
| 3574 | 3778 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3779 | + } |
|
| 3575 | 3780 | |
| 3576 | 3781 | if ($db_show_debug === true) |
| 3577 | 3782 | { |
| 3578 | 3783 | // Try to keep only what's useful. |
| 3579 | 3784 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3580 | - foreach ($context['css_files'] as $file) |
|
| 3581 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3785 | + foreach ($context['css_files'] as $file) { |
|
| 3786 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3787 | + } |
|
| 3582 | 3788 | } |
| 3583 | 3789 | |
| 3584 | 3790 | if (!empty($context['css_header'])) |
@@ -3586,9 +3792,10 @@ discard block |
||
| 3586 | 3792 | echo ' |
| 3587 | 3793 | <style>'; |
| 3588 | 3794 | |
| 3589 | - foreach ($context['css_header'] as $css) |
|
| 3590 | - echo $css .' |
|
| 3795 | + foreach ($context['css_header'] as $css) { |
|
| 3796 | + echo $css .' |
|
| 3591 | 3797 | '; |
| 3798 | + } |
|
| 3592 | 3799 | |
| 3593 | 3800 | echo' |
| 3594 | 3801 | </style>'; |
@@ -3612,15 +3819,17 @@ discard block |
||
| 3612 | 3819 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
| 3613 | 3820 | $data = !empty($data) ? $data : false; |
| 3614 | 3821 | |
| 3615 | - if (empty($type) || empty($data)) |
|
| 3616 | - return false; |
|
| 3822 | + if (empty($type) || empty($data)) { |
|
| 3823 | + return false; |
|
| 3824 | + } |
|
| 3617 | 3825 | |
| 3618 | 3826 | // Did we already did this? |
| 3619 | 3827 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3620 | 3828 | |
| 3621 | 3829 | // Already done? |
| 3622 | - if (!empty($toCache)) |
|
| 3623 | - return true; |
|
| 3830 | + if (!empty($toCache)) { |
|
| 3831 | + return true; |
|
| 3832 | + } |
|
| 3624 | 3833 | |
| 3625 | 3834 | // No namespaces, sorry! |
| 3626 | 3835 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3702,8 +3911,9 @@ discard block |
||
| 3702 | 3911 | global $modSettings, $smcFunc; |
| 3703 | 3912 | |
| 3704 | 3913 | // Just make up a nice hash... |
| 3705 | - if ($new) |
|
| 3706 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 3914 | + if ($new) { |
|
| 3915 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 3916 | + } |
|
| 3707 | 3917 | |
| 3708 | 3918 | // Just make sure that attachment id is only a int |
| 3709 | 3919 | $attachment_id = (int) $attachment_id; |
@@ -3720,23 +3930,25 @@ discard block |
||
| 3720 | 3930 | 'id_attach' => $attachment_id, |
| 3721 | 3931 | )); |
| 3722 | 3932 | |
| 3723 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3724 | - return false; |
|
| 3933 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 3934 | + return false; |
|
| 3935 | + } |
|
| 3725 | 3936 | |
| 3726 | 3937 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3727 | 3938 | $smcFunc['db_free_result']($request); |
| 3728 | 3939 | } |
| 3729 | 3940 | |
| 3730 | 3941 | // Still no hash? mmm... |
| 3731 | - if (empty($file_hash)) |
|
| 3732 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3942 | + if (empty($file_hash)) { |
|
| 3943 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3944 | + } |
|
| 3733 | 3945 | |
| 3734 | 3946 | // Are we using multiple directories? |
| 3735 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
| 3736 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3737 | - |
|
| 3738 | - else |
|
| 3739 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3947 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
| 3948 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3949 | + } else { |
|
| 3950 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3951 | + } |
|
| 3740 | 3952 | |
| 3741 | 3953 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3742 | 3954 | } |
@@ -3751,8 +3963,9 @@ discard block |
||
| 3751 | 3963 | function ip2range($fullip) |
| 3752 | 3964 | { |
| 3753 | 3965 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3754 | - if ($fullip == 'unknown') |
|
| 3755 | - $fullip = '255.255.255.255'; |
|
| 3966 | + if ($fullip == 'unknown') { |
|
| 3967 | + $fullip = '255.255.255.255'; |
|
| 3968 | + } |
|
| 3756 | 3969 | |
| 3757 | 3970 | $ip_parts = explode('-', $fullip); |
| 3758 | 3971 | $ip_array = array(); |
@@ -3776,10 +3989,11 @@ discard block |
||
| 3776 | 3989 | $ip_array['low'] = $ip_parts[0]; |
| 3777 | 3990 | $ip_array['high'] = $ip_parts[1]; |
| 3778 | 3991 | return $ip_array; |
| 3779 | - } |
|
| 3780 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 3992 | + } elseif (count($ip_parts) == 2) { |
|
| 3993 | + // if ip 22.22.*-22.22.* |
|
| 3781 | 3994 | { |
| 3782 | 3995 | $valid_low = isValidIP($ip_parts[0]); |
| 3996 | + } |
|
| 3783 | 3997 | $valid_high = isValidIP($ip_parts[1]); |
| 3784 | 3998 | $count = 0; |
| 3785 | 3999 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3794,7 +4008,9 @@ discard block |
||
| 3794 | 4008 | $ip_parts[0] .= $mode . $min; |
| 3795 | 4009 | $valid_low = isValidIP($ip_parts[0]); |
| 3796 | 4010 | $count++; |
| 3797 | - if ($count > 9) break; |
|
| 4011 | + if ($count > 9) { |
|
| 4012 | + break; |
|
| 4013 | + } |
|
| 3798 | 4014 | } |
| 3799 | 4015 | } |
| 3800 | 4016 | |
@@ -3808,7 +4024,9 @@ discard block |
||
| 3808 | 4024 | $ip_parts[1] .= $mode . $max; |
| 3809 | 4025 | $valid_high = isValidIP($ip_parts[1]); |
| 3810 | 4026 | $count++; |
| 3811 | - if ($count > 9) break; |
|
| 4027 | + if ($count > 9) { |
|
| 4028 | + break; |
|
| 4029 | + } |
|
| 3812 | 4030 | } |
| 3813 | 4031 | } |
| 3814 | 4032 | |
@@ -3833,46 +4051,54 @@ discard block |
||
| 3833 | 4051 | { |
| 3834 | 4052 | global $modSettings; |
| 3835 | 4053 | |
| 3836 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3837 | - return $host; |
|
| 4054 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4055 | + return $host; |
|
| 4056 | + } |
|
| 3838 | 4057 | $t = microtime(); |
| 3839 | 4058 | |
| 3840 | 4059 | // Try the Linux host command, perhaps? |
| 3841 | 4060 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3842 | 4061 | { |
| 3843 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3844 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3845 | - else |
|
| 3846 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4062 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4063 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4064 | + } else { |
|
| 4065 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4066 | + } |
|
| 3847 | 4067 | |
| 3848 | 4068 | // Did host say it didn't find anything? |
| 3849 | - if (strpos($test, 'not found') !== false) |
|
| 3850 | - $host = ''; |
|
| 4069 | + if (strpos($test, 'not found') !== false) { |
|
| 4070 | + $host = ''; |
|
| 4071 | + } |
|
| 3851 | 4072 | // Invalid server option? |
| 3852 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3853 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4073 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4074 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4075 | + } |
|
| 3854 | 4076 | // Maybe it found something, after all? |
| 3855 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3856 | - $host = $match[1]; |
|
| 4077 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4078 | + $host = $match[1]; |
|
| 4079 | + } |
|
| 3857 | 4080 | } |
| 3858 | 4081 | |
| 3859 | 4082 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3860 | 4083 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3861 | 4084 | { |
| 3862 | 4085 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3863 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3864 | - $host = ''; |
|
| 3865 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3866 | - $host = $match[1]; |
|
| 4086 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4087 | + $host = ''; |
|
| 4088 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4089 | + $host = $match[1]; |
|
| 4090 | + } |
|
| 3867 | 4091 | } |
| 3868 | 4092 | |
| 3869 | 4093 | // This is the last try :/. |
| 3870 | - if (!isset($host) || $host === false) |
|
| 3871 | - $host = @gethostbyaddr($ip); |
|
| 4094 | + if (!isset($host) || $host === false) { |
|
| 4095 | + $host = @gethostbyaddr($ip); |
|
| 4096 | + } |
|
| 3872 | 4097 | |
| 3873 | 4098 | // It took a long time, so let's cache it! |
| 3874 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3875 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4099 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4100 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4101 | + } |
|
| 3876 | 4102 | |
| 3877 | 4103 | return $host; |
| 3878 | 4104 | } |
@@ -3908,20 +4134,21 @@ discard block |
||
| 3908 | 4134 | { |
| 3909 | 4135 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3910 | 4136 | $total = 0; |
| 3911 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3912 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4137 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4138 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4139 | + } |
|
| 3913 | 4140 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 3914 | 4141 | } |
| 3915 | 4142 | } |
| 3916 | 4143 | return array_unique($returned_ints); |
| 3917 | - } |
|
| 3918 | - else |
|
| 4144 | + } else |
|
| 3919 | 4145 | { |
| 3920 | 4146 | // Trim characters before and after and add slashes for database insertion. |
| 3921 | 4147 | $returned_words = array(); |
| 3922 | - foreach ($words as $word) |
|
| 3923 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4148 | + foreach ($words as $word) { |
|
| 4149 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 3924 | 4150 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4151 | + } |
|
| 3925 | 4152 | |
| 3926 | 4153 | // Filter out all words that occur more than once. |
| 3927 | 4154 | return array_unique($returned_words); |
@@ -3943,16 +4170,18 @@ discard block |
||
| 3943 | 4170 | global $settings, $txt; |
| 3944 | 4171 | |
| 3945 | 4172 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 3946 | - if (function_exists('template_create_button') && !$force_use) |
|
| 3947 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4173 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4174 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4175 | + } |
|
| 3948 | 4176 | |
| 3949 | - if (!$settings['use_image_buttons']) |
|
| 3950 | - return $txt[$alt]; |
|
| 3951 | - elseif (!empty($settings['use_buttons'])) |
|
| 3952 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 3953 | - else |
|
| 3954 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 3955 | -} |
|
| 4177 | + if (!$settings['use_image_buttons']) { |
|
| 4178 | + return $txt[$alt]; |
|
| 4179 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4180 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4181 | + } else { |
|
| 4182 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4183 | + } |
|
| 4184 | + } |
|
| 3956 | 4185 | |
| 3957 | 4186 | /** |
| 3958 | 4187 | * Sets up all of the top menu buttons |
@@ -3995,9 +4224,10 @@ discard block |
||
| 3995 | 4224 | var user_menus = new smc_PopupMenu(); |
| 3996 | 4225 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3997 | 4226 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 3998 | - if ($context['allow_pm']) |
|
| 3999 | - addInlineJavaScript(' |
|
| 4227 | + if ($context['allow_pm']) { |
|
| 4228 | + addInlineJavaScript(' |
|
| 4000 | 4229 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4230 | + } |
|
| 4001 | 4231 | |
| 4002 | 4232 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 4003 | 4233 | { |
@@ -4157,88 +4387,96 @@ discard block |
||
| 4157 | 4387 | |
| 4158 | 4388 | // Now we put the buttons in the context so the theme can use them. |
| 4159 | 4389 | $menu_buttons = array(); |
| 4160 | - foreach ($buttons as $act => $button) |
|
| 4161 | - if (!empty($button['show'])) |
|
| 4390 | + foreach ($buttons as $act => $button) { |
|
| 4391 | + if (!empty($button['show'])) |
|
| 4162 | 4392 | { |
| 4163 | 4393 | $button['active_button'] = false; |
| 4394 | + } |
|
| 4164 | 4395 | |
| 4165 | 4396 | // This button needs some action. |
| 4166 | - if (isset($button['action_hook'])) |
|
| 4167 | - $needs_action_hook = true; |
|
| 4397 | + if (isset($button['action_hook'])) { |
|
| 4398 | + $needs_action_hook = true; |
|
| 4399 | + } |
|
| 4168 | 4400 | |
| 4169 | 4401 | // Make sure the last button truly is the last button. |
| 4170 | 4402 | if (!empty($button['is_last'])) |
| 4171 | 4403 | { |
| 4172 | - if (isset($last_button)) |
|
| 4173 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4404 | + if (isset($last_button)) { |
|
| 4405 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4406 | + } |
|
| 4174 | 4407 | $last_button = $act; |
| 4175 | 4408 | } |
| 4176 | 4409 | |
| 4177 | 4410 | // Go through the sub buttons if there are any. |
| 4178 | - if (!empty($button['sub_buttons'])) |
|
| 4179 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4411 | + if (!empty($button['sub_buttons'])) { |
|
| 4412 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4180 | 4413 | { |
| 4181 | 4414 | if (empty($subbutton['show'])) |
| 4182 | 4415 | unset($button['sub_buttons'][$key]); |
| 4416 | + } |
|
| 4183 | 4417 | |
| 4184 | 4418 | // 2nd level sub buttons next... |
| 4185 | 4419 | if (!empty($subbutton['sub_buttons'])) |
| 4186 | 4420 | { |
| 4187 | 4421 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4188 | 4422 | { |
| 4189 | - if (empty($sub_button2['show'])) |
|
| 4190 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4423 | + if (empty($sub_button2['show'])) { |
|
| 4424 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4425 | + } |
|
| 4191 | 4426 | } |
| 4192 | 4427 | } |
| 4193 | 4428 | } |
| 4194 | 4429 | |
| 4195 | 4430 | // Does this button have its own icon? |
| 4196 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4197 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4198 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4199 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4200 | - elseif (isset($button['icon'])) |
|
| 4201 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4202 | - else |
|
| 4203 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4431 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4432 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4433 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4434 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4435 | + } elseif (isset($button['icon'])) { |
|
| 4436 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4437 | + } else { |
|
| 4438 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4439 | + } |
|
| 4204 | 4440 | |
| 4205 | 4441 | $menu_buttons[$act] = $button; |
| 4206 | 4442 | } |
| 4207 | 4443 | |
| 4208 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4209 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4444 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4445 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4446 | + } |
|
| 4210 | 4447 | } |
| 4211 | 4448 | |
| 4212 | 4449 | $context['menu_buttons'] = $menu_buttons; |
| 4213 | 4450 | |
| 4214 | 4451 | // Logging out requires the session id in the url. |
| 4215 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4216 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4452 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4453 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4454 | + } |
|
| 4217 | 4455 | |
| 4218 | 4456 | // Figure out which action we are doing so we can set the active tab. |
| 4219 | 4457 | // Default to home. |
| 4220 | 4458 | $current_action = 'home'; |
| 4221 | 4459 | |
| 4222 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4223 | - $current_action = $context['current_action']; |
|
| 4224 | - elseif ($context['current_action'] == 'search2') |
|
| 4225 | - $current_action = 'search'; |
|
| 4226 | - elseif ($context['current_action'] == 'theme') |
|
| 4227 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4228 | - elseif ($context['current_action'] == 'register2') |
|
| 4229 | - $current_action = 'register'; |
|
| 4230 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4231 | - $current_action = 'login'; |
|
| 4232 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4233 | - $current_action = 'moderate'; |
|
| 4460 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4461 | + $current_action = $context['current_action']; |
|
| 4462 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4463 | + $current_action = 'search'; |
|
| 4464 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4465 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4466 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4467 | + $current_action = 'register'; |
|
| 4468 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4469 | + $current_action = 'login'; |
|
| 4470 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4471 | + $current_action = 'moderate'; |
|
| 4472 | + } |
|
| 4234 | 4473 | |
| 4235 | 4474 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4236 | 4475 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4237 | 4476 | { |
| 4238 | 4477 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4239 | 4478 | $context[$current_action] = true; |
| 4240 | - } |
|
| 4241 | - elseif ($context['current_action'] == 'pm') |
|
| 4479 | + } elseif ($context['current_action'] == 'pm') |
|
| 4242 | 4480 | { |
| 4243 | 4481 | $current_action = 'self_pm'; |
| 4244 | 4482 | $context['self_pm'] = true; |
@@ -4281,12 +4519,14 @@ discard block |
||
| 4281 | 4519 | } |
| 4282 | 4520 | |
| 4283 | 4521 | // Not all actions are simple. |
| 4284 | - if (!empty($needs_action_hook)) |
|
| 4285 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4522 | + if (!empty($needs_action_hook)) { |
|
| 4523 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4524 | + } |
|
| 4286 | 4525 | |
| 4287 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4288 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4289 | -} |
|
| 4526 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4527 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4528 | + } |
|
| 4529 | + } |
|
| 4290 | 4530 | |
| 4291 | 4531 | /** |
| 4292 | 4532 | * Generate a random seed and ensure it's stored in settings. |
@@ -4310,16 +4550,19 @@ discard block |
||
| 4310 | 4550 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4311 | 4551 | global $context, $txt; |
| 4312 | 4552 | |
| 4313 | - if ($db_show_debug === true) |
|
| 4314 | - $context['debug']['hooks'][] = $hook; |
|
| 4553 | + if ($db_show_debug === true) { |
|
| 4554 | + $context['debug']['hooks'][] = $hook; |
|
| 4555 | + } |
|
| 4315 | 4556 | |
| 4316 | 4557 | // Need to have some control. |
| 4317 | - if (!isset($context['instances'])) |
|
| 4318 | - $context['instances'] = array(); |
|
| 4558 | + if (!isset($context['instances'])) { |
|
| 4559 | + $context['instances'] = array(); |
|
| 4560 | + } |
|
| 4319 | 4561 | |
| 4320 | 4562 | $results = array(); |
| 4321 | - if (empty($modSettings[$hook])) |
|
| 4322 | - return $results; |
|
| 4563 | + if (empty($modSettings[$hook])) { |
|
| 4564 | + return $results; |
|
| 4565 | + } |
|
| 4323 | 4566 | |
| 4324 | 4567 | // Define some needed vars. |
| 4325 | 4568 | $function = false; |
@@ -4329,14 +4572,16 @@ discard block |
||
| 4329 | 4572 | foreach ($functions as $function) |
| 4330 | 4573 | { |
| 4331 | 4574 | // Hook has been marked as "disabled". Skip it! |
| 4332 | - if (strpos($function, '!') !== false) |
|
| 4333 | - continue; |
|
| 4575 | + if (strpos($function, '!') !== false) { |
|
| 4576 | + continue; |
|
| 4577 | + } |
|
| 4334 | 4578 | |
| 4335 | 4579 | $call = call_helper($function, true); |
| 4336 | 4580 | |
| 4337 | 4581 | // Is it valid? |
| 4338 | - if (!empty($call)) |
|
| 4339 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4582 | + if (!empty($call)) { |
|
| 4583 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4584 | + } |
|
| 4340 | 4585 | |
| 4341 | 4586 | // Whatever it was suppose to call, it failed :( |
| 4342 | 4587 | elseif (!empty($function)) |
@@ -4352,8 +4597,9 @@ discard block |
||
| 4352 | 4597 | } |
| 4353 | 4598 | |
| 4354 | 4599 | // "Assume" the file resides on $boarddir somewhere... |
| 4355 | - else |
|
| 4356 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4600 | + else { |
|
| 4601 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4602 | + } |
|
| 4357 | 4603 | } |
| 4358 | 4604 | } |
| 4359 | 4605 | |
@@ -4375,12 +4621,14 @@ discard block |
||
| 4375 | 4621 | global $smcFunc, $modSettings; |
| 4376 | 4622 | |
| 4377 | 4623 | // Any objects? |
| 4378 | - if ($object) |
|
| 4379 | - $function = $function . '#'; |
|
| 4624 | + if ($object) { |
|
| 4625 | + $function = $function . '#'; |
|
| 4626 | + } |
|
| 4380 | 4627 | |
| 4381 | 4628 | // Any files to load? |
| 4382 | - if (!empty($file) && is_string($file)) |
|
| 4383 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4629 | + if (!empty($file) && is_string($file)) { |
|
| 4630 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4631 | + } |
|
| 4384 | 4632 | |
| 4385 | 4633 | // Get the correct string. |
| 4386 | 4634 | $integration_call = $function; |
@@ -4402,13 +4650,14 @@ discard block |
||
| 4402 | 4650 | if (!empty($current_functions)) |
| 4403 | 4651 | { |
| 4404 | 4652 | $current_functions = explode(',', $current_functions); |
| 4405 | - if (in_array($integration_call, $current_functions)) |
|
| 4406 | - return; |
|
| 4653 | + if (in_array($integration_call, $current_functions)) { |
|
| 4654 | + return; |
|
| 4655 | + } |
|
| 4407 | 4656 | |
| 4408 | 4657 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4658 | + } else { |
|
| 4659 | + $permanent_functions = array($integration_call); |
|
| 4409 | 4660 | } |
| 4410 | - else |
|
| 4411 | - $permanent_functions = array($integration_call); |
|
| 4412 | 4661 | |
| 4413 | 4662 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4414 | 4663 | } |
@@ -4417,8 +4666,9 @@ discard block |
||
| 4417 | 4666 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4418 | 4667 | |
| 4419 | 4668 | // Do nothing, if it's already there. |
| 4420 | - if (in_array($integration_call, $functions)) |
|
| 4421 | - return; |
|
| 4669 | + if (in_array($integration_call, $functions)) { |
|
| 4670 | + return; |
|
| 4671 | + } |
|
| 4422 | 4672 | |
| 4423 | 4673 | $functions[] = $integration_call; |
| 4424 | 4674 | $modSettings[$hook] = implode(',', $functions); |
@@ -4441,12 +4691,14 @@ discard block |
||
| 4441 | 4691 | global $smcFunc, $modSettings; |
| 4442 | 4692 | |
| 4443 | 4693 | // Any objects? |
| 4444 | - if ($object) |
|
| 4445 | - $function = $function . '#'; |
|
| 4694 | + if ($object) { |
|
| 4695 | + $function = $function . '#'; |
|
| 4696 | + } |
|
| 4446 | 4697 | |
| 4447 | 4698 | // Any files to load? |
| 4448 | - if (!empty($file) && is_string($file)) |
|
| 4449 | - $function = $file . '|' . $function; |
|
| 4699 | + if (!empty($file) && is_string($file)) { |
|
| 4700 | + $function = $file . '|' . $function; |
|
| 4701 | + } |
|
| 4450 | 4702 | |
| 4451 | 4703 | // Get the correct string. |
| 4452 | 4704 | $integration_call = $function; |
@@ -4467,16 +4719,18 @@ discard block |
||
| 4467 | 4719 | { |
| 4468 | 4720 | $current_functions = explode(',', $current_functions); |
| 4469 | 4721 | |
| 4470 | - if (in_array($integration_call, $current_functions)) |
|
| 4471 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4722 | + if (in_array($integration_call, $current_functions)) { |
|
| 4723 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4724 | + } |
|
| 4472 | 4725 | } |
| 4473 | 4726 | |
| 4474 | 4727 | // Turn the function list into something usable. |
| 4475 | 4728 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4476 | 4729 | |
| 4477 | 4730 | // You can only remove it if it's available. |
| 4478 | - if (!in_array($integration_call, $functions)) |
|
| 4479 | - return; |
|
| 4731 | + if (!in_array($integration_call, $functions)) { |
|
| 4732 | + return; |
|
| 4733 | + } |
|
| 4480 | 4734 | |
| 4481 | 4735 | $functions = array_diff($functions, array($integration_call)); |
| 4482 | 4736 | $modSettings[$hook] = implode(',', $functions); |
@@ -4497,17 +4751,20 @@ discard block |
||
| 4497 | 4751 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4498 | 4752 | |
| 4499 | 4753 | // Really? |
| 4500 | - if (empty($string)) |
|
| 4501 | - return false; |
|
| 4754 | + if (empty($string)) { |
|
| 4755 | + return false; |
|
| 4756 | + } |
|
| 4502 | 4757 | |
| 4503 | 4758 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4504 | 4759 | // A closure? should be a callable one. |
| 4505 | - if (is_array($string) || $string instanceof Closure) |
|
| 4506 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4760 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4761 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4762 | + } |
|
| 4507 | 4763 | |
| 4508 | 4764 | // No full objects, sorry! pass a method or a property instead! |
| 4509 | - if (is_object($string)) |
|
| 4510 | - return false; |
|
| 4765 | + if (is_object($string)) { |
|
| 4766 | + return false; |
|
| 4767 | + } |
|
| 4511 | 4768 | |
| 4512 | 4769 | // Stay vitaminized my friends... |
| 4513 | 4770 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4516,8 +4773,9 @@ discard block |
||
| 4516 | 4773 | $string = load_file($string); |
| 4517 | 4774 | |
| 4518 | 4775 | // Loaded file failed |
| 4519 | - if (empty($string)) |
|
| 4520 | - return false; |
|
| 4776 | + if (empty($string)) { |
|
| 4777 | + return false; |
|
| 4778 | + } |
|
| 4521 | 4779 | |
| 4522 | 4780 | // Found a method. |
| 4523 | 4781 | if (strpos($string, '::') !== false) |
@@ -4538,8 +4796,9 @@ discard block |
||
| 4538 | 4796 | // Add another one to the list. |
| 4539 | 4797 | if ($db_show_debug === true) |
| 4540 | 4798 | { |
| 4541 | - if (!isset($context['debug']['instances'])) |
|
| 4542 | - $context['debug']['instances'] = array(); |
|
| 4799 | + if (!isset($context['debug']['instances'])) { |
|
| 4800 | + $context['debug']['instances'] = array(); |
|
| 4801 | + } |
|
| 4543 | 4802 | |
| 4544 | 4803 | $context['debug']['instances'][$class] = $class; |
| 4545 | 4804 | } |
@@ -4549,13 +4808,15 @@ discard block |
||
| 4549 | 4808 | } |
| 4550 | 4809 | |
| 4551 | 4810 | // Right then. This is a call to a static method. |
| 4552 | - else |
|
| 4553 | - $func = array($class, $method); |
|
| 4811 | + else { |
|
| 4812 | + $func = array($class, $method); |
|
| 4813 | + } |
|
| 4554 | 4814 | } |
| 4555 | 4815 | |
| 4556 | 4816 | // Nope! just a plain regular function. |
| 4557 | - else |
|
| 4558 | - $func = $string; |
|
| 4817 | + else { |
|
| 4818 | + $func = $string; |
|
| 4819 | + } |
|
| 4559 | 4820 | |
| 4560 | 4821 | // Right, we got what we need, time to do some checks. |
| 4561 | 4822 | if (!is_callable($func, false, $callable_name)) |
@@ -4571,17 +4832,18 @@ discard block |
||
| 4571 | 4832 | else |
| 4572 | 4833 | { |
| 4573 | 4834 | // What are we gonna do about it? |
| 4574 | - if ($return) |
|
| 4575 | - return $func; |
|
| 4835 | + if ($return) { |
|
| 4836 | + return $func; |
|
| 4837 | + } |
|
| 4576 | 4838 | |
| 4577 | 4839 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4578 | 4840 | else |
| 4579 | 4841 | { |
| 4580 | - if (is_array($func)) |
|
| 4581 | - call_user_func($func); |
|
| 4582 | - |
|
| 4583 | - else |
|
| 4584 | - $func(); |
|
| 4842 | + if (is_array($func)) { |
|
| 4843 | + call_user_func($func); |
|
| 4844 | + } else { |
|
| 4845 | + $func(); |
|
| 4846 | + } |
|
| 4585 | 4847 | } |
| 4586 | 4848 | } |
| 4587 | 4849 | } |
@@ -4598,31 +4860,34 @@ discard block |
||
| 4598 | 4860 | { |
| 4599 | 4861 | global $sourcedir, $txt, $boarddir, $settings; |
| 4600 | 4862 | |
| 4601 | - if (empty($string)) |
|
| 4602 | - return false; |
|
| 4863 | + if (empty($string)) { |
|
| 4864 | + return false; |
|
| 4865 | + } |
|
| 4603 | 4866 | |
| 4604 | 4867 | if (strpos($string, '|') !== false) |
| 4605 | 4868 | { |
| 4606 | 4869 | list ($file, $string) = explode('|', $string); |
| 4607 | 4870 | |
| 4608 | 4871 | // Match the wildcards to their regular vars. |
| 4609 | - if (empty($settings['theme_dir'])) |
|
| 4610 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4611 | - |
|
| 4612 | - else |
|
| 4613 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4872 | + if (empty($settings['theme_dir'])) { |
|
| 4873 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4874 | + } else { |
|
| 4875 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4876 | + } |
|
| 4614 | 4877 | |
| 4615 | 4878 | // Load the file if it can be loaded. |
| 4616 | - if (file_exists($absPath)) |
|
| 4617 | - require_once($absPath); |
|
| 4879 | + if (file_exists($absPath)) { |
|
| 4880 | + require_once($absPath); |
|
| 4881 | + } |
|
| 4618 | 4882 | |
| 4619 | 4883 | // No? try a fallback to $sourcedir |
| 4620 | 4884 | else |
| 4621 | 4885 | { |
| 4622 | 4886 | $absPath = $sourcedir .'/'. $file; |
| 4623 | 4887 | |
| 4624 | - if (file_exists($absPath)) |
|
| 4625 | - require_once($absPath); |
|
| 4888 | + if (file_exists($absPath)) { |
|
| 4889 | + require_once($absPath); |
|
| 4890 | + } |
|
| 4626 | 4891 | |
| 4627 | 4892 | // Sorry, can't do much for you at this point. |
| 4628 | 4893 | else |
@@ -4649,8 +4914,9 @@ discard block |
||
| 4649 | 4914 | global $user_info, $smcFunc; |
| 4650 | 4915 | |
| 4651 | 4916 | // Make sure we have something to work with. |
| 4652 | - if (empty($topic)) |
|
| 4653 | - return array(); |
|
| 4917 | + if (empty($topic)) { |
|
| 4918 | + return array(); |
|
| 4919 | + } |
|
| 4654 | 4920 | |
| 4655 | 4921 | |
| 4656 | 4922 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4673,8 +4939,9 @@ discard block |
||
| 4673 | 4939 | 'topic' => $topic, |
| 4674 | 4940 | ) |
| 4675 | 4941 | ); |
| 4676 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4677 | - $temp[] = (int) $row['content_id']; |
|
| 4942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4943 | + $temp[] = (int) $row['content_id']; |
|
| 4944 | + } |
|
| 4678 | 4945 | |
| 4679 | 4946 | cache_put_data($cache_key, $temp, $ttl); |
| 4680 | 4947 | } |
@@ -4695,8 +4962,9 @@ discard block |
||
| 4695 | 4962 | { |
| 4696 | 4963 | global $context; |
| 4697 | 4964 | |
| 4698 | - if (empty($string)) |
|
| 4699 | - return $string; |
|
| 4965 | + if (empty($string)) { |
|
| 4966 | + return $string; |
|
| 4967 | + } |
|
| 4700 | 4968 | |
| 4701 | 4969 | // UTF-8 occurences of MS special characters |
| 4702 | 4970 | $findchars_utf8 = array( |
@@ -4737,10 +5005,11 @@ discard block |
||
| 4737 | 5005 | '--', // — |
| 4738 | 5006 | ); |
| 4739 | 5007 | |
| 4740 | - if ($context['utf8']) |
|
| 4741 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4742 | - else |
|
| 4743 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5008 | + if ($context['utf8']) { |
|
| 5009 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 5010 | + } else { |
|
| 5011 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5012 | + } |
|
| 4744 | 5013 | |
| 4745 | 5014 | return $string; |
| 4746 | 5015 | } |
@@ -4759,49 +5028,59 @@ discard block |
||
| 4759 | 5028 | { |
| 4760 | 5029 | global $context; |
| 4761 | 5030 | |
| 4762 | - if (!isset($matches[2])) |
|
| 4763 | - return ''; |
|
| 5031 | + if (!isset($matches[2])) { |
|
| 5032 | + return ''; |
|
| 5033 | + } |
|
| 4764 | 5034 | |
| 4765 | 5035 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4766 | 5036 | |
| 4767 | 5037 | // remove left to right / right to left overrides |
| 4768 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4769 | - return ''; |
|
| 5038 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5039 | + return ''; |
|
| 5040 | + } |
|
| 4770 | 5041 | |
| 4771 | 5042 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4772 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4773 | - return '&#' . $num . ';'; |
|
| 5043 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5044 | + return '&#' . $num . ';'; |
|
| 5045 | + } |
|
| 4774 | 5046 | |
| 4775 | 5047 | if (empty($context['utf8'])) |
| 4776 | 5048 | { |
| 4777 | 5049 | // no control characters |
| 4778 | - if ($num < 0x20) |
|
| 4779 | - return ''; |
|
| 5050 | + if ($num < 0x20) { |
|
| 5051 | + return ''; |
|
| 5052 | + } |
|
| 4780 | 5053 | // text is text |
| 4781 | - elseif ($num < 0x80) |
|
| 4782 | - return chr($num); |
|
| 5054 | + elseif ($num < 0x80) { |
|
| 5055 | + return chr($num); |
|
| 5056 | + } |
|
| 4783 | 5057 | // all others get html-ised |
| 4784 | - else |
|
| 4785 | - return '&#' . $matches[2] . ';'; |
|
| 4786 | - } |
|
| 4787 | - else |
|
| 5058 | + else { |
|
| 5059 | + return '&#' . $matches[2] . ';'; |
|
| 5060 | + } |
|
| 5061 | + } else |
|
| 4788 | 5062 | { |
| 4789 | 5063 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4790 | 5064 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4791 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4792 | - return ''; |
|
| 5065 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5066 | + return ''; |
|
| 5067 | + } |
|
| 4793 | 5068 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4794 | - elseif ($num < 0x80) |
|
| 4795 | - return chr($num); |
|
| 5069 | + elseif ($num < 0x80) { |
|
| 5070 | + return chr($num); |
|
| 5071 | + } |
|
| 4796 | 5072 | // <0x800 (2048) |
| 4797 | - elseif ($num < 0x800) |
|
| 4798 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5073 | + elseif ($num < 0x800) { |
|
| 5074 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5075 | + } |
|
| 4799 | 5076 | // < 0x10000 (65536) |
| 4800 | - elseif ($num < 0x10000) |
|
| 4801 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5077 | + elseif ($num < 0x10000) { |
|
| 5078 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5079 | + } |
|
| 4802 | 5080 | // <= 0x10FFFF (1114111) |
| 4803 | - else |
|
| 4804 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5081 | + else { |
|
| 5082 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5083 | + } |
|
| 4805 | 5084 | } |
| 4806 | 5085 | } |
| 4807 | 5086 | |
@@ -4817,28 +5096,34 @@ discard block |
||
| 4817 | 5096 | */ |
| 4818 | 5097 | function fixchar__callback($matches) |
| 4819 | 5098 | { |
| 4820 | - if (!isset($matches[1])) |
|
| 4821 | - return ''; |
|
| 5099 | + if (!isset($matches[1])) { |
|
| 5100 | + return ''; |
|
| 5101 | + } |
|
| 4822 | 5102 | |
| 4823 | 5103 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4824 | 5104 | |
| 4825 | 5105 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4826 | 5106 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4827 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4828 | - return ''; |
|
| 5107 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5108 | + return ''; |
|
| 5109 | + } |
|
| 4829 | 5110 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4830 | - elseif ($num < 0x80) |
|
| 4831 | - return chr($num); |
|
| 5111 | + elseif ($num < 0x80) { |
|
| 5112 | + return chr($num); |
|
| 5113 | + } |
|
| 4832 | 5114 | // <0x800 (2048) |
| 4833 | - elseif ($num < 0x800) |
|
| 4834 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5115 | + elseif ($num < 0x800) { |
|
| 5116 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5117 | + } |
|
| 4835 | 5118 | // < 0x10000 (65536) |
| 4836 | - elseif ($num < 0x10000) |
|
| 4837 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5119 | + elseif ($num < 0x10000) { |
|
| 5120 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5121 | + } |
|
| 4838 | 5122 | // <= 0x10FFFF (1114111) |
| 4839 | - else |
|
| 4840 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4841 | -} |
|
| 5123 | + else { |
|
| 5124 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5125 | + } |
|
| 5126 | + } |
|
| 4842 | 5127 | |
| 4843 | 5128 | /** |
| 4844 | 5129 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4851,17 +5136,19 @@ discard block |
||
| 4851 | 5136 | */ |
| 4852 | 5137 | function entity_fix__callback($matches) |
| 4853 | 5138 | { |
| 4854 | - if (!isset($matches[2])) |
|
| 4855 | - return ''; |
|
| 5139 | + if (!isset($matches[2])) { |
|
| 5140 | + return ''; |
|
| 5141 | + } |
|
| 4856 | 5142 | |
| 4857 | 5143 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4858 | 5144 | |
| 4859 | 5145 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4860 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4861 | - return ''; |
|
| 4862 | - else |
|
| 4863 | - return '&#' . $num . ';'; |
|
| 4864 | -} |
|
| 5146 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5147 | + return ''; |
|
| 5148 | + } else { |
|
| 5149 | + return '&#' . $num . ';'; |
|
| 5150 | + } |
|
| 5151 | + } |
|
| 4865 | 5152 | |
| 4866 | 5153 | /** |
| 4867 | 5154 | * Return a Gravatar URL based on |
@@ -4885,18 +5172,23 @@ discard block |
||
| 4885 | 5172 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4886 | 5173 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4887 | 5174 | $url_params = array(); |
| 4888 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4889 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4890 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4891 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4892 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4893 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4894 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4895 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5175 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5176 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5177 | + } |
|
| 5178 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5179 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5180 | + } |
|
| 5181 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5182 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5183 | + } |
|
| 5184 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5185 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4896 | 5186 | $size_string = $modSettings['avatar_max_height_external']; |
| 5187 | + } |
|
| 4897 | 5188 | |
| 4898 | - if (!empty($size_string)) |
|
| 4899 | - $url_params[] = 's=' . $size_string; |
|
| 5189 | + if (!empty($size_string)) { |
|
| 5190 | + $url_params[] = 's=' . $size_string; |
|
| 5191 | + } |
|
| 4900 | 5192 | } |
| 4901 | 5193 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4902 | 5194 | |
@@ -4915,22 +5207,26 @@ discard block |
||
| 4915 | 5207 | static $timezones = null, $lastwhen = null; |
| 4916 | 5208 | |
| 4917 | 5209 | // No point doing this over if we already did it once |
| 4918 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 4919 | - return $timezones; |
|
| 4920 | - else |
|
| 4921 | - $lastwhen = $when; |
|
| 5210 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5211 | + return $timezones; |
|
| 5212 | + } else { |
|
| 5213 | + $lastwhen = $when; |
|
| 5214 | + } |
|
| 4922 | 5215 | |
| 4923 | 5216 | // Parseable datetime string? |
| 4924 | - if (is_int($timestamp = strtotime($when))) |
|
| 4925 | - $when = $timestamp; |
|
| 5217 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5218 | + $when = $timestamp; |
|
| 5219 | + } |
|
| 4926 | 5220 | |
| 4927 | 5221 | // A Unix timestamp? |
| 4928 | - elseif (is_numeric($when)) |
|
| 4929 | - $when = intval($when); |
|
| 5222 | + elseif (is_numeric($when)) { |
|
| 5223 | + $when = intval($when); |
|
| 5224 | + } |
|
| 4930 | 5225 | |
| 4931 | 5226 | // Invalid value? Just get current Unix timestamp. |
| 4932 | - else |
|
| 4933 | - $when = time(); |
|
| 5227 | + else { |
|
| 5228 | + $when = time(); |
|
| 5229 | + } |
|
| 4934 | 5230 | |
| 4935 | 5231 | // We'll need this too |
| 4936 | 5232 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4993,8 +5289,9 @@ discard block |
||
| 4993 | 5289 | foreach ($priority_countries as $country) |
| 4994 | 5290 | { |
| 4995 | 5291 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 4996 | - if (!empty($country_tzids)) |
|
| 4997 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5292 | + if (!empty($country_tzids)) { |
|
| 5293 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5294 | + } |
|
| 4998 | 5295 | } |
| 4999 | 5296 | |
| 5000 | 5297 | // Process the preferred timezones first, then the rest. |
@@ -5004,8 +5301,9 @@ discard block |
||
| 5004 | 5301 | foreach ($tzids as $tzid) |
| 5005 | 5302 | { |
| 5006 | 5303 | // We don't want UTC right now |
| 5007 | - if ($tzid == 'UTC') |
|
| 5008 | - continue; |
|
| 5304 | + if ($tzid == 'UTC') { |
|
| 5305 | + continue; |
|
| 5306 | + } |
|
| 5009 | 5307 | |
| 5010 | 5308 | // First, get the set of transition rules for this tzid |
| 5011 | 5309 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -5016,8 +5314,9 @@ discard block |
||
| 5016 | 5314 | $tz_location = timezone_location_get(timezone_open($tzid)); |
| 5017 | 5315 | |
| 5018 | 5316 | // Kazakstan |
| 5019 | - if ($tz_location['country_code'] == 'KZ') |
|
| 5020 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5317 | + if ($tz_location['country_code'] == 'KZ') { |
|
| 5318 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
| 5319 | + } |
|
| 5021 | 5320 | |
| 5022 | 5321 | // Russia likes to experiment with time zones |
| 5023 | 5322 | if ($tz_location['country_code'] == 'RU') |
@@ -5028,19 +5327,22 @@ discard block |
||
| 5028 | 5327 | } |
| 5029 | 5328 | |
| 5030 | 5329 | // Still no good? We'll just mark it as a UTC offset |
| 5031 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
| 5032 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5330 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
| 5331 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
| 5332 | + } |
|
| 5033 | 5333 | } |
| 5034 | 5334 | |
| 5035 | 5335 | $tzkey = serialize($tzinfo); |
| 5036 | 5336 | |
| 5037 | 5337 | // Don't overwrite our preferred tzids |
| 5038 | - if (empty($zones[$tzkey]['tzid'])) |
|
| 5039 | - $zones[$tzkey]['tzid'] = $tzid; |
|
| 5338 | + if (empty($zones[$tzkey]['tzid'])) { |
|
| 5339 | + $zones[$tzkey]['tzid'] = $tzid; |
|
| 5340 | + } |
|
| 5040 | 5341 | |
| 5041 | 5342 | // A time zone from a prioritized country? |
| 5042 | - if (in_array($tzid, $priority_tzids)) |
|
| 5043 | - $priority_zones[$tzkey] = true; |
|
| 5343 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5344 | + $priority_zones[$tzkey] = true; |
|
| 5345 | + } |
|
| 5044 | 5346 | |
| 5045 | 5347 | // Keep track of the location and offset for this tzid |
| 5046 | 5348 | $tzid_parts = explode('/', $tzid); |
@@ -5058,15 +5360,17 @@ discard block |
||
| 5058 | 5360 | { |
| 5059 | 5361 | $tzinfo = unserialize($tzkey); |
| 5060 | 5362 | |
| 5061 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5062 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5063 | - else |
|
| 5064 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5363 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5364 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5365 | + } else { |
|
| 5366 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5367 | + } |
|
| 5065 | 5368 | |
| 5066 | - if (isset($priority_zones[$tzkey])) |
|
| 5067 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5068 | - else |
|
| 5069 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5369 | + if (isset($priority_zones[$tzkey])) { |
|
| 5370 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5371 | + } else { |
|
| 5372 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
| 5373 | + } |
|
| 5070 | 5374 | } |
| 5071 | 5375 | |
| 5072 | 5376 | $timezones = array_merge( |
@@ -5084,8 +5388,9 @@ discard block |
||
| 5084 | 5388 | */ |
| 5085 | 5389 | function inet_ptod($ip_address) |
| 5086 | 5390 | { |
| 5087 | - if (!isValidIP($ip_address)) |
|
| 5088 | - return $ip_address; |
|
| 5391 | + if (!isValidIP($ip_address)) { |
|
| 5392 | + return $ip_address; |
|
| 5393 | + } |
|
| 5089 | 5394 | |
| 5090 | 5395 | $bin = inet_pton($ip_address); |
| 5091 | 5396 | return $bin; |
@@ -5097,13 +5402,15 @@ discard block |
||
| 5097 | 5402 | */ |
| 5098 | 5403 | function inet_dtop($bin) |
| 5099 | 5404 | { |
| 5100 | - if(empty($bin)) |
|
| 5101 | - return ''; |
|
| 5405 | + if(empty($bin)) { |
|
| 5406 | + return ''; |
|
| 5407 | + } |
|
| 5102 | 5408 | |
| 5103 | 5409 | global $db_type; |
| 5104 | 5410 | |
| 5105 | - if ($db_type == 'postgresql') |
|
| 5106 | - return $bin; |
|
| 5411 | + if ($db_type == 'postgresql') { |
|
| 5412 | + return $bin; |
|
| 5413 | + } |
|
| 5107 | 5414 | |
| 5108 | 5415 | $ip_address = inet_ntop($bin); |
| 5109 | 5416 | |
@@ -5128,26 +5435,32 @@ discard block |
||
| 5128 | 5435 | */ |
| 5129 | 5436 | function _safe_serialize($value) |
| 5130 | 5437 | { |
| 5131 | - if(is_null($value)) |
|
| 5132 | - return 'N;'; |
|
| 5438 | + if(is_null($value)) { |
|
| 5439 | + return 'N;'; |
|
| 5440 | + } |
|
| 5133 | 5441 | |
| 5134 | - if(is_bool($value)) |
|
| 5135 | - return 'b:'. (int) $value .';'; |
|
| 5442 | + if(is_bool($value)) { |
|
| 5443 | + return 'b:'. (int) $value .';'; |
|
| 5444 | + } |
|
| 5136 | 5445 | |
| 5137 | - if(is_int($value)) |
|
| 5138 | - return 'i:'. $value .';'; |
|
| 5446 | + if(is_int($value)) { |
|
| 5447 | + return 'i:'. $value .';'; |
|
| 5448 | + } |
|
| 5139 | 5449 | |
| 5140 | - if(is_float($value)) |
|
| 5141 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5450 | + if(is_float($value)) { |
|
| 5451 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5452 | + } |
|
| 5142 | 5453 | |
| 5143 | - if(is_string($value)) |
|
| 5144 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5454 | + if(is_string($value)) { |
|
| 5455 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5456 | + } |
|
| 5145 | 5457 | |
| 5146 | 5458 | if(is_array($value)) |
| 5147 | 5459 | { |
| 5148 | 5460 | $out = ''; |
| 5149 | - foreach($value as $k => $v) |
|
| 5150 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5461 | + foreach($value as $k => $v) { |
|
| 5462 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5463 | + } |
|
| 5151 | 5464 | |
| 5152 | 5465 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5153 | 5466 | } |
@@ -5173,8 +5486,9 @@ discard block |
||
| 5173 | 5486 | |
| 5174 | 5487 | $out = _safe_serialize($value); |
| 5175 | 5488 | |
| 5176 | - if (isset($mbIntEnc)) |
|
| 5177 | - mb_internal_encoding($mbIntEnc); |
|
| 5489 | + if (isset($mbIntEnc)) { |
|
| 5490 | + mb_internal_encoding($mbIntEnc); |
|
| 5491 | + } |
|
| 5178 | 5492 | |
| 5179 | 5493 | return $out; |
| 5180 | 5494 | } |
@@ -5191,8 +5505,9 @@ discard block |
||
| 5191 | 5505 | function _safe_unserialize($str) |
| 5192 | 5506 | { |
| 5193 | 5507 | // Input is not a string. |
| 5194 | - if(empty($str) || !is_string($str)) |
|
| 5195 | - return false; |
|
| 5508 | + if(empty($str) || !is_string($str)) { |
|
| 5509 | + return false; |
|
| 5510 | + } |
|
| 5196 | 5511 | |
| 5197 | 5512 | $stack = array(); |
| 5198 | 5513 | $expected = array(); |
@@ -5208,43 +5523,38 @@ discard block |
||
| 5208 | 5523 | while($state != 1) |
| 5209 | 5524 | { |
| 5210 | 5525 | $type = isset($str[0]) ? $str[0] : ''; |
| 5211 | - if($type == '}') |
|
| 5212 | - $str = substr($str, 1); |
|
| 5213 | - |
|
| 5214 | - else if($type == 'N' && $str[1] == ';') |
|
| 5526 | + if($type == '}') { |
|
| 5527 | + $str = substr($str, 1); |
|
| 5528 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5215 | 5529 | { |
| 5216 | 5530 | $value = null; |
| 5217 | 5531 | $str = substr($str, 2); |
| 5218 | - } |
|
| 5219 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5532 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5220 | 5533 | { |
| 5221 | 5534 | $value = $matches[1] == '1' ? true : false; |
| 5222 | 5535 | $str = substr($str, 4); |
| 5223 | - } |
|
| 5224 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5536 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5225 | 5537 | { |
| 5226 | 5538 | $value = (int)$matches[1]; |
| 5227 | 5539 | $str = $matches[2]; |
| 5228 | - } |
|
| 5229 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5540 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5230 | 5541 | { |
| 5231 | 5542 | $value = (float)$matches[1]; |
| 5232 | 5543 | $str = $matches[3]; |
| 5233 | - } |
|
| 5234 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5544 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5235 | 5545 | { |
| 5236 | 5546 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5237 | 5547 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5238 | - } |
|
| 5239 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5548 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5240 | 5549 | { |
| 5241 | 5550 | $expectedLength = (int)$matches[1]; |
| 5242 | 5551 | $str = $matches[2]; |
| 5243 | 5552 | } |
| 5244 | 5553 | |
| 5245 | 5554 | // Object or unknown/malformed type. |
| 5246 | - else |
|
| 5247 | - return false; |
|
| 5555 | + else { |
|
| 5556 | + return false; |
|
| 5557 | + } |
|
| 5248 | 5558 | |
| 5249 | 5559 | switch($state) |
| 5250 | 5560 | { |
@@ -5272,8 +5582,9 @@ discard block |
||
| 5272 | 5582 | if($type == '}') |
| 5273 | 5583 | { |
| 5274 | 5584 | // Array size is less than expected. |
| 5275 | - if(count($list) < end($expected)) |
|
| 5276 | - return false; |
|
| 5585 | + if(count($list) < end($expected)) { |
|
| 5586 | + return false; |
|
| 5587 | + } |
|
| 5277 | 5588 | |
| 5278 | 5589 | unset($list); |
| 5279 | 5590 | $list = &$stack[count($stack)-1]; |
@@ -5282,8 +5593,9 @@ discard block |
||
| 5282 | 5593 | // Go to terminal state if we're at the end of the root array. |
| 5283 | 5594 | array_pop($expected); |
| 5284 | 5595 | |
| 5285 | - if(count($expected) == 0) |
|
| 5286 | - $state = 1; |
|
| 5596 | + if(count($expected) == 0) { |
|
| 5597 | + $state = 1; |
|
| 5598 | + } |
|
| 5287 | 5599 | |
| 5288 | 5600 | break; |
| 5289 | 5601 | } |
@@ -5291,8 +5603,9 @@ discard block |
||
| 5291 | 5603 | if($type == 'i' || $type == 's') |
| 5292 | 5604 | { |
| 5293 | 5605 | // Array size exceeds expected length. |
| 5294 | - if(count($list) >= end($expected)) |
|
| 5295 | - return false; |
|
| 5606 | + if(count($list) >= end($expected)) { |
|
| 5607 | + return false; |
|
| 5608 | + } |
|
| 5296 | 5609 | |
| 5297 | 5610 | $key = $value; |
| 5298 | 5611 | $state = 3; |
@@ -5326,8 +5639,9 @@ discard block |
||
| 5326 | 5639 | } |
| 5327 | 5640 | |
| 5328 | 5641 | // Trailing data in input. |
| 5329 | - if(!empty($str)) |
|
| 5330 | - return false; |
|
| 5642 | + if(!empty($str)) { |
|
| 5643 | + return false; |
|
| 5644 | + } |
|
| 5331 | 5645 | |
| 5332 | 5646 | return $data; |
| 5333 | 5647 | } |
@@ -5350,8 +5664,9 @@ discard block |
||
| 5350 | 5664 | |
| 5351 | 5665 | $out = _safe_unserialize($str); |
| 5352 | 5666 | |
| 5353 | - if (isset($mbIntEnc)) |
|
| 5354 | - mb_internal_encoding($mbIntEnc); |
|
| 5667 | + if (isset($mbIntEnc)) { |
|
| 5668 | + mb_internal_encoding($mbIntEnc); |
|
| 5669 | + } |
|
| 5355 | 5670 | |
| 5356 | 5671 | return $out; |
| 5357 | 5672 | } |
@@ -5366,12 +5681,14 @@ discard block |
||
| 5366 | 5681 | function smf_chmod($file, $value = 0) |
| 5367 | 5682 | { |
| 5368 | 5683 | // No file? no checks! |
| 5369 | - if (empty($file)) |
|
| 5370 | - return false; |
|
| 5684 | + if (empty($file)) { |
|
| 5685 | + return false; |
|
| 5686 | + } |
|
| 5371 | 5687 | |
| 5372 | 5688 | // Already writable? |
| 5373 | - if (is_writable($file)) |
|
| 5374 | - return true; |
|
| 5689 | + if (is_writable($file)) { |
|
| 5690 | + return true; |
|
| 5691 | + } |
|
| 5375 | 5692 | |
| 5376 | 5693 | // Do we have a file or a dir? |
| 5377 | 5694 | $isDir = is_dir($file); |
@@ -5387,10 +5704,9 @@ discard block |
||
| 5387 | 5704 | { |
| 5388 | 5705 | $isWritable = true; |
| 5389 | 5706 | break; |
| 5707 | + } else { |
|
| 5708 | + @chmod($file, $val); |
|
| 5390 | 5709 | } |
| 5391 | - |
|
| 5392 | - else |
|
| 5393 | - @chmod($file, $val); |
|
| 5394 | 5710 | } |
| 5395 | 5711 | |
| 5396 | 5712 | return $isWritable; |
@@ -5409,8 +5725,9 @@ discard block |
||
| 5409 | 5725 | global $txt; |
| 5410 | 5726 | |
| 5411 | 5727 | // Come on... |
| 5412 | - if (empty($json) || !is_string($json)) |
|
| 5413 | - return array(); |
|
| 5728 | + if (empty($json) || !is_string($json)) { |
|
| 5729 | + return array(); |
|
| 5730 | + } |
|
| 5414 | 5731 | |
| 5415 | 5732 | $returnArray = @json_decode($json, $returnAsArray); |
| 5416 | 5733 | |
@@ -5448,11 +5765,11 @@ discard block |
||
| 5448 | 5765 | $jsonDebug = $jsonDebug[0]; |
| 5449 | 5766 | loadLanguage('Errors'); |
| 5450 | 5767 | |
| 5451 | - if (!empty($jsonDebug)) |
|
| 5452 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5453 | - |
|
| 5454 | - else |
|
| 5455 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5768 | + if (!empty($jsonDebug)) { |
|
| 5769 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5770 | + } else { |
|
| 5771 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5772 | + } |
|
| 5456 | 5773 | |
| 5457 | 5774 | // Everyone expects an array. |
| 5458 | 5775 | return array(); |
@@ -5482,8 +5799,9 @@ discard block |
||
| 5482 | 5799 | global $db_show_debug, $modSettings; |
| 5483 | 5800 | |
| 5484 | 5801 | // Defensive programming anyone? |
| 5485 | - if (empty($data)) |
|
| 5486 | - return false; |
|
| 5802 | + if (empty($data)) { |
|
| 5803 | + return false; |
|
| 5804 | + } |
|
| 5487 | 5805 | |
| 5488 | 5806 | // Don't need extra stuff... |
| 5489 | 5807 | $db_show_debug = false; |
@@ -5491,11 +5809,11 @@ discard block |
||
| 5491 | 5809 | // Kill anything else. |
| 5492 | 5810 | ob_end_clean(); |
| 5493 | 5811 | |
| 5494 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5495 | - @ob_start('ob_gzhandler'); |
|
| 5496 | - |
|
| 5497 | - else |
|
| 5498 | - ob_start(); |
|
| 5812 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5813 | + @ob_start('ob_gzhandler'); |
|
| 5814 | + } else { |
|
| 5815 | + ob_start(); |
|
| 5816 | + } |
|
| 5499 | 5817 | |
| 5500 | 5818 | // Set the header. |
| 5501 | 5819 | header($type); |
@@ -5527,8 +5845,9 @@ discard block |
||
| 5527 | 5845 | static $done = false; |
| 5528 | 5846 | |
| 5529 | 5847 | // If we don't need to do anything, don't |
| 5530 | - if (!$update && $done) |
|
| 5531 | - return; |
|
| 5848 | + if (!$update && $done) { |
|
| 5849 | + return; |
|
| 5850 | + } |
|
| 5532 | 5851 | |
| 5533 | 5852 | // Should we get a new copy of the official list of TLDs? |
| 5534 | 5853 | if ($update) |
@@ -5549,10 +5868,11 @@ discard block |
||
| 5549 | 5868 | // Clean $tlds and convert it to an array |
| 5550 | 5869 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5551 | 5870 | $line = trim($line); |
| 5552 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5553 | - return false; |
|
| 5554 | - else |
|
| 5555 | - return true; |
|
| 5871 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5872 | + return false; |
|
| 5873 | + } else { |
|
| 5874 | + return true; |
|
| 5875 | + } |
|
| 5556 | 5876 | }); |
| 5557 | 5877 | |
| 5558 | 5878 | // Convert Punycode to Unicode |
@@ -5606,8 +5926,9 @@ discard block |
||
| 5606 | 5926 | $idx += $digit * $w; |
| 5607 | 5927 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5608 | 5928 | |
| 5609 | - if ($digit < $t) |
|
| 5610 | - break; |
|
| 5929 | + if ($digit < $t) { |
|
| 5930 | + break; |
|
| 5931 | + } |
|
| 5611 | 5932 | |
| 5612 | 5933 | $w = (int) ($w * ($base - $t)); |
| 5613 | 5934 | } |
@@ -5616,8 +5937,9 @@ discard block |
||
| 5616 | 5937 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5617 | 5938 | $delta += intval($delta / ($deco_len + 1)); |
| 5618 | 5939 | |
| 5619 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5620 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5940 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5941 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5942 | + } |
|
| 5621 | 5943 | |
| 5622 | 5944 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5623 | 5945 | $is_first = false; |
@@ -5626,8 +5948,9 @@ discard block |
||
| 5626 | 5948 | |
| 5627 | 5949 | if ($deco_len > 0) |
| 5628 | 5950 | { |
| 5629 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5630 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 5951 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 5952 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 5953 | + } |
|
| 5631 | 5954 | } |
| 5632 | 5955 | $decoded[$idx++] = $char; |
| 5633 | 5956 | } |
@@ -5635,24 +5958,29 @@ discard block |
||
| 5635 | 5958 | foreach ($decoded as $k => $v) |
| 5636 | 5959 | { |
| 5637 | 5960 | // 7bit are transferred literally |
| 5638 | - if ($v < 128) |
|
| 5639 | - $output .= chr($v); |
|
| 5961 | + if ($v < 128) { |
|
| 5962 | + $output .= chr($v); |
|
| 5963 | + } |
|
| 5640 | 5964 | |
| 5641 | 5965 | // 2 bytes |
| 5642 | - elseif ($v < (1 << 11)) |
|
| 5643 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5966 | + elseif ($v < (1 << 11)) { |
|
| 5967 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5968 | + } |
|
| 5644 | 5969 | |
| 5645 | 5970 | // 3 bytes |
| 5646 | - elseif ($v < (1 << 16)) |
|
| 5647 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5971 | + elseif ($v < (1 << 16)) { |
|
| 5972 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5973 | + } |
|
| 5648 | 5974 | |
| 5649 | 5975 | // 4 bytes |
| 5650 | - elseif ($v < (1 << 21)) |
|
| 5651 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5976 | + elseif ($v < (1 << 21)) { |
|
| 5977 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5978 | + } |
|
| 5652 | 5979 | |
| 5653 | 5980 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5654 | - else |
|
| 5655 | - $output .= $safe_char; |
|
| 5981 | + else { |
|
| 5982 | + $output .= $safe_char; |
|
| 5983 | + } |
|
| 5656 | 5984 | } |
| 5657 | 5985 | |
| 5658 | 5986 | $output_parts[] = $output; |
@@ -5747,8 +6075,7 @@ discard block |
||
| 5747 | 6075 | |
| 5748 | 6076 | $strlen = 'mb_strlen'; |
| 5749 | 6077 | $substr = 'mb_substr'; |
| 5750 | - } |
|
| 5751 | - else |
|
| 6078 | + } else |
|
| 5752 | 6079 | { |
| 5753 | 6080 | $strlen = $smcFunc['strlen']; |
| 5754 | 6081 | $substr = $smcFunc['substr']; |
@@ -5762,20 +6089,21 @@ discard block |
||
| 5762 | 6089 | |
| 5763 | 6090 | $first = $substr($string, 0, 1); |
| 5764 | 6091 | |
| 5765 | - if (empty($index[$first])) |
|
| 5766 | - $index[$first] = array(); |
|
| 6092 | + if (empty($index[$first])) { |
|
| 6093 | + $index[$first] = array(); |
|
| 6094 | + } |
|
| 5767 | 6095 | |
| 5768 | 6096 | if ($strlen($string) > 1) |
| 5769 | 6097 | { |
| 5770 | 6098 | // Sanity check on recursion |
| 5771 | - if ($depth > 99) |
|
| 5772 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5773 | - |
|
| 5774 | - else |
|
| 5775 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6099 | + if ($depth > 99) { |
|
| 6100 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6101 | + } else { |
|
| 6102 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6103 | + } |
|
| 6104 | + } else { |
|
| 6105 | + $index[$first][''] = ''; |
|
| 5776 | 6106 | } |
| 5777 | - else |
|
| 5778 | - $index[$first][''] = ''; |
|
| 5779 | 6107 | |
| 5780 | 6108 | $depth--; |
| 5781 | 6109 | return $index; |
@@ -5798,9 +6126,9 @@ discard block |
||
| 5798 | 6126 | $key_regex = preg_quote($key, $delim); |
| 5799 | 6127 | $new_key = $key; |
| 5800 | 6128 | |
| 5801 | - if (empty($value)) |
|
| 5802 | - $sub_regex = ''; |
|
| 5803 | - else |
|
| 6129 | + if (empty($value)) { |
|
| 6130 | + $sub_regex = ''; |
|
| 6131 | + } else |
|
| 5804 | 6132 | { |
| 5805 | 6133 | $sub_regex = $index_to_regex($value, $delim); |
| 5806 | 6134 | |
@@ -5808,22 +6136,22 @@ discard block |
||
| 5808 | 6136 | { |
| 5809 | 6137 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5810 | 6138 | $new_key .= $new_key_array[0]; |
| 6139 | + } else { |
|
| 6140 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5811 | 6141 | } |
| 5812 | - else |
|
| 5813 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5814 | 6142 | } |
| 5815 | 6143 | |
| 5816 | - if ($depth > 1) |
|
| 5817 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5818 | - else |
|
| 6144 | + if ($depth > 1) { |
|
| 6145 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6146 | + } else |
|
| 5819 | 6147 | { |
| 5820 | 6148 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5821 | 6149 | { |
| 5822 | 6150 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5823 | 6151 | unset($index[$key]); |
| 6152 | + } else { |
|
| 6153 | + break; |
|
| 5824 | 6154 | } |
| 5825 | - else |
|
| 5826 | - break; |
|
| 5827 | 6155 | } |
| 5828 | 6156 | } |
| 5829 | 6157 | |
@@ -5832,10 +6160,11 @@ discard block |
||
| 5832 | 6160 | $l1 = $strlen($k1); |
| 5833 | 6161 | $l2 = $strlen($k2); |
| 5834 | 6162 | |
| 5835 | - if ($l1 == $l2) |
|
| 5836 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5837 | - else |
|
| 5838 | - return $l1 > $l2 ? -1 : 1; |
|
| 6163 | + if ($l1 == $l2) { |
|
| 6164 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6165 | + } else { |
|
| 6166 | + return $l1 > $l2 ? -1 : 1; |
|
| 6167 | + } |
|
| 5839 | 6168 | }); |
| 5840 | 6169 | |
| 5841 | 6170 | $depth--; |
@@ -5846,15 +6175,18 @@ discard block |
||
| 5846 | 6175 | $index = array(); |
| 5847 | 6176 | $regexes = array(); |
| 5848 | 6177 | |
| 5849 | - foreach ($strings as $string) |
|
| 5850 | - $index = $add_string_to_index($string, $index); |
|
| 6178 | + foreach ($strings as $string) { |
|
| 6179 | + $index = $add_string_to_index($string, $index); |
|
| 6180 | + } |
|
| 5851 | 6181 | |
| 5852 | - while (!empty($index)) |
|
| 5853 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6182 | + while (!empty($index)) { |
|
| 6183 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6184 | + } |
|
| 5854 | 6185 | |
| 5855 | 6186 | // Restore PHP's internal character encoding to whatever it was originally |
| 5856 | - if (!empty($current_encoding)) |
|
| 5857 | - mb_internal_encoding($current_encoding); |
|
| 6187 | + if (!empty($current_encoding)) { |
|
| 6188 | + mb_internal_encoding($current_encoding); |
|
| 6189 | + } |
|
| 5858 | 6190 | |
| 5859 | 6191 | return $regexes; |
| 5860 | 6192 | } |